Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions apps/server/src/project/AgentSessionScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import * as Queue from "effect/Queue";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";

import * as ServerConfig from "../config.ts";
import * as ProcessRunner from "../processRunner.ts";
import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as AgentSessionScanner from "./AgentSessionScanner.ts";
Expand Down Expand Up @@ -56,10 +58,16 @@ interface ScannerTestInput {
readonly importedWorkspaceRoots?: ReadonlyArray<string>;
readonly configBaseDir?: string;
readonly providerInstances?: ContractServerSettings["providerInstances"];
readonly processRunner?: Layer.Layer<ProcessRunner.ProcessRunner>;
}

const layerScannerTest = (input: ScannerTestInput) =>
AgentSessionScanner.layer.pipe(
(input.processRunner === undefined
? AgentSessionScanner.layer
: Layer.effect(AgentSessionScanner.AgentSessionScanner, AgentSessionScanner.make).pipe(
Layer.provide(input.processRunner),
)
).pipe(
Layer.provide(
Layer.mergeAll(
ServerSettings.layerTest({
Expand Down Expand Up @@ -1959,11 +1967,38 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
});
}

// The deadline fires for every read still in flight, so on a slow runner the
// neighbours' `cat` children must have exited before the clock moves.
const neighbourConfigs = new Set(
[repos[0], repos[2]].map((repo) => path.join(repo, ".git", "config")),
);
const finishedNeighbourReads = yield* Queue.unbounded<string>();
const processRunner = Layer.effect(
ProcessRunner.ProcessRunner,
Effect.gen(function* () {
const runner = yield* ProcessRunner.ProcessRunner;
return ProcessRunner.ProcessRunner.of({
run: (input) => {
const filePath = input.args.at(-1) ?? "";
return neighbourConfigs.has(filePath)
? runner
.run(input)
.pipe(Effect.ensuring(Queue.offer(finishedNeighbourReads, filePath)))
: runner.run(input);
},
});
}),
).pipe(Layer.provide(ProcessRunner.layer), Layer.provide(NodeServices.layer));

for (let attempt = 1; attempt <= 2; attempt++) {
const scan = yield* Effect.forkChild(runScan({ claudeHomePath, codexHomePath }));
const scan = yield* Effect.forkChild(
runScan({ claudeHomePath, codexHomePath, processRunner }),
);
const result = yield* Effect.scoped(
Effect.gen(function* () {
yield* awaitGateReader(path.join(repos[1], ".git", "config"));
yield* Queue.take(finishedNeighbourReads);
yield* Queue.take(finishedNeighbourReads);
yield* TestClock.adjust("2 seconds");
return yield* Fiber.join(scan);
}),
Expand Down
Loading