feat(platform): add streaming ndjson, stats profiling, flat normalization, and public sdk surface
This commit is contained in:
1 parent
26a6b7318c
commit
03195bbbe5
12 files changed
+649
-9
No files matched your search
@@ -405,4 +405,113 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
expect(execRes.stdout).toContain("已执行");
|
||||
expect(editSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("platform records 支持 --stats 画像统计(计算状态、重名与编码聚类)", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
spies.push(
|
||||
spyOn(api, "searchEntityRecords").mockResolvedValue({
|
||||
total: 3,
|
||||
data: [
|
||||
{ id: "r-1", dataLink: { id: "r-1", name: "场地A", code: "0-DT-2026-month-1", active: true } },
|
||||
{ id: "r-2", dataLink: { id: "r-2", name: "场地A", code: "0-DT-2026-period-1", active: false } },
|
||||
{ id: "r-3", dataLink: { id: "r-3", name: "场地B", code: "0-DT-2026-month-2", active: true } },
|
||||
],
|
||||
actions: [],
|
||||
components: [],
|
||||
path: null,
|
||||
template: null,
|
||||
})
|
||||
);
|
||||
|
||||
// 1. 命令行表格输出测试
|
||||
const textRes = await handlePlatformCommand(
|
||||
{
|
||||
area: "platform",
|
||||
action: "records",
|
||||
args: ["platform-1", "entity-1"],
|
||||
options: { stats: true },
|
||||
raw: ["platform", "records", "platform-1", "entity-1", "--stats"],
|
||||
},
|
||||
dummyRuntime
|
||||
);
|
||||
expect(textRes.exitCode).toBe(0);
|
||||
expect(textRes.stdout).toContain("宏观状态与数据画像");
|
||||
expect(textRes.stdout).toContain("启用 2 条");
|
||||
expect(textRes.stdout).toContain("停用 1 条");
|
||||
expect(textRes.stdout).toContain("N-DT-N-month-N");
|
||||
|
||||
// 2. JSON 结构化输出测试
|
||||
const jsonRes = await handlePlatformCommand(
|
||||
{
|
||||
area: "platform",
|
||||
action: "records",
|
||||
args: ["platform-1", "entity-1"],
|
||||
options: { stats: true },
|
||||
raw: ["platform", "records", "platform-1", "entity-1", "--stats"],
|
||||
},
|
||||
{ ...dummyRuntime, jsonMode: true }
|
||||
);
|
||||
expect(jsonRes.exitCode).toBe(0);
|
||||
const parsed = JSON.parse(jsonRes.stdout);
|
||||
expect(parsed.total).toBe(3);
|
||||
expect(parsed.activeCount).toBe(2);
|
||||
expect(parsed.inactiveCount).toBe(1);
|
||||
expect(parsed.duplicateNamesCount).toBe(1);
|
||||
});
|
||||
|
||||
it("platform records 支持 --ndjson 流式逐行下发与 --flat 归一化", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
spies.push(
|
||||
spyOn(api, "searchEntityRecords").mockResolvedValue({
|
||||
total: 2,
|
||||
data: [
|
||||
{
|
||||
id: "r-1",
|
||||
dataLink: { id: "r-1", name: "项目1", code: "P1", active: true, customField: "测试值" },
|
||||
},
|
||||
{
|
||||
id: "r-2",
|
||||
dataLink: { id: "r-2", name: "项目2", code: "P2", active: false, customField: "停用值" },
|
||||
},
|
||||
],
|
||||
actions: [],
|
||||
components: [],
|
||||
path: null,
|
||||
template: null,
|
||||
})
|
||||
);
|
||||
|
||||
const streamedLines: string[] = [];
|
||||
const writeSpy = spyOn(process.stdout, "write").mockImplementation((str: any) => {
|
||||
streamedLines.push(String(str));
|
||||
return true;
|
||||
});
|
||||
spies.push(writeSpy);
|
||||
|
||||
const streamRes = await handlePlatformCommand(
|
||||
{
|
||||
area: "platform",
|
||||
action: "records",
|
||||
args: ["platform-1", "entity-1"],
|
||||
options: { ndjson: true },
|
||||
raw: ["platform", "records", "platform-1", "entity-1", "--ndjson"],
|
||||
},
|
||||
dummyRuntime
|
||||
);
|
||||
|
||||
expect(streamRes.exitCode).toBe(0);
|
||||
expect(streamedLines.length).toBe(2);
|
||||
|
||||
const row1 = JSON.parse(streamedLines[0].trim());
|
||||
expect(row1.id).toBe("r-1");
|
||||
expect(row1.name).toBe("项目1");
|
||||
expect(row1.code).toBe("P1");
|
||||
expect(row1.active).toBe(true);
|
||||
expect(row1.fields["自定义字段"]).toBe("测试值");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user