Skip to content

Commit 65af8f8

Browse files
committed
fix(claude): report unknown auth when init carries no account metadata
1 parent 711ae06 commit 65af8f8

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeProvider.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,18 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
543543
const slashCommands = [COMPACT_SLASH_COMMAND, ...(capabilities?.slashCommands ?? [])];
544544
const dedupedSlashCommands = dedupeSlashCommands(slashCommands);
545545

546-
if (!capabilities) {
546+
// Account metadata is how the CLI tells us who it is signed in as. An init
547+
// without any of it (older CLIs, or an SDK/CLI mismatch) cannot be trusted
548+
// as authenticated, so it lands on the same unverified status as a failed
549+
// probe.
550+
const hasAccountMetadata =
551+
capabilities !== undefined &&
552+
(capabilities.email !== undefined ||
553+
capabilities.tokenSource !== undefined ||
554+
capabilities.apiKeySource !== undefined ||
555+
capabilities.subscriptionType !== undefined ||
556+
capabilities.apiProvider !== undefined);
557+
if (!capabilities || !hasAccountMetadata) {
547558
return buildServerProvider({
548559
presentation: CLAUDE_PRESENTATION,
549560
enabled: claudeSettings.enabled,

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
26512651
Effect.gen(function* () {
26522652
const status = yield* checkClaudeProviderStatus(
26532653
defaultClaudeSettings,
2654-
claudeCapabilities(),
2654+
claudeCapabilities({ tokenSource: "oauth" }),
26552655
);
26562656
assert.strictEqual(status.status, "ready");
26572657
assert.strictEqual(status.installed, true);
@@ -2768,6 +2768,25 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
27682768
),
27692769
);
27702770

2771+
it.effect("reports unknown auth when the initialization result has no account metadata", () =>
2772+
Effect.gen(function* () {
2773+
const status = yield* checkClaudeProviderStatus(
2774+
defaultClaudeSettings,
2775+
claudeCapabilities(),
2776+
);
2777+
assert.strictEqual(status.status, "warning");
2778+
assert.strictEqual(status.auth.status, "unknown");
2779+
}).pipe(
2780+
Effect.provide(
2781+
mockSpawnerLayer((args) => {
2782+
const joined = args.join(" ");
2783+
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
2784+
throw new Error(`Unexpected args: ${joined}`);
2785+
}),
2786+
),
2787+
),
2788+
);
2789+
27712790
it.effect("reports unauthenticated when the first-party CLI is logged out", () =>
27722791
Effect.gen(function* () {
27732792
const status = yield* checkClaudeProviderStatus(
@@ -2858,7 +2877,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
28582877
...defaultClaudeSettings,
28592878
homePath: claudeConfigDir,
28602879
},
2861-
claudeCapabilities(),
2880+
claudeCapabilities({ tokenSource: "oauth" }),
28622881
);
28632882
assert.strictEqual(status.status, "ready");
28642883
// The home is resolved through the host Path before it reaches the env.

0 commit comments

Comments
 (0)