fix(web-probe): reject empty analyze stdout contracts
This commit is contained in:
@@ -85,6 +85,50 @@ test("child JSON recovery falls back to artifact when stdout is not JSON", () =>
|
||||
assert.equal(resolved.diagnostics.fallbackReason, "stdout-not-json");
|
||||
});
|
||||
|
||||
test("child JSON recovery rejects ok-only stdout contract and uses artifact", () => {
|
||||
const resolved = resolveCliChildJsonObject({
|
||||
stdout: JSON.stringify({ ok: true }),
|
||||
requestedStdoutType: "web-probe observe analyze compact JSON",
|
||||
acceptParsed: (value) => typeof value.reportJsonPath === "string" || typeof value.counts === "object",
|
||||
artifactFallback: {
|
||||
path: "analysis/report.json",
|
||||
nextCommand: "collect report",
|
||||
read: () => ({ ok: true, value: { ok: true, reportJsonPath: "analysis/report.json", counts: { network: 9 } } }),
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(resolved.source, "artifact");
|
||||
assert.equal(resolved.parsed?.reportJsonPath, "analysis/report.json");
|
||||
assert.deepEqual(resolved.parsed?.counts, { network: 9 });
|
||||
assert.equal(resolved.diagnostics.stdoutKind, "json");
|
||||
assert.equal(resolved.diagnostics.fallbackReason, "stdout-json-contract-invalid");
|
||||
assert.equal(resolved.diagnostics.stdoutContractAccepted, false);
|
||||
});
|
||||
|
||||
test("child JSON recovery drops invalid ok-only stdout when artifact fallback is missing", () => {
|
||||
const resolved = resolveCliChildJsonObject({
|
||||
stdout: JSON.stringify({ ok: true }),
|
||||
requestedStdoutType: "web-probe observe analyze compact JSON",
|
||||
acceptParsed: (value) => typeof value.reportJsonPath === "string" || typeof value.counts === "object",
|
||||
artifactFallback: {
|
||||
path: "analysis/report.json",
|
||||
nextCommand: "collect report",
|
||||
read: () => ({ ok: false, reason: "artifact-missing", path: "analysis/report.json" }),
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(resolved.parsed, null);
|
||||
assert.equal(resolved.source, null);
|
||||
assert.equal(resolved.diagnostics.stdoutKind, "json");
|
||||
assert.equal(resolved.diagnostics.fallbackReason, "stdout-json-contract-invalid");
|
||||
assert.equal(resolved.diagnostics.stdoutContractAccepted, false);
|
||||
const artifact = resolved.diagnostics.artifact as Record<string, unknown>;
|
||||
assert.equal(artifact.ok, false);
|
||||
assert.equal(artifact.reason, "artifact-missing");
|
||||
assert.equal(artifact.path, "analysis/report.json");
|
||||
assert.equal(artifact.nextCommand, "collect report");
|
||||
});
|
||||
|
||||
test("child JSON recovery reports artifact fallback failure when stdout is unusable and artifact is missing", () => {
|
||||
const resolved = resolveCliChildJsonObject({
|
||||
stdout: "not json",
|
||||
|
||||
Reference in New Issue
Block a user