test(host-service): fix the clock in the PR history ordering test
Summary
- Fixes a flaky test:
PullRequestRuntimeManager workspace PR history > history accumulates across branch moves; unlink hides the pointer, never the history.
Why / Context
The test links PR 101, moves the workspace to a new branch, links PR 102, then unlinks. After the unlink no PR is current, so history is sorted by linkedAt alone, and the test expects [102, 101]. Both links take linkedAt from Date.now(). On a slow run (seen in a full bun test of host-service) both refreshes finish in the same millisecond, the sort ties, and the test gets [101, 102].
The test now sets the system time with setSystemTime, so the two links are one second apart, and resets it in finally. The only code change is the clock; the assertions are the same. Most of the diff is the test body indented one level for the try.
Testing
bun test src/runtime/pull-requests/pull-requests.test.ts: 52 pass, 3 runs in a row- Checked the cause: giving both links the same time makes the test fail with the same
[101, 102]diff as the flaky run. With the clock fix it passes. bun run typecheck(host-service),biome check: pass
Summary by cubic
Fixes the flaky PullRequestRuntimeManager history test by controlling the test clock so the two PR links receive distinct linkedAt timestamps.
- Both links previously read
Date.now()directly, so a slow run could put them in the same millisecond and make the sort order undefined. - The test now uses
setSystemTimeto space the links one second apart and restores the clock infinally; only the test file changes.
Summary by CodeRabbit
- Tests
- Expanded coverage for workspace pull request history across branch changes and unlinking. Tests verify that linked pull requests remain in newest-first order, only the active link is marked current, and unlinking clears the current pull request without removing history.