Files
modelstudioai__cli/packages/commands/tests/auth-console-ui.test.ts
inhai e1caee99f2 feat(config-ui): MCP management, skill zip install, and UI polish
- MCP: editable JSON config in the detail drawer with secret masking and
  mask-preserving writes; create/update/delete across claude-code, qwen-code,
  opencode, cursor, windsurf, gemini, qoderwork, openclaw and Claude Desktop
- Skills: upload a .zip and install into any agent's skills root (self-contained
  ZIP reader, zip-slip safe); scan more roots (openclaw workspace, qoderwork,
  windsurf/codeium, gemini antigravity, workbuddy)
- Markdown: GFM table rendering in the skill detail drawer
- Layout: collapsible grouped sidebar with icons + persistent state, responsive
  breakpoint, wider main, single-line tile titles, 2-line description clamp,
  round icon run buttons, custom file picker, modal spacing
- Server: /api/mcp POST/DELETE, /api/skill/install, binary upload reader,
  constant-time token compare, CSP/no-store headers, error logging
2026-07-23 10:52:26 +08:00

72 lines
2.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from "vite-plus/test";
import { makeAuthUiBridge } from "../src/commands/auth/console-ui.ts";
import type { AuthState, AuthStore, Identity, Settings } from "bailian-cli-core";
/** Build a bridge over a fake AuthStore. Only describe()/logout() are used by
* the surface under test; startConsoleLogin() is intentionally not exercised
* (it opens a browser and starts a real callback server). */
function bridgeWith(state: AuthState, onLogout?: (scope: string) => Promise<boolean>) {
const authStore = {
describe: () => state,
stored: () => ({ apiKey: false, console: false, openapi: false }),
resolveBaseUrl: () => "https://dashscope.aliyuncs.com",
login: async () => {},
logout: onLogout ?? (async () => false),
path: "/tmp/config.json",
} as unknown as AuthStore;
return makeAuthUiBridge({
identity: {} as unknown as Identity,
settings: {} as unknown as Settings,
authStore,
});
}
test("status: console 凭证 -> primary=console带 region/site 与掩码 token", () => {
const st = bridgeWith({
console: {
token: "abcd1234efgh5678",
region: "cn-beijing",
site: "domestic",
source: "config",
},
}).status();
expect(st.authenticated).toBe(true);
expect(st.primary).toBe("console");
expect(st.methods).toEqual({ apiKey: false, console: true, openapi: false });
expect(st.region).toBe("cn-beijing");
expect(st.site).toBe("domestic");
expect(st.masked).toContain("...");
// Masked, never the raw token.
expect(st.masked).not.toBe("abcd1234efgh5678");
});
test("status: 无任何凭证 -> 未认证,无 masked", () => {
const st = bridgeWith({}).status();
expect(st.authenticated).toBe(false);
expect(st.primary).toBe(null);
expect(st.masked).toBeUndefined();
expect(st.methods).toEqual({ apiKey: false, console: false, openapi: false });
});
test("status: 仅 apiKey -> primary=apiKey", () => {
const st = bridgeWith({
apiKey: { token: "sk-1234567890", baseUrl: "https://dashscope.aliyuncs.com", source: "env" },
}).status();
expect(st.primary).toBe("apiKey");
expect(st.methods.apiKey).toBe(true);
expect(st.region).toBeUndefined();
});
test("logout 委托给 authStore.logout('all')", async () => {
let scope = "";
const bridge = bridgeWith(
{ apiKey: { token: "sk-x", baseUrl: "https://x", source: "config" } },
async (s) => {
scope = s;
return true;
},
);
expect(await bridge.logout()).toBe(true);
expect(scope).toBe("all");
});