Remote /v1/run now emits additive result_v1; Go validates run_id, digest, and paths before materializing, and only accepts missing typed payloads with an explicit legacy handshake. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { withResultV1, membersDigest, typedErrorCode } from "./result-v1.mjs";
|
|
|
|
test("withResultV1 is additive and strips stderr", () => {
|
|
const out = withResultV1({
|
|
ok: true,
|
|
run_id: "run-1",
|
|
stderr: "secret-trace",
|
|
patches: [{ rel_path: "output.md", content: "hello" }],
|
|
});
|
|
assert.equal(out.ok, true);
|
|
assert.equal(out.patches[0].rel_path, "output.md");
|
|
assert.equal(out.stderr, undefined);
|
|
assert.equal(out.capabilities.typed_result, true);
|
|
assert.equal(out.runner_protocol, "typed-v1");
|
|
assert.equal(out.result_v1.schema_version, 1);
|
|
assert.equal(out.result_v1.run_id, "run-1");
|
|
assert.equal(out.result_v1.outcome, "success");
|
|
assert.equal(out.result_v1.members.length, 1);
|
|
assert.equal(out.result_v1.content_digest, membersDigest(out.result_v1.members));
|
|
});
|
|
|
|
test("typedErrorCode is allowlisted and ignores raw stderr", () => {
|
|
assert.equal(typedErrorCode({ ok: false, fallback_reason: "prompt_empty" }), "PROMPT_EMPTY");
|
|
assert.equal(typedErrorCode({ ok: false, fallback_reason: "Connection error." }), "TRANSIENT");
|
|
const out = withResultV1({
|
|
ok: false,
|
|
run_id: "run-2",
|
|
retryable: true,
|
|
fallback_reason: "Connection error. /tmp/secret",
|
|
stderr: "token=abc",
|
|
patches: [],
|
|
});
|
|
assert.equal(out.stderr, undefined);
|
|
assert.equal(out.result_v1.error_code, "TRANSIENT");
|
|
assert.equal(out.result_v1.retryable, true);
|
|
assert.equal(out.result_v1.outcome, "error");
|
|
});
|
|
|
|
test("path escape members are omitted", () => {
|
|
const out = withResultV1({
|
|
ok: true,
|
|
run_id: "run-3",
|
|
patches: [
|
|
{ rel_path: "../etc/passwd", content: "x" },
|
|
{ rel_path: "/abs.md", content: "y" },
|
|
{ rel_path: "output.md", content: "ok" },
|
|
],
|
|
});
|
|
assert.deepEqual(out.result_v1.members.map((m) => m.path), ["output.md"]);
|
|
});
|