feat(platform): support native server filterBy, workflow compact list and auto-corp credentials

This commit is contained in:
gitea committed 2026-10-22 16:50:25 +08:00
1 parent deed5a5628
commit 975f76af74
10 files changed
+483 -28

No files matched your search

+125
View File
@@ -1,6 +1,7 @@
import { describe, expect, it, spyOn, afterEach } from "bun:test";
import { handleWorkflowCommand } from "./workflow/index.js";
import * as helpers from "../helpers.js";
import * as platformServices from "../../domains/platform/services.js";
import type { CliRuntime } from "../types.js";
import type { CorpConfig } from "../../core/config/types.js";
@@ -2169,3 +2170,127 @@ describe("CLI - workflow job 执行详情与异常精准透视", () => {
});
});
describe("CLI - workflow list 轻量化与名称搜索", () => {
let spies: ReturnType<typeof spyOn>[] = [];
afterEach(() => {
for (const spy of spies) {
spy.mockRestore();
}
spies = [];
});
const mockWorkflows = [
{
id: "wf_001",
pipelineName: "待摊台账拆分计划",
state: 1,
runningCount: 0,
errorCount: 0,
updateTime: "2026-08-26 23:31:04",
updateUser: "张三",
platformId: "p_1",
platformName: "合同台账",
tasks: [
{ name: "t1", type: "trigger", code: "long script 1..." },
{ name: "t2", type: "code", code: "long script 2..." },
],
},
{
id: "wf_002",
pipelineName: "费用报销审批同步",
state: 0,
runningCount: 0,
errorCount: 0,
updateTime: "2026-09-01 10:00:00",
updateUser: "李四",
platformId: "p_2",
platformName: "费用应用",
tasks: [{ name: "t1", type: "trigger", code: "long script 3..." }],
},
];
it("默认以轻量化模式输出 JSON,剥离庞大的 tasks 数组并提供 nodeCount", async () => {
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({} as any),
spyOn(platformServices, "listAllWorkflows").mockResolvedValue({
workflows: mockWorkflows as any,
errors: [],
})
);
const res = await handleWorkflowCommand(
{
area: "workflow",
action: "list",
args: [],
options: { json: true },
raw: ["workflow", "list", "--json"],
},
{ ...mockRuntime, jsonMode: true }
);
expect(res.exitCode).toBe(0);
const data = JSON.parse(res.stdout);
expect(data.workflows).toHaveLength(2);
expect(data.workflows[0].tasks).toBeUndefined();
expect(data.workflows[0].nodeCount).toBe(2);
expect(data.workflows[1].nodeCount).toBe(1);
expect(data.totalWorkflows).toBe(2);
});
it("传入 --full 或 --with-tasks 时保留完整的 tasks 节点结构", async () => {
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({} as any),
spyOn(platformServices, "listAllWorkflows").mockResolvedValue({
workflows: mockWorkflows as any,
errors: [],
})
);
const res = await handleWorkflowCommand(
{
area: "workflow",
action: "list",
args: [],
options: { json: true, full: true },
raw: ["workflow", "list", "--json", "--full"],
},
{ ...mockRuntime, jsonMode: true }
);
expect(res.exitCode).toBe(0);
const data = JSON.parse(res.stdout);
expect(data.workflows[0].tasks).toHaveLength(2);
expect(data.workflows[0].tasks[0].code).toBe("long script 1...");
});
it("支持通过 --keyword 或 -q 过滤工作流名称", async () => {
spies.push(
spyOn(helpers, "createClientsForCorp").mockResolvedValue({} as any),
spyOn(platformServices, "listAllWorkflows").mockResolvedValue({
workflows: mockWorkflows as any,
errors: [],
})
);
const res = await handleWorkflowCommand(
{
area: "workflow",
action: "list",
args: [],
options: { keyword: "待摊", json: true },
raw: ["workflow", "list", "--keyword=待摊", "--json"],
},
{ ...mockRuntime, jsonMode: true }
);
expect(res.exitCode).toBe(0);
const data = JSON.parse(res.stdout);
expect(data.workflows).toHaveLength(1);
expect(data.workflows[0].id).toBe("wf_001");
expect(data.workflows[0].pipelineName).toBe("待摊台账拆分计划");
expect(data.totalWorkflows).toBe(1);
});
});