From ca3c31203b7ffc9a293f908e9a4143517da54d6f Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 16 Sep 2026 18:58:25 -0700 Subject: [PATCH 1/3] fix(checks): validate receipt parity during merges --- .../pi-qualification-receipt-refresh.mts | 25 ++++++++++--- .../pi-qualification-receipt-refresh.test.ts | 35 +++++++++++++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/scripts/checks/pi-qualification-receipt-refresh.mts b/scripts/checks/pi-qualification-receipt-refresh.mts index e4bc96f82d5..5a853b54cee 100644 --- a/scripts/checks/pi-qualification-receipt-refresh.mts +++ b/scripts/checks/pi-qualification-receipt-refresh.mts @@ -163,10 +163,14 @@ function parseReceipt( function requireReceiptSourceParity( git: GitRunner, revision: string, - comparisonRevision: string, + comparisonRevision: string | null, imageSourcePaths: readonly string[], ): void { - const result = git(["diff", "--quiet", revision, comparisonRevision, "--", ...imageSourcePaths]); + const result = git( + comparisonRevision === null + ? ["diff", "--quiet", "--cached", revision, "--", ...imageSourcePaths] + : ["diff", "--quiet", revision, comparisonRevision, "--", ...imageSourcePaths], + ); if (result.error) { throw new Error(`Could not run git to validate Pi receipt source parity (${result.error})`); } @@ -180,8 +184,21 @@ function requireReceiptSourceParity( ); } -function receiptComparisonRevision(git: GitRunner, explicit?: string): string { +function receiptComparisonRevision(git: GitRunner, explicit?: string): string | null { if (explicit) return explicit; + if (process.env.GITHUB_ACTIONS !== "true") { + const mergeHead = git(["rev-parse", "--quiet", "--verify", "MERGE_HEAD"]); + if (mergeHead.error) { + throw new Error(`Could not detect an in-progress merge (${mergeHead.error})`); + } + if (mergeHead.status === 0) return null; + if (mergeHead.status !== 1) { + const detail = mergeHead.stderr?.trim(); + throw new Error( + `Could not detect an in-progress merge: git exited ${mergeHead.status ?? "without status"}${detail ? ` (${detail})` : ""}`, + ); + } + } if (process.env.GITHUB_ACTIONS !== "true" || process.env.GITHUB_EVENT_NAME !== "pull_request") { return "HEAD"; } @@ -199,7 +216,7 @@ function validateReceiptPair( imageSourcePaths: readonly string[], receipts: readonly { path: string; platform: ManagedImagePlatform }[], acceptedDigests: ReadonlySet, - comparisonRevision: string, + comparisonRevision: string | null, ): void { const validated = receipts.map((receipt) => parseReceipt(rootDir, receipt, acceptedDigests)); const contracts = validated.map(({ contract }) => contract); diff --git a/test/repository/pi-qualification-receipt-refresh.test.ts b/test/repository/pi-qualification-receipt-refresh.test.ts index db9b36a17cf..37920a39b63 100644 --- a/test/repository/pi-qualification-receipt-refresh.test.ts +++ b/test/repository/pi-qualification-receipt-refresh.test.ts @@ -73,7 +73,8 @@ describe("Pi qualification receipt refresh", () => { changedPaths: readonly string[], options: { accepted?: ReadonlySet; - headRevision?: string; + headRevision?: string | null; + mergeInProgress?: boolean; sourceParity?: boolean; stagedPaths?: readonly string[]; } = {}, @@ -89,18 +90,23 @@ describe("Pi qualification receipt refresh", () => { status: 0, stdout: `${(args.includes("--cached") ? (options.stagedPaths ?? []) : changedPaths).join("\0")}\0`, } - : args.includes("--quiet") - ? args[3] === (options.headRevision ?? "HEAD") - ? { status: options.sourceParity === false ? 1 : 0, stdout: "" } + : args[0] === "rev-parse" + ? options.mergeInProgress + ? { status: 0, stdout: `${"e".repeat(40)}\n` } + : { status: 1, stdout: "" } + : args.includes("--quiet") + ? (args.includes("--cached") && options.mergeInProgress) || + args[3] === (options.headRevision ?? "HEAD") + ? { status: options.sourceParity === false ? 1 : 0, stdout: "" } + : (() => { + throw new Error(`Unexpected source parity arguments: ${args.join(" ")}`); + })() : (() => { - throw new Error(`Unexpected comparison revision: ${args[3]}`); - })() - : (() => { - throw new Error(`Unexpected git arguments: ${args.join(" ")}`); - })(), + throw new Error(`Unexpected git arguments: ${args.join(" ")}`); + })(), receipts: RECEIPTS, rootDir, - headRevision: options.headRevision ?? "HEAD", + ...(options.headRevision !== null ? { headRevision: options.headRevision ?? "HEAD" } : {}), }); } @@ -150,6 +156,15 @@ describe("Pi qualification receipt refresh", () => { ).not.toThrow(); }); + it("compares receipt parity against the staged tree during a local merge", () => { + expect(() => + run(["protected/app/config.json", ...RECEIPTS.map(({ path }) => path)], { + headRevision: null, + mergeInProgress: true, + }), + ).not.toThrow(); + }); + it("does not require receipts for unrelated changes", () => { expect(() => run(["docs/reference/pi.mdx"])).not.toThrow(); }); From 5a1332c5d8065e0f06531f40de672c2241bed9a6 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 16 Sep 2026 19:37:14 -0700 Subject: [PATCH 2/3] test(checks): isolate merge receipt parity --- .../pi-qualification-receipt-refresh.mts | 22 +++++++++---------- .../pi-qualification-receipt-refresh.test.ts | 14 ++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/scripts/checks/pi-qualification-receipt-refresh.mts b/scripts/checks/pi-qualification-receipt-refresh.mts index 5a853b54cee..640a5bb7302 100644 --- a/scripts/checks/pi-qualification-receipt-refresh.mts +++ b/scripts/checks/pi-qualification-receipt-refresh.mts @@ -186,18 +186,16 @@ function requireReceiptSourceParity( function receiptComparisonRevision(git: GitRunner, explicit?: string): string | null { if (explicit) return explicit; - if (process.env.GITHUB_ACTIONS !== "true") { - const mergeHead = git(["rev-parse", "--quiet", "--verify", "MERGE_HEAD"]); - if (mergeHead.error) { - throw new Error(`Could not detect an in-progress merge (${mergeHead.error})`); - } - if (mergeHead.status === 0) return null; - if (mergeHead.status !== 1) { - const detail = mergeHead.stderr?.trim(); - throw new Error( - `Could not detect an in-progress merge: git exited ${mergeHead.status ?? "without status"}${detail ? ` (${detail})` : ""}`, - ); - } + const mergeHead = git(["rev-parse", "--quiet", "--verify", "MERGE_HEAD"]); + if (mergeHead.error) { + throw new Error(`Could not detect an in-progress merge (${mergeHead.error})`); + } + if (mergeHead.status === 0) return null; + if (mergeHead.status !== 1) { + const detail = mergeHead.stderr?.trim(); + throw new Error( + `Could not detect an in-progress merge: git exited ${mergeHead.status ?? "without status"}${detail ? ` (${detail})` : ""}`, + ); } if (process.env.GITHUB_ACTIONS !== "true" || process.env.GITHUB_EVENT_NAME !== "pull_request") { return "HEAD"; diff --git a/test/repository/pi-qualification-receipt-refresh.test.ts b/test/repository/pi-qualification-receipt-refresh.test.ts index 37920a39b63..71a5f49cd60 100644 --- a/test/repository/pi-qualification-receipt-refresh.test.ts +++ b/test/repository/pi-qualification-receipt-refresh.test.ts @@ -91,11 +91,17 @@ describe("Pi qualification receipt refresh", () => { stdout: `${(args.includes("--cached") ? (options.stagedPaths ?? []) : changedPaths).join("\0")}\0`, } : args[0] === "rev-parse" - ? options.mergeInProgress - ? { status: 0, stdout: `${"e".repeat(40)}\n` } - : { status: 1, stdout: "" } + ? args.join("\0") === ["rev-parse", "--quiet", "--verify", "MERGE_HEAD"].join("\0") + ? options.mergeInProgress + ? { status: 0, stdout: `${"e".repeat(40)}\n` } + : { status: 1, stdout: "" } + : (() => { + throw new Error(`Unexpected revision probe: ${args.join(" ")}`); + })() : args.includes("--quiet") - ? (args.includes("--cached") && options.mergeInProgress) || + ? (args.includes("--cached") && + options.mergeInProgress && + args[3] === SOURCE_REVISION) || args[3] === (options.headRevision ?? "HEAD") ? { status: options.sourceParity === false ? 1 : 0, stdout: "" } : (() => { From 53b065ad3369206023fd25857c218928cefa43f7 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 16 Sep 2026 19:57:54 -0700 Subject: [PATCH 3/3] test(checks): cover automatic receipt revisions --- .../pi-qualification-receipt-refresh.test.ts | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/test/repository/pi-qualification-receipt-refresh.test.ts b/test/repository/pi-qualification-receipt-refresh.test.ts index 71a5f49cd60..b15125eb154 100644 --- a/test/repository/pi-qualification-receipt-refresh.test.ts +++ b/test/repository/pi-qualification-receipt-refresh.test.ts @@ -6,7 +6,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { checkPiQualificationReceiptRefresh } from "../../scripts/checks/pi-qualification-receipt-refresh.mts"; @@ -49,6 +49,8 @@ describe("Pi qualification receipt refresh", () => { let acceptedDigests: Set; beforeEach(() => { + vi.stubEnv("GITHUB_ACTIONS", "false"); + vi.stubEnv("GITHUB_EVENT_NAME", ""); rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-pi-receipt-refresh-")); fs.mkdirSync(path.join(rootDir, "agents/pi"), { recursive: true }); fs.mkdirSync(path.join(rootDir, "ci"), { recursive: true }); @@ -67,7 +69,10 @@ describe("Pi qualification receipt refresh", () => { acceptedDigests = new Set([receiptDigest(amd64Contents), receiptDigest(arm64Contents)]); }); - afterEach(() => fs.rmSync(rootDir, { force: true, recursive: true })); + afterEach(() => { + vi.unstubAllEnvs(); + fs.rmSync(rootDir, { force: true, recursive: true }); + }); function run( changedPaths: readonly string[], @@ -75,6 +80,7 @@ describe("Pi qualification receipt refresh", () => { accepted?: ReadonlySet; headRevision?: string | null; mergeInProgress?: boolean; + pullRequestHeadRevision?: string; sourceParity?: boolean; stagedPaths?: readonly string[]; } = {}, @@ -95,14 +101,17 @@ describe("Pi qualification receipt refresh", () => { ? options.mergeInProgress ? { status: 0, stdout: `${"e".repeat(40)}\n` } : { status: 1, stdout: "" } - : (() => { - throw new Error(`Unexpected revision probe: ${args.join(" ")}`); - })() + : args.join("\0") === ["rev-parse", "--verify", "HEAD^2"].join("\0") && + options.pullRequestHeadRevision + ? { status: 0, stdout: `${options.pullRequestHeadRevision}\n` } + : (() => { + throw new Error(`Unexpected revision probe: ${args.join(" ")}`); + })() : args.includes("--quiet") ? (args.includes("--cached") && options.mergeInProgress && args[3] === SOURCE_REVISION) || - args[3] === (options.headRevision ?? "HEAD") + args[3] === (options.headRevision ?? options.pullRequestHeadRevision ?? "HEAD") ? { status: options.sourceParity === false ? 1 : 0, stdout: "" } : (() => { throw new Error(`Unexpected source parity arguments: ${args.join(" ")}`); @@ -153,7 +162,7 @@ describe("Pi qualification receipt refresh", () => { ).not.toThrow(); }); - it("compares receipt parity against the exact PR head instead of a synthetic merge", () => { + it("compares receipt parity against an explicit head revision", () => { const headRevision = "d".repeat(40); expect(() => run(["protected/app/config.json", ...RECEIPTS.map(({ path }) => path)], { @@ -162,6 +171,27 @@ describe("Pi qualification receipt refresh", () => { ).not.toThrow(); }); + it("probes for a merge before comparing receipt parity against HEAD", () => { + expect(() => + run(["protected/app/config.json", ...RECEIPTS.map(({ path }) => path)], { + headRevision: null, + }), + ).not.toThrow(); + }); + + it("compares receipt parity against the exact PR head instead of a synthetic merge", () => { + const pullRequestHeadRevision = "d".repeat(40); + vi.stubEnv("GITHUB_ACTIONS", "true"); + vi.stubEnv("GITHUB_EVENT_NAME", "pull_request"); + + expect(() => + run(["protected/app/config.json", ...RECEIPTS.map(({ path }) => path)], { + headRevision: null, + pullRequestHeadRevision, + }), + ).not.toThrow(); + }); + it("compares receipt parity against the staged tree during a local merge", () => { expect(() => run(["protected/app/config.json", ...RECEIPTS.map(({ path }) => path)], {