@devries-cameron20 / t3code Mirror · read-only / commits / 2432ee10c6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 17:15 UTC

test(server): blocked pointer-file scan test waits for the unblocked read (#36031)

Julius Marminge committed Nov 12, 2026 at 22:10 UTC 2432ee10c6c02a27a2a0dcf7c40a807faa213ef6
1 file changed +48 -33
apps/server/src/project/AgentSessionScanner.test.ts
+48 -33
@@ -326,6 +326,30 @@ const awaitGateReader = (gatePath: string) =>
326 (handle) => Effect.promise(() => handle.close()),
327 );
328
329 +/**
330 + * Offers each of `filePaths` to `finished` once its `cat` child has exited. A
331 + * deadline fires for every read still in flight, so a test must wait for the
332 + * unblocked reads before it moves the clock.
333 + */
334 +const layerReportingProcessRunner = (
335 + filePaths: ReadonlySet<string>,
336 + finished: Queue.Queue<string>,
337 +) =>
338 + Layer.effect(
339 + ProcessRunner.ProcessRunner,
340 + Effect.gen(function* () {
341 + const runner = yield* ProcessRunner.ProcessRunner;
342 + return ProcessRunner.ProcessRunner.of({
343 + run: (input) => {
344 + const filePath = input.args.at(-1) ?? "";
345 + return filePaths.has(filePath)
346 + ? runner.run(input).pipe(Effect.ensuring(Queue.offer(finished, filePath)))
347 + : runner.run(input);
348 + },
349 + });
350 + }),
351 + ).pipe(Layer.provide(ProcessRunner.layer), Layer.provide(NodeServices.layer));
352 +
353 it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
354 describe("scan", () => {
355 it.effect("reads Claude project cwds from transcripts, newest first", () =>
@@ -2557,28 +2581,11 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
2581 });
2582 }
2583
2560 - // The deadline fires for every read still in flight, so on a slow runner the
2561 - // neighbours' `cat` children must have exited before the clock moves.
2562 - const neighbourConfigs = new Set(
2563 - [repos[0], repos[2]].map((repo) => path.join(repo, ".git", "config")),
2564 - );
2584 const finishedNeighbourReads = yield* Queue.unbounded<string>();
2566 - const processRunner = Layer.effect(
2567 - ProcessRunner.ProcessRunner,
2568 - Effect.gen(function* () {
2569 - const runner = yield* ProcessRunner.ProcessRunner;
2570 - return ProcessRunner.ProcessRunner.of({
2571 - run: (input) => {
2572 - const filePath = input.args.at(-1) ?? "";
2573 - return neighbourConfigs.has(filePath)
2574 - ? runner
2575 - .run(input)
2576 - .pipe(Effect.ensuring(Queue.offer(finishedNeighbourReads, filePath)))
2577 - : runner.run(input);
2578 - },
2579 - });
2580 - }),
2581 - ).pipe(Layer.provide(ProcessRunner.layer), Layer.provide(NodeServices.layer));
2585 + const processRunner = layerReportingProcessRunner(
2586 + new Set([repos[0], repos[2]].map((repo) => path.join(repo, ".git", "config"))),
2587 + finishedNeighbourReads,
2588 + );
2589
2590 for (let attempt = 1; attempt <= 2; attempt++) {
2591 const scan = yield* Effect.forkChild(
@@ -2687,6 +2694,12 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
2694 });
2695 }
2696
2697 + const finishedPointerReads = yield* Queue.unbounded<string>();
2698 + const processRunner = layerReportingProcessRunner(
2699 + new Set([path.join(worktree, ".git")]),
2700 + finishedPointerReads,
2701 + );
2702 +
2703 // One scanner across scans: later scans skip the files that blocked.
2704 yield* Effect.gen(function* () {
2705 const scanner = yield* AgentSessionScanner.AgentSessionScanner;
@@ -2695,22 +2708,24 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
2708 );
2709 const first = yield* Effect.forkChild(scanPaths);
2710 // Pointer files are read first, then the commondir files they lead to.
2698 - for (const gatePath of [
2699 - path.join(pointerCheckout, ".git"),
2700 - path.join(worktreeGitDir, "commondir"),
2701 - ]) {
2702 - yield* Effect.scoped(
2703 - Effect.gen(function* () {
2704 - yield* awaitGateReader(gatePath);
2705 - yield* TestClock.adjust("2 seconds");
2706 - }),
2707 - );
2708 - }
2711 + yield* Effect.scoped(
2712 + Effect.gen(function* () {
2713 + yield* awaitGateReader(path.join(pointerCheckout, ".git"));
2714 + yield* Queue.take(finishedPointerReads);
2715 + yield* TestClock.adjust("2 seconds");
2716 + }),
2717 + );
2718 + yield* Effect.scoped(
2719 + Effect.gen(function* () {
2720 + yield* awaitGateReader(path.join(worktreeGitDir, "commondir"));
2721 + yield* TestClock.adjust("2 seconds");
2722 + }),
2723 + );
2724 expect(yield* Fiber.join(first)).toEqual([pointerCheckout]);
2725 for (let attempt = 2; attempt <= LIBUV_POOL_SIZE + 1; attempt++) {
2726 expect(yield* scanPaths, `scan ${attempt}`).toEqual([pointerCheckout]);
2727 }
2713 - }).pipe(Effect.provide(layerScannerTest({ claudeHomePath, codexHomePath })));
2728 + }).pipe(Effect.provide(layerScannerTest({ claudeHomePath, codexHomePath, processRunner })));
2729 // Hangs if the scans left libuv pool threads stuck in open().
2730 yield* fileSystem.readFileString(path.join(worktree, ".git"));
2731 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),