Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/server/management/agent-settings-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,10 +948,16 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
const { parseDesktopProfile, reconcileDesktopProfile } = await import("../../claude/desktop-profile");
const parsed = parseDesktopProfile(body.profile);
const current = await buildClaudeDesktopState(config);
const availableRoutes = new Set(current.models.filter(item => item.available).map(item => item.route));
for (const route of Object.keys(parsed.assignments)) {
if (!current.profile.assignments[route] && !availableRoutes.has(route)) {
throw new Error(`현재 사용할 수 없는 모델은 추가할 수 없습니다: ${route}`);
}
}
for (const model of current.models.filter(item => !item.available)) {
const before = current.profile.assignments[model.route];
const after = parsed.assignments[model.route];
if (JSON.stringify(before) !== JSON.stringify(after)) {
if (after !== undefined && JSON.stringify(before) !== JSON.stringify(after)) {
throw new Error(`현재 사용할 수 없는 모델은 옮길 수 없습니다: ${model.route}`);
}
}
Expand Down
61 changes: 61 additions & 0 deletions tests/claude-integration/claude-management-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,64 @@ test("Claude Desktop PUT retains but cannot move an unavailable route", async ()
await server.stop(true);
}
});

test("Claude Desktop PUT allows deleting an unavailable route, but rejects modifying or adding one", async () => {
const seeded = loadConfig();
seeded.claudeCode = {
desktopProfile: {
version: 1,
assignments: {
"missing/old-model": { family: "opus", alias: "claude-opus-4-8-20260101" },
},
defaults: { opus: "missing/old-model", fable: null, sonnet: null, haiku: null },
},
};
saveConfig(seeded);
const server = startServer(0);
try {
const state = await fetch(new URL("/api/claude-desktop", server.url)).then(r => r.json()) as Record<string, any>;
expect(state.models.find((model: { route: string }) => model.route === "missing/old-model")?.available).toBe(false);

// Modifying an existing unavailable assignment (e.g. changing alias) is rejected with 400.
const modifyEdit = structuredClone(state.profile);
modifyEdit.assignments["missing/old-model"].alias = "claude-opus-4-8-20260202";
const putModify = await fetch(new URL("/api/claude-desktop", server.url), {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ profile: modifyEdit }),
});
expect(putModify.status).toBe(400);
expect((await putModify.json() as { error: string }).error).toContain("현재 사용할 수 없는 모델은 옮길 수 없습니다: missing/old-model");
expect(loadConfig().claudeCode?.desktopProfile?.assignments["missing/old-model"]?.alias).toBe("claude-opus-4-8-20260101");

// Deleting an existing unavailable assignment succeeds with 200.
const deleteEdit = structuredClone(state.profile);
delete deleteEdit.assignments["missing/old-model"];
deleteEdit.defaults.opus = Object.keys(deleteEdit.assignments).filter(route => deleteEdit.assignments[route].family === "opus").sort()[0] ?? null;

const putDelete = await fetch(new URL("/api/claude-desktop", server.url), {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ profile: deleteEdit }),
});
expect(putDelete.status).toBe(200);
const deleteResult = await putDelete.json() as Record<string, any>;
expect(deleteResult.models.some((model: { route: string }) => model.route === "missing/old-model")).toBe(false);
expect(deleteResult.profile.assignments["missing/old-model"]).toBeUndefined();
expect(loadConfig().claudeCode?.desktopProfile?.assignments["missing/old-model"]).toBeUndefined();

// Adding a newly unavailable assignment is rejected with 400.
const addEdit = structuredClone(deleteResult.profile);
addEdit.assignments["missing/new-model"] = { family: "fable", alias: "claude-opus-4-8-20260102" };
addEdit.defaults.fable = "missing/new-model";
const putAdd = await fetch(new URL("/api/claude-desktop", server.url), {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ profile: addEdit }),
});
expect(putAdd.status).toBe(400);
expect((await putAdd.json() as { error: string }).error).toContain("현재 사용할 수 없는 모델은 추가할 수 없습니다: missing/new-model");
} finally {
await server.stop(true);
}
});
Loading