Skip to content

Commit 56044e4

Browse files
test(server): AgentSessionScanner blocked-repo test no longer races the git-read timeout
The test advanced the TestClock as soon as the blocked repo's config was opened. On a slow runner the neighbours' `cat` children were still running, so the jump fired their deadlines too and they came back with no git identity. The test now waits until both neighbour reads have returned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d51bc58 commit 56044e4

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import * as FileSystem from "effect/FileSystem";
2222
import * as Layer from "effect/Layer";
2323
import * as Option from "effect/Option";
2424
import * as Path from "effect/Path";
25+
import * as Queue from "effect/Queue";
2526
import * as Schema from "effect/Schema";
2627
import * as Stream from "effect/Stream";
2728
import * as TestClock from "effect/testing/TestClock";
2829

2930
import * as ServerConfig from "../config.ts";
31+
import * as ProcessRunner from "../processRunner.ts";
3032
import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
3133
import * as ServerSettings from "../serverSettings.ts";
3234
import * as AgentSessionScanner from "./AgentSessionScanner.ts";
@@ -56,10 +58,16 @@ interface ScannerTestInput {
5658
readonly importedWorkspaceRoots?: ReadonlyArray<string>;
5759
readonly configBaseDir?: string;
5860
readonly providerInstances?: ContractServerSettings["providerInstances"];
61+
readonly processRunner?: Layer.Layer<ProcessRunner.ProcessRunner>;
5962
}
6063

6164
const layerScannerTest = (input: ScannerTestInput) =>
62-
AgentSessionScanner.layer.pipe(
65+
(input.processRunner === undefined
66+
? AgentSessionScanner.layer
67+
: Layer.effect(AgentSessionScanner.AgentSessionScanner, AgentSessionScanner.make).pipe(
68+
Layer.provide(input.processRunner),
69+
)
70+
).pipe(
6371
Layer.provide(
6472
Layer.mergeAll(
6573
ServerSettings.layerTest({
@@ -1959,11 +1967,38 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
19591967
});
19601968
}
19611969

1970+
// The deadline fires for every read still in flight, so on a slow runner the
1971+
// neighbours' `cat` children must have exited before the clock moves.
1972+
const neighbourConfigs = new Set(
1973+
[repos[0], repos[2]].map((repo) => path.join(repo, ".git", "config")),
1974+
);
1975+
const finishedNeighbourReads = yield* Queue.unbounded<string>();
1976+
const processRunner = Layer.effect(
1977+
ProcessRunner.ProcessRunner,
1978+
Effect.gen(function* () {
1979+
const runner = yield* ProcessRunner.ProcessRunner;
1980+
return ProcessRunner.ProcessRunner.of({
1981+
run: (input) => {
1982+
const filePath = input.args.at(-1) ?? "";
1983+
return neighbourConfigs.has(filePath)
1984+
? runner
1985+
.run(input)
1986+
.pipe(Effect.tap(() => Queue.offer(finishedNeighbourReads, filePath)))
1987+
: runner.run(input);
1988+
},
1989+
});
1990+
}),
1991+
).pipe(Layer.provide(ProcessRunner.layer), Layer.provide(NodeServices.layer));
1992+
19621993
for (let attempt = 1; attempt <= 2; attempt++) {
1963-
const scan = yield* Effect.forkChild(runScan({ claudeHomePath, codexHomePath }));
1994+
const scan = yield* Effect.forkChild(
1995+
runScan({ claudeHomePath, codexHomePath, processRunner }),
1996+
);
19641997
const result = yield* Effect.scoped(
19651998
Effect.gen(function* () {
19661999
yield* awaitGateReader(path.join(repos[1], ".git", "config"));
2000+
yield* Queue.take(finishedNeighbourReads);
2001+
yield* Queue.take(finishedNeighbourReads);
19672002
yield* TestClock.adjust("2 seconds");
19682003
return yield* Fiber.join(scan);
19692004
}),

0 commit comments

Comments
 (0)