refactor(coding-agent): remove test-only config cache reset APIs (#1849)
1- Removed internal test-only configuration cache reset hooks.3 unmodified lines456788910118 unmodified lines202122232524252627804 unmodified linesExpand all832833834835838839840841842843844845846847848849850851852853854855856857836837838839269 unmodified linesExpand all3 unmodified linesimport { registerOAuthProvider } from "@earendil-works/pi-ai/oauth";import lockfile from "proper-lockfile";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { AuthStorage } from "../src/core/auth-storage.js";import { clearConfigValueCache } from "../src/core/resolve-config-value.js";
describe("AuthStorage", () => { let tempDir: string; let authJsonPath: string;8 unmodified lines afterEach(() => { if (tempDir && existsSync(tempDir)) { rmSync(tempDir, { recursive: true }); } clearConfigValueCache(); vi.restoreAllMocks(); });
function writeAuthJson(data: Record<string, unknown>) {804 unmodified linesExpand all const count = parseInt(readFileSync(counterFile, "utf-8").trim(), 10); expect(count).toBe(1); });
test("clearConfigValueCache allows command to run again", async () => { const counterFile = join(tempDir, "counter"); writeFileSync(counterFile, "0");
const counterPath = toShPath(counterFile); const command = `!sh -c 'count=$(cat "${counterPath}"); echo $((count + 1)) > "${counterPath}"; echo "key-value"'`; writeAuthJson({ anthropic: { type: "api_key", key: command }, });
authStorage = AuthStorage.create(authJsonPath); await authStorage.getApiKey("anthropic");
clearConfigValueCache(); await authStorage.getApiKey("anthropic");
const count = parseInt(readFileSync(counterFile, "utf-8").trim(), 10); expect(count).toBe(2); });
test("different commands are cached separately", async () => { writeAuthJson({ anthropic: { type: "api_key", key: "!echo key-anthropic" }, openai: { type: "api_key", key: "!echo key-openai" },269 unmodified linesExpand all4 unmodified lines567899101112139 unmodified lines2324252627272829301628 unmodified linesExpand all4 unmodified linesimport { getApiProvider } from "@earendil-works/pi-ai";import { getOAuthProvider, registerOAuthProvider } from "@earendil-works/pi-ai/oauth";import { afterEach, beforeEach, describe, expect, test } from "vitest";import { AuthStorage } from "../src/core/auth-storage.js";import { clearApiKeyCache, ModelRegistry, type ProviderConfigInput } from "../src/core/model-registry.js";import { ModelRegistry, type ProviderConfigInput } from "../src/core/model-registry.js";
describe("ModelRegistry", () => { let tempDir: string; let modelsJsonPath: string;9 unmodified lines afterEach(() => { if (tempDir && existsSync(tempDir)) { rmSync(tempDir, { recursive: true }); } clearApiKeyCache(); });
function providerConfig( baseUrl: string,1628 unmodified linesExpand all35 unmodified lines363738394040414243303 unmodified linesExpand all3473483493503523533543513523533541239 unmodified linesExpand all35 unmodified lines isPrivatePrimeInferenceModel,} from "./prime-inference-models.js";import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "./provider-display-names.js";import { clearConfigValueCache, resolveConfigValueOrThrow, resolveConfigValueUncached, resolveHeadersOrThrow,} from "./resolve-config-value.js";303 unmodified linesExpand all
return result;}
/** Clear the config value command cache. Exported for testing. */export const clearApiKeyCache = clearConfigValueCache;
function readOpenAICodexAccountId(token: string): string | undefined { try { const payload = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString("utf8")) as { "https://api.openai.com/auth"?: { chatgpt_account_id?: unknown };1239 unmodified linesExpand all139 unmodified linesExpand all140141142143144145146147148139 unmodified linesExpand all resolved[key] = resolveConfigValueOrThrow(value, `${description} header "${key}"`); } return Object.keys(resolved).length > 0 ? resolved : undefined;}
/** Clear the config value command cache. Exported for testing. */export function clearConfigValueCache(): void { commandResultCache.clear();}