From ea1ec11cd16d3fafac3fa41704a53a1320fca488 Mon Sep 17 00:00:00 2001 From: mnovak Date: Sun, 22 Nov 2026 19:28:52 +0100 Subject: [PATCH] [fabrica] Release pin, tests first (QC round 2): a forged pinned commit is refused, a rebased-away one is accepted with the tagged commit as the build reference (red) --- scripts/release-pin.test.mjs | 48 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/scripts/release-pin.test.mjs b/scripts/release-pin.test.mjs index 854b217..450f3df 100644 --- a/scripts/release-pin.test.mjs +++ b/scripts/release-pin.test.mjs @@ -94,7 +94,7 @@ test("a pin from an older commit, with code changed since: refused", () => { } }); -test("a pin from the parent where only pin.json changed: accepted, and the pinned commit is published", () => { +test("a pin from the parent where only pin.json changed: accepted; the tagged commit is the build reference", () => { const r = repo(); try { r.write("crates/a.rs", "fn a() {}\n"); @@ -104,10 +104,52 @@ test("a pin from the parent where only pin.json changed: accepted, and the pinne const out = run(r, b); assert.equal(out.status, 0, out.stdout + out.stderr); const published = JSON.parse(readFileSync(join(r.dir, "target/nix/ianitor-nix.json"), "utf8")); - assert.equal(published.commit, a, "the pin names the commit it was built from"); + assert.equal(published.commit, a, "the commit the pin was made at, for the record"); + assert.equal(published.commitChecked, true, "its objects are here, so its tree was checked"); assert.equal(published.taggedCommit, b); assert.equal(published.tag, "v1.0.0"); - assert.match(published.flake, new RegExp(`rev=${a}`)); + // Verifiers build the tagged commit: the same source by construction, and it surely exists. + assert.equal(published.flake, `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${b}`); + } finally { + r.done(); + } +}); + +test("a forged commit (present, but another source tree): refused", () => { + const r = repo(); + try { + r.write("crates/a.rs", "fn other() {}\n"); + const x = r.commit("other code at X"); + r.write("crates/a.rs", "fn a() {}\n"); + const a = r.commit("code at A"); + const pin = JSON.parse(pinFor(r, a)); + pin.commit = x; // the tree is A's, the commit named is X + r.write(".fabrica/nix/pin.json", JSON.stringify(pin)); + const b = r.commit("pin"); + const out = run(r, b); + assert.equal(out.status, 1, out.stdout + out.stderr); + assert.match(out.stderr, /does not hold the source tree/); + } finally { + r.done(); + } +}); + +test("a commit rebased away (absent): accepted, the tagged commit is the build reference", () => { + const r = repo(); + try { + r.write("crates/a.rs", "fn a() {}\n"); + const a = r.commit("code at A"); + const pin = JSON.parse(pinFor(r, a)); + pin.commit = "f".repeat(40); // no such object here (rebased away, or a shallow clone) + r.write(".fabrica/nix/pin.json", JSON.stringify(pin)); + const b = r.commit("pin"); + const out = run(r, b); + assert.equal(out.status, 0, out.stdout + out.stderr); + const published = JSON.parse(readFileSync(join(r.dir, "target/nix/ianitor-nix.json"), "utf8")); + assert.equal(published.taggedCommit, b); + assert.equal(published.commit, "f".repeat(40)); + assert.equal(published.commitChecked, false); + assert.equal(published.flake, `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${b}`); } finally { r.done(); }