@devries-cameron20 / t3code-1 / commits / aeaf19cc61
Fork 0

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

fix(server): a slow or broken hosting CLI is no longer told to install itself (#23410)

Julius Marminge committed Nov 11, 2026 at 15:58 UTC aeaf19cc61cd739ac186986863d66362c3ab48e2
4 files changed +161 -21
apps/server/src/sourceControl/SourceControlDiscovery.test.ts
+88 -13
@@ -1,10 +1,20 @@
1 -import { SourceControlProviderKind, VcsProcessSpawnError } from "@t3tools/contracts";
1 +import {
2 + SourceControlProviderKind,
3 + type VcsError,
4 + VcsProcessExitError,
5 + VcsProcessSpawnError,
6 + VcsProcessTimeoutError,
7 +} from "@t3tools/contracts";
8 import { assert, it } from "@effect/vitest";
9 import * as NodeServices from "@effect/platform-node/NodeServices";
10 import * as Effect from "effect/Effect";
11 import * as Layer from "effect/Layer";
12 import * as Option from "effect/Option";
7 -import { providerAuth } from "@t3tools/source-control-core/server/discovery";
13 +import * as PlatformError from "effect/PlatformError";
14 +import {
15 + providerAuth,
16 + type SourceControlProviderDiscoverySpec,
17 +} from "@t3tools/source-control-core/server/discovery";
18 import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
19 import {
20 fakeDiscovery,
@@ -29,7 +39,29 @@ const run = (
39 SourceControlHost.SourceControlProcessInput,
40 "operation" | "command" | "args" | "cwd"
41 >,
32 -): Effect.Effect<SourceControlHost.SourceControlProcessOutput, VcsProcessSpawnError> => {
42 +): Effect.Effect<SourceControlHost.SourceControlProcessOutput, VcsError> => {
43 + const context = { operation: input.operation, command: input.command, cwd: input.cwd };
44 + if (input.command === "slow-cli") {
45 + return Effect.fail(new VcsProcessTimeoutError({ ...context, timeoutMs: 5_000 }));
46 + }
47 + if (input.command === "broken-cli") {
48 + return Effect.fail(
49 + new VcsProcessExitError({ ...context, exitCode: 1, detail: "broken-cli: bad install" }),
50 + );
51 + }
52 + if (input.command === "absent-cli") {
53 + return Effect.fail(
54 + new VcsProcessSpawnError({
55 + ...context,
56 + cause: PlatformError.systemError({
57 + _tag: "NotFound",
58 + module: "ChildProcess",
59 + method: "spawn",
60 + pathOrDescriptor: input.command,
61 + }),
62 + }),
63 + );
64 + }
65 if (input.args[0] === "--version") {
66 return input.command === "missing-cli"
67 ? Effect.fail(
@@ -47,29 +79,37 @@ const run = (
79 );
80 };
81
50 -const cliDiscovery = (name: string) => ({
82 +const cliDiscovery = (
83 + name: string,
84 + executable = name === "beta" ? "missing-cli" : `${name}-cli`,
85 +) => ({
86 type: "cli" as const,
87 kind: kind(name),
88 label: name,
89 installHint: `Install ${name}.`,
55 - executable: name === "beta" ? "missing-cli" : `${name}-cli`,
90 + executable,
91 versionArgs: ["--version"],
92 authArgs: ["auth", "status"],
93 parseAuth: ({ stdout }: { readonly stdout: string }) =>
94 providerAuth({ status: "authenticated", account: /as (\S+)/.exec(stdout)?.[1] }),
95 });
96
62 -const layerDiscovery = (runProcess = run) =>
97 +const defaultDiscoveries = [
98 + cliDiscovery("alpha"),
99 + cliDiscovery("beta"),
100 + fakeDiscovery("gamma", {
101 + probeAuth: Effect.succeed(providerAuth({ status: "authenticated", account: "api-user" })),
102 + }),
103 +];
104 +
105 +const layerDiscovery = (
106 + runProcess = run,
107 + discoveries: ReadonlyArray<SourceControlProviderDiscoverySpec> = defaultDiscoveries,
108 +) =>
109 Layer.effect(
110 SourceControlProviderRegistry.SourceControlProviderRegistry,
111 SourceControlProviderRegistry.makeWithProviders(
66 - [
67 - cliDiscovery("alpha"),
68 - cliDiscovery("beta"),
69 - fakeDiscovery("gamma", {
70 - probeAuth: Effect.succeed(providerAuth({ status: "authenticated", account: "api-user" })),
71 - }),
72 - ].map((discovery) => ({
112 + discoveries.map((discovery) => ({
113 kind: discovery.kind,
114 provider: fakeSourceControlProvider(discovery.kind),
115 discovery,
@@ -133,6 +173,41 @@ it.effect("reports every hosting integration in registry order with its sign-in"
173 }).pipe(Effect.provide(SourceControlDiscovery.layer.pipe(Layer.provide(layerDiscovery())))),
174 );
175
176 +it.effect("explains a hosting CLI whose version probe failed instead of advising an install", () =>
177 + Effect.gen(function* () {
178 + const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
179 + const result = yield* discovery.discover;
180 + const item = (name: string) => {
181 + const found = result.sourceControlProviders.find((entry) => entry.kind === kind(name));
182 + assert.isDefined(found);
183 + return found;
184 + };
185 + const authDetail = (name: string) => Option.getOrElse(item(name).auth.detail, () => "");
186 +
187 + assert.notInclude(item("slow").installHint, "Install slow.");
188 + assert.include(item("slow").installHint, "timed out after 5000ms");
189 + assert.strictEqual(authDetail("slow"), item("slow").installHint);
190 +
191 + assert.notInclude(item("broken").installHint, "Install broken.");
192 + assert.include(item("broken").installHint, "exited with status 1");
193 + assert.strictEqual(authDetail("broken"), item("broken").installHint);
194 +
195 + assert.strictEqual(item("absent").installHint, "Install absent.");
196 + }).pipe(
197 + Effect.provide(
198 + SourceControlDiscovery.layer.pipe(
199 + Layer.provide(
200 + layerDiscovery(run, [
201 + cliDiscovery("slow", "slow-cli"),
202 + cliDiscovery("broken", "broken-cli"),
203 + cliDiscovery("absent", "absent-cli"),
204 + ]),
205 + ),
206 + ),
207 + ),
208 + ),
209 +);
210 +
211 it.effect.each(["darwin", "linux"] as const)(
212 "names incompatible executables only on macOS (%s)",
213 (platform) => {
packages/source-control-core/src/server/discovery.ts
+23 -6
@@ -1,6 +1,8 @@
1 import * as NodeUtil from "node:util";
2 import {
3 + VcsProcessExitError,
4 VcsProcessSpawnError,
5 + VcsProcessTimeoutError,
6 type SourceControlProviderAuth,
7 type SourceControlProviderDiscoveryItem,
8 type SourceControlProviderInfo,
@@ -190,6 +192,20 @@ function isCliRemoteRefinementSpec(
192 return spec.type === "cli" && spec.refineUnknownRemote !== undefined;
193 }
194
195 +const isVcsProcessTimeoutError = Schema.is(VcsProcessTimeoutError);
196 +const isVcsProcessExitError = Schema.is(VcsProcessExitError);
197 +
198 +/** An installed CLI whose version probe failed needs a repair, not install advice. */
199 +function probeFailureHint(spec: SourceControlCliDiscoverySpec, cause: unknown): string {
200 + const command = `\`${[spec.executable, ...spec.versionArgs].join(" ")}\``;
201 + const outcome = isVcsProcessTimeoutError(cause)
202 + ? `timed out after ${cause.timeoutMs}ms`
203 + : isVcsProcessExitError(cause)
204 + ? `exited with status ${cause.exitCode}`
205 + : "failed";
206 + return `${command} ${outcome}. Check the \`${spec.executable}\` that the server's PATH resolves.`;
207 +}
208 +
209 function probeCli(input: {
210 readonly spec: SourceControlCliDiscoverySpec;
211 readonly process: SourceControlHost.SourceControlHost["Service"]["process"];
@@ -222,7 +238,7 @@ function probeCli(input: {
238 ),
239 Effect.catch((cause) =>
240 Effect.gen(function* () {
225 - const installHint = yield* unavailableInstallHint(
241 + const hint = yield* unavailableInstallHint(
242 input.spec.executable,
243 input.spec.installHint,
244 cause,
@@ -233,7 +249,11 @@ function probeCli(input: {
249 executable: input.spec.executable,
250 status: "missing" as const,
251 version: Option.none<string>(),
236 - installHint,
252 + // A wrong-CPU hint or an absent executable keeps its advice; other failures need repair.
253 + installHint:
254 + hint !== input.spec.installHint || isMissingExecutable(cause)
255 + ? hint
256 + : probeFailureHint(input.spec, cause),
257 detail: detailFromCause(cause),
258 } satisfies DiscoveryProbeResult;
259 }),
@@ -319,10 +339,7 @@ export function probeSourceControlProvider(input: {
339 ([item, auth]) =>
340 ({
341 ...item,
322 - auth:
323 - item.status === "available"
324 - ? auth
325 - : unknownAuth("Hosting integration command was not found on the server PATH."),
342 + auth: item.status === "available" ? auth : unknownAuth(item.installHint),
343 }) satisfies SourceControlProviderDiscoveryItem,
344 ),
345 );
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+46 -1
@@ -5,12 +5,13 @@ import * as Exit from "effect/Exit";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Layer from "effect/Layer";
7 import * as Option from "effect/Option";
8 +import * as PlatformError from "effect/PlatformError";
9 import * as Schema from "effect/Schema";
10 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
11 import * as HttpClient from "effect/http/HttpClient";
12 import * as HttpClientRequest from "effect/http/HttpClientRequest";
13 import * as HttpClientResponse from "effect/http/HttpClientResponse";
13 -import { VcsProcessSpawnError } from "@t3tools/contracts";
14 +import { VcsProcessSpawnError, VcsProcessTimeoutError } from "@t3tools/contracts";
15 import { firstNonEmptyLine } from "@t3tools/source-control-core/server/discovery";
16 import * as HostProcess from "@t3tools/shared/HostProcess";
17 import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
@@ -1991,3 +1992,47 @@ it.effect(
1992 }
1993 }),
1994 );
1995 +
1996 +it.effect("explains a slow fj instead of advising an install when tea is absent", () =>
1997 + Effect.gen(function* () {
1998 + const spec = yield* ForgejoSourceControlProvider.makeDiscovery;
1999 + assert.strictEqual(spec.type, "managed-cli");
2000 + if (spec.type !== "managed-cli") return;
2001 + const result = yield* spec.probe("/repo");
2002 + assert.strictEqual(result.status, "missing");
2003 + assert.strictEqual(result.executable, "fj");
2004 + assert.include(result.installHint, "`fj version` timed out");
2005 + assert.notInclude(result.installHint, "Install");
2006 + }).pipe(
2007 + Effect.provide(
2008 + Layer.mergeAll(
2009 + Layer.mock(ForgejoCli.ForgejoCli)({ listLogins: () => Effect.succeed([]) }),
2010 + TestSourceControlHost.layer({
2011 + process: {
2012 + run: (input) => {
2013 + const context = {
2014 + operation: input.operation,
2015 + command: input.command,
2016 + cwd: input.cwd,
2017 + };
2018 + if (input.command === "git") return Effect.succeed(processOutput(""));
2019 + if (input.command === "fj")
2020 + return Effect.fail(new VcsProcessTimeoutError({ ...context, timeoutMs: 5_000 }));
2021 + return Effect.fail(
2022 + new VcsProcessSpawnError({
2023 + ...context,
2024 + cause: PlatformError.systemError({
2025 + _tag: "NotFound",
2026 + module: "ChildProcess",
2027 + method: "spawn",
2028 + pathOrDescriptor: input.command,
2029 + }),
2030 + }),
2031 + );
2032 + },
2033 + },
2034 + }),
2035 + ),
2036 + ),
2037 + ),
2038 +);
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts
+4 -1
@@ -143,7 +143,10 @@ export const makeDiscovery = Effect.gen(function* () {
143 return fj;
144 }
145 const tea = yield* probeSourceControlProvider({ cwd, process, spec: discovery });
146 - return tea.status === "available" || fj.status === "missing" ? tea : fj;
146 + // Discovery keeps the install hint only for an absent executable; a slow or broken fj
147 + // explains itself better than tea's install advice.
148 + const fjAbsent = fj.status === "missing" && fj.installHint === discovery.installHint;
149 + return tea.status === "available" || fjAbsent ? tea : fj;
150 }),
151 refineUnknownRemote: Effect.fn("ForgejoSourceControlProvider.refineUnknownRemote")(
152 function* (input: {