From bbac3af5fc7375e6d5bf85e69dea3acf27a7057c Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 11 Oct 2026 06:51:00 -0700 Subject: [PATCH] [CI] Clean up runtime test callbacks (#27483) --- .../ipc/worktree-change-invalidators.test.ts | 26 ++++++++++++++ .../orca-runtime-test-lifecycle.spec.ts | 35 +++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/main/ipc/worktree-change-invalidators.test.ts diff --git a/src/main/ipc/worktree-change-invalidators.test.ts b/src/main/ipc/worktree-change-invalidators.test.ts new file mode 100644 index 00000000000..f6c85aaf216 --- /dev/null +++ b/src/main/ipc/worktree-change-invalidators.test.ts @@ -0,0 +1,26 @@ +import { expect, it } from 'vitest' +import { + registerWorktreeChangeInvalidator, + runWorktreeChangeInvalidators +} from './worktree-change-invalidators' + +it('retires one worktree invalidator while keeping another active', () => { + const first: string[] = [] + const second: string[] = [] + const unsubscribeFirst = registerWorktreeChangeInvalidator((repoId) => first.push(repoId)) + const unsubscribeSecond = registerWorktreeChangeInvalidator((repoId) => second.push(repoId)) + + try { + runWorktreeChangeInvalidators('repo-1') + expect(first).toEqual(['repo-1']) + expect(second).toEqual(['repo-1']) + + unsubscribeFirst() + runWorktreeChangeInvalidators('repo-2') + expect(first).toEqual(['repo-1']) + expect(second).toEqual(['repo-1', 'repo-2']) + } finally { + unsubscribeFirst() + unsubscribeSecond() + } +}) diff --git a/src/main/runtime/orca-runtime-test-lifecycle.spec.ts b/src/main/runtime/orca-runtime-test-lifecycle.spec.ts index 4b5b67dd440..c27e6476794 100644 --- a/src/main/runtime/orca-runtime-test-lifecycle.spec.ts +++ b/src/main/runtime/orca-runtime-test-lifecycle.spec.ts @@ -1,6 +1,11 @@ import * as mocks from './orca-runtime-test-mocks.spec' +import type { MockInstance } from 'vitest' +import * as worktreeChangeInvalidators from '../ipc/worktree-change-invalidators' import { awaitBackgroundRemovalsInRuntimeTests } from './orca-runtime-background-removal-test-support' -import { _resetPendingWorktreeRemovalsForTests } from '../worktree-background-removal' +import { + _resetPendingWorktreeRemovalsForTests, + _settlePendingWorktreeRemovalsForTests +} from '../worktree-background-removal' import { _resetCanonicalRepoKeyCacheForTests } from '../git/canonical-repo-key' const { MOCK_GIT_WORKTREES, RuntimeBrowserCommands, _resetTerminalViewAttributesForTest } = mocks @@ -338,7 +343,31 @@ function resetRuntimeTestMocks(): void { getIssueMock.mockResolvedValue(null) } -beforeEach(resetRuntimeTestMocks) -afterEach(resetRuntimeTestMocks) +let registrationSpy: + | MockInstance + | undefined + +beforeEach(() => { + resetRuntimeTestMocks() + registrationSpy = vi.spyOn(worktreeChangeInvalidators, 'registerWorktreeChangeInvalidator') +}) +afterEach(async () => { + try { + await _settlePendingWorktreeRemovalsForTests() + } finally { + try { + // Runtime fixtures share a process; invalidators must end with their case. + for (const result of registrationSpy?.mock.results ?? []) { + if (result.type === 'return') { + result.value() + } + } + } finally { + registrationSpy?.mockRestore() + registrationSpy = undefined + resetRuntimeTestMocks() + } + } +}) export { resetRuntimeTestMocks }