426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
255 lines
8.1 KiB
TypeScript
255 lines
8.1 KiB
TypeScript
/**
|
|
* Verifies isMultiAccountAgentType.
|
|
* Deterministic unit test with a stubbed runtime; no live model.
|
|
*/
|
|
import { CODING_AGENT_SELECTOR_BRIDGE_SYMBOL as BRIDGE_SYMBOL } from "@elizaos/core";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
accountMetaFromSessionMetadata,
|
|
classifyAccountFailure,
|
|
diagnoseCodingAccountFallback,
|
|
getCodingAccountBridge,
|
|
isMultiAccountAgentType,
|
|
isTokenExpiryText,
|
|
resolveCodingAccountStrategy,
|
|
selectCodingAccount,
|
|
} from "../../src/services/coding-account-selection.js";
|
|
|
|
function clearBridge() {
|
|
delete (globalThis as Record<symbol, unknown>)[BRIDGE_SYMBOL];
|
|
}
|
|
|
|
afterEach(clearBridge);
|
|
|
|
describe("isMultiAccountAgentType", () => {
|
|
it("is true for pool-rotated coding agents (claude/codex + opencode→cerebras)", () => {
|
|
for (const t of ["claude", "codex", "opencode", "CLAUDE", "Codex"]) {
|
|
expect(isMultiAccountAgentType(t)).toBe(true);
|
|
}
|
|
});
|
|
it("is false for runtime/local agents and providers without a coding CLI", () => {
|
|
// elizaos/pi-agent authenticate via their own backend; z.ai/kimi/glm have
|
|
// no first-party coding CLI to spawn.
|
|
for (const t of ["elizaos", "pi-agent", "zai", "glm", "kimi", ""]) {
|
|
expect(isMultiAccountAgentType(t)).toBe(false);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("resolveCodingAccountStrategy", () => {
|
|
it("normalizes known strategies", () => {
|
|
expect(resolveCodingAccountStrategy("least-used")).toBe("least-used");
|
|
expect(resolveCodingAccountStrategy(" Round-Robin ")).toBe("round-robin");
|
|
expect(resolveCodingAccountStrategy("priority")).toBe("priority");
|
|
expect(resolveCodingAccountStrategy("quota-aware")).toBe("quota-aware");
|
|
});
|
|
it("returns undefined for unknown / empty", () => {
|
|
expect(resolveCodingAccountStrategy("nonsense")).toBeUndefined();
|
|
expect(resolveCodingAccountStrategy(undefined)).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("accountMetaFromSessionMetadata", () => {
|
|
it("parses a stamped account", () => {
|
|
const meta = accountMetaFromSessionMetadata({
|
|
account: {
|
|
providerId: "openai-codex",
|
|
accountId: "acc-1",
|
|
label: "Personal",
|
|
source: "oauth",
|
|
strategy: "least-used",
|
|
},
|
|
});
|
|
expect(meta).toEqual({
|
|
providerId: "openai-codex",
|
|
accountId: "acc-1",
|
|
label: "Personal",
|
|
source: "oauth",
|
|
strategy: "least-used",
|
|
});
|
|
});
|
|
it("returns null when absent or malformed", () => {
|
|
expect(accountMetaFromSessionMetadata(undefined)).toBeNull();
|
|
expect(accountMetaFromSessionMetadata({})).toBeNull();
|
|
expect(
|
|
accountMetaFromSessionMetadata({ account: { providerId: 1 } }),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("selectCodingAccount", () => {
|
|
it("returns null when no bridge is installed", async () => {
|
|
clearBridge();
|
|
expect(getCodingAccountBridge()).toBeNull();
|
|
expect(await selectCodingAccount("claude", {})).toBeNull();
|
|
});
|
|
|
|
it("returns null for non-multi-account agent types even with a bridge", async () => {
|
|
const select = vi.fn(async () => ({
|
|
providerId: "anthropic-subscription",
|
|
accountId: "x",
|
|
label: "x",
|
|
source: "oauth" as const,
|
|
strategy: "least-used",
|
|
envPatch: { CLAUDE_CODE_OAUTH_TOKEN: "t" },
|
|
}));
|
|
(globalThis as Record<symbol, unknown>)[BRIDGE_SYMBOL] = { select };
|
|
expect(await selectCodingAccount("elizaos", {})).toBeNull();
|
|
expect(select).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("returns the bridge selection + non-secret meta for a coding agent", async () => {
|
|
(globalThis as Record<symbol, unknown>)[BRIDGE_SYMBOL] = {
|
|
select: vi.fn(async () => ({
|
|
providerId: "anthropic-subscription",
|
|
accountId: "acc-work",
|
|
label: "Work",
|
|
source: "oauth" as const,
|
|
strategy: "least-used",
|
|
envPatch: { CLAUDE_CODE_OAUTH_TOKEN: "sk-ant-oat-X" },
|
|
})),
|
|
};
|
|
const resolved = await selectCodingAccount("claude", { sessionKey: "s1" });
|
|
expect(resolved?.selection.envPatch.CLAUDE_CODE_OAUTH_TOKEN).toBe(
|
|
"sk-ant-oat-X",
|
|
);
|
|
expect(resolved?.meta).toEqual({
|
|
providerId: "anthropic-subscription",
|
|
accountId: "acc-work",
|
|
label: "Work",
|
|
source: "oauth",
|
|
strategy: "least-used",
|
|
});
|
|
// meta carries no secret
|
|
expect(JSON.stringify(resolved?.meta)).not.toContain("sk-ant-oat-X");
|
|
});
|
|
|
|
it("never throws when the bridge select rejects", async () => {
|
|
(globalThis as Record<symbol, unknown>)[BRIDGE_SYMBOL] = {
|
|
select: vi.fn(async () => {
|
|
throw new Error("pool exploded");
|
|
}),
|
|
};
|
|
expect(await selectCodingAccount("codex", {})).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("diagnoseCodingAccountFallback (#9960 loud degradation)", () => {
|
|
function installDescribe(
|
|
describe: () => Record<
|
|
string,
|
|
{ providerId: string; total: number; enabled: number; healthy: number }[]
|
|
>,
|
|
) {
|
|
(globalThis as Record<symbol, unknown>)[BRIDGE_SYMBOL] = { describe };
|
|
}
|
|
|
|
it("is silent for a benign empty/single-account host (no bridge, no accounts)", () => {
|
|
clearBridge();
|
|
expect(diagnoseCodingAccountFallback("claude")).toBeNull();
|
|
installDescribe(() => ({
|
|
claude: [
|
|
{
|
|
providerId: "anthropic-subscription",
|
|
total: 0,
|
|
enabled: 0,
|
|
healthy: 0,
|
|
},
|
|
],
|
|
}));
|
|
// Zero accounts connected → single-account by choice, not a misconfig.
|
|
expect(diagnoseCodingAccountFallback("claude")).toBeNull();
|
|
});
|
|
|
|
it("is silent for non-multi-account agent types", () => {
|
|
installDescribe(() => ({
|
|
claude: [
|
|
{
|
|
providerId: "anthropic-subscription",
|
|
total: 2,
|
|
enabled: 0,
|
|
healthy: 0,
|
|
},
|
|
],
|
|
}));
|
|
expect(diagnoseCodingAccountFallback("elizaos")).toBeNull();
|
|
});
|
|
|
|
it("warns loudly when accounts are connected but NONE are healthy", () => {
|
|
installDescribe(() => ({
|
|
codex: [
|
|
{ providerId: "openai-codex", total: 2, enabled: 2, healthy: 0 },
|
|
{ providerId: "openai-api", total: 0, enabled: 0, healthy: 0 },
|
|
],
|
|
}));
|
|
const msg = diagnoseCodingAccountFallback("codex");
|
|
expect(msg).toContain("codex");
|
|
expect(msg).toContain("2 account(s) connected but 0 healthy");
|
|
expect(msg).toContain("single-account credentials");
|
|
});
|
|
|
|
it("stays silent when at least one account is healthy (rotation works)", () => {
|
|
installDescribe(() => ({
|
|
claude: [
|
|
{
|
|
providerId: "anthropic-subscription",
|
|
total: 2,
|
|
enabled: 2,
|
|
healthy: 1,
|
|
},
|
|
],
|
|
}));
|
|
expect(diagnoseCodingAccountFallback("claude")).toBeNull();
|
|
});
|
|
|
|
it("never throws when describe() throws", () => {
|
|
installDescribe(() => {
|
|
throw new Error("describe exploded");
|
|
});
|
|
expect(diagnoseCodingAccountFallback("codex")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("isTokenExpiryText", () => {
|
|
it("detects explicit injected-token expiry phrasing", () => {
|
|
for (const phrase of [
|
|
"OAuth token has expired",
|
|
"access token expired",
|
|
"the token is expired",
|
|
"jwt expired",
|
|
"session expired",
|
|
"expired_token from provider",
|
|
"Error 401: token expired, refresh required",
|
|
]) {
|
|
expect(isTokenExpiryText(phrase)).toBe(true);
|
|
}
|
|
});
|
|
|
|
it("does NOT treat a bare auth failure as a token-expiry (stays needs-reauth)", () => {
|
|
for (const phrase of [
|
|
"401 Unauthorized",
|
|
"invalid_grant",
|
|
"please re-authenticate",
|
|
"revoked credential",
|
|
"authentication failed",
|
|
]) {
|
|
expect(isTokenExpiryText(phrase)).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("is false/empty-safe on nullish input", () => {
|
|
expect(isTokenExpiryText("")).toBe(false);
|
|
expect(isTokenExpiryText(null)).toBe(false);
|
|
expect(isTokenExpiryText(undefined)).toBe(false);
|
|
});
|
|
|
|
it("a token-expiry message is still an auth-shaped failure for the pool", () => {
|
|
// The typed reason REFINES an auth failure; it must not change that the
|
|
// pool still classifies it as needs-reauth (so account-health marking and
|
|
// the router's failover keep working).
|
|
expect(classifyAccountFailure("oauth token has expired")).toBe(
|
|
"needs-reauth",
|
|
);
|
|
});
|
|
});
|