Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): drop the thread's retry state when the endpoint folder can't be made; unit-test the folder step
AdityaUmale0c115a3f6a37
diff --git a/server/drivers/claude-endpoint-folder.test.ts b/server/drivers/claude-endpoint-folder.test.tsnew file mode 100644index 0000000000..34126c1161--- /dev/null+++ b/server/drivers/claude-endpoint-folder.test.ts@@ -0,0 +1,33 @@+import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { withEndpointFolder } from "./claude-endpoint-folder.ts";++describe("withEndpointFolder", () => {+ let scratch = "";+ beforeEach(() => { scratch = mkdtempSync(join(tmpdir(), "omb-endpoint-folder-")); });+ afterEach(() => rmSync(scratch, { recursive: true, force: true }));++ it("makes a missing custom endpoint folder, wherever it lives", () => {+ const dir = join(scratch, "providers", "claude-endpoint");+ const env = { CLAUDE_CONFIG_DIR: dir };+ expect(withEndpointFolder(env, { endpointModels: ["glm-test"], configDir: dir })).toBe(env);+ expect(existsSync(dir)).toBe(true);+ });++ it("leaves Claude accounts and the default Claude alone", () => {+ const dir = join(scratch, "providers", "claude-account");+ withEndpointFolder({ CLAUDE_CONFIG_DIR: dir }, { configDir: dir });+ expect(existsSync(dir)).toBe(false);+ });++ it("runs onFail before rethrowing a failed mkdir", () => {+ const file = join(scratch, "not-a-folder");+ writeFileSync(file, "");+ const dir = join(file, "claude-endpoint");+ const onFail = vi.fn();+ expect(() => withEndpointFolder({ CLAUDE_CONFIG_DIR: dir }, { endpointModels: ["glm-test"], configDir: dir }, onFail)).toThrow();+ expect(onFail).toHaveBeenCalledOnce();+ });+});diff --git a/server/drivers/claude-endpoint-folder.ts b/server/drivers/claude-endpoint-folder.tsindex 901f7450df..e2310dc76c 100644--- a/server/drivers/claude-endpoint-folder.ts+++ b/server/drivers/claude-endpoint-folder.ts@@ -4,10 +4,17 @@ import { mkdirSync } from "node:fs";* A custom endpoint (Settings > Custom endpoint) gets its own Claude folder under providers/, but no sign-in that would* make it. On a Cloud the bot box binds that folder as a required path, and bubblewrap stops the turn when it is missing* ("Can't find source path"), so it is made before every spawn. Claude accounts and the default Claude are untouched.+ * `onFail` runs before a failed mkdir is rethrown, so the caller can drop per-turn state it already recorded.*/export function withEndpointFolder<T extends Record<string, string | undefined>>(- env: T, config: { endpointModels?: unknown; configDir?: string },+ env: T, config: { endpointModels?: unknown; configDir?: string }, onFail?: () => void,): T {- if (config.endpointModels && config.configDir && env.CLAUDE_CONFIG_DIR) mkdirSync(env.CLAUDE_CONFIG_DIR, { recursive: true, mode: 0o700 });+ if (!config.endpointModels || !config.configDir || !env.CLAUDE_CONFIG_DIR) return env;+ try {+ mkdirSync(env.CLAUDE_CONFIG_DIR, { recursive: true, mode: 0o700 });+ } catch (error) {+ onFail?.();+ throw error;+ }return env;}diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex 57edac1535..fd2785ff67 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -1135,7 +1135,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {allowed.push("mcp__ogb", ...gateQueryTools(mcpServers));// A guest pre-allows only harness tools; anything else (the browser can open file:) asks.if (turn.guestConfined) allowed.splice(0, allowed.length, ...allowed.filter((name) => name === "mcp__ogb" || name === "mcp__agents"));- const env = withEndpointFolder(environment(config.endpointModels ? undefined : turnModel), config);+ const env = withEndpointFolder(environment(config.endpointModels ? undefined : turnModel), config, () => retryState.delete(threadId));// The MCP config carries credentials and argv is readable via `ps`: a 0600 file, removed at settle.let mcpConfigPath: string | null = null;if (Object.keys(mcpServers).length) {