Files
ai_ops/tests/config.test.ts

62 lines
2.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { buildClaudeAuthEnv, loadConfig, resolveAnthropicToken } from "../src/config.js";
test("loads defaults and freezes config", () => {
const config = loadConfig({});
assert.equal(config.agentManager.maxConcurrentAgents, 4);
assert.equal(config.orchestration.maxDepth, 4);
assert.equal(config.provisioning.portRange.basePort, 36000);
assert.equal(config.discovery.fileRelativePath, ".agent-context/resources.json");
assert.equal(config.security.violationHandling, "hard_abort");
assert.equal(config.security.commandTimeoutMs, 120000);
assert.equal(Object.isFrozen(config), true);
assert.equal(Object.isFrozen(config.orchestration), true);
});
test("validates boolean env values", () => {
assert.throws(
() => loadConfig({ CODEX_SKIP_GIT_CHECK: "maybe" }),
/must be "true" or "false"/,
);
});
test("validates security violation mode", () => {
assert.throws(
() => loadConfig({ AGENT_SECURITY_VIOLATION_MODE: "retry_forever" }),
/invalid_union|Invalid input/i,
);
});
test("prefers CLAUDE_CODE_OAUTH_TOKEN over ANTHROPIC_API_KEY", () => {
const config = loadConfig({
CLAUDE_CODE_OAUTH_TOKEN: "oauth-token",
ANTHROPIC_API_KEY: "api-key",
});
assert.equal(config.provider.anthropicOauthToken, "oauth-token");
assert.equal(config.provider.anthropicApiKey, "api-key");
assert.equal(config.provider.anthropicToken, "oauth-token");
assert.equal(resolveAnthropicToken(config.provider), "oauth-token");
const authEnv = buildClaudeAuthEnv(config.provider);
assert.equal(authEnv.CLAUDE_CODE_OAUTH_TOKEN, "oauth-token");
assert.equal(authEnv.ANTHROPIC_API_KEY, undefined);
});
test("falls back to ANTHROPIC_API_KEY when oauth token is absent", () => {
const config = loadConfig({
ANTHROPIC_API_KEY: "api-key",
});
assert.equal(config.provider.anthropicOauthToken, undefined);
assert.equal(config.provider.anthropicApiKey, "api-key");
assert.equal(config.provider.anthropicToken, "api-key");
assert.equal(resolveAnthropicToken(config.provider), "api-key");
const authEnv = buildClaudeAuthEnv(config.provider);
assert.equal(authEnv.CLAUDE_CODE_OAUTH_TOKEN, undefined);
assert.equal(authEnv.ANTHROPIC_API_KEY, "api-key");
});