[CI] Clean up runtime test callbacks (#27483)

This commit is contained in:
Neil
2026-10-11 06:51:00 -07:00
committed by GitHub
parent 741f95356f
commit bbac3af5fc
2 changed files with 58 additions and 3 deletions
@@ -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()
}
})
@@ -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<typeof worktreeChangeInvalidators.registerWorktreeChangeInvalidator>
| 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 }