Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Treat an unreadable Claude sign-in check as unknown, not signed out
Klaus Singera46959d49293
diff --git a/server/drivers/claude-auth-status.ts b/server/drivers/claude-auth-status.tsindex 40e78817f3..6bd69d7071 100644--- a/server/drivers/claude-auth-status.ts+++ b/server/drivers/claude-auth-status.ts@@ -3,8 +3,9 @@ import type { ProviderSnapshot } from "../contracts.ts";import { execCli } from "../procs.ts";/** Whether `claude` is signed in, per the CLI's own `auth status`: credential storage varies by- * platform (Keychain, a JSON file) and presence checks accept stale credentials. A check that- * timed out (a Keychain prompt left open) says nothing, so `authenticated` is left out. */+ * platform (Keychain, a JSON file) and presence checks accept stale credentials. Only `loggedIn: false`+ * means signed out. A check that timed out (a Keychain prompt left open) or gave no readable status+ * says nothing, so `authenticated` is left out. */export function claudeAuthStatus(cli: string,env: NodeJS.ProcessEnv,@@ -15,9 +16,8 @@ export function claudeAuthStatus(if ((error as { killed?: boolean } | null)?.killed) return resolve({});try {const status: unknown = JSON.parse(stdout);- if (!status || typeof status !== "object" || !("loggedIn" in status) || status.loggedIn !== true) {- return resolve({ authenticated: false });- }+ const loggedIn = status && typeof status === "object" && "loggedIn" in status ? status.loggedIn : undefined;+ if (loggedIn !== true) return resolve(loggedIn === false ? { authenticated: false } : {});const identity = status as { email?: unknown; orgName?: unknown; authMethod?: unknown };const boundedText = (value: unknown, max: number): string | undefined =>typeof value === "string" && value.trim().length > 0 && value.length <= max && !/[\p{Cc}\p{Cf}]/u.test(value)@@ -32,7 +32,7 @@ export function claudeAuthStatus(};resolve({ authenticated: true, ...(Object.keys(account).length ? { account } : {}) });} catch {- resolve({ authenticated: false });+ resolve({});}});});diff --git a/server/drivers/claude-auth.test.ts b/server/drivers/claude-auth.test.tsindex 04b4bda6b5..81cb480c15 100644--- a/server/drivers/claude-auth.test.ts+++ b/server/drivers/claude-auth.test.ts@@ -1,7 +1,7 @@// These tests inject the CLI runner, so they never read or change the developer's real credentials.import { describe, expect, it } from "vitest";-import { claudeSignedIn } from "./claude-auth-status.ts";+import { claudeAuthStatus, claudeSignedIn } from "./claude-auth-status.ts";import { claudeAuthFailure } from "./claude-auth-recovery.ts";import { claudeVersionTooOld } from "./claude-limits.ts";import { claudeResultError } from "./claude.ts";@@ -28,16 +28,16 @@ describe("claudeSignedIn", () => {expect(await claudeSignedIn("claude", {}, run)).toBe(false);});- it("fails closed when the command has no valid status", async () => {- const failed = ((_cli, _args, _options, callback) => {- callback(new Error("auth status unavailable"), "");- }) satisfies typeof import("../procs.ts").execCli;- const malformed = ((_cli, _args, _options, callback) => {- callback(null, "not json");+ it("leaves sign-in unknown, not signed out, when the command gives no readable status", async () => {+ const answering = (error: Error | null, stdout: string) => ((_cli, _args, _options, callback) => {+ callback(error, stdout);}) satisfies typeof import("../procs.ts").execCli;- expect(await claudeSignedIn("claude", {}, failed)).toBe(false);- expect(await claudeSignedIn("claude", {}, malformed)).toBe(false);+ for (const [error, stdout] of [[new Error("auth status unavailable"), ""], [null, "not json"], [null, "null"], [null, "{}"], [null, '{"loggedIn":"yes"}']] as const) {+ expect(await claudeAuthStatus("claude", {}, answering(error, stdout)), stdout).toEqual({});+ expect(await claudeSignedIn("claude", {}, answering(error, stdout)), stdout).toBe(false);+ }+ expect(await claudeAuthStatus("claude", {}, answering(new Error("exit code 1"), '{"loggedIn":false}'))).toEqual({ authenticated: false });});});diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex d33d86e712..20f7ce4548 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -4265,14 +4265,16 @@ describe("ClaudeDriver snapshot auth (fake CLI)", () => {expect(await instance.snapshot()).toMatchObject({ state: "available", authenticated: false });});- it("fails closed instead of trusting stale credential storage", async () => {+ it("leaves an unreadable `auth status` unconfirmed instead of trusting stale credential storage", async () => {await create();process.env.FAKE_CLAUDE_AUTH = "unsupported";- expect(await instance.snapshot()).toMatchObject({ state: "available", authenticated: false });+ const unsupported = await instance.snapshot();+ expect(unsupported.state).toBe("available");+ expect(unsupported.authenticated).toBeUndefined();process.env.FAKE_CLAUDE_AUTH = "malformed";- expect(await instance.snapshot()).toMatchObject({ state: "available", authenticated: false });+ expect((await instance.snapshot()).authenticated).toBeUndefined();// The turn strips inherited API keys, so the auth probe must too.process.env.FAKE_CLAUDE_AUTH = "inherited-api-key";