mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-07-09 17:18:24 +00:00
122 lines
5 KiB
JavaScript
122 lines
5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import {
|
|
buildProfileLaunchPlan,
|
|
ccrManagedProfileDir,
|
|
defaultProfileOpenSurface,
|
|
findProfileForOpen,
|
|
profileOpenCommand,
|
|
profileOpenSurfaces,
|
|
resolveClaudeCodeSettingsFile,
|
|
resolveCodexConfigFile,
|
|
resolveProfileOpenSurface
|
|
} from "../../src/main/profile-launch-core.ts";
|
|
|
|
const claudeProfile = {
|
|
agent: "claude-code",
|
|
enabled: true,
|
|
id: "claude-main",
|
|
model: "provider,model",
|
|
name: "Claude Main",
|
|
scope: "ccr",
|
|
smallFastModel: "provider,small",
|
|
surface: "auto"
|
|
};
|
|
|
|
const codexProfile = {
|
|
agent: "codex",
|
|
enabled: true,
|
|
id: "codex-main",
|
|
model: "provider,model",
|
|
name: "Codex Main",
|
|
providerId: "openai-codex",
|
|
scope: "ccr",
|
|
surface: "auto"
|
|
};
|
|
|
|
test("findProfileForOpen resolves enabled profiles and reports ambiguous names", () => {
|
|
const config = {
|
|
profile: {
|
|
profiles: [
|
|
claudeProfile,
|
|
{ ...claudeProfile, enabled: false, id: "disabled", name: "Disabled" },
|
|
{ ...codexProfile, id: "duplicate-a", name: "Duplicate Name" },
|
|
{ ...codexProfile, id: "duplicate-b", name: "duplicate name" }
|
|
]
|
|
}
|
|
};
|
|
|
|
assert.equal(findProfileForOpen(config, "claude-main").id, "claude-main");
|
|
assert.equal(findProfileForOpen(config, "claude main").id, "claude-main");
|
|
assert.throws(() => findProfileForOpen(config, "duplicate name"), /ambiguous/);
|
|
assert.throws(() => findProfileForOpen(config, "Disabled"), /not found or is disabled/);
|
|
});
|
|
|
|
test("profile open surfaces enforce agent capabilities", () => {
|
|
assert.deepEqual(profileOpenSurfaces(claudeProfile), ["cli", "app"]);
|
|
assert.deepEqual(profileOpenSurfaces({ ...claudeProfile, surface: "cli" }), ["cli"]);
|
|
assert.deepEqual(profileOpenSurfaces({ ...codexProfile, agent: "zcode" }), ["app"]);
|
|
assert.equal(resolveProfileOpenSurface(codexProfile, "app"), "app");
|
|
assert.throws(() => resolveProfileOpenSurface({ ...claudeProfile, surface: "cli" }, "app"), /does not support APP/);
|
|
});
|
|
|
|
test("default profile command surface is CLI unless the agent is app-only", () => {
|
|
assert.equal(defaultProfileOpenSurface(claudeProfile), "cli");
|
|
assert.equal(defaultProfileOpenSurface(codexProfile), "cli");
|
|
assert.equal(defaultProfileOpenSurface({ ...codexProfile, surface: "app" }), "cli");
|
|
assert.equal(defaultProfileOpenSurface({ ...codexProfile, agent: "zcode" }), "app");
|
|
});
|
|
|
|
test("buildProfileLaunchPlan creates CCR-managed launcher paths", () => {
|
|
const configDir = path.join(path.sep, "tmp", "ccr-config");
|
|
const codexPlan = buildProfileLaunchPlan(configDir, codexProfile, "app");
|
|
const claudePlan = buildProfileLaunchPlan(configDir, claudeProfile, "cli", ["--debug"]);
|
|
|
|
assert.equal(codexPlan.surface, "app");
|
|
assert.deepEqual(codexPlan.args, ["app"]);
|
|
assert.equal(path.basename(codexPlan.command), process.platform === "win32" ? "ccr-codex-cli-stdio-codex-main.cmd" : "ccr-codex-cli-stdio-codex-main");
|
|
assert.equal(codexPlan.env.CCR_PROFILE_SURFACE, "app");
|
|
|
|
assert.equal(claudePlan.surface, "cli");
|
|
assert.deepEqual(claudePlan.args, ["--debug"]);
|
|
assert.equal(path.basename(claudePlan.command), process.platform === "win32" ? "ccr-claude-code-wrapper-claude-main.cmd" : "ccr-claude-code-wrapper-claude-main");
|
|
assert.equal(claudePlan.env.CCR_PROFILE_SURFACE, "cli");
|
|
assert.match(claudePlan.env.CLAUDE_CONFIG_DIR, /claude$/);
|
|
assert.equal(claudePlan.env.ANTHROPIC_MODEL, "provider/model");
|
|
assert.equal(claudePlan.env.CCR_CLAUDE_CODE_MODEL, "provider/model");
|
|
assert.equal(claudePlan.env.CODEXL_CLAUDE_CODE_MODEL, "provider/model");
|
|
assert.equal(claudePlan.env.ANTHROPIC_SMALL_FAST_MODEL, "provider/small");
|
|
|
|
assert.throws(() => buildProfileLaunchPlan(configDir, claudeProfile, "app"), /Claude App opening/);
|
|
});
|
|
|
|
test("profile config paths honor CCR, custom, and global scopes", () => {
|
|
const configDir = path.join(path.sep, "tmp", "ccr-config");
|
|
const customProfile = { ...codexProfile, id: "Custom Profile", scope: "custom" };
|
|
const globalCodex = { ...codexProfile, codexHome: "~/codex-home", scope: "global" };
|
|
|
|
assert.equal(
|
|
ccrManagedProfileDir(configDir, customProfile),
|
|
path.join(configDir, "profiles", "custom-profile", "custom")
|
|
);
|
|
assert.equal(
|
|
resolveClaudeCodeSettingsFile(configDir, claudeProfile),
|
|
path.join(configDir, "profiles", "claude-main", "claude", "settings.json")
|
|
);
|
|
assert.equal(
|
|
resolveCodexConfigFile(configDir, customProfile),
|
|
path.join(configDir, "profiles", "custom-profile", "custom", "codex", "config.toml")
|
|
);
|
|
assert.equal(resolveCodexConfigFile(configDir, globalCodex), path.join(process.env.HOME, "codex-home", "config.toml"));
|
|
});
|
|
|
|
test("profileOpenCommand quotes profile references for shell usage", () => {
|
|
const cliCommand = profileOpenCommand(claudeProfile, "cli", "ccr", "Claude Main");
|
|
const appCommand = profileOpenCommand(codexProfile, "app", "ccr", "Codex Main");
|
|
|
|
assert.match(cliCommand, /Claude/);
|
|
assert.match(cliCommand, /Main/);
|
|
assert.equal(cliCommand.endsWith(" cli"), false);
|
|
assert.match(appCommand, / app$/);
|
|
});
|