Skip to content

Commit 4d2365d

Browse files
committed
test(checkpoints): stop the checkpoint suite from outrunning its hook budget on Windows
platform-unit-test (windows-latest) failed test:services with 5 failures in ShadowCheckpointService.spec.ts, every one of them a hook timeout in the shared beforeEach. One setup there spawns about 14 git subprocesses (workspace repo init plus shadow repo init), and the ~40 tests that share those hooks never released the repositories they created, so the shared temp dir carried one git repository pair per test until the afterAll. vitest.config.ts gives this lane two workers only on Windows CI, and every repository that is still on disk is extra cost on every spawn, which is what pushed the hook past the 20s hookTimeout there and nowhere else. Release each test's pair in the afterEach, the way the standalone tests in this file already release their own scratch repos, and give the setup and cleanup hooks the same 60s allowance the afterAll cleanup already carries. Nothing was skipped and no suppression was added. Two tests pin the release: a marker written into the repository the hooks created has to be gone before the next test runs. With the two rmScratch calls commented out the suite reports 1 failed | 43 passed (44) and the failure reads "AssertionError: expected true to be false // Object.is equality. With them restored the suite reports 44 passed.
1 parent 3535359 commit 4d2365d

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

‎src/services/checkpoints/__tests__/ShadowCheckpointService.spec.ts‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ afterAll(() => {
4141
}
4242
})
4343

44+
// Each test gets its own shadow + workspace repo, so the shared temp dir would otherwise
45+
// hold one git repository pair per test until the afterAll. Removing them as soon as the test
46+
// ends is what keeps the git-heavy setup below inside its hook budget on Windows CI workers,
47+
// where the retry absorbs the window in which git's own handles and antivirus scans still
48+
// hold the just-used repository.
49+
const rmScratch = async (dir: string) => {
50+
await fs.rm(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
51+
}
52+
4453
const initWorkspaceRepo = async ({
4554
workspaceDir,
4655
userName = "Roo Code",
@@ -83,22 +92,34 @@ describe.each([[RepoPerTaskCheckpointService, "RepoPerTaskCheckpointService"]])(
8392
let workspaceGit: SimpleGit
8493
let testFile: string
8594
let service: RepoPerTaskCheckpointService
95+
let shadowDir: string
96+
let workspaceDir: string
8697

98+
// One test setup spawns about 14 git subprocesses: workspace repo init plus shadow repo
99+
// init. On a Windows CI worker, where vitest.config.ts gives this lane two workers and
100+
// every spawn is scanned, that can outrun the 20s hook budget from vitest.config.ts, so
101+
// setup and cleanup get the same 60s allowance the afterAll cleanup already carries.
87102
beforeEach(async () => {
88-
const shadowDir = path.join(tmpDir, `${prefix}-${Date.now()}`)
89-
const workspaceDir = path.join(tmpDir, `workspace-${Date.now()}`)
103+
shadowDir = path.join(tmpDir, `${prefix}-${Date.now()}`)
104+
workspaceDir = path.join(tmpDir, `workspace-${Date.now()}`)
90105
const repo = await initWorkspaceRepo({ workspaceDir })
91106

92107
workspaceGit = repo.git
93108
testFile = repo.testFile
94109

95110
service = await klass.create({ taskId, shadowDir, workspaceDir, log: () => {} })
96111
await service.initShadowGit()
97-
})
112+
}, 60_000)
98113

99114
afterEach(async () => {
100115
vitest.restoreAllMocks()
101-
})
116+
117+
// The standalone tests below already delete the scratch repos they create; this hook
118+
// does the same for the pair created above, so the temp dir never accumulates one
119+
// repository pair per test for the ~40 tests that share these hooks.
120+
await rmScratch(shadowDir)
121+
await rmScratch(workspaceDir)
122+
}, 60_000)
102123

103124
afterAll(async () => {
104125
await fs.rm(tmpDir, { recursive: true, force: true })
@@ -1166,6 +1187,22 @@ describe.each([[RepoPerTaskCheckpointService, "RepoPerTaskCheckpointService"]])(
11661187
}
11671188
})
11681189
})
1190+
1191+
describe(`${klass.name}#scratchCleanup`, () => {
1192+
let markedFile: string
1193+
1194+
it("writes a marker into the repository its hooks created", async () => {
1195+
markedFile = path.join(workspaceDir, "scratch-marker.txt")
1196+
1197+
await fs.writeFile(markedFile, "written by the marker test")
1198+
1199+
expect(await fileExistsAtPath(markedFile)).toBe(true)
1200+
})
1201+
1202+
it("removes the marker with the repository before the next test runs", async () => {
1203+
expect(await fileExistsAtPath(markedFile)).toBe(false)
1204+
})
1205+
})
11691206
},
11701207
)
11711208

0 commit comments

Comments
 (0)