@devries-cameron20 / t3code Mirror · read-only / commits / 385b1b1a8b
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 22, 09:30 UTC

fix(server): Source Control names a CLI built for another CPU instead of asking to install it (#21606)

Co-authored-by: maria-rcks <maria@kuuro.net>

tiliakoos committed Oct 31, 2026 at 04:47 UTC 385b1b1a8bbb8eee5a465a0150ae15b6f33effe5
3 files changed +129 -46
apps/server/src/sourceControl/SourceControlDiscovery.test.ts
+68 -26
@@ -10,6 +10,8 @@ import {
10 fakeDiscovery,
11 fakeSourceControlProvider,
12 } from "@t3tools/source-control-testing/fakeSourceControlDriver";
13 +import * as HostProcess from "@t3tools/shared/HostProcess";
14 +import { SpawnExecutableResolution } from "@t3tools/shared/shell";
15 import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
16
17 import * as ServerConfig from "../config.ts";
@@ -57,31 +59,32 @@ const cliDiscovery = (name: string) => ({
59 providerAuth({ status: "authenticated", account: /as (\S+)/.exec(stdout)?.[1] }),
60 });
61
60 -const layerDiscovery = Layer.effect(
61 - SourceControlProviderRegistry.SourceControlProviderRegistry,
62 - SourceControlProviderRegistry.makeWithProviders(
63 - [
64 - cliDiscovery("alpha"),
65 - cliDiscovery("beta"),
66 - fakeDiscovery("gamma", {
67 - probeAuth: Effect.succeed(providerAuth({ status: "authenticated", account: "api-user" })),
68 - }),
69 - ].map((discovery) => ({
70 - kind: discovery.kind,
71 - provider: fakeSourceControlProvider(discovery.kind),
72 - discovery,
73 - })),
74 - ),
75 -).pipe(
76 - Layer.provideMerge(TestSourceControlHost.layer({ process: { run } })),
77 - Layer.provideMerge(ServerSettings.ServerSettingsService.layerTest()),
78 - Layer.provideMerge(Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({})),
79 - Layer.provideMerge(Layer.mock(VcsProcess.VcsProcess)({ run })),
80 - Layer.provideMerge(
81 - ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
82 - ),
83 - Layer.provideMerge(NodeServices.layer),
84 -);
62 +const layerDiscovery = (runProcess = run) =>
63 + Layer.effect(
64 + SourceControlProviderRegistry.SourceControlProviderRegistry,
65 + 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) => ({
73 + kind: discovery.kind,
74 + provider: fakeSourceControlProvider(discovery.kind),
75 + discovery,
76 + })),
77 + ),
78 + ).pipe(
79 + Layer.provideMerge(TestSourceControlHost.layer({ process: { run: runProcess } })),
80 + Layer.provideMerge(ServerSettings.ServerSettingsService.layerTest()),
81 + Layer.provideMerge(Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({})),
82 + Layer.provideMerge(Layer.mock(VcsProcess.VcsProcess)({ run: runProcess })),
83 + Layer.provideMerge(
84 + ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
85 + ),
86 + Layer.provideMerge(NodeServices.layer),
87 + );
88
89 it.effect("reports every hosting integration in registry order with its sign-in", () =>
90 Effect.gen(function* () {
@@ -127,5 +130,44 @@ it.effect("reports every hosting integration in registry order with its sign-in"
130 ["jj", "available"],
131 ],
132 );
130 - }).pipe(Effect.provide(SourceControlDiscovery.layer.pipe(Layer.provide(layerDiscovery)))),
133 + }).pipe(Effect.provide(SourceControlDiscovery.layer.pipe(Layer.provide(layerDiscovery())))),
134 +);
135 +
136 +it.effect.each(["darwin", "linux"] as const)(
137 + "names incompatible executables only on macOS (%s)",
138 + (platform) => {
139 + const runProcess: typeof run = (input) =>
140 + Effect.fail(
141 + new VcsProcessSpawnError({
142 + operation: input.operation,
143 + command: input.command,
144 + cwd: input.cwd,
145 + cause:
146 + input.command === "missing-cli"
147 + ? new Error("not found")
148 + : Object.assign(new Error("spawn Unknown system error -86"), { errno: -86 }),
149 + }),
150 + );
151 + return Effect.gen(function* () {
152 + const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
153 + const result = yield* discovery.discover;
154 + for (const item of [...result.versionControlSystems, ...result.sourceControlProviders]) {
155 + if (item.kind === kind("gamma")) continue;
156 + assert.strictEqual(item.status, "missing");
157 + if (platform === "darwin" && item.executable !== "missing-cli") {
158 + assert.include(
159 + item.installHint,
160 + `\`/usr/local/bin/${item.executable}\` is built for another CPU architecture, so this arm64 machine cannot run it. Remove or replace it.`,
161 + );
162 + } else {
163 + assert.notInclude(item.installHint, "CPU architecture");
164 + }
165 + }
166 + }).pipe(
167 + Effect.provide(SourceControlDiscovery.layer.pipe(Layer.provide(layerDiscovery(runProcess)))),
168 + Effect.provideService(SpawnExecutableResolution, (command) => `/usr/local/bin/${command}`),
169 + Effect.provideService(HostProcess.Platform, platform),
170 + Effect.provideService(HostProcess.Architecture, "arm64"),
171 + );
172 + },
173 );
apps/server/src/sourceControl/SourceControlDiscovery.ts
+18 -11
@@ -10,7 +10,11 @@ import * as Option from "effect/Option";
10
11 import * as ServerConfig from "../config.ts";
12 import * as VcsProcess from "../vcs/VcsProcess.ts";
13 -import { detailFromCause, firstNonEmptyLine } from "@t3tools/source-control-core/server/discovery";
13 +import {
14 + detailFromCause,
15 + firstNonEmptyLine,
16 + unavailableInstallHint,
17 +} from "@t3tools/source-control-core/server/discovery";
18 import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
19
20 interface DiscoveryProbe {
@@ -103,16 +107,19 @@ export const make = Effect.gen(function* () {
107 }) satisfies DiscoveryProbeResult<Kind>,
108 ),
109 Effect.catch((cause) =>
106 - Effect.succeed({
107 - kind: input.kind,
108 - label: input.label,
109 - executable,
110 - implemented: input.implemented,
111 - status: "missing" as const,
112 - version: Option.none<string>(),
113 - installHint: input.installHint,
114 - detail: detailFromCause(cause),
115 - } satisfies DiscoveryProbeResult<Kind>),
110 + Effect.gen(function* () {
111 + const installHint = yield* unavailableInstallHint(executable, input.installHint, cause);
112 + return {
113 + kind: input.kind,
114 + label: input.label,
115 + executable,
116 + implemented: input.implemented,
117 + status: "missing" as const,
118 + version: Option.none<string>(),
119 + installHint,
120 + detail: detailFromCause(cause),
121 + } satisfies DiscoveryProbeResult<Kind>;
122 + }),
123 ),
124 );
125 };
packages/source-control-core/src/server/discovery.ts
+43 -9
@@ -6,6 +6,8 @@ import {
6 type SourceControlProviderInfo,
7 type SourceControlProviderKind,
8 } from "@t3tools/contracts";
9 +import * as HostProcess from "@t3tools/shared/HostProcess";
10 +import { SpawnExecutableResolution } from "@t3tools/shared/shell";
11 import type * as Cause from "effect/Cause";
12 import * as Effect from "effect/Effect";
13 import * as Option from "effect/Option";
@@ -217,15 +219,22 @@ function probeCli(input: {
219 }) satisfies DiscoveryProbeResult,
220 ),
221 Effect.catch((cause) =>
220 - Effect.succeed({
221 - kind: input.spec.kind,
222 - label: input.spec.label,
223 - executable: input.spec.executable,
224 - status: "missing" as const,
225 - version: Option.none<string>(),
226 - installHint: input.spec.installHint,
227 - detail: detailFromCause(cause),
228 - } satisfies DiscoveryProbeResult),
222 + Effect.gen(function* () {
223 + const installHint = yield* unavailableInstallHint(
224 + input.spec.executable,
225 + input.spec.installHint,
226 + cause,
227 + );
228 + return {
229 + kind: input.spec.kind,
230 + label: input.spec.label,
231 + executable: input.spec.executable,
232 + status: "missing" as const,
233 + version: Option.none<string>(),
234 + installHint,
235 + detail: detailFromCause(cause),
236 + } satisfies DiscoveryProbeResult;
237 + }),
238 ),
239 );
240 }
@@ -314,6 +323,31 @@ export function isMissingExecutable(error: unknown): boolean {
323 );
324 }
325
326 +// macOS's EBADARCH, which Node has no name for: the binary is built for another CPU, such as an
327 +// Intel-only `gh` on Apple Silicon without Rosetta.
328 +const BAD_CPU_TYPE_ERRNO = -86;
329 +
330 +export const unavailableInstallHint = Effect.fn("discovery.unavailableInstallHint")(function* (
331 + executable: string,
332 + installHint: string,
333 + cause: unknown,
334 +) {
335 + const platform = yield* HostProcess.Platform;
336 + if (
337 + platform !== "darwin" ||
338 + !isVcsProcessSpawnError(cause) ||
339 + !(cause.cause instanceof Error) ||
340 + !("errno" in cause.cause) ||
341 + cause.cause.errno !== BAD_CPU_TYPE_ERRNO
342 + ) {
343 + return installHint;
344 + }
345 + const resolveExecutable = yield* SpawnExecutableResolution;
346 + const path = resolveExecutable(executable, platform, yield* HostProcess.Environment);
347 + const architecture = yield* HostProcess.Architecture;
348 + return `\`${path ?? executable}\` is built for another CPU architecture, so this ${architecture} machine cannot run it. Remove or replace it. ${installHint}`;
349 +});
350 +
351 class UnknownRemoteUnanswered extends Schema.TaggedError<UnknownRemoteUnanswered>()(
352 "UnknownRemoteUnanswered",
353 {},