feat(assist-platform): add assist platform automation and tenant onboarding
- Add SSO QR status poller and assist platform HTTP client - Add assist-platform session store with 0600 secure permissions - Implement domains/assist-platform (api, services, types) for corporation search, detail, tickets, staff query and passwordless token generation - Implement cli/commands/assist-platform with aliases assist-center and ap - Support seamless --save --switch --elevate pipeline to import tenant and extract persistent OpenAPI credentials - Update embedded skill documentation, reference guide, and test suites
This commit is contained in:
1 parent
d839fcbe2b
commit
ed9fa979e0
25 files changed
+1811
-2
No files matched your search
@@ -0,0 +1,130 @@
|
||||
import { describe, expect, it, beforeEach } from "bun:test";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { handleAssistPlatformCommand } from "./assist-platform/index.js";
|
||||
import {
|
||||
saveAssistPlatformSession,
|
||||
clearAssistPlatformSession,
|
||||
} from "../../core/auth/assist-platform-store.js";
|
||||
import type { CliParsedArgs, CliRuntime } from "../types.js";
|
||||
|
||||
function createMockRuntime(enterprisesDir: string): CliRuntime {
|
||||
return {
|
||||
jsonMode: false,
|
||||
selectedCorp: null,
|
||||
corpContext: {
|
||||
enterprisesDir,
|
||||
corps: new Map(),
|
||||
stateful: true,
|
||||
current: undefined,
|
||||
defaultCorpId: undefined,
|
||||
getCorp: () => undefined,
|
||||
switchCorp: () => true,
|
||||
listCorps: () => [],
|
||||
getAllCorps: () => [],
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
describe("CLI Commands - assist-platform (合思协助平台)", () => {
|
||||
let tempDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tempDir = mkdtempSync(join(tmpdir(), "hose-assist-test-"));
|
||||
process.env.HOSE_STATE_DIR = tempDir;
|
||||
clearAssistPlatformSession();
|
||||
});
|
||||
|
||||
it("assist-platform help 输出完整使用指南与子命令", async () => {
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "help",
|
||||
args: [],
|
||||
options: {},
|
||||
raw: ["assist-platform", "help"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("合思协助平台");
|
||||
expect(res.stdout).toContain("login");
|
||||
expect(res.stdout).toContain("search");
|
||||
expect(res.stdout).toContain("tickets");
|
||||
expect(res.stdout).toContain("enter");
|
||||
expect(res.stdout).toContain("assist-center");
|
||||
});
|
||||
|
||||
it("assist-platform login 无凭证时给出指引", async () => {
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "login",
|
||||
args: [],
|
||||
options: {},
|
||||
raw: ["assist-platform", "login"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(1);
|
||||
expect(res.stderr).toContain("未检测到协助平台登录凭证");
|
||||
});
|
||||
|
||||
it("assist-platform login --logout 能够注销凭证", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "login",
|
||||
args: [],
|
||||
options: { logout: true },
|
||||
raw: ["assist-platform", "login", "--logout"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("已成功注销");
|
||||
});
|
||||
|
||||
it("未登录时运行 tickets 提示需要先登录", async () => {
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "tickets",
|
||||
args: ["Cxa3oOtQi2eS$g"],
|
||||
options: {},
|
||||
raw: ["assist-platform", "tickets", "Cxa3oOtQi2eS$g"],
|
||||
};
|
||||
|
||||
try {
|
||||
await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(true).toBe(false);
|
||||
} catch (err: any) {
|
||||
expect(err.message).toContain("未检测到协助平台登录凭证");
|
||||
}
|
||||
});
|
||||
|
||||
it("assist-platform enter --save --dry-run 能够输出变更预览", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "enter",
|
||||
args: ["Cxa3oOtQi2eS$g"],
|
||||
options: { save: true, dryRun: true },
|
||||
raw: ["assist-platform", "enter", "Cxa3oOtQi2eS$g", "--save", "--dry-run"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("Cxa3oOtQi2eS$g");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user