mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 08:02:51 +00:00
* refactor(tests): split oversized test files off the max-lines suppression list Every `*.test.ts`/`*.spec.ts` that carried an `eslint/oxlint-disable max-lines` directive is now split into focused, behavior-scoped suites that fit the 800-line test budget, with shared setup extracted into co-located `*-test-harness.ts` / `*-test-fixtures.ts` modules (300-line budget). 83 files became ~930; the largest output is 797 effective lines. `orca-runtime.test.ts` is intentionally untouched. Test bodies were moved by scripted line-range slicing rather than retyped, so assertions are byte-identical. The only permitted body edits were mechanical rebinding where a shared value moved into a harness (e.g. `tmpHome` -> `homes.tmpHome`). Registries that enumerate test files were updated in lockstep: - config/max-lines-baseline.txt: pruned 341 -> 258 entries (all 83 removed). - config/reliability-gates.jsonc: 33 gates repointed at the split files, with assertionRefs split per file where a gate's coverage now spans several. - .github/workflows/pr.yml: the real-zsh lane now lists the 4 split files that actually exercise zsh, so they keep running in the dedicated shell lane. Also renamed agent-hooks `server-test-fixtures.ts` to `server.test-fixtures.ts` so the global-fetch call-site audit keeps skipping it, and added `.js` extensions to the CLI suites' dynamic harness imports (node16 resolution) to unbreak `build:cli`. Verification: full suite 52,449 passing vs 52,448 at baseline with zero assertions lost; `pnpm lint`, `pnpm typecheck`, and `pnpm build:cli` all exit 0; the terminal-pane e2e spec runs 31/31 headless. * refactor(tests): split hook-idle arbitration suite that oxfmt pushed over budget The pre-commit oxfmt pass reflowed pty-connection-hook-idle-arbitration.test.ts to 811 effective lines, 11 over the test budget. Split the hook-completion side effect and replacement-agent veto cases into their own suite; both files now sit well under the cap and the 15 tests are unchanged. * test: port upstream test changes into the split files after rebase Rebasing onto main surfaced 27 tests that main had added to files this branch deleted, plus edits to tests that had already moved. Taking the deletion side of those modify/delete conflicts would have dropped that coverage silently, so each upstream change is ported into the split file that now owns the behavior — for example main's six orchestration mailbox tests land across orchestration-runs, -send, and -check. Also repoints `orchestration.notification-mailbox-consistency`, a gate main added after this branch's gate remap, at those same three split files, and re-prunes the max-lines baseline against main's (257 entries). Verified: all 27 upstream test titles present; full suite 52,761 passing with the only diff vs baseline being 12 tests main itself removed and 3 that moved from skipped to passing; lint and typecheck exit 0. * fix(test): flush pending continuations before tearing down terminal test globals CI shard 5/16 failed on both Node 24 and 26 with `ReferenceError: window is not defined` from pty-connection.ts, surfacing through pty-connection-daemon-snapshot-replay.test.ts. The reattach/settle chains `await` a real promise and then touch `window.api`. Under fake timers those continuations cannot run, so they only become schedulable once restoreTerminalTestGlobals() switches back to real timers — which previously happened immediately before `delete globalThis.window`, so a late continuation threw and failed the whole file. Flush async ticks in that window instead. This is latent in the source rather than new: the pre-split 25k-line file kept running other tests after these, which gave the chains time to settle before teardown. Splitting the file moved teardown directly behind them. * fix(test): keep an inert window after terminal test teardown instead of deleting it The async-tick flush was not enough: the reattach/settle chain can resolve after teardown regardless of how long we drain, so CI shard 5/16 still failed with `ReferenceError: window is not defined` from pty-connection.ts. A real renderer never loses `window`, so deleting it was the artificial part. Swap in an inert proxy whose properties resolve to callables and whose calls resolve to undefined, making a late `window.api.pty.*` call a harmless no-op. The next test replaces it wholesale via installTerminalTestGlobals(), and no test asserts that `window` is absent.
401 lines
13 KiB
TypeScript
401 lines
13 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import type { GitHubPRRefreshCandidate } from '../../shared/github/pull-request-refresh-types'
|
|
|
|
const { coordinatorMocks, moduleMocks } = await vi.hoisted(async () => {
|
|
const moduleMocks = await import('./pr-refresh-coordinator-test-mocks')
|
|
return { coordinatorMocks: moduleMocks.createPRRefreshCoordinatorMocks(), moduleMocks }
|
|
})
|
|
|
|
vi.mock('electron', () => moduleMocks.electronModuleMock(coordinatorMocks))
|
|
vi.mock('./client', () => moduleMocks.clientModuleMock(coordinatorMocks))
|
|
vi.mock('./github-api-repository', () =>
|
|
moduleMocks.githubApiRepositoryModuleMock(coordinatorMocks)
|
|
)
|
|
vi.mock('./rate-limit', () => moduleMocks.rateLimitModuleMock(coordinatorMocks))
|
|
vi.mock('../ipc/ui', () => moduleMocks.ipcUiModuleMock(coordinatorMocks))
|
|
|
|
import { makeCandidate, makePR } from './pr-refresh-coordinator-test-harness'
|
|
|
|
const { sendMock, getPRForBranchOutcomeMock } = coordinatorMocks
|
|
|
|
describe('pr-refresh-coordinator', () => {
|
|
beforeEach(() => {
|
|
moduleMocks.resetPRRefreshCoordinatorMocks(coordinatorMocks)
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('cancels queued work when a later enqueue marks the candidate invalid', async () => {
|
|
const { enqueuePRRefresh, reportVisiblePRRefreshCandidates } =
|
|
await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'success' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
const candidate = makeCandidate()
|
|
reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
|
await vi.advanceTimersByTimeAsync(0)
|
|
|
|
enqueuePRRefresh(
|
|
{ ...candidate, isArchived: true, cachedFetchedAt: Date.now() },
|
|
'active',
|
|
80,
|
|
1
|
|
)
|
|
await vi.advanceTimersByTimeAsync(10 * 60_000)
|
|
|
|
const skippedEvents = sendMock.mock.calls
|
|
.map(([, event]) => event)
|
|
.filter((event) => event.status === 'skipped')
|
|
|
|
expect(skippedEvents.at(-1)?.skippedReason).toBe('archived')
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('does not cancel other aliases when one coalesced PR alias becomes invalid', async () => {
|
|
const { enqueuePRRefresh, reportVisiblePRRefreshCandidates } =
|
|
await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'success' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'success', state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
const first = makeCandidate({
|
|
cacheKey: '/repo::feature/a',
|
|
branch: 'feature/a',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-a'
|
|
})
|
|
const second = makeCandidate({
|
|
cacheKey: '/repo::feature/b',
|
|
branch: 'feature/b',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-b'
|
|
})
|
|
reportVisiblePRRefreshCandidates([first, second], 1, 1)
|
|
await vi.advanceTimersByTimeAsync(0)
|
|
|
|
enqueuePRRefresh({ ...first, isArchived: true, cachedFetchedAt: Date.now() }, 'active', 80, 1)
|
|
enqueuePRRefresh({ ...second, cachedFetchedAt: Date.now() }, 'active', 80, 1)
|
|
await vi.advanceTimersByTimeAsync(0)
|
|
|
|
const outcomeEvents = sendMock.mock.calls
|
|
.map(([, event]) => event)
|
|
.filter((event) => event.outcome)
|
|
|
|
expect(outcomeEvents.at(-1)?.aliases.map((alias) => alias.cacheKey)).toEqual([
|
|
'/repo::feature/b'
|
|
])
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
it('probes with the survivor head after the representative alias is invalidated', async () => {
|
|
const { enqueuePRRefresh } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValue({
|
|
kind: 'found',
|
|
pr: makePR({ state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
const survivor = makeCandidate({
|
|
cacheKey: '/repo::feature/b',
|
|
branch: 'feature/b',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-b',
|
|
currentHeadOid: 'head-b'
|
|
})
|
|
const representative = makeCandidate({
|
|
cacheKey: '/repo::feature/a',
|
|
branch: 'feature/a',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-a',
|
|
currentHeadOid: 'head-a'
|
|
})
|
|
|
|
// Enqueue the survivor first, then the representative (active coalescing
|
|
// promotes the latter to representative), then invalidate the representative
|
|
// so the still-queued entry rebinds to the survivor before draining.
|
|
enqueuePRRefresh(survivor, 'active', 80, 1)
|
|
enqueuePRRefresh(representative, 'active', 80, 1)
|
|
enqueuePRRefresh({ ...representative, isArchived: true }, 'active', 80, 1)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
const probedHeads = getPRForBranchOutcomeMock.mock.calls.map((call) => call[5]?.currentHeadOid)
|
|
expect(probedHeads).toContain('head-b')
|
|
expect(probedHeads).not.toContain('head-a')
|
|
})
|
|
|
|
it('probes with the survivor head after the representative worktree is pruned', async () => {
|
|
const { enqueuePRRefresh, pruneWorktreePRRefreshAliases } =
|
|
await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValue({
|
|
kind: 'found',
|
|
pr: makePR({ state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
const survivor = makeCandidate({
|
|
cacheKey: '/repo::feature/b',
|
|
branch: 'feature/b',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-b',
|
|
currentHeadOid: 'head-b'
|
|
})
|
|
const representative = makeCandidate({
|
|
cacheKey: '/repo::feature/a',
|
|
branch: 'feature/a',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-a',
|
|
currentHeadOid: 'head-a'
|
|
})
|
|
|
|
enqueuePRRefresh(survivor, 'active', 80, 1)
|
|
enqueuePRRefresh(representative, 'active', 80, 1)
|
|
pruneWorktreePRRefreshAliases('wt-a')
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
const probedHeads = getPRForBranchOutcomeMock.mock.calls.map((call) => call[5]?.currentHeadOid)
|
|
expect(probedHeads).toContain('head-b')
|
|
expect(probedHeads).not.toContain('head-a')
|
|
})
|
|
|
|
it('refreshes the representative head when the same worktree re-reports a moved head', async () => {
|
|
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValue({
|
|
kind: 'found',
|
|
pr: makePR({ state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
// Same worktree/branch, moved head, coalescing visible→visible (no promote):
|
|
// the representative head must track the newest report before the drain.
|
|
reportVisiblePRRefreshCandidates(
|
|
[makeCandidate({ linkedPRNumber: 12, worktreeId: 'wt-a', currentHeadOid: 'head-a' })],
|
|
1,
|
|
1
|
|
)
|
|
reportVisiblePRRefreshCandidates(
|
|
[makeCandidate({ linkedPRNumber: 12, worktreeId: 'wt-a', currentHeadOid: 'head-b' })],
|
|
2,
|
|
1
|
|
)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
const probedHeads = getPRForBranchOutcomeMock.mock.calls.map((call) => call[5]?.currentHeadOid)
|
|
expect(probedHeads).toContain('head-b')
|
|
expect(probedHeads).not.toContain('head-a')
|
|
})
|
|
|
|
it('does not coalesce local and SSH refreshes for the same branch', async () => {
|
|
const { enqueuePRRefresh } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ number: 12 }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ number: 44 }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
enqueuePRRefresh(makeCandidate({ cacheKey: 'local::repo-1::feature/test' }), 'active', 80, 1)
|
|
enqueuePRRefresh(
|
|
makeCandidate({
|
|
cacheKey: 'ssh:ssh-1::repo-1::feature/test',
|
|
connectionId: 'ssh-1'
|
|
}),
|
|
'active',
|
|
80,
|
|
1
|
|
)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(2)
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
null
|
|
)
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
'ssh-1',
|
|
null
|
|
)
|
|
})
|
|
|
|
it('does not coalesce host and WSL refreshes for the same local branch', async () => {
|
|
const { enqueuePRRefresh } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ number: 12 }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ number: 44 }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
enqueuePRRefresh(makeCandidate({ cacheKey: 'host::repo-1::feature/test' }), 'active', 80, 1)
|
|
enqueuePRRefresh(
|
|
makeCandidate({
|
|
cacheKey: 'wsl::repo-1::feature/test',
|
|
localGitOptions: { wslDistro: 'Ubuntu' }
|
|
}),
|
|
'active',
|
|
80,
|
|
1
|
|
)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(2)
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
null
|
|
)
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
null,
|
|
{ localGitExecOptions: { wslDistro: 'Ubuntu' } }
|
|
)
|
|
})
|
|
|
|
it('preserves coalesced aliases across visible follow-up refreshes', async () => {
|
|
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'pending', mergeable: 'MERGEABLE' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'success' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
reportVisiblePRRefreshCandidates(
|
|
[
|
|
makeCandidate({
|
|
cacheKey: '/repo::feature/a',
|
|
branch: 'feature/a',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-a'
|
|
}),
|
|
makeCandidate({
|
|
cacheKey: '/repo::feature/b',
|
|
branch: 'feature/b',
|
|
linkedPRNumber: 12,
|
|
worktreeId: 'wt-b'
|
|
})
|
|
],
|
|
1,
|
|
1
|
|
)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
await vi.advanceTimersByTimeAsync(90_000)
|
|
|
|
const outcomeEvents = sendMock.mock.calls
|
|
.map(([, event]) => event)
|
|
.filter((event) => event.outcome)
|
|
|
|
expect(outcomeEvents).toHaveLength(2)
|
|
expect(outcomeEvents[1].aliases.map((alias) => alias.cacheKey).sort()).toEqual([
|
|
'/repo::feature/a',
|
|
'/repo::feature/b'
|
|
])
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
describe('pruneWorktreePRRefreshAliases', () => {
|
|
// Several local worktrees tracking the same linked PR coalesce into one
|
|
// queue entry (same refreshKey) whose alias map keeps one entry each.
|
|
const LINKED_PR_KEY = 'local::runtime:host::/repo::pr::42'
|
|
|
|
function makeLinkedCandidate(worktreeId: string): GitHubPRRefreshCandidate {
|
|
return makeCandidate({
|
|
worktreeId,
|
|
cacheKey: `/repo::${worktreeId}`,
|
|
branch: `feature/${worktreeId}`,
|
|
linkedPRNumber: 42
|
|
})
|
|
}
|
|
|
|
it('drops a removed worktree alias and deletes the entry when it was the last', async () => {
|
|
const { enqueuePRRefresh, pruneWorktreePRRefreshAliases, _getPRRefreshAliasCountForTests } =
|
|
await import('./pr-refresh-coordinator')
|
|
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-1'), 'visible', 40, 1)
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-2'), 'visible', 40, 1)
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-3'), 'visible', 40, 1)
|
|
expect(_getPRRefreshAliasCountForTests(LINKED_PR_KEY)).toBe(3)
|
|
|
|
pruneWorktreePRRefreshAliases('wt-2')
|
|
expect(_getPRRefreshAliasCountForTests(LINKED_PR_KEY)).toBe(2)
|
|
|
|
pruneWorktreePRRefreshAliases('wt-1')
|
|
pruneWorktreePRRefreshAliases('wt-3')
|
|
// Last alias gone -> the whole queue entry is dropped.
|
|
expect(_getPRRefreshAliasCountForTests(LINKED_PR_KEY)).toBe(0)
|
|
})
|
|
|
|
it('keeps the entry alive and rebinds the candidate when other aliases remain', async () => {
|
|
const {
|
|
enqueuePRRefresh,
|
|
pruneWorktreePRRefreshAliases,
|
|
_getPRRefreshAliasCountForTests,
|
|
_getPRRefreshQueueSizeForTests
|
|
} = await import('./pr-refresh-coordinator')
|
|
|
|
// wt-1 becomes the entry's representative candidate (enqueued first).
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-1'), 'visible', 40, 1)
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-2'), 'visible', 40, 1)
|
|
expect(_getPRRefreshQueueSizeForTests()).toBe(1)
|
|
|
|
// Removing the representative worktree must not orphan the entry.
|
|
pruneWorktreePRRefreshAliases('wt-1')
|
|
expect(_getPRRefreshAliasCountForTests(LINKED_PR_KEY)).toBe(1)
|
|
expect(_getPRRefreshQueueSizeForTests()).toBe(1)
|
|
})
|
|
|
|
it('is a no-op for a worktree with no queued aliases', async () => {
|
|
const { enqueuePRRefresh, pruneWorktreePRRefreshAliases, _getPRRefreshAliasCountForTests } =
|
|
await import('./pr-refresh-coordinator')
|
|
|
|
enqueuePRRefresh(makeLinkedCandidate('wt-1'), 'visible', 40, 1)
|
|
pruneWorktreePRRefreshAliases('wt-unknown')
|
|
expect(_getPRRefreshAliasCountForTests(LINKED_PR_KEY)).toBe(1)
|
|
})
|
|
})
|
|
})
|