Skip to content

Commit a045dfe

Browse files
radroidclaude
authored andcommitted
fix(server): treat slow az --version as present, not missing
The source-control discovery probe hard-capped the CLI version probe at 5s and mapped every failure — including a timeout — to `status: "missing"`, which rendered the "install az" hint and skipped the fast auth check. On Windows `az --version` routinely takes 6-8s (Python startup + the Azure CLI "updates available" check), so an installed, authenticated Azure CLI was reported "not available". - Raise the discovery CLI probe timeout from 5s to 15s (CLI_PROBE_TIMEOUT_MS). - Branch probeCli's error handler on the cause tag: only VcsProcessSpawnError (ENOENT) => "missing" + install hint. A timeout (or other runtime failure) => "available", so probeSourceControlProvider still runs the fast `az account show` auth probe instead of short-circuiting. Adds SourceControlProviderDiscovery.test.ts covering: timeout => available + auth runs, spawn error => missing + auth skipped, the raised timeout, and timeout + unauthenticated. Fixes #4 Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent 22a9756 commit a045dfe

2 files changed

Lines changed: 194 additions & 8 deletions

File tree

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { assert, it } from "@effect/vitest";
2+
import * as Effect from "effect/Effect";
3+
import * as Option from "effect/Option";
4+
import { ChildProcessSpawner } from "effect/unstable/process";
5+
import { type VcsError, VcsProcessSpawnError, VcsProcessTimeoutError } from "@t3tools/contracts";
6+
7+
import * as VcsProcess from "../vcs/VcsProcess.ts";
8+
import * as AzureDevOps from "./AzureDevOpsSourceControlProvider.ts";
9+
import { probeSourceControlProvider } from "./SourceControlProviderDiscovery.ts";
10+
11+
const processOutput = (
12+
stdout: string,
13+
options?: {
14+
readonly stderr?: string;
15+
readonly exitCode?: ChildProcessSpawner.ExitCode;
16+
},
17+
): VcsProcess.VcsProcessOutput => ({
18+
exitCode: options?.exitCode ?? ChildProcessSpawner.ExitCode(0),
19+
stdout,
20+
stderr: options?.stderr ?? "",
21+
stdoutTruncated: false,
22+
stderrTruncated: false,
23+
});
24+
25+
interface CapturingProcess {
26+
readonly process: VcsProcess.VcsProcess["Service"];
27+
readonly calls: ReadonlyArray<VcsProcess.VcsProcessInput>;
28+
}
29+
30+
const makeProcess = (
31+
run: (input: VcsProcess.VcsProcessInput) => Effect.Effect<VcsProcess.VcsProcessOutput, VcsError>,
32+
): CapturingProcess => {
33+
const calls: VcsProcess.VcsProcessInput[] = [];
34+
return {
35+
calls,
36+
process: {
37+
run: (input) => {
38+
calls.push(input);
39+
return run(input);
40+
},
41+
},
42+
};
43+
};
44+
45+
const isVersionCall = (input: VcsProcess.VcsProcessInput): boolean => input.args[0] === "--version";
46+
const isAuthCall = (input: VcsProcess.VcsProcessInput): boolean => input.args[0] === "account";
47+
48+
it.effect(
49+
"reports Azure CLI as available and still runs the auth probe when `--version` times out",
50+
() =>
51+
Effect.gen(function* () {
52+
const { process, calls } = makeProcess((input) => {
53+
if (isVersionCall(input)) {
54+
return Effect.fail(
55+
new VcsProcessTimeoutError({
56+
operation: input.operation,
57+
command: input.command,
58+
cwd: input.cwd,
59+
timeoutMs: input.timeoutMs ?? 0,
60+
}),
61+
);
62+
}
63+
return Effect.succeed(processOutput("[email protected]\n"));
64+
});
65+
66+
const item = yield* probeSourceControlProvider({
67+
spec: AzureDevOps.discovery,
68+
process,
69+
cwd: "/repo",
70+
});
71+
72+
assert.strictEqual(item.status, "available");
73+
assert.strictEqual(item.auth.status, "authenticated");
74+
assert.deepStrictEqual(item.auth.account, Option.some("[email protected]"));
75+
assert.ok(
76+
calls.some(isAuthCall),
77+
"expected an `account show` auth probe to run after a slow `--version`",
78+
);
79+
}),
80+
);
81+
82+
it.effect(
83+
"reports Azure CLI as missing and skips the auth probe when `--version` cannot spawn",
84+
() =>
85+
Effect.gen(function* () {
86+
const { process, calls } = makeProcess((input) => {
87+
if (isVersionCall(input)) {
88+
return Effect.fail(
89+
new VcsProcessSpawnError({
90+
operation: input.operation,
91+
command: input.command,
92+
cwd: input.cwd,
93+
cause: Object.assign(new Error("spawn az ENOENT"), { code: "ENOENT" }),
94+
}),
95+
);
96+
}
97+
return Effect.succeed(processOutput("[email protected]\n"));
98+
});
99+
100+
const item = yield* probeSourceControlProvider({
101+
spec: AzureDevOps.discovery,
102+
process,
103+
cwd: "/repo",
104+
});
105+
106+
assert.strictEqual(item.status, "missing");
107+
assert.strictEqual(item.auth.status, "unknown");
108+
assert.strictEqual(calls.length, 1);
109+
assert.strictEqual(calls[0]?.args[0], "--version");
110+
}),
111+
);
112+
113+
it.effect(
114+
"raises the `--version` probe timeout above 15s and reports the version on the happy path",
115+
() =>
116+
Effect.gen(function* () {
117+
const { process, calls } = makeProcess((input) => {
118+
if (isVersionCall(input)) {
119+
return Effect.succeed(processOutput("azure-cli 2.87.0\n"));
120+
}
121+
return Effect.succeed(processOutput("[email protected]\n"));
122+
});
123+
124+
const item = yield* probeSourceControlProvider({
125+
spec: AzureDevOps.discovery,
126+
process,
127+
cwd: "/repo",
128+
});
129+
130+
const versionCall = calls.find(isVersionCall);
131+
assert.ok(versionCall, "expected a `--version` probe to run");
132+
assert.ok(
133+
(versionCall.timeoutMs ?? 0) >= 15_000,
134+
`expected the \`--version\` probe timeout to be >= 15000ms, got ${String(versionCall.timeoutMs)}`,
135+
);
136+
assert.deepStrictEqual(item.version, Option.some("azure-cli 2.87.0"));
137+
assert.strictEqual(item.status, "available");
138+
assert.strictEqual(item.auth.status, "authenticated");
139+
}),
140+
);
141+
142+
it.effect(
143+
"reports available but unauthenticated when `--version` times out and `account show` exits non-zero",
144+
() =>
145+
Effect.gen(function* () {
146+
const { process } = makeProcess((input) => {
147+
if (isVersionCall(input)) {
148+
return Effect.fail(
149+
new VcsProcessTimeoutError({
150+
operation: input.operation,
151+
command: input.command,
152+
cwd: input.cwd,
153+
timeoutMs: input.timeoutMs ?? 0,
154+
}),
155+
);
156+
}
157+
return Effect.succeed(
158+
processOutput("", {
159+
stderr: "ERROR: Please run 'az login' to setup account.",
160+
exitCode: ChildProcessSpawner.ExitCode(1),
161+
}),
162+
);
163+
});
164+
165+
const item = yield* probeSourceControlProvider({
166+
spec: AzureDevOps.discovery,
167+
process,
168+
cwd: "/repo",
169+
});
170+
171+
assert.strictEqual(item.status, "available");
172+
assert.strictEqual(item.auth.status, "unauthenticated");
173+
}),
174+
);

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import * as Option from "effect/Option";
1010
import type * as SourceControlProvider from "./SourceControlProvider.ts";
1111
import type * as VcsProcess from "../vcs/VcsProcess.ts";
1212

13+
// `az --version` on Windows routinely takes 6-8s (Python startup + Azure CLI's
14+
// "updates available" check), so the old 5s cap misclassified a present-but-slow
15+
// CLI as missing. Raise the discovery probe budget well above that. (issue #4)
16+
const CLI_PROBE_TIMEOUT_MS = 15_000;
17+
1318
export interface SourceControlAuthProbeInput {
1419
readonly stdout: string;
1520
readonly stderr: string;
@@ -167,7 +172,7 @@ function probeCli(input: {
167172
command: input.spec.executable,
168173
args: input.spec.versionArgs,
169174
cwd: input.cwd,
170-
timeoutMs: 5_000,
175+
timeoutMs: CLI_PROBE_TIMEOUT_MS,
171176
maxOutputBytes: 8_000,
172177
appendTruncationMarker: true,
173178
})
@@ -186,17 +191,24 @@ function probeCli(input: {
186191
detail: Option.none<string>(),
187192
}) satisfies DiscoveryProbeResult,
188193
),
189-
Effect.catch((cause) =>
190-
Effect.succeed({
194+
Effect.catch((cause) => {
195+
// Only a genuine spawn failure (e.g. ENOENT) means the CLI is absent, so
196+
// that is the sole case that reports "missing" and shows the install hint.
197+
// Any other failure (timeout, non-zero exit, etc.) means the CLI is present
198+
// but the version probe was slow/noisy; keep it "available" so
199+
// `probeSourceControlProvider` still runs the fast `account show` auth
200+
// probe instead of short-circuiting to the install hint. (issue #4)
201+
const status = cause._tag === "VcsProcessSpawnError" ? "missing" : "available";
202+
return Effect.succeed({
191203
kind: input.spec.kind,
192204
label: input.spec.label,
193205
executable: input.spec.executable,
194-
status: "missing" as const,
206+
status,
195207
version: Option.none<string>(),
196208
installHint: input.spec.installHint,
197209
detail: detailFromCause(cause),
198-
} satisfies DiscoveryProbeResult),
199-
),
210+
} satisfies DiscoveryProbeResult);
211+
}),
200212
);
201213
}
202214

@@ -244,7 +256,7 @@ export function probeSourceControlProvider(input: {
244256
args: spec.authArgs,
245257
cwd: input.cwd,
246258
allowNonZeroExit: true,
247-
timeoutMs: 5_000,
259+
timeoutMs: CLI_PROBE_TIMEOUT_MS,
248260
maxOutputBytes: 8_000,
249261
appendTruncationMarker: true,
250262
})
@@ -287,7 +299,7 @@ export const refineUnknownRemoteProvider = Effect.fn("refineUnknownRemoteProvide
287299
args: spec.authArgs,
288300
cwd: input.cwd,
289301
allowNonZeroExit: true,
290-
timeoutMs: 5_000,
302+
timeoutMs: CLI_PROBE_TIMEOUT_MS,
291303
maxOutputBytes: 8_000,
292304
appendTruncationMarker: true,
293305
})

0 commit comments

Comments
 (0)