Skip to content
Merged
Show file tree
Hide file tree
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
45 changes: 45 additions & 0 deletions apps/server/src/vcs/VcsDriverRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,49 @@ describe("VcsDriverRegistry", () => {
);
}).pipe(Effect.provide(layer));
});

it.effect("detects a repository created after a negative lookup", () => {
let insideWorkTreeChecks = 0;
const layer = Layer.effect(VcsDriverRegistry.VcsDriverRegistry, VcsDriverRegistry.make).pipe(
Layer.provide(NodeServices.layer),
Layer.provide(
Layer.mock(VcsProjectConfig.VcsProjectConfig)({
resolveKind: (input) => Effect.succeed(input.requestedKind ?? "auto"),
}),
),
Layer.provide(
Layer.mock(VcsProcess.VcsProcess)({
run: (input) =>
Effect.sync(() => {
const command = normalizeGitArgs(input.args).join(" ");
if (command === "rev-parse --is-inside-work-tree") {
insideWorkTreeChecks += 1;
return insideWorkTreeChecks === 1
? {
...processOutput(""),
exitCode: ChildProcessSpawner.ExitCode(128),
stderr: "fatal: not a git repository",
}
: processOutput("true\n");
}
if (command === "rev-parse --show-toplevel") {
return processOutput("/repo\n");
}
if (command === "rev-parse --git-common-dir") {
return processOutput("/repo/.git\n");
}
return processOutput("");
}),
}),
),
);

return Effect.gen(function* () {
const registry = yield* VcsDriverRegistry.VcsDriverRegistry;

assert.equal(yield* registry.detect({ cwd: "/repo" }), null);
assert.equal((yield* registry.detect({ cwd: "/repo" }))?.repository.rootPath, "/repo");
assert.equal(insideWorkTreeChecks, 2);
}).pipe(Effect.provide(layer));
});
});
5 changes: 4 additions & 1 deletion apps/server/src/vcs/VcsDriverRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export const make = Effect.gen(function* () {
(key) => detectResolvedKind(parseDetectionCacheKey(key)),
{
capacity: DETECTION_CACHE_CAPACITY,
timeToLive: (exit) => (Exit.isSuccess(exit) ? DETECTION_CACHE_TTL : Duration.zero),
timeToLive: Exit.match({
onSuccess: (detected) => (detected === null ? Duration.zero : DETECTION_CACHE_TTL),
onFailure: () => Duration.zero,
}),
},
);

Expand Down
Loading