Skip to content

Commit f40ccd2

Browse files
fix(github): keep real failures of the unknown-remote probe in the trace
The probe gets its own span that catches the expected credential misses, so a gh timeout or keyring failure still records a failure there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3523994 commit f40ccd2

2 files changed

Lines changed: 52 additions & 39 deletions

File tree

‎packages/source-control-github/src/server/GitHubSourceControlProvider.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,30 @@ export const makeDiscovery = Effect.gen(function* () {
292292
} satisfies SourceControlProviderDiscoveryItem);
293293
}),
294294
// Claim disabled hosts so errors identify the setting.
295-
refineUnknownRemote: ({ context }) => {
295+
refineUnknownRemote: Effect.fn("GitHubSourceControlProvider.refineUnknownRemote")(function* ({
296+
context,
297+
}) {
296298
const url = URL.parse(context.provider.baseUrl);
297-
if (!url?.host) return Effect.succeed(null);
299+
if (!url?.host) return null;
298300
// A timeout or keyring failure propagates: the registry does not keep that answer.
299-
return api.credential(url.host).pipe(
300-
// Most unknown hosts are not GitHub, so a missing credential is not a failure to trace.
301+
const known = yield* api.credential(url.host).pipe(
302+
// Most unknown hosts are not GitHub: only this span records a failure, and only a real one.
301303
Effect.withTracerEnabled(false),
302304
Effect.as(true),
303305
Effect.catchTags({
304306
GitHubCliMissingError: () => Effect.succeed(false),
305307
GitHubHostDisabledError: () => Effect.succeed(true),
306308
GitHubNotSignedInError: () => Effect.succeed(false),
307309
}),
308-
Effect.map((known) =>
309-
known
310-
? ({
311-
kind: SourceControlProviderKind.make("github"),
312-
name: "GitHub Self-Hosted",
313-
baseUrl: context.provider.baseUrl,
314-
} as const)
315-
: null,
316-
),
317310
);
318-
},
311+
return known
312+
? ({
313+
kind: SourceControlProviderKind.make("github"),
314+
name: "GitHub Self-Hosted",
315+
baseUrl: context.provider.baseUrl,
316+
} as const)
317+
: null;
318+
}),
319319
} satisfies SourceControlManagedCliDiscoverySpec;
320320
});
321321

‎packages/source-control-github/src/server/gitHubDiscovery.test.ts‎

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2-
import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts";
2+
import {
3+
SourceControlProviderKind,
4+
VcsProcessExitError,
5+
VcsProcessTimeoutError,
6+
} from "@t3tools/contracts";
37
import * as HostProcess from "@t3tools/shared/HostProcess";
48
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
59
import { assert, it } from "@effect/vitest";
@@ -86,7 +90,7 @@ it.effect("asks for no credential when the identity resolver left the base URL e
8690
}),
8791
);
8892

89-
it.effect("records no failed span when gh is not signed in to an unknown host", () =>
93+
const probeWithGhFailure = (error: VcsProcessExitError | VcsProcessTimeoutError) =>
9094
Effect.gen(function* () {
9195
const spans: Array<Tracer.NativeSpan> = [];
9296
const tracer = Tracer.make({
@@ -96,20 +100,7 @@ it.effect("records no failed span when gh is not signed in to an unknown host",
96100
return span;
97101
},
98102
});
99-
const host = TestSourceControlHost.layer({
100-
process: {
101-
run: (input) =>
102-
Effect.fail(
103-
new VcsProcessExitError({
104-
operation: input.operation,
105-
command: input.command,
106-
cwd: input.cwd,
107-
exitCode: 1,
108-
detail: "no oauth token found for code.example.test",
109-
}),
110-
),
111-
},
112-
});
103+
const host = TestSourceControlHost.layer({ process: { run: () => Effect.fail(error) } });
113104
const discovery = yield* GitHubSourceControlProvider.makeDiscovery.pipe(
114105
Effect.provide(
115106
GitHubRest.layer.pipe(
@@ -134,16 +125,38 @@ it.effect("records no failed span when gh is not signed in to an unknown host",
134125
),
135126
Effect.provideService(HostProcess.Environment, {}),
136127
);
137-
if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI");
138-
const provider = yield* discovery
128+
if (discovery.type !== "managed-cli") return yield* Effect.die("expected a managed CLI");
129+
const exit = yield* discovery
139130
.refineUnknownRemote({ cwd: "/repo", context: unknownContext("https://code.example.test") })
140-
.pipe(Effect.withTracer(tracer));
141-
assert.strictEqual(provider, null);
142-
assert.deepStrictEqual(
143-
spans.flatMap((span) =>
144-
span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [],
145-
),
146-
[],
131+
.pipe(Effect.withTracer(tracer), Effect.exit);
132+
const failedSpans = spans.flatMap((span) =>
133+
span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [],
134+
);
135+
return { exit, failedSpans };
136+
});
137+
138+
const ghCommand = { operation: "GitHubCredentials.get", command: "gh", cwd: "/repo" };
139+
140+
it.effect("records no failed span when gh is not signed in to an unknown host", () =>
141+
Effect.gen(function* () {
142+
const { exit, failedSpans } = yield* probeWithGhFailure(
143+
new VcsProcessExitError({
144+
...ghCommand,
145+
exitCode: 1,
146+
detail: "no oauth token found for code.example.test",
147+
}),
148+
);
149+
assert.deepStrictEqual(exit, Exit.succeed(null));
150+
assert.deepStrictEqual(failedSpans, []);
151+
}),
152+
);
153+
154+
it.effect("records a failed probe span when gh times out for an unknown host", () =>
155+
Effect.gen(function* () {
156+
const { exit, failedSpans } = yield* probeWithGhFailure(
157+
new VcsProcessTimeoutError({ ...ghCommand, timeoutMs: 10_000 }),
147158
);
159+
assert.isTrue(Exit.isFailure(exit));
160+
assert.deepStrictEqual(failedSpans, ["GitHubSourceControlProvider.refineUnknownRemote"]);
148161
}),
149162
);

0 commit comments

Comments
 (0)