Skip to content

Commit c544c27

Browse files
fix(server): a failed Git version probe no longer advises installing Git (pingdotgg#35638)
1 parent 3595b9e commit c544c27

3 files changed

Lines changed: 47 additions & 30 deletions

File tree

‎apps/server/src/sourceControl/SourceControlDiscovery.test.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ it.effect("reports every hosting integration in registry order with its sign-in"
175175
}).pipe(Effect.provide(SourceControlDiscovery.layer.pipe(Layer.provide(layerDiscovery())))),
176176
);
177177

178-
it.effect("explains a hosting CLI whose version probe failed instead of advising an install", () =>
178+
it.effect("explains a CLI whose version probe failed instead of advising an install", () =>
179179
Effect.gen(function* () {
180180
const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
181181
const result = yield* discovery.discover;
@@ -195,15 +195,23 @@ it.effect("explains a hosting CLI whose version probe failed instead of advising
195195
assert.strictEqual(authDetail("broken"), item("broken").installHint);
196196

197197
assert.strictEqual(item("absent").installHint, "Install absent.");
198+
199+
const git = result.versionControlSystems.find((entry) => entry.kind === "git");
200+
assert.isDefined(git);
201+
assert.notInclude(git.installHint, "Install Git from");
202+
assert.include(git.installHint, "`git --version` exited with status 1");
198203
}).pipe(
199204
Effect.provide(
200205
SourceControlDiscovery.layer.pipe(
201206
Layer.provide(
202-
layerDiscovery(run, [
203-
cliDiscovery("slow", "slow-cli"),
204-
cliDiscovery("broken", "broken-cli"),
205-
cliDiscovery("absent", "absent-cli"),
206-
]),
207+
layerDiscovery(
208+
(input) => run(input.command === "git" ? { ...input, command: "broken-cli" } : input),
209+
[
210+
cliDiscovery("slow", "slow-cli"),
211+
cliDiscovery("broken", "broken-cli"),
212+
cliDiscovery("absent", "absent-cli"),
213+
],
214+
),
207215
),
208216
),
209217
),

‎apps/server/src/sourceControl/SourceControlDiscovery.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { refreshPathFromLoginShell } from "../os-jank.ts";
1515
import * as VcsProcess from "../vcs/VcsProcess.ts";
1616
import {
1717
detailFromCause,
18+
failedProbeHint,
1819
firstNonEmptyLine,
19-
unavailableInstallHint,
2020
} from "@t3tools/source-control-core/server/discovery";
2121
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
2222

@@ -119,7 +119,7 @@ export const make = Effect.gen(function* () {
119119
),
120120
Effect.catch((cause) =>
121121
Effect.gen(function* () {
122-
const installHint = yield* unavailableInstallHint(executable, input.installHint, cause);
122+
const installHint = yield* failedProbeHint(input, cause);
123123
return {
124124
kind: input.kind,
125125
label: input.label,

‎packages/source-control-core/src/server/discovery.ts‎

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ function isCliRemoteRefinementSpec(
195195
const isVcsProcessTimeoutError = Schema.is(VcsProcessTimeoutError);
196196
const isVcsProcessExitError = Schema.is(VcsProcessExitError);
197197

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-
209198
function probeCli(input: {
210199
readonly spec: SourceControlCliDiscoverySpec;
211200
readonly process: SourceControlHost.SourceControlHost["Service"]["process"];
@@ -238,22 +227,13 @@ function probeCli(input: {
238227
),
239228
Effect.catch((cause) =>
240229
Effect.gen(function* () {
241-
const hint = yield* unavailableInstallHint(
242-
input.spec.executable,
243-
input.spec.installHint,
244-
cause,
245-
);
246230
return {
247231
kind: input.spec.kind,
248232
label: input.spec.label,
249233
executable: input.spec.executable,
250234
status: "missing" as const,
251235
version: Option.none<string>(),
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),
236+
installHint: yield* failedProbeHint(input.spec, cause),
257237
detail: detailFromCause(cause),
258238
} satisfies DiscoveryProbeResult;
259239
}),
@@ -361,7 +341,7 @@ export function isMissingExecutable(error: unknown): boolean {
361341
// Intel-only `gh` on Apple Silicon without Rosetta.
362342
const BAD_CPU_TYPE_ERRNO = -86;
363343

364-
export const unavailableInstallHint = Effect.fn("discovery.unavailableInstallHint")(function* (
344+
const unavailableInstallHint = Effect.fn("discovery.unavailableInstallHint")(function* (
365345
executable: string,
366346
installHint: string,
367347
cause: unknown,
@@ -382,6 +362,35 @@ export const unavailableInstallHint = Effect.fn("discovery.unavailableInstallHin
382362
return `\`${path ?? executable}\` is built for another CPU architecture, so this ${architecture} machine cannot run it. Remove or replace it. ${installHint}`;
383363
});
384364

365+
/** An installed CLI whose version probe failed needs a repair, not install advice. */
366+
function probeFailureHint(
367+
probe: { readonly executable: string; readonly versionArgs: ReadonlyArray<string> },
368+
cause: unknown,
369+
): string {
370+
const command = `\`${[probe.executable, ...probe.versionArgs].join(" ")}\``;
371+
const outcome = isVcsProcessTimeoutError(cause)
372+
? `timed out after ${cause.timeoutMs}ms`
373+
: isVcsProcessExitError(cause)
374+
? `exited with status ${cause.exitCode}`
375+
: "failed";
376+
return `${command} ${outcome}. Check the \`${probe.executable}\` that the server's PATH resolves.`;
377+
}
378+
379+
export const failedProbeHint = Effect.fn("discovery.failedProbeHint")(function* (
380+
probe: {
381+
readonly executable: string;
382+
readonly versionArgs: ReadonlyArray<string>;
383+
readonly installHint: string;
384+
},
385+
cause: unknown,
386+
) {
387+
const hint = yield* unavailableInstallHint(probe.executable, probe.installHint, cause);
388+
// A wrong-CPU hint or an absent executable keeps its advice; other failures need repair.
389+
return hint !== probe.installHint || isMissingExecutable(cause)
390+
? hint
391+
: probeFailureHint(probe, cause);
392+
});
393+
385394
class UnknownRemoteUnanswered extends Schema.TaggedError<UnknownRemoteUnanswered>()(
386395
"UnknownRemoteUnanswered",
387396
{},

0 commit comments

Comments
 (0)