Repository navigation
fix(pi): refresh qualification receipts #10866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c659f8
test(pi): detect stale qualification receipts
jyaunches 642b1e9
fix(pi): require receipt refresh with image inputs
jyaunches 73384f9
fix(pi): validate receipt source parity
jyaunches 839a398
test(pi): tighten receipt refresh coverage
jyaunches f8fb9af
fix(pi): preserve check module interop
jyaunches b1f25fd
test(pi): cover all protected receipt inputs
jyaunches 4700c2a
fix(pi): bind receipt authority inputs
jyaunches e91ca41
test(pi): clarify receipt refresh recovery
jyaunches e64665c
Merge remote-tracking branch 'origin/main' into codex/fix-pi-receipt-…
jyaunches File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** Requires both Pi qualification receipts when a Pi image input changes. */ | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| import { directDockerfileCopySources } from "../lib/dockerfile-copy-sources.mts"; | ||
|
|
||
| type GitResult = { | ||
| error?: string; | ||
| status: number | null; | ||
| stdout: string; | ||
| }; | ||
|
|
||
| type GitRunner = (args: readonly string[]) => GitResult; | ||
|
|
||
| const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); | ||
| const PI_DOCKERFILES = ["agents/pi/Dockerfile", "agents/pi/Dockerfile.base"] as const; | ||
| export const PI_QUALIFICATION_RECEIPTS = [ | ||
| "ci/pi-agent-qualification-v1-linux-amd64.json", | ||
| "ci/pi-agent-qualification-v1-linux-arm64.json", | ||
| ] as const; | ||
|
|
||
| function ownsPath(source: string, changedPath: string): boolean { | ||
| const normalizedSource = source.replace(/\/+$/u, ""); | ||
| return changedPath === normalizedSource || changedPath.startsWith(`${normalizedSource}/`); | ||
| } | ||
|
|
||
| export function missingPiQualificationReceiptRefreshes( | ||
| changedPaths: readonly string[], | ||
| imageSourcePaths: readonly string[], | ||
| receiptPaths: readonly string[] = PI_QUALIFICATION_RECEIPTS, | ||
| ): string[] { | ||
| if ( | ||
| !changedPaths.some((changedPath) => | ||
| imageSourcePaths.some((source) => ownsPath(source, changedPath)), | ||
| ) | ||
| ) { | ||
| return []; | ||
| } | ||
| return receiptPaths.filter((receipt) => !changedPaths.includes(receipt)); | ||
| } | ||
|
|
||
| function runGit(args: readonly string[]): GitResult { | ||
| const result = spawnSync("git", [...args], { | ||
| cwd: REPO_ROOT, | ||
| encoding: "utf8", | ||
| timeout: 10_000, | ||
| }); | ||
| return { | ||
| error: result.error?.message, | ||
| status: result.status, | ||
| stdout: result.stdout ?? "", | ||
| }; | ||
| } | ||
|
|
||
| function requireGitOutput(result: GitResult, operation: string): string { | ||
| if (result.error) throw new Error(`${operation}: ${result.error}`); | ||
| if (result.status !== 0) | ||
| throw new Error(`${operation}: git exited ${result.status ?? "without status"}`); | ||
| return result.stdout; | ||
| } | ||
|
|
||
| function mergeBaseRevision(git: GitRunner, baseBranch: string | undefined): string { | ||
| const baseRef = baseBranch ? `origin/${baseBranch}` : "origin/main"; | ||
| const revision = requireGitOutput( | ||
| git(["merge-base", "HEAD", baseRef]), | ||
| `Could not resolve the Pi receipt comparison base against ${baseRef}`, | ||
| ).trim(); | ||
| if (!revision) { | ||
| throw new Error(`Could not resolve the Pi receipt comparison base against ${baseRef}`); | ||
| } | ||
| return revision; | ||
| } | ||
|
|
||
| function changedPathsFromBase(git: GitRunner, revision: string): string[] { | ||
| return requireGitOutput( | ||
| git(["diff", "--no-ext-diff", "--no-textconv", "--name-only", "-z", revision, "HEAD", "--"]), | ||
| `Could not inspect changes after ${revision}`, | ||
| ) | ||
| .split("\0") | ||
| .filter(Boolean); | ||
| } | ||
|
|
||
| function piImageSourcePaths(rootDir: string): string[] { | ||
| const copiedSources = PI_DOCKERFILES.flatMap((dockerfile) => | ||
| directDockerfileCopySources(path.join(rootDir, dockerfile), dockerfile).map( | ||
| ({ source }) => source, | ||
| ), | ||
| ); | ||
| return [...new Set([".dockerignore", ...PI_DOCKERFILES, ...copiedSources])].sort(); | ||
| } | ||
|
|
||
| export function checkPiQualificationReceiptRefresh( | ||
| git: GitRunner = runGit, | ||
| rootDir: string = REPO_ROOT, | ||
| baseBranch: string | undefined = process.env.GITHUB_BASE_REF?.trim(), | ||
| ): void { | ||
| const revision = mergeBaseRevision(git, baseBranch); | ||
| const changedPaths = changedPathsFromBase(git, revision); | ||
| const missingReceipts = missingPiQualificationReceiptRefreshes( | ||
| changedPaths, | ||
| piImageSourcePaths(rootDir), | ||
| ); | ||
| if (missingReceipts.length === 0) return; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| throw new Error( | ||
| [ | ||
| "Pi image inputs changed without refreshing both qualification receipts.", | ||
| "Publish one exact-commit AMD64 and ARM64 Pi candidate cohort, then update:", | ||
| ...missingReceipts.map((receipt) => `- ${receipt}`), | ||
| ].join("\n"), | ||
| ); | ||
| } | ||
|
|
||
| const currentModule = fileURLToPath(import.meta.url); | ||
| if (process.argv[1] && path.resolve(process.argv[1]) === currentModule) { | ||
| checkPiQualificationReceiptRefresh(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { missingPiQualificationReceiptRefreshes } from "../../scripts/checks/pi-qualification-receipt-refresh.mts"; | ||
|
|
||
| const RECEIPTS = ["ci/pi-amd64.json", "ci/pi-arm64.json"]; | ||
| const IMAGE_SOURCES = ["agents/pi/Dockerfile", "blueprint/"]; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| describe("Pi qualification receipt refresh", () => { | ||
| it("requires both architecture receipts after an image input changes", () => { | ||
| expect( | ||
| missingPiQualificationReceiptRefreshes( | ||
| ["blueprint/provider-profiles/example.yaml"], | ||
| IMAGE_SOURCES, | ||
| RECEIPTS, | ||
| ), | ||
| ).toEqual(RECEIPTS); | ||
| }); | ||
|
|
||
| it("rejects a partial architecture receipt refresh", () => { | ||
| expect( | ||
| missingPiQualificationReceiptRefreshes( | ||
| ["agents/pi/Dockerfile", RECEIPTS[0]!], | ||
| IMAGE_SOURCES, | ||
| RECEIPTS, | ||
| ), | ||
| ).toEqual([RECEIPTS[1]]); | ||
| }); | ||
|
|
||
| it("accepts one cohort refresh for both architectures", () => { | ||
| expect( | ||
| missingPiQualificationReceiptRefreshes( | ||
| ["blueprint/policy.yaml", ...RECEIPTS], | ||
| IMAGE_SOURCES, | ||
| RECEIPTS, | ||
| ), | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it("does not require receipts for unrelated changes", () => { | ||
| expect( | ||
| missingPiQualificationReceiptRefreshes(["docs/reference/pi.mdx"], IMAGE_SOURCES, RECEIPTS), | ||
| ).toEqual([]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.