From 139e24c87f75cc9cd8c096c8ecf09233959680ea Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 04:38:38 +0000 Subject: [PATCH 1/4] test(github): reproduce #29056 failed spans from the unknown-remote probe These tests reproduce #29056: resolving an unknown host that gh is not signed in to returns null, but GitHubRest.credential, GitHubCredentials.get and GitHubCredentials.lookup still end with a Failure exit. Co-Authored-By: Claude Opus 5.5 --- .../src/server/gitHubDiscovery.test.ts | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/source-control-github/src/server/gitHubDiscovery.test.ts b/packages/source-control-github/src/server/gitHubDiscovery.test.ts index cd8a838b2372..57013a309ae0 100644 --- a/packages/source-control-github/src/server/gitHubDiscovery.test.ts +++ b/packages/source-control-github/src/server/gitHubDiscovery.test.ts @@ -1,13 +1,19 @@ -import { SourceControlProviderKind } from "@t3tools/contracts"; +import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; +import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; +import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; import { assert, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; import * as Layer from "effect/Layer"; import * as Redacted from "effect/Redacted"; +import * as Tracer from "effect/Tracer"; +import { HttpClient } from "effect/http"; import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost"; import * as GitHubCredentials from "./GitHubCredentials.ts"; import * as GitHubAppSignIn from "./GitHubAppSignIn.ts"; +import * as GitHubQuota from "./GitHubQuota.ts"; import * as GitHubRest from "./GitHubRest.ts"; import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts"; @@ -79,3 +85,65 @@ it.effect("asks for no credential when the identity resolver left the base URL e assert.deepStrictEqual(hosts, []); }), ); + +it.effect("records no failed span when gh is not signed in to an unknown host", () => + Effect.gen(function* () { + const spans: Array = []; + const tracer = Tracer.make({ + span: (options) => { + const span = new Tracer.NativeSpan(options); + spans.push(span); + return span; + }, + }); + const host = TestSourceControlHost.layer({ + process: { + run: (input) => + Effect.fail( + new VcsProcessExitError({ + operation: input.operation, + command: input.command, + cwd: input.cwd, + exitCode: 1, + detail: "no oauth token found for code.example.test", + }), + ), + }, + }); + const discovery = yield* GitHubSourceControlProvider.makeDiscovery.pipe( + Effect.provide( + GitHubRest.layer.pipe( + Layer.provideMerge(GitHubCredentials.layer), + Layer.provideMerge( + Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({ + enabled: false, + token: () => Effect.succeedNone, + }), + ), + Layer.provideMerge(GitHubQuota.layer), + Layer.provideMerge(SourceControlRateLimit.layer), + Layer.provideMerge(host), + Layer.provide(NodeCrypto.layer), + Layer.provide( + Layer.succeed( + HttpClient.HttpClient, + HttpClient.make((request) => Effect.die(`Unexpected request to ${request.url}`)), + ), + ), + ), + ), + Effect.provideService(HostProcess.Environment, {}), + ); + if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI"); + const provider = yield* discovery + .refineUnknownRemote({ cwd: "/repo", context: unknownContext("https://code.example.test") }) + .pipe(Effect.withTracer(tracer)); + assert.strictEqual(provider, null); + assert.deepStrictEqual( + spans.flatMap((span) => + span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [], + ), + [], + ); + }), +); From 35239945b0c36b94d62fa12f1351f0add170f124 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 04:42:20 +0000 Subject: [PATCH 2/4] fix(github): unknown-remote probe no longer records failed credential spans Resolving an unknown host ran gh auth token for it, and the expected not-signed-in exit was recorded as failed GitHubRest.credential, GitHubCredentials.get/lookup and VcsProcess spans, which Diagnostics counted on every re-probe. Run the probe's credential lookup with the tracer disabled; its answers and normal callers' spans are unchanged. Fixes pingdotgg/t3code#29056 Co-Authored-By: Claude Opus 5.5 --- .../src/server/GitHubSourceControlProvider.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts index bc0438cf41b6..8471d0c3dc58 100644 --- a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts +++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts @@ -297,6 +297,8 @@ export const makeDiscovery = Effect.gen(function* () { if (!url?.host) return Effect.succeed(null); // A timeout or keyring failure propagates: the registry does not keep that answer. return api.credential(url.host).pipe( + // Most unknown hosts are not GitHub, so a missing credential is not a failure to trace. + Effect.withTracerEnabled(false), Effect.as(true), Effect.catchTags({ GitHubCliMissingError: () => Effect.succeed(false), From f40ccd29c900a483606111a562b891c903a0069c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 04:51:53 +0000 Subject: [PATCH 3/4] 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 --- .../src/server/GitHubSourceControlProvider.ts | 28 ++++----- .../src/server/gitHubDiscovery.test.ts | 63 +++++++++++-------- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts index 8471d0c3dc58..d5af172a506a 100644 --- a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts +++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts @@ -292,12 +292,14 @@ export const makeDiscovery = Effect.gen(function* () { } satisfies SourceControlProviderDiscoveryItem); }), // Claim disabled hosts so errors identify the setting. - refineUnknownRemote: ({ context }) => { + refineUnknownRemote: Effect.fn("GitHubSourceControlProvider.refineUnknownRemote")(function* ({ + context, + }) { const url = URL.parse(context.provider.baseUrl); - if (!url?.host) return Effect.succeed(null); + if (!url?.host) return null; // A timeout or keyring failure propagates: the registry does not keep that answer. - return api.credential(url.host).pipe( - // Most unknown hosts are not GitHub, so a missing credential is not a failure to trace. + const known = yield* api.credential(url.host).pipe( + // Most unknown hosts are not GitHub: only this span records a failure, and only a real one. Effect.withTracerEnabled(false), Effect.as(true), Effect.catchTags({ @@ -305,17 +307,15 @@ export const makeDiscovery = Effect.gen(function* () { GitHubHostDisabledError: () => Effect.succeed(true), GitHubNotSignedInError: () => Effect.succeed(false), }), - Effect.map((known) => - known - ? ({ - kind: SourceControlProviderKind.make("github"), - name: "GitHub Self-Hosted", - baseUrl: context.provider.baseUrl, - } as const) - : null, - ), ); - }, + return known + ? ({ + kind: SourceControlProviderKind.make("github"), + name: "GitHub Self-Hosted", + baseUrl: context.provider.baseUrl, + } as const) + : null; + }), } satisfies SourceControlManagedCliDiscoverySpec; }); diff --git a/packages/source-control-github/src/server/gitHubDiscovery.test.ts b/packages/source-control-github/src/server/gitHubDiscovery.test.ts index 57013a309ae0..362d48596613 100644 --- a/packages/source-control-github/src/server/gitHubDiscovery.test.ts +++ b/packages/source-control-github/src/server/gitHubDiscovery.test.ts @@ -1,5 +1,9 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; -import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts"; +import { + SourceControlProviderKind, + VcsProcessExitError, + VcsProcessTimeoutError, +} from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; 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 }), ); -it.effect("records no failed span when gh is not signed in to an unknown host", () => +const probeWithGhFailure = (error: VcsProcessExitError | VcsProcessTimeoutError) => Effect.gen(function* () { const spans: Array = []; const tracer = Tracer.make({ @@ -96,20 +100,7 @@ it.effect("records no failed span when gh is not signed in to an unknown host", return span; }, }); - const host = TestSourceControlHost.layer({ - process: { - run: (input) => - Effect.fail( - new VcsProcessExitError({ - operation: input.operation, - command: input.command, - cwd: input.cwd, - exitCode: 1, - detail: "no oauth token found for code.example.test", - }), - ), - }, - }); + const host = TestSourceControlHost.layer({ process: { run: () => Effect.fail(error) } }); const discovery = yield* GitHubSourceControlProvider.makeDiscovery.pipe( Effect.provide( GitHubRest.layer.pipe( @@ -134,16 +125,38 @@ it.effect("records no failed span when gh is not signed in to an unknown host", ), Effect.provideService(HostProcess.Environment, {}), ); - if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI"); - const provider = yield* discovery + if (discovery.type !== "managed-cli") return yield* Effect.die("expected a managed CLI"); + const exit = yield* discovery .refineUnknownRemote({ cwd: "/repo", context: unknownContext("https://code.example.test") }) - .pipe(Effect.withTracer(tracer)); - assert.strictEqual(provider, null); - assert.deepStrictEqual( - spans.flatMap((span) => - span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [], - ), - [], + .pipe(Effect.withTracer(tracer), Effect.exit); + const failedSpans = spans.flatMap((span) => + span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [], + ); + return { exit, failedSpans }; + }); + +const ghCommand = { operation: "GitHubCredentials.get", command: "gh", cwd: "/repo" }; + +it.effect("records no failed span when gh is not signed in to an unknown host", () => + Effect.gen(function* () { + const { exit, failedSpans } = yield* probeWithGhFailure( + new VcsProcessExitError({ + ...ghCommand, + exitCode: 1, + detail: "no oauth token found for code.example.test", + }), + ); + assert.deepStrictEqual(exit, Exit.succeed(null)); + assert.deepStrictEqual(failedSpans, []); + }), +); + +it.effect("records a failed probe span when gh times out for an unknown host", () => + Effect.gen(function* () { + const { exit, failedSpans } = yield* probeWithGhFailure( + new VcsProcessTimeoutError({ ...ghCommand, timeoutMs: 10_000 }), ); + assert.isTrue(Exit.isFailure(exit)); + assert.deepStrictEqual(failedSpans, ["GitHubSourceControlProvider.refineUnknownRemote"]); }), ); From 79c6fae34db4a37955921f63b94011fa810f4f71 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 00:58:19 +0000 Subject: [PATCH 4/4] test(github): cover the unknown-host probe spans with the existing discovery mock AI-assisted; verified with the tests and tools listed above. --- .../src/server/gitHubDiscovery.test.ts | 90 +++++++------------ 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/packages/source-control-github/src/server/gitHubDiscovery.test.ts b/packages/source-control-github/src/server/gitHubDiscovery.test.ts index 948d3282a896..9b0b00cd5b68 100644 --- a/packages/source-control-github/src/server/gitHubDiscovery.test.ts +++ b/packages/source-control-github/src/server/gitHubDiscovery.test.ts @@ -1,12 +1,9 @@ -import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import { ServerSettings, SourceControlProviderKind, - VcsProcessExitError, VcsProcessTimeoutError, } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; -import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; import { assert, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; @@ -15,14 +12,12 @@ import * as Option from "effect/Option"; import * as Redacted from "effect/Redacted"; import * as Schema from "effect/Schema"; import * as Tracer from "effect/Tracer"; -import { HttpClient } from "effect/http"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost"; import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost"; import * as GitHubCredentials from "./GitHubCredentials.ts"; import * as GitHubAppSignIn from "./GitHubAppSignIn.ts"; -import * as GitHubQuota from "./GitHubQuota.ts"; import * as GitHubRest from "./GitHubRest.ts"; import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts"; @@ -192,7 +187,27 @@ it.effect.each([ }), ); -const probeWithGhFailure = (error: VcsProcessExitError | VcsProcessTimeoutError) => +it.effect.each([ + { + name: "no failed span when gh is not signed in", + error: (host: string) => new GitHubCredentials.GitHubNotSignedInError({ host }), + failedSpans: [], + }, + { + name: "a failed probe span when the lookup fails for real", + error: (host: string) => + new GitHubCredentials.GitHubCliFailedError({ + host, + cause: new VcsProcessTimeoutError({ + operation: "GitHubCredentials.get", + command: "gh", + cwd: "/repo", + timeoutMs: 10_000, + }), + }), + failedSpans: ["GitHubSourceControlProvider.refineUnknownRemote"], + }, +])("records $name for an unknown host", (scenario) => Effect.gen(function* () { const spans: Array = []; const tracer = Tracer.make({ @@ -202,63 +217,18 @@ const probeWithGhFailure = (error: VcsProcessExitError | VcsProcessTimeoutError) return span; }, }); - const host = TestSourceControlHost.layer({ process: { run: () => Effect.fail(error) } }); - const discovery = yield* GitHubSourceControlProvider.makeDiscovery.pipe( - Effect.provide( - GitHubRest.layer.pipe( - Layer.provideMerge(GitHubCredentials.layer), - Layer.provideMerge( - Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({ - enabled: false, - token: () => Effect.succeedNone, - }), - ), - Layer.provideMerge(GitHubQuota.layer), - Layer.provideMerge(SourceControlRateLimit.layer), - Layer.provideMerge(host), - Layer.provide(NodeCrypto.layer), - Layer.provide( - Layer.succeed( - HttpClient.HttpClient, - HttpClient.make((request) => Effect.die(`Unexpected request to ${request.url}`)), - ), - ), - ), - ), - Effect.provideService(HostProcess.Environment, {}), + const discovery = yield* makeDiscovery((host) => + Effect.fail(scenario.error(host)).pipe(Effect.withSpan("GitHubRest.credential")), ); - if (discovery.type !== "managed-cli") return yield* Effect.die("expected a managed CLI"); - const exit = yield* discovery + if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI"); + yield* discovery .refineUnknownRemote({ cwd: "/repo", context: unknownContext("https://code.example.test") }) .pipe(Effect.withTracer(tracer), Effect.exit); - const failedSpans = spans.flatMap((span) => - span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [], - ); - return { exit, failedSpans }; - }); - -const ghCommand = { operation: "GitHubCredentials.get", command: "gh", cwd: "/repo" }; - -it.effect("records no failed span when gh is not signed in to an unknown host", () => - Effect.gen(function* () { - const { exit, failedSpans } = yield* probeWithGhFailure( - new VcsProcessExitError({ - ...ghCommand, - exitCode: 1, - detail: "no oauth token found for code.example.test", - }), - ); - assert.deepStrictEqual(exit, Exit.succeed(null)); - assert.deepStrictEqual(failedSpans, []); - }), -); - -it.effect("records a failed probe span when gh times out for an unknown host", () => - Effect.gen(function* () { - const { exit, failedSpans } = yield* probeWithGhFailure( - new VcsProcessTimeoutError({ ...ghCommand, timeoutMs: 10_000 }), + assert.deepStrictEqual( + spans.flatMap((span) => + span.status._tag === "Ended" && Exit.isFailure(span.status.exit) ? [span.name] : [], + ), + scenario.failedSpans, ); - assert.isTrue(Exit.isFailure(exit)); - assert.deepStrictEqual(failedSpans, ["GitHubSourceControlProvider.refineUnknownRemote"]); }), );