Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/candidate-review-signal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# This PR-context workflow only wakes the default-branch admission controller.
# It uses permissions: {} and has no checkout, artifacts, or admission authority.
name: Security / Candidate Review Signal
on:
pull_request_review:
types: [submitted, edited, dismissed]
permissions: {}
jobs:
signal:
if: ${{ github.repository == 'NVIDIA/NemoClaw' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.repo.full_name == 'NVIDIA/NemoClaw' }}
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Signal a review change
run: echo 'Candidate admission will read the current PR reviews.'
30 changes: 22 additions & 8 deletions .github/workflows/candidate-upgrade-admission.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ name: Security / Candidate Upgrade Admission
on:
pull_request_target:
types: [opened, reopened, synchronize, edited, ready_for_review]
issue_comment:
types: [created, edited, deleted]
workflow_run:
workflows: [Security / Candidate Review Signal]
types: [completed]
permissions:
contents: read
pull-requests: read
jobs:
candidate-upgrade-admission:
if: ${{ github.repository == 'NVIDIA/NemoClaw' && ((github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.repo.full_name == 'NVIDIA/NemoClaw') || (github.event_name == 'issue_comment' && github.event.issue.pull_request && (contains(github.event.comment.body, 'NemoClaw-Upgrade-E2E:') || contains(github.event.changes.body.from, 'NemoClaw-Upgrade-E2E:')))) }}
if: ${{ github.repository == 'NVIDIA/NemoClaw' && ((github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.repo.full_name == 'NVIDIA/NemoClaw') || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request_review' && github.event.workflow_run.head_repository.full_name == 'NVIDIA/NemoClaw')) }}
concurrency:
group: candidate-upgrade-admission-${{ github.event.pull_request.number || github.event.issue.number }}
group: candidate-upgrade-admission-${{ github.event.pull_request.head.ref || github.event.workflow_run.head_branch }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 5
Expand All @@ -35,13 +36,26 @@ jobs:
with:
script: |
if (context.repo.owner !== "NVIDIA" || context.repo.repo !== "NemoClaw") throw new Error("Unexpected upgrade repository");
if (!["pull_request_target", "issue_comment"].includes(context.eventName)) throw new Error("Unexpected upgrade event");
const marker = value => typeof value === "string" && value.includes("NemoClaw-Upgrade-E2E:");
if (context.eventName === "issue_comment" && (!context.payload.issue?.pull_request || (!marker(context.payload.comment?.body) && !marker(context.payload.changes?.body?.from)))) return;
const number = context.payload.pull_request?.number ?? context.payload.issue?.number;
if (!["pull_request_target", "workflow_run"].includes(context.eventName)) throw new Error("Unexpected upgrade event");
const signal = context.payload.workflow_run;
let number = context.payload.pull_request?.number;
if (context.eventName === "workflow_run") {
if (signal?.event !== "pull_request_review" || signal?.name !== "Security / Candidate Review Signal" ||
signal?.head_repository?.full_name !== "NVIDIA/NemoClaw" ||
typeof signal?.head_branch !== "string" || !signal.head_branch)
throw new Error("Invalid candidate review signal");
// Review-triggered runs can omit pull_requests. Resolve the current upstream PR;
// the signal only requests reevaluation and supplies no approval authority.
const { data: prs } = await github.rest.pulls.list({ ...context.repo,
head: context.repo.owner + ":" + signal.head_branch, base: "main", state: "open", per_page: 2 });
if (!Array.isArray(prs) || prs.length > 1) throw new Error("Ambiguous candidate review signal");
if (prs.length === 0) return;
number = prs[0].number;
}
if (!Number.isSafeInteger(number) || number <= 0) throw new Error("Invalid upgrade PR number");
const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: number });
if (pr.state !== "open") return;
if (context.eventName === "workflow_run" && pr.head.ref !== signal.head_branch) throw new Error("Candidate review branch changed");
if (pr.head.repo?.full_name !== "NVIDIA/NemoClaw" || pr.base.repo?.full_name !== "NVIDIA/NemoClaw" || pr.base.ref !== "main") throw new Error("Unsupported upgrade PR identity");
if (!/^[a-f0-9]{40}$/.test(pr.head.sha) || !/^[a-f0-9]{40}$/.test(pr.base.sha)) throw new Error("Invalid upgrade commits");
await github.rest.repos.createCommitStatus({
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/installer-hash-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
ci/openshell-upgrade-trust.json
tools/e2e/candidate-openshell-trust.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
sparse-checkout-cone-mode: false

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -250,6 +251,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/npm-diagnostics.sh
scripts/lib/openclaw-npm-remediation.mts
Expand Down Expand Up @@ -304,7 +306,7 @@ jobs:
and .status == "completed" and .conclusion == "success"
and ((.event == "pull_request_target" and .head_sha == $sha
and any(.pull_requests[]?; .number == $pr and .head.sha == $sha and .base.sha == $base))
or (.event == "issue_comment" and .head_branch == "main"))
or (.event == "workflow_run" and .head_branch == "main"))
else
(.path | split("@")[0]) == ".github/workflows/main.yaml" and .head_branch == "main"
and (.event == "push" or .event == "workflow_dispatch")
Expand Down Expand Up @@ -398,6 +400,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -478,6 +481,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -555,6 +559,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -693,6 +698,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -835,6 +841,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down Expand Up @@ -897,6 +904,7 @@ jobs:
scripts/lib/reviewed-ci-npm-install.mts
scripts/checks/candidate-openshell-sdk.mts
tools/e2e/candidate-upgrade-admission.mts
tools/e2e/candidate-review-scope.mts
tools/e2e/base-image-publication.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
Expand Down
5 changes: 5 additions & 0 deletions ci/source-shape-test-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@
"file": "test/automation/e2e/platform-vitest-main-workflow.test.ts",
"test": "budgets WSL shard 1 for serial live tests, cleanup and evidence upload",
"category": "compatibility"
},
{
"file": "test/automation/pull-requests/candidate-upgrade-admission-workflow.test.ts",
"test": "refreshes admission through the configured %s review handoff after %s",
"category": "security"
}
]
}
6 changes: 3 additions & 3 deletions scripts/checks/candidate-openshell-sdk.mts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function readApprovedOpenShellSdkConfig(
request,
identity.mergeSha,
);
if (merged.commentId !== admission.commentId || merged.reviewer !== admission.reviewer)
if (merged.reviewId !== admission.reviewId || merged.reviewer !== admission.reviewer)
throw new Error("Candidate SDK admission changed during merge verification");
sources = { ...sources, ...merged.sources };
// The merge can update other dependencies, but cannot select a different SDK or audit policy.
Expand All @@ -185,7 +185,7 @@ export async function readApprovedOpenShellSdkConfig(
configSource: JSON.stringify(policy),
sources,
reviewer: admission.reviewer,
commentId: admission.commentId,
reviewId: admission.reviewId,
};
}

Expand Down Expand Up @@ -218,7 +218,7 @@ function artifactDecision(
required: true,
candidate: true,
artifactName: parseAuditConfig(admitted.configSource).sourceRegistryPackage.artifactName,
bundleName: `candidate-openshell-sdk-${identity.prNumber}-${identity.candidateSha}-${identity.baseSha}-${admitted.commentId}`,
bundleName: `candidate-openshell-sdk-${identity.prNumber}-${identity.candidateSha}-${identity.baseSha}-${admitted.reviewId}`,
} as const;
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/checks/package-openshell-sdk-for-pr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function packageApprovedCandidateOpenShellSdk(
if (
before.configSource !== after.configSource ||
JSON.stringify(before.sources) !== JSON.stringify(after.sources) ||
before.commentId !== after.commentId ||
before.reviewId !== after.reviewId ||
before.reviewer !== after.reviewer
) {
throw new Error("Candidate SDK admission changed during packaging");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { describe, expect, it, vi } from "vitest";
import { join } from "node:path";
import { readYaml, type WorkflowJob } from "../../helpers/e2e-workflow-contract";

const workflow = readYaml<{ jobs: Record<string, WorkflowJob> }>(
".github/workflows/candidate-upgrade-admission.yaml",
);
const workflow = readYaml<{
on: { workflow_run: { workflows: string[]; types: string[] } };
jobs: Record<string, WorkflowJob>;
}>(".github/workflows/candidate-upgrade-admission.yaml");
const reviewSignal = readYaml<{
name: string;
on: { pull_request_review: { types: string[] } };
}>(".github/workflows/candidate-review-signal.yaml");
const steps = workflow.jobs["candidate-upgrade-admission"]!.steps!;
const start = steps.find((step) => step.id === "identity")!.with!.script as string;
const finish = steps.find((step) => step.name === "Report current candidate upgrade admission")!
Expand Down Expand Up @@ -56,7 +61,7 @@ function packagingFixture() {
function fixture() {
const pr = {
state: "open",
head: { sha: head, repo: { full_name: "NVIDIA/NemoClaw" } },
head: { sha: head, ref: "codex/candidate", repo: { full_name: "NVIDIA/NemoClaw" } },
base: { sha: base, ref: "main", repo: { full_name: "NVIDIA/NemoClaw" } },
};
const context = {
Expand All @@ -66,21 +71,27 @@ function fixture() {
runId: 456,
payload: {
pull_request: { number: 123 },
issue: { number: 123, pull_request: {} },
comment: { body: `NemoClaw-Upgrade-E2E: approve ${head} ${base}` },
changes: { body: { from: "" } },
workflow_run: {
event: "pull_request_review",
name: "Security / Candidate Review Signal",
head_repository: { full_name: "NVIDIA/NemoClaw" },
head_branch: "codex/candidate",
pull_requests: [] as { number: number }[],
},
},
};
const outputs: Record<string, string> = {};
const status = vi.fn(async (_value: unknown) => ({}));
const get = vi.fn(async () => ({ data: pr }));
const github = { rest: { pulls: { get }, repos: { createCommitStatus: status } } };
const list = vi.fn(async () => ({ data: [{ number: 123 }] }));
const github = { rest: { pulls: { get, list }, repos: { createCommitStatus: status } } };
return {
pr,
context,
status,
outputs,
get,
list,
start: () =>
new AsyncFunction("github", "context", "core", start)(github, context, {
setOutput: (name: string, value: string) => {
Expand Down Expand Up @@ -140,34 +151,109 @@ describe("candidate upgrade admission status", () => {
expect(f.status).toHaveBeenLastCalledWith(expect.objectContaining({ state: "failure" }));
});

it.each(["approve", "revoke", "quoted approve"])(
"invalidates the merge status for %s without granting permission",
async (action) => {
// source-shape-contract: security -- GitHub must relay every review change to the trusted admission controller so dismissed approvals cannot leave candidate authorization stale.
it.each([
["submitted", "success"],
["edited", "success"],
["dismissed", "success"],
["dismissed", "failure"],
["dismissed", "cancelled"],
["dismissed", "skipped"],
])(
"refreshes admission through the configured %s review handoff after %s",
async (action, conclusion) => {
expect(reviewSignal.on.pull_request_review.types).toContain(action);
expect(workflow.on.workflow_run).toEqual({
workflows: [reviewSignal.name],
types: ["completed"],
});
const f = fixture();
f.context.eventName = "issue_comment";
f.context.payload.comment.body = `NemoClaw-Upgrade-E2E: ${action} ${head} ${base}`;
f.context.eventName = "workflow_run";
f.context.payload.workflow_run.name = reviewSignal.name;
f.context.payload.workflow_run.event = Object.keys(reviewSignal.on)[0]!;
const condition = String(workflow.jobs["candidate-upgrade-admission"]!.if).slice(3, -2);
const selected = (repository: string, conclusion: string) =>
new Function("github", `return (${condition});`)({
repository: "NVIDIA/NemoClaw",
event_name: "workflow_run",
event: {
workflow_run: {
...f.context.payload.workflow_run,
conclusion,
head_repository: { full_name: repository },
},
},
});
expect(selected("NVIDIA/NemoClaw", conclusion)).toBe(true);
expect(selected("other/NemoClaw", conclusion)).toBe(false);
await f.start();
expect(f.status).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({
sha: head,
context: "check-hash",
state: "pending",
}),
expect.objectContaining({ sha: head, context: "check-hash", state: "pending" }),
);
expect(f.outputs).toEqual({ pr_number: "123", head_sha: head, base_sha: base });
expect(f.list).toHaveBeenCalledExactlyOnceWith({
owner: "NVIDIA",
repo: "NemoClaw",
head: "NVIDIA:codex/candidate",
base: "main",
state: "open",
per_page: 2,
});
},
);

it.each(["wrong-event", "wrong-workflow", "fork", "missing-branch"])(
"rejects a %s review signal",
async (kind) => {
const f = fixture();
f.context.eventName = "workflow_run";
const signal = f.context.payload.workflow_run;
const mutate: Record<string, () => unknown> = {
"wrong-event": () => {
signal.event = "push";
},
"wrong-workflow": () => {
signal.name = "Other workflow";
},
fork: () => {
signal.head_repository.full_name = "other/NemoClaw";
},
"missing-branch": () => {
signal.head_branch = "";
},
};
mutate[kind]!();
await expect(f.start()).rejects.toThrow(/Invalid candidate review signal/);
expect(f.status).not.toHaveBeenCalled();
},
);

it("refreshes when editing removes the approval marker", async () => {
it("ignores a review signal after its branch has no open PR", async () => {
const f = fixture();
f.context.eventName = "issue_comment";
f.context.payload.changes.body.from = f.context.payload.comment.body;
f.context.payload.comment.body = "removed";
f.context.eventName = "workflow_run";
f.list.mockResolvedValueOnce({ data: [] });
await f.start();
expect(f.status).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ state: "pending" }));
expect(f.status).not.toHaveBeenCalled();
expect(f.outputs).toEqual({});
});

it("rejects ambiguous open PRs for a review branch", async () => {
const f = fixture();
f.context.eventName = "workflow_run";
f.list.mockResolvedValueOnce({ data: [{ number: 123 }, { number: 124 }] });
await expect(f.start()).rejects.toThrow(/Ambiguous/);
expect(f.status).not.toHaveBeenCalled();
});

it("rejects a branch mismatch after resolving the review signal", async () => {
const f = fixture();
f.context.eventName = "workflow_run";
f.pr.head.ref = "other-branch";
await expect(f.start()).rejects.toThrow(/branch changed/);
expect(f.status).not.toHaveBeenCalled();
});

it.each(["pull_request", "push", "workflow_dispatch"])(
it.each(["pull_request", "push", "workflow_dispatch", "issue_comment", "pull_request_review"])(
"rejects untrusted or unrelated event %s",
async (event) => {
const f = fixture();
Expand Down
Loading
Loading