|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { createHash } from "node:crypto"; |
| 5 | +import fs from "node:fs"; |
| 6 | +import os from "node:os"; |
| 7 | +import path from "node:path"; |
| 8 | + |
| 9 | +import { afterEach, describe, expect, it } from "vitest"; |
| 10 | + |
| 11 | +import { writeNativeRuntimeQualificationProducerEvidence } from "../../../tools/e2e/native-runtime-qualification-producer-evidence.mts"; |
| 12 | +import { |
| 13 | + buildNativeRuntimeQualificationProducerPlan, |
| 14 | + NATIVE_RUNTIME_QUALIFICATION_FOCUSED_CASE, |
| 15 | +} from "../../../tools/e2e/native-runtime-qualification-producer-plan.mts"; |
| 16 | + |
| 17 | +const roots: string[] = []; |
| 18 | +const INSTALLER = "#!/usr/bin/env bash\nexit 0\n"; |
| 19 | +const INSTALLER_SHA256 = createHash("sha256").update(INSTALLER).digest("hex"); |
| 20 | + |
| 21 | +function fixture() { |
| 22 | + const root = fs.mkdtempSync(path.join(os.tmpdir(), "native-runtime-producer-evidence-")); |
| 23 | + roots.push(root); |
| 24 | + const row = buildNativeRuntimeQualificationProducerPlan({ |
| 25 | + source: { |
| 26 | + repository: "NVIDIA/NemoClaw", |
| 27 | + producerWorkflow: ".github/workflows/e2e.yaml", |
| 28 | + pullRequestNumber: 8064, |
| 29 | + candidateRepository: "NVIDIA/NemoClaw", |
| 30 | + candidateSha: "a".repeat(40), |
| 31 | + baseRef: "main", |
| 32 | + baseSha: "b".repeat(40), |
| 33 | + workflowSha: "b".repeat(40), |
| 34 | + producerRunId: "123456789", |
| 35 | + producerRunAttempt: 1, |
| 36 | + dispatchArtifact: { |
| 37 | + id: "42", |
| 38 | + name: "e2e-dispatch-123456789-1", |
| 39 | + digest: `sha256:${"c".repeat(64)}`, |
| 40 | + sizeInBytes: 4096, |
| 41 | + }, |
| 42 | + }, |
| 43 | + installerSha256: INSTALLER_SHA256, |
| 44 | + arm64GpuRunner: "reviewed-native-arm64-gpu-runner", |
| 45 | + }).include.find((entry) => entry.id === NATIVE_RUNTIME_QUALIFICATION_FOCUSED_CASE)!; |
| 46 | + const installerDirectory = path.join(root, "installer"); |
| 47 | + const executionPath = path.join(root, "execution.json"); |
| 48 | + const evidenceDirectory = path.join(root, "evidence"); |
| 49 | + fs.mkdirSync(installerDirectory); |
| 50 | + fs.writeFileSync(path.join(installerDirectory, "installer.sh"), INSTALLER); |
| 51 | + fs.writeFileSync( |
| 52 | + path.join(installerDirectory, "invocation.json"), |
| 53 | + JSON.stringify({ |
| 54 | + receiptVersion: 1, |
| 55 | + script: "scripts/install.sh", |
| 56 | + scriptSha256: INSTALLER_SHA256, |
| 57 | + candidateSha: row.source.candidateSha, |
| 58 | + architecture: row.case.architecture, |
| 59 | + }), |
| 60 | + ); |
| 61 | + fs.writeFileSync( |
| 62 | + path.join(installerDirectory, "candidate-source.json"), |
| 63 | + JSON.stringify({ |
| 64 | + receiptVersion: 1, |
| 65 | + repository: "https://github.com/NVIDIA/NemoClaw.git", |
| 66 | + revision: row.source.candidateSha, |
| 67 | + installerSha256: INSTALLER_SHA256, |
| 68 | + }), |
| 69 | + ); |
| 70 | + fs.writeFileSync( |
| 71 | + path.join(installerDirectory, "installed-source.json"), |
| 72 | + JSON.stringify({ |
| 73 | + receiptVersion: 1, |
| 74 | + repository: "https://github.com/NVIDIA/NemoClaw.git", |
| 75 | + requestedRevision: row.source.candidateSha, |
| 76 | + installedRevision: row.source.candidateSha, |
| 77 | + installMode: "managed", |
| 78 | + installerSha256: INSTALLER_SHA256, |
| 79 | + }), |
| 80 | + ); |
| 81 | + fs.writeFileSync( |
| 82 | + path.join(installerDirectory, "architecture.json"), |
| 83 | + JSON.stringify({ receiptVersion: 1, requested: "amd64", runner: "amd64" }), |
| 84 | + ); |
| 85 | + const dockerPosture = { |
| 86 | + dockerCommandGuarded: true, |
| 87 | + dockerEnvironmentVariablesUnset: true, |
| 88 | + dockerServiceInactive: true, |
| 89 | + dockerSocketUnitInactive: true, |
| 90 | + dockerdProcessNameAbsent: true, |
| 91 | + defaultSocketPathsAbsent: true, |
| 92 | + }; |
| 93 | + fs.writeFileSync( |
| 94 | + path.join(installerDirectory, "docker-absence.json"), |
| 95 | + JSON.stringify({ |
| 96 | + receiptVersion: 1, |
| 97 | + preExecution: dockerPosture, |
| 98 | + postExecution: dockerPosture, |
| 99 | + }), |
| 100 | + ); |
| 101 | + const execution = { |
| 102 | + schemaVersion: 1, |
| 103 | + kind: "nemoclaw-native-runtime-qualification-execution-v1", |
| 104 | + caseId: row.id, |
| 105 | + candidateSha: row.source.candidateSha, |
| 106 | + installerSha256: row.installerSha256, |
| 107 | + architecture: row.case.architecture, |
| 108 | + acceleration: row.case.acceleration, |
| 109 | + agent: row.case.agent, |
| 110 | + inference: row.case.inference, |
| 111 | + rootModes: row.rootModes, |
| 112 | + obligations: row.case.obligations, |
| 113 | + focusedOperations: row.focusedOperations, |
| 114 | + evidenceKinds: row.case.evidenceKinds, |
| 115 | + dockerUnavailable: { beforeCandidate: true, afterCandidate: true }, |
| 116 | + credentialBoundary: { |
| 117 | + githubCredentialsAbsent: true, |
| 118 | + modelCredentialsAbsent: true, |
| 119 | + isolatedUid: true, |
| 120 | + }, |
| 121 | + result: "passed", |
| 122 | + }; |
| 123 | + fs.writeFileSync(executionPath, JSON.stringify(execution)); |
| 124 | + return { evidenceDirectory, execution, executionPath, installerDirectory, root, row }; |
| 125 | +} |
| 126 | + |
| 127 | +afterEach(() => { |
| 128 | + for (const root of roots.splice(0)) fs.rmSync(root, { force: true, recursive: true }); |
| 129 | +}); |
| 130 | + |
| 131 | +describe("native runtime qualification producer evidence", () => { |
| 132 | + it("emits the bounded case-evidence envelope after validating installer and execution receipts", () => { |
| 133 | + const value = fixture(); |
| 134 | + |
| 135 | + writeNativeRuntimeQualificationProducerEvidence( |
| 136 | + value.row, |
| 137 | + value.installerDirectory, |
| 138 | + value.executionPath, |
| 139 | + value.evidenceDirectory, |
| 140 | + ); |
| 141 | + |
| 142 | + expect(fs.readdirSync(value.evidenceDirectory)).toEqual(["evidence.json"]); |
| 143 | + expect( |
| 144 | + JSON.parse(fs.readFileSync(path.join(value.evidenceDirectory, "evidence.json"), "utf8")), |
| 145 | + ).toEqual({ |
| 146 | + schemaVersion: 1, |
| 147 | + kind: "nemoclaw-native-runtime-qualification-case-evidence-v1", |
| 148 | + qualificationId: "podman-protected-host-local-inference", |
| 149 | + providerId: "podman", |
| 150 | + source: value.row.source, |
| 151 | + case: value.row.case, |
| 152 | + result: "passed", |
| 153 | + }); |
| 154 | + expect(fs.statSync(path.join(value.evidenceDirectory, "evidence.json")).mode & 0o777).toBe( |
| 155 | + 0o600, |
| 156 | + ); |
| 157 | + }); |
| 158 | + |
| 159 | + it.each([ |
| 160 | + [ |
| 161 | + "candidate identity", |
| 162 | + (value: ReturnType<typeof fixture>) => ({ ...value.execution, candidateSha: "d".repeat(40) }), |
| 163 | + ], |
| 164 | + [ |
| 165 | + "rootful focus", |
| 166 | + (value: ReturnType<typeof fixture>) => ({ ...value.execution, rootModes: ["rootless"] }), |
| 167 | + ], |
| 168 | + [ |
| 169 | + "cleanup operation", |
| 170 | + (value: ReturnType<typeof fixture>) => ({ |
| 171 | + ...value.execution, |
| 172 | + focusedOperations: value.row.focusedOperations.slice(0, -1), |
| 173 | + }), |
| 174 | + ], |
| 175 | + [ |
| 176 | + "credential boundary", |
| 177 | + (value: ReturnType<typeof fixture>) => ({ |
| 178 | + ...value.execution, |
| 179 | + credentialBoundary: { |
| 180 | + ...value.execution.credentialBoundary, |
| 181 | + githubCredentialsAbsent: false, |
| 182 | + }, |
| 183 | + }), |
| 184 | + ], |
| 185 | + [ |
| 186 | + "Docker boundary", |
| 187 | + (value: ReturnType<typeof fixture>) => ({ |
| 188 | + ...value.execution, |
| 189 | + dockerUnavailable: { beforeCandidate: true, afterCandidate: false }, |
| 190 | + }), |
| 191 | + ], |
| 192 | + ])("rejects an invalid %s receipt", (_label, mutate) => { |
| 193 | + const value = fixture(); |
| 194 | + fs.writeFileSync(value.executionPath, JSON.stringify(mutate(value))); |
| 195 | + |
| 196 | + expect(() => |
| 197 | + writeNativeRuntimeQualificationProducerEvidence( |
| 198 | + value.row, |
| 199 | + value.installerDirectory, |
| 200 | + value.executionPath, |
| 201 | + value.evidenceDirectory, |
| 202 | + ), |
| 203 | + ).toThrow("Native runtime qualification"); |
| 204 | + }); |
| 205 | + |
| 206 | + it("rejects a forged installer receipt", () => { |
| 207 | + const value = fixture(); |
| 208 | + fs.writeFileSync( |
| 209 | + path.join(value.installerDirectory, "installer.sh"), |
| 210 | + `${INSTALLER}echo forged\n`, |
| 211 | + ); |
| 212 | + |
| 213 | + expect(() => |
| 214 | + writeNativeRuntimeQualificationProducerEvidence( |
| 215 | + value.row, |
| 216 | + value.installerDirectory, |
| 217 | + value.executionPath, |
| 218 | + value.evidenceDirectory, |
| 219 | + ), |
| 220 | + ).toThrow("installer receipt is invalid"); |
| 221 | + }); |
| 222 | + |
| 223 | + it("rejects unexpected files in the installer receipt directory", () => { |
| 224 | + const value = fixture(); |
| 225 | + fs.writeFileSync(path.join(value.installerDirectory, "log.txt"), "candidate output"); |
| 226 | + |
| 227 | + expect(() => |
| 228 | + writeNativeRuntimeQualificationProducerEvidence( |
| 229 | + value.row, |
| 230 | + value.installerDirectory, |
| 231 | + value.executionPath, |
| 232 | + value.evidenceDirectory, |
| 233 | + ), |
| 234 | + ).toThrow("receipt files are invalid"); |
| 235 | + }); |
| 236 | + |
| 237 | + it("rejects a symbolic link used as the execution receipt", () => { |
| 238 | + const value = fixture(); |
| 239 | + const target = path.join(value.root, "linked-execution.json"); |
| 240 | + fs.renameSync(value.executionPath, target); |
| 241 | + fs.symlinkSync(target, value.executionPath); |
| 242 | + |
| 243 | + expect(() => |
| 244 | + writeNativeRuntimeQualificationProducerEvidence( |
| 245 | + value.row, |
| 246 | + value.installerDirectory, |
| 247 | + value.executionPath, |
| 248 | + value.evidenceDirectory, |
| 249 | + ), |
| 250 | + ).toThrow("receipt is missing or invalid"); |
| 251 | + }); |
| 252 | +}); |
0 commit comments