fix: 接受 Web Probe 文件采集合同

This commit is contained in:
Codex
2026-07-10 19:08:48 +02:00
parent e0288b4348
commit dbf61e52aa
2 changed files with 38 additions and 1 deletions
@@ -135,6 +135,42 @@ test("collects an exact failed command artifact without treating artifact failur
expect(String(rendered.renderedText)).toContain("terminal event arrived before subscriber disconnect");
});
test("accepts the standard file collect envelope without requiring a summary view", () => {
const options = collectOptions();
options.collectView = "files";
options.collectFile = "commands/failed/cmd-fixture.json";
const payload = buildNodeWebProbeObserveCollectPayload(options, { workspace: "/workspace" }, {
command: ["trans", "NC01:/workspace", "sh"],
cwd: "/repo",
exitCode: 0,
stdout: JSON.stringify({
ok: true,
command: "web-probe-observe collect",
stateDir: "/remote/state",
mode: "file",
requestedFile: options.collectFile,
resolvedFile: options.collectFile,
file: {
relative: options.collectFile,
byteCount: 21885,
sha256: "sha256:fixture",
jsonSummary: { topLevelKeys: ["ok", "commandId", "type", "failedAt", "error"] },
},
valuesRedacted: true,
}),
stderr: "",
signal: null,
timedOut: false,
} satisfies CommandResult);
expect(payload.ok).toBe(true);
expect(payload.status).toBe("collected");
expect(payload.degradedReason).toBeNull();
const collect = payload.collect as Record<string, any>;
expect(collect.mode).toBe("file");
expect(collect.file.byteCount).toBe(21885);
});
function collectOptions(): NodeWebProbeObserveOptions {
return {
action: "observe",
@@ -89,6 +89,7 @@ export function buildNodeWebProbeObserveCollectPayload(
export function isWebObserveCollectJsonContract(value: Record<string, unknown>, requestedFile: string | null = null): boolean {
const command = stringOrNull(value.command);
const view = stringOrNull(value.view);
const mode = stringOrNull(value.mode);
const stateDir = stringOrNull(value.stateDir);
if (commandArtifactBucket(value, requestedFile) !== null) return true;
if (value.ok === false) {
@@ -98,7 +99,7 @@ export function isWebObserveCollectJsonContract(value: Record<string, unknown>,
|| stringOrNull(value.error) !== null;
}
return command === "web-probe-observe collect"
&& view !== null
&& (view !== null || mode === "file")
&& stateDir !== null;
}