docs(agent): 补齐 platform records --all 的流式导出约束与 JSON 错误测试
- platform records 的 JSON 结构化错误补充 exitCode 与 nextAction,与 runner 的统一错误形状对齐;非 JSON 路径同步携带 nextAction; - 新增 --json 模式下 DATASET_TOO_LARGE 单测,覆盖分页与流式导出建议; - Skill 与 workflow 参考文档中的 --all 示例统一改为 --ndjson -o,并补充 DATASET_TOO_LARGE 的恢复说明,修正 bbcf96c 声称完成但遗漏的 skill guidelines; - datalink README 补充 --all 的流式导出约束与结构化错误字段。 校验:bun test 1156 pass / 0 fail;bun run check 通过; check:readme 的 specs/ 与 src/core/db/ 缺失为仓库既有问题,与本次改动无关。
This commit is contained in:
1 parent
4ea73ef322
commit
235e4b806d
5 files changed
+40
-6
No files matched your search
@@ -528,6 +528,33 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
).rejects.toThrow("--all 不再直接返回全量");
|
||||
});
|
||||
|
||||
it("platform records --all --json 返回 DATASET_TOO_LARGE 结构化错误", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(servicesApplications, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
const result = await handlePlatformCommand(
|
||||
{
|
||||
area: "platform",
|
||||
action: "records",
|
||||
args: ["platform-1", "entity-1"],
|
||||
options: { all: true, json: true },
|
||||
raw: ["platform", "records", "platform-1", "entity-1", "--all", "--json"],
|
||||
},
|
||||
{ ...dummyRuntime, jsonMode: true }
|
||||
);
|
||||
|
||||
expect(result.exitCode).toBe(2);
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
expect(parsed.error).toBe(true);
|
||||
expect(parsed.code).toBe("DATASET_TOO_LARGE");
|
||||
expect(parsed.exitCode).toBe(2);
|
||||
expect(parsed.nextAction).toContain("--ndjson");
|
||||
expect(parsed.suggestions).toEqual([
|
||||
{ type: "paginate", command: "--page=1 --pageSize=500" },
|
||||
{ type: "stream_export", command: "--ndjson --output-file=<path>" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects malformed batch predicates before fetching all records or calling the writer", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(servicesApplications, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
|
||||
@@ -65,12 +65,15 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
if (!isStream || !runtime.outputOptions?.outputFile) {
|
||||
const message =
|
||||
"--all 不再直接返回全量 JSON/表格。请使用 --page/--count 分页查询,或使用 --ndjson --output-file <path> 流式导出;大范围检索建议交给脚本处理。";
|
||||
const nextAction = "hose-use platform records <应用> <业务对象> --ndjson --output-file <path>";
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: JSON.stringify({
|
||||
error: true,
|
||||
code: "DATASET_TOO_LARGE",
|
||||
message: message,
|
||||
message,
|
||||
exitCode: 2,
|
||||
nextAction,
|
||||
suggestions: [
|
||||
{ type: "paginate", command: "--page=1 --pageSize=500" },
|
||||
{ type: "stream_export", command: "--ndjson --output-file=<path>" },
|
||||
@@ -80,7 +83,7 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
exitCode: 2,
|
||||
};
|
||||
}
|
||||
throw usageError(message);
|
||||
throw usageError(message, nextAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ hose-use platform imports <应用 ID|名称> <对象 ID|名称>
|
||||
- `records <业务对象>`(单参数免应用查询):当企业自建应用较多时,无需事先查询 platformId。直接输入业务对象名称或编码,CLI 自动遍历企业全量自建应用进行智能反查与寻址;若跨应用重名则抛出精准候选项提示,避免人工心智负担。
|
||||
|
||||
- `records --ndjson`(或 `--stream`):针对万级~十万级海量记录,采用 AsyncGenerator 分页流式生成,逐行向 `stdout` 发射 NDJSON。内存恒定为 $O(\text{pageSize})$,严防大报文撑爆内存或终端,无缝对接下游 `jq`、Python 处理流水线。
|
||||
|
||||
- `records --all`:全量记录不再直接返回 JSON/表格;必须与 `--ndjson --output-file <path>` 一起使用,否则返回 `DATASET_TOO_LARGE`(exitCode 2)并附分页/流式导出建议。`--json` 模式下该错误以 `{ error, code, message, exitCode, nextAction, suggestions }` 结构化输出,Agent 可直接解析。
|
||||
- 终端入口提供显式输出回调并等待写入完成以响应背压;`--ndjson -o <path>` 写入真正的 NDJSON 文件,返回文件路径、字节数和记录数摘要。
|
||||
- MCP / HTTP 默认不提供终端输出通道;未指定文件时拒绝直接流式输出,避免污染协议 stdout 或返回空的成功响应。输出逐行执行统一脱敏。
|
||||
- `records --page=<页码> --count=<每页>`:分页查询,默认 `count=20`;用于替代无边界全量拉取。
|
||||
|
||||
Reference in new issue
Block a user