From f609a4da2af6f1bd5b5bc077488e5c18954657cf Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:19:35 +0200 Subject: [PATCH] fix(server): detect repositories after initialization --- apps/server/src/vcs/VcsDriverRegistry.test.ts | 45 +++++++++++++++++++ apps/server/src/vcs/VcsDriverRegistry.ts | 5 ++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/apps/server/src/vcs/VcsDriverRegistry.test.ts b/apps/server/src/vcs/VcsDriverRegistry.test.ts index 7a531a5adcc..0ad2450eb19 100644 --- a/apps/server/src/vcs/VcsDriverRegistry.test.ts +++ b/apps/server/src/vcs/VcsDriverRegistry.test.ts @@ -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)); + }); }); diff --git a/apps/server/src/vcs/VcsDriverRegistry.ts b/apps/server/src/vcs/VcsDriverRegistry.ts index 0bf95c2ffba..f40e1dadea3 100644 --- a/apps/server/src/vcs/VcsDriverRegistry.ts +++ b/apps/server/src/vcs/VcsDriverRegistry.ts @@ -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, + }), }, );