From a40ca88cbe53ce5af5fecb1c089d61de48c03ea6 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:05:32 +0000 Subject: [PATCH 01/33] feat(readiness): define system readiness report contract Signed-off-by: Remy the Refactoror --- schemas/system-readiness.schema.json | 177 ++++++++++++++++++ src/lib/readiness/compatibility.ts | 30 +++ src/lib/readiness/contract.test.ts | 70 +++++++ src/lib/readiness/index.ts | 24 +++ src/lib/readiness/types.ts | 71 +++++++ .../system-readiness/incompatible.json | 31 +++ .../system-readiness/inconclusive.json | 32 ++++ test/fixtures/system-readiness/supported.json | 25 +++ 8 files changed, 460 insertions(+) create mode 100644 schemas/system-readiness.schema.json create mode 100644 src/lib/readiness/compatibility.ts create mode 100644 src/lib/readiness/contract.test.ts create mode 100644 src/lib/readiness/index.ts create mode 100644 src/lib/readiness/types.ts create mode 100644 test/fixtures/system-readiness/incompatible.json create mode 100644 test/fixtures/system-readiness/inconclusive.json create mode 100644 test/fixtures/system-readiness/supported.json diff --git a/schemas/system-readiness.schema.json b/schemas/system-readiness.schema.json new file mode 100644 index 00000000000..ebcf705f879 --- /dev/null +++ b/schemas/system-readiness.schema.json @@ -0,0 +1,177 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json", + "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0", + "title": "NemoClaw system readiness report", + "description": "Version 1 consumer-neutral contract for a read-only system readiness report. Unknown major versions are incompatible. Consumers must ignore unrecognized optional fields in major version 1. Evidence is bounded diagnostic context and does not affect compatibility decisions unless a capability or finding references it by evidenceId.", + "type": "object", + "required": ["schemaVersion", "status", "exitCode", "mutated", "provenance", "observations", "capabilities", "qualifications", "findings", "evidence"], + "properties": { + "schemaVersion": { + "type": "string", + "pattern": "^1\\.[0-9]+\\.[0-9]+$", + "description": "Semantic contract version. Consumers must reject unknown major versions. New optional fields may be added within major version 1." + }, + "status": { + "enum": ["supported", "incompatible", "inconclusive"], + "description": "Overall readiness result. supported maps to exit 0, incompatible to exit 2, and inconclusive to exit 3." + }, + "exitCode": { + "enum": [0, 2, 3], + "description": "Deterministic process result: 0 supported, 2 incompatible, 3 inconclusive." + }, + "mutated": { + "const": false, + "description": "The report operation did not mutate the host or NemoClaw state." + }, + "provenance": { "$ref": "#/$defs/provenance" }, + "observations": { + "type": "array", + "maxItems": 256, + "items": { "$ref": "#/$defs/observation" } + }, + "capabilities": { + "type": "array", + "maxItems": 256, + "items": { "$ref": "#/$defs/capability" } + }, + "qualifications": { + "type": "array", + "maxItems": 128, + "items": { "$ref": "#/$defs/qualification" } + }, + "findings": { + "type": "array", + "maxItems": 256, + "items": { "$ref": "#/$defs/finding" } + }, + "evidence": { + "type": "array", + "maxItems": 256, + "items": { "$ref": "#/$defs/evidence" }, + "description": "Bounded diagnostic context. Evidence is not a compatibility input unless a stable capability or finding references its ID." + } + }, + "allOf": [ + { + "if": { "properties": { "status": { "const": "supported" } }, "required": ["status"] }, + "then": { "properties": { "exitCode": { "const": 0 } } } + }, + { + "if": { "properties": { "status": { "const": "incompatible" } }, "required": ["status"] }, + "then": { "properties": { "exitCode": { "const": 2 } } } + }, + { + "if": { "properties": { "status": { "const": "inconclusive" } }, "required": ["status"] }, + "then": { "properties": { "exitCode": { "const": 3 } } } + } + ], + "additionalProperties": true, + "$defs": { + "stableId": { + "type": "string", + "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+$", + "maxLength": 128, + "description": "Stable machine identifier. It must not derive from a display title or remediation text." + }, + "state": { + "enum": ["present", "absent", "unknown"], + "description": "present means observed or derived to exist; absent means checked and not found; unknown means the check could not determine presence." + }, + "provenance": { + "type": "object", + "required": ["nemoclawVersion", "observedAt"], + "properties": { + "nemoclawVersion": { "type": "string", "minLength": 1, "maxLength": 128 }, + "sourceRevision": { + "type": "string", + "pattern": "^[0-9a-f]{40,64}$", + "description": "Immutable source revision when the build provides one." + }, + "observedAt": { "type": "string", "format": "date-time" } + }, + "additionalProperties": true + }, + "observation": { + "type": "object", + "required": ["id", "state"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "state": { "$ref": "#/$defs/state" }, + "value": { "$ref": "#/$defs/scalar" }, + "evidenceIds": { "$ref": "#/$defs/evidenceIds" } + }, + "additionalProperties": true + }, + "capability": { + "type": "object", + "required": ["id", "state"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "state": { "$ref": "#/$defs/state" }, + "evidenceIds": { "$ref": "#/$defs/evidenceIds" } + }, + "additionalProperties": true + }, + "qualification": { + "type": "object", + "required": ["id", "status"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "status": { "enum": ["qualified", "unqualified", "unknown"] }, + "capabilityIds": { + "type": "array", + "maxItems": 64, + "uniqueItems": true, + "items": { "$ref": "#/$defs/stableId" } + } + }, + "additionalProperties": true + }, + "finding": { + "type": "object", + "required": ["id", "severity", "summary"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "severity": { "enum": ["info", "warning", "blocking", "fatal"] }, + "summary": { "type": "string", "minLength": 1, "maxLength": 512 }, + "capabilityIds": { + "type": "array", + "maxItems": 64, + "uniqueItems": true, + "items": { "$ref": "#/$defs/stableId" } + }, + "evidenceIds": { "$ref": "#/$defs/evidenceIds" } + }, + "additionalProperties": true + }, + "evidence": { + "type": "object", + "required": ["id", "summary"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "summary": { "type": "string", "minLength": 1, "maxLength": 1024 }, + "details": { + "type": "object", + "maxProperties": 16, + "additionalProperties": { "$ref": "#/$defs/scalar" } + } + }, + "additionalProperties": true + }, + "evidenceIds": { + "type": "array", + "maxItems": 32, + "uniqueItems": true, + "items": { "$ref": "#/$defs/stableId" } + }, + "scalar": { + "oneOf": [ + { "type": "string", "maxLength": 1024 }, + { "type": "number" }, + { "type": "boolean" }, + { "type": "null" } + ] + } + } +} diff --git a/src/lib/readiness/compatibility.ts b/src/lib/readiness/compatibility.ts new file mode 100644 index 00000000000..11a41d40671 --- /dev/null +++ b/src/lib/readiness/compatibility.ts @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR } from "./types.js"; + +export type SchemaCompatibility = + | { compatible: true; major: number } + | { compatible: false; major: number | null; reason: string }; + +export function checkSystemReadinessSchemaVersion(schemaVersion: unknown): SchemaCompatibility { + if (typeof schemaVersion !== "string") { + return { compatible: false, major: null, reason: "schemaVersion must be a string" }; + } + + const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(schemaVersion); + if (!match) { + return { compatible: false, major: null, reason: "schemaVersion must use major.minor.patch" }; + } + + const major = Number(match[1]); + if (major !== SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR) { + return { + compatible: false, + major, + reason: `unsupported system readiness schema major ${major}`, + }; + } + + return { compatible: true, major }; +} diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts new file mode 100644 index 00000000000..16bc4d89ca8 --- /dev/null +++ b/src/lib/readiness/contract.test.ts @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { readFile } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; +import { describe, expect, it } from "vitest"; +import { checkSystemReadinessSchemaVersion } from "./compatibility.js"; + +const repositoryRoot = fileURLToPath(new URL("../../..", import.meta.url)); +const schemaPath = `${repositoryRoot}/schemas/system-readiness.schema.json`; +const fixtureRoot = `${repositoryRoot}/test/fixtures/system-readiness`; + +async function readJson(path: string): Promise { + return JSON.parse(await readFile(path, "utf8")); +} + +async function createValidator() { + const ajv = new Ajv2020({ allErrors: true, strict: true }); + ajv.addFormat("date-time", { type: "string", validate: (value: string) => !Number.isNaN(Date.parse(value)) }); + return ajv.compile((await readJson(schemaPath)) as AnySchema); +} + +describe("system readiness contract", () => { + it.each(["supported", "incompatible", "inconclusive"])( + "validates the %s golden fixture (#7409)", + async (name) => { + const validate = await createValidator(); + const fixture = await readJson(`${fixtureRoot}/${name}.json`); + + expect(validate(fixture), JSON.stringify(validate.errors)).toBe(true); + }, + ); + + it("accepts optional fields in schema major 1 (#7409)", async () => { + const validate = await createValidator(); + const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; + fixture.consumerExtension = { value: true }; + + expect(checkSystemReadinessSchemaVersion("1.7.4")).toEqual({ compatible: true, major: 1 }); + expect(validate({ ...fixture, schemaVersion: "1.7.4" }), JSON.stringify(validate.errors)).toBe( + true, + ); + }); + + it("rejects unknown schema majors before reading the report (#7409)", () => { + expect(checkSystemReadinessSchemaVersion("2.0.0")).toEqual({ + compatible: false, + major: 2, + reason: "unsupported system readiness schema major 2", + }); + expect(checkSystemReadinessSchemaVersion("not-a-version").compatible).toBe(false); + }); + + it("rejects status and exit-code mismatches (#7409)", async () => { + const validate = await createValidator(); + const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; + + expect(validate({ ...fixture, exitCode: 2 })).toBe(false); + }); + + it("rejects mutation and unbounded evidence (#7409)", async () => { + const validate = await createValidator(); + const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; + const evidence = [{ id: "probe.output", summary: "x".repeat(1025) }]; + + expect(validate({ ...fixture, mutated: true })).toBe(false); + expect(validate({ ...fixture, evidence })).toBe(false); + }); +}); diff --git a/src/lib/readiness/index.ts b/src/lib/readiness/index.ts new file mode 100644 index 00000000000..f0495543b73 --- /dev/null +++ b/src/lib/readiness/index.ts @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +export { checkSystemReadinessSchemaVersion } from "./compatibility.js"; +export type { SchemaCompatibility } from "./compatibility.js"; +export { + SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR, + SYSTEM_READINESS_SCHEMA_VERSION, +} from "./types.js"; +export type { + EvidenceScalar, + FindingSeverity, + QualificationStatus, + ReadinessCapability, + ReadinessEvidence, + ReadinessExitCode, + ReadinessFinding, + ReadinessObservation, + ReadinessProvenance, + ReadinessQualification, + ReadinessState, + ReadinessStatus, + SystemReadinessReport, +} from "./types.js"; diff --git a/src/lib/readiness/types.ts b/src/lib/readiness/types.ts new file mode 100644 index 00000000000..208debcd103 --- /dev/null +++ b/src/lib/readiness/types.ts @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +export const SYSTEM_READINESS_SCHEMA_VERSION = "1.0.0" as const; +export const SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR = 1; + +export type ReadinessState = "present" | "absent" | "unknown"; +export type ReadinessStatus = "supported" | "incompatible" | "inconclusive"; +export type ReadinessExitCode = 0 | 2 | 3; +export type FindingSeverity = "info" | "warning" | "blocking" | "fatal"; +export type QualificationStatus = "qualified" | "unqualified" | "unknown"; +export type EvidenceScalar = string | number | boolean | null; + +export interface ReadinessProvenance { + nemoclawVersion: string; + sourceRevision?: string; + observedAt: string; + [key: string]: unknown; +} + +export interface ReadinessObservation { + id: string; + state: ReadinessState; + value?: EvidenceScalar; + evidenceIds?: readonly string[]; + [key: string]: unknown; +} + +export interface ReadinessCapability { + id: string; + state: ReadinessState; + evidenceIds?: readonly string[]; + [key: string]: unknown; +} + +export interface ReadinessQualification { + id: string; + status: QualificationStatus; + capabilityIds?: readonly string[]; + [key: string]: unknown; +} + +export interface ReadinessFinding { + id: string; + severity: FindingSeverity; + summary: string; + capabilityIds?: readonly string[]; + evidenceIds?: readonly string[]; + [key: string]: unknown; +} + +export interface ReadinessEvidence { + id: string; + summary: string; + details?: Readonly>; + [key: string]: unknown; +} + +export interface SystemReadinessReport { + schemaVersion: string; + status: ReadinessStatus; + exitCode: ReadinessExitCode; + mutated: false; + provenance: ReadinessProvenance; + observations: readonly ReadinessObservation[]; + capabilities: readonly ReadinessCapability[]; + qualifications: readonly ReadinessQualification[]; + findings: readonly ReadinessFinding[]; + evidence: readonly ReadinessEvidence[]; + [key: string]: unknown; +} diff --git a/test/fixtures/system-readiness/incompatible.json b/test/fixtures/system-readiness/incompatible.json new file mode 100644 index 00000000000..ac05e22b7db --- /dev/null +++ b/test/fixtures/system-readiness/incompatible.json @@ -0,0 +1,31 @@ +{ + "schemaVersion": "1.0.0", + "status": "incompatible", + "exitCode": 2, + "mutated": false, + "provenance": { + "nemoclawVersion": "0.1.0", + "observedAt": "2026-06-01T12:00:00Z" + }, + "observations": [ + { "id": "runtime.docker", "state": "absent", "evidenceIds": ["docker.not-found"] } + ], + "capabilities": [ + { "id": "sandbox.container-runtime", "state": "absent", "evidenceIds": ["docker.not-found"] } + ], + "qualifications": [ + { "id": "platform.generic-linux", "status": "unqualified", "capabilityIds": ["sandbox.container-runtime"] } + ], + "findings": [ + { + "id": "runtime.docker-required", + "severity": "blocking", + "summary": "A container runtime is required.", + "capabilityIds": ["sandbox.container-runtime"], + "evidenceIds": ["docker.not-found"] + } + ], + "evidence": [ + { "id": "docker.not-found", "summary": "The Docker executable was not found." } + ] +} diff --git a/test/fixtures/system-readiness/inconclusive.json b/test/fixtures/system-readiness/inconclusive.json new file mode 100644 index 00000000000..21382ff1d03 --- /dev/null +++ b/test/fixtures/system-readiness/inconclusive.json @@ -0,0 +1,32 @@ +{ + "schemaVersion": "1.0.0", + "status": "inconclusive", + "exitCode": 3, + "mutated": false, + "provenance": { + "nemoclawVersion": "0.1.0", + "sourceRevision": "21e60ae287e8c2a184f71406ac8b418f046330d1", + "observedAt": "2026-06-01T12:00:00Z" + }, + "observations": [ + { "id": "gpu.nvidia", "state": "unknown", "evidenceIds": ["gpu.permission-denied"] } + ], + "capabilities": [ + { "id": "inference.nvidia-gpu", "state": "unknown", "evidenceIds": ["gpu.permission-denied"] } + ], + "qualifications": [ + { "id": "platform.generic-linux", "status": "unknown", "capabilityIds": ["inference.nvidia-gpu"] } + ], + "findings": [ + { + "id": "gpu.visibility-undetermined", + "severity": "warning", + "summary": "NemoClaw could not determine GPU visibility.", + "capabilityIds": ["inference.nvidia-gpu"], + "evidenceIds": ["gpu.permission-denied"] + } + ], + "evidence": [ + { "id": "gpu.permission-denied", "summary": "The GPU query was denied." } + ] +} diff --git a/test/fixtures/system-readiness/supported.json b/test/fixtures/system-readiness/supported.json new file mode 100644 index 00000000000..6fac1884d75 --- /dev/null +++ b/test/fixtures/system-readiness/supported.json @@ -0,0 +1,25 @@ +{ + "schemaVersion": "1.0.0", + "status": "supported", + "exitCode": 0, + "mutated": false, + "provenance": { + "nemoclawVersion": "0.1.0", + "sourceRevision": "21e60ae287e8c2a184f71406ac8b418f046330d1", + "observedAt": "2026-06-01T12:00:00Z" + }, + "observations": [ + { "id": "host.os", "state": "present", "value": "linux" }, + { "id": "runtime.docker", "state": "present" } + ], + "capabilities": [ + { "id": "sandbox.container-runtime", "state": "present", "evidenceIds": ["docker.reachable"] } + ], + "qualifications": [ + { "id": "platform.generic-linux", "status": "qualified", "capabilityIds": ["sandbox.container-runtime"] } + ], + "findings": [], + "evidence": [ + { "id": "docker.reachable", "summary": "The container runtime responded.", "details": { "version": "27.5.1" } } + ] +} From 20e905d0eecba120de3290b1c9ff153f6a4277a2 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:16:02 +0000 Subject: [PATCH 02/33] fix(readiness): format contract validator setup Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index 16bc4d89ca8..ecb4beafd9e 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -17,7 +17,10 @@ async function readJson(path: string): Promise { async function createValidator() { const ajv = new Ajv2020({ allErrors: true, strict: true }); - ajv.addFormat("date-time", { type: "string", validate: (value: string) => !Number.isNaN(Date.parse(value)) }); + ajv.addFormat("date-time", { + type: "string", + validate: (value: string) => !Number.isNaN(Date.parse(value)), + }); return ajv.compile((await readJson(schemaPath)) as AnySchema); } From d8e5dea7d001358f3468d365af804cbdd5a3ab33 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:28:44 +0000 Subject: [PATCH 03/33] fix(readiness): import schema as contract data Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index ecb4beafd9e..7c4e5626e1b 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -5,10 +5,10 @@ import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; import { describe, expect, it } from "vitest"; +import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { type: "json" }; import { checkSystemReadinessSchemaVersion } from "./compatibility.js"; const repositoryRoot = fileURLToPath(new URL("../../..", import.meta.url)); -const schemaPath = `${repositoryRoot}/schemas/system-readiness.schema.json`; const fixtureRoot = `${repositoryRoot}/test/fixtures/system-readiness`; async function readJson(path: string): Promise { @@ -21,7 +21,7 @@ async function createValidator() { type: "string", validate: (value: string) => !Number.isNaN(Date.parse(value)), }); - return ajv.compile((await readJson(schemaPath)) as AnySchema); + return ajv.compile(systemReadinessSchema as AnySchema); } describe("system readiness contract", () => { From a34e5c447722b75f85598a402bd6c1a38336adf6 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:30:26 +0000 Subject: [PATCH 04/33] test(readiness): reject invalid calendar timestamps Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index 7c4e5626e1b..94a092bb9f8 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -15,12 +15,21 @@ async function readJson(path: string): Promise { return JSON.parse(await readFile(path, "utf8")); } +function isRfc3339DateTime(value: string): boolean { + const match = /^(\d{4})-(\d{2})-(\d{2})T(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec( + value, + ); + if (!match) return false; + + const year = Number(match[1]); + const month = Number(match[2]); + const day = Number(match[3]); + return month >= 1 && month <= 12 && day >= 1 && day <= new Date(Date.UTC(year, month, 0)).getUTCDate(); +} + async function createValidator() { const ajv = new Ajv2020({ allErrors: true, strict: true }); - ajv.addFormat("date-time", { - type: "string", - validate: (value: string) => !Number.isNaN(Date.parse(value)), - }); + ajv.addFormat("date-time", { type: "string", validate: isRfc3339DateTime }); return ajv.compile(systemReadinessSchema as AnySchema); } @@ -55,6 +64,14 @@ describe("system readiness contract", () => { expect(checkSystemReadinessSchemaVersion("not-a-version").compatible).toBe(false); }); + it("rejects invalid calendar timestamps (#7409)", async () => { + const validate = await createValidator(); + const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; + const provenance = { ...(fixture.provenance as Record) }; + + expect(validate({ ...fixture, provenance: { ...provenance, observedAt: "2026-02-30T00:00:00Z" } })).toBe(false); + }); + it("rejects status and exit-code mismatches (#7409)", async () => { const validate = await createValidator(); const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; From d6a376785c1daada3eef52fb2a74f4cb435177ac Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:32:46 +0000 Subject: [PATCH 05/33] test(readiness): keep timestamp validator linear Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index 94a092bb9f8..8fa5ebcdb0d 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -19,12 +19,17 @@ function isRfc3339DateTime(value: string): boolean { const match = /^(\d{4})-(\d{2})-(\d{2})T(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec( value, ); - if (!match) return false; - - const year = Number(match[1]); - const month = Number(match[2]); - const day = Number(match[3]); - return month >= 1 && month <= 12 && day >= 1 && day <= new Date(Date.UTC(year, month, 0)).getUTCDate(); + const [, yearText = "0", monthText = "0", dayText = "0"] = match ?? []; + const year = Number(yearText); + const month = Number(monthText); + const day = Number(dayText); + return ( + match !== null && + month >= 1 && + month <= 12 && + day >= 1 && + day <= new Date(Date.UTC(year, month, 0)).getUTCDate() + ); } async function createValidator() { From 7b5e5b382dfff194c3f3c4a4283de28407ea9b24 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:45:10 +0000 Subject: [PATCH 06/33] fix(readiness): format timestamp assertion Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index 8fa5ebcdb0d..6670b3700f1 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -74,7 +74,9 @@ describe("system readiness contract", () => { const fixture = (await readJson(`${fixtureRoot}/supported.json`)) as Record; const provenance = { ...(fixture.provenance as Record) }; - expect(validate({ ...fixture, provenance: { ...provenance, observedAt: "2026-02-30T00:00:00Z" } })).toBe(false); + expect( + validate({ ...fixture, provenance: { ...provenance, observedAt: "2026-02-30T00:00:00Z" } }), + ).toBe(false); }); it("rejects status and exit-code mismatches (#7409)", async () => { From 8d76127f7790768b04ba33e414ede40df49cbe00 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:52:21 +0000 Subject: [PATCH 07/33] fix(readiness): apply biome assertion layout Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index 6670b3700f1..f99a71b4e43 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -75,7 +75,10 @@ describe("system readiness contract", () => { const provenance = { ...(fixture.provenance as Record) }; expect( - validate({ ...fixture, provenance: { ...provenance, observedAt: "2026-02-30T00:00:00Z" } }), + validate({ + ...fixture, + provenance: { ...provenance, observedAt: "2026-02-30T00:00:00Z" }, + }), ).toBe(false); }); From 61afc450bce49091cc9da47f8086d4dfdf3b52b6 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:54:06 +0000 Subject: [PATCH 08/33] fix(readiness): align schema version grammar Signed-off-by: Remy the Refactoror --- schemas/system-readiness.schema.json | 2 +- src/lib/readiness/contract.test.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/schemas/system-readiness.schema.json b/schemas/system-readiness.schema.json index ebcf705f879..d417e4505f8 100644 --- a/schemas/system-readiness.schema.json +++ b/schemas/system-readiness.schema.json @@ -9,7 +9,7 @@ "properties": { "schemaVersion": { "type": "string", - "pattern": "^1\\.[0-9]+\\.[0-9]+$", + "pattern": "^1\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$", "description": "Semantic contract version. Consumers must reject unknown major versions. New optional fields may be added within major version 1." }, "status": { diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index f99a71b4e43..c2495300e7a 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -58,6 +58,8 @@ describe("system readiness contract", () => { expect(validate({ ...fixture, schemaVersion: "1.7.4" }), JSON.stringify(validate.errors)).toBe( true, ); + expect(checkSystemReadinessSchemaVersion("1.01.0").compatible).toBe(false); + expect(validate({ ...fixture, schemaVersion: "1.01.0" })).toBe(false); }); it("rejects unknown schema majors before reading the report (#7409)", () => { From 97500e120450c87d23d199d41363d1a8bfdcd929 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 12:58:54 +0000 Subject: [PATCH 09/33] fix(readiness): apply contract formatting Signed-off-by: Remy the Refactoror --- src/lib/readiness/contract.test.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib/readiness/contract.test.ts b/src/lib/readiness/contract.test.ts index c2495300e7a..7a3b2d714a1 100644 --- a/src/lib/readiness/contract.test.ts +++ b/src/lib/readiness/contract.test.ts @@ -5,7 +5,9 @@ import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; import { describe, expect, it } from "vitest"; -import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { type: "json" }; +import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { + type: "json", +}; import { checkSystemReadinessSchemaVersion } from "./compatibility.js"; const repositoryRoot = fileURLToPath(new URL("../../..", import.meta.url)); @@ -16,9 +18,10 @@ async function readJson(path: string): Promise { } function isRfc3339DateTime(value: string): boolean { - const match = /^(\d{4})-(\d{2})-(\d{2})T(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec( - value, - ); + const match = + /^(\d{4})-(\d{2})-(\d{2})T(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec( + value, + ); const [, yearText = "0", monthText = "0", dayText = "0"] = match ?? []; const year = Number(yearText); const month = Number(monthText); @@ -39,15 +42,16 @@ async function createValidator() { } describe("system readiness contract", () => { - it.each(["supported", "incompatible", "inconclusive"])( - "validates the %s golden fixture (#7409)", - async (name) => { - const validate = await createValidator(); - const fixture = await readJson(`${fixtureRoot}/${name}.json`); - - expect(validate(fixture), JSON.stringify(validate.errors)).toBe(true); - }, - ); + it.each([ + "supported", + "incompatible", + "inconclusive", + ])("validates the %s golden fixture (#7409)", async (name) => { + const validate = await createValidator(); + const fixture = await readJson(`${fixtureRoot}/${name}.json`); + + expect(validate(fixture), JSON.stringify(validate.errors)).toBe(true); + }); it("accepts optional fields in schema major 1 (#7409)", async () => { const validate = await createValidator(); From 359d4c9a2959ff570db4f5e334ed7f396a3c9cc7 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Sat, 25 Jul 2026 12:54:44 -0400 Subject: [PATCH 10/33] fix(readiness): name evidence IDs correctly Signed-off-by: Remy the Refactoror --- schemas/system-readiness.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/system-readiness.schema.json b/schemas/system-readiness.schema.json index d417e4505f8..92a344dc2c3 100644 --- a/schemas/system-readiness.schema.json +++ b/schemas/system-readiness.schema.json @@ -3,7 +3,7 @@ "$id": "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json", "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0", "title": "NemoClaw system readiness report", - "description": "Version 1 consumer-neutral contract for a read-only system readiness report. Unknown major versions are incompatible. Consumers must ignore unrecognized optional fields in major version 1. Evidence is bounded diagnostic context and does not affect compatibility decisions unless a capability or finding references it by evidenceId.", + "description": "Version 1 consumer-neutral contract for a read-only system readiness report. Unknown major versions are incompatible. Consumers must ignore unrecognized optional fields in major version 1. Evidence is bounded diagnostic context and does not affect compatibility decisions unless a capability or finding references its ID in evidenceIds.", "type": "object", "required": ["schemaVersion", "status", "exitCode", "mutated", "provenance", "observations", "capabilities", "qualifications", "findings", "evidence"], "properties": { From f1c79e98790ddc90abfa6f6c424f63b5da4f40c1 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 13:33:28 +0000 Subject: [PATCH 11/33] feat(readiness): project host observations into readiness report Signed-off-by: Remy the Refactoror --- src/lib/readiness/host.test.ts | 158 ++++++++++++++ src/lib/readiness/host.ts | 386 +++++++++++++++++++++++++++++++++ src/lib/readiness/index.ts | 11 + 3 files changed, 555 insertions(+) create mode 100644 src/lib/readiness/host.test.ts create mode 100644 src/lib/readiness/host.ts diff --git a/src/lib/readiness/host.test.ts b/src/lib/readiness/host.test.ts new file mode 100644 index 00000000000..f860aae330d --- /dev/null +++ b/src/lib/readiness/host.test.ts @@ -0,0 +1,158 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it, vi } from "vitest"; +import type { HostAssessment } from "../onboard/preflight"; +import { collectHostObservations, projectHostReadiness } from "./host"; + +const NOW = new Date("2026-06-01T12:00:00Z"); + +function host(overrides: Partial = {}): HostAssessment { + return { + platform: "linux", + isWsl: false, + runtime: "docker", + dockerInstalled: true, + dockerRunning: true, + dockerReachable: true, + nodeInstalled: true, + openshellInstalled: true, + dockerCgroupVersion: "v2", + dockerDefaultCgroupnsMode: "private", + dockerStorageDriver: "overlay2", + dockerUsesContainerdSnapshotter: false, + dockerCpus: 8, + dockerMemTotalBytes: 16 * 1024 ** 3, + isContainerRuntimeUnderProvisioned: false, + hasNestedOverlayConflict: false, + requiresHostCgroupnsFix: false, + isUnsupportedRuntime: false, + isHeadlessLikely: false, + hasNvidiaGpu: true, + dockerCdiSpecDirs: ["/etc/cdi"], + cdiNvidiaGpuSpecMissing: false, + cdiNvidiaGpuSpecStale: false, + cdiNvidiaGpuSpecNeedsRepair: false, + nvidiaContainerToolkitInstalled: true, + notes: [], + ...overrides, + }; +} + +function report(overrides: Partial = {}) { + return projectHostReadiness( + collectHostObservations({ assess: () => host(overrides), architecture: "x64", now: () => NOW }), + { nemoclawVersion: "0.1.0", now: () => NOW }, + ); +} + +function state(result: ReturnType, id: string) { + return result.capabilities.find((entry) => entry.id === id)?.state; +} + +function findingIds(result: ReturnType) { + return result.findings.map(({ id }) => id); +} + +describe("host readiness projection (#7408)", () => { + it("keeps collection dependency-injected and separate from pure evaluation", () => { + const assess = vi.fn(() => host()); + const snapshot = collectHostObservations({ assess, now: () => NOW }); + + expect(assess).toHaveBeenCalledOnce(); + expect(snapshot.observations).toMatchObject({ platform: "linux", architecture: process.arch }); + expect( + projectHostReadiness(snapshot, { nemoclawVersion: "0.1.0", now: () => NOW }).mutated, + ).toBe(false); + }); + + it.each([ + [ + { dockerInstalled: false, dockerReachable: false }, + "host.docker.available", + "absent", + "host.docker.unavailable", + ], + [ + { dockerReachable: false }, + "host.docker.daemon_reachable", + "absent", + "host.docker.daemon_unreachable", + ], + [ + { isContainerRuntimeUnderProvisioned: true }, + "host.docker.resources_sufficient", + "absent", + "host.docker.resources_insufficient", + ], + [ + { isUnsupportedRuntime: true, runtime: "podman" }, + "host.docker.runtime_supported", + "absent", + "host.docker.runtime_unsupported", + ], + [ + { nvidiaContainerToolkitInstalled: false }, + "host.gpu.container_toolkit_available", + "absent", + "host.gpu.container_toolkit_missing", + ], + [ + { cdiNvidiaGpuSpecMissing: true, cdiNvidiaGpuSpecNeedsRepair: true }, + "host.gpu.cdi_healthy", + "absent", + "host.gpu.cdi_missing", + ], + [ + { cdiNvidiaGpuSpecStale: true, cdiNvidiaGpuSpecNeedsRepair: true }, + "host.gpu.cdi_healthy", + "absent", + "host.gpu.cdi_stale", + ], + ] as const)("returns stable results for %s", (overrides, capabilityId, expectedState, findingId) => { + const result = report(overrides); + + expect(state(result, capabilityId)).toBe(expectedState); + expect(findingIds(result)).toContain(findingId); + }); + + it("uses unknown for dependent facts when Docker is unreachable", () => { + const result = report({ dockerReachable: false }); + + expect(state(result, "host.docker.runtime_supported")).toBe("unknown"); + expect(state(result, "host.docker.resources_sufficient")).toBe("unknown"); + expect(result.observations.find(({ id }) => id === "host.docker.runtime")?.state).toBe( + "unknown", + ); + }); + + it("bounds and redacts failed probe evidence and projects unknown", () => { + const failure = `token=top-secret ${"x".repeat(1500)}`; + const snapshot = collectHostObservations({ + assess: () => { + throw new Error(failure); + }, + now: () => NOW, + }); + const result = projectHostReadiness(snapshot, { nemoclawVersion: "0.1.0", now: () => NOW }); + + expect(result.status).toBe("inconclusive"); + expect( + result.capabilities.every(({ state: capabilityState }) => capabilityState === "unknown"), + ).toBe(true); + expect(result.evidence[0]?.summary).not.toContain("top-secret"); + expect(result.evidence[0]?.summary.length).toBeLessThanOrEqual(1024); + }); + + it("rejects stale observations unless reuse is explicitly safe", () => { + const current = collectHostObservations({ assess: () => host(), now: () => NOW }); + const snapshot = { ...current, observedAt: "2026-06-01T11:00:00Z", reusable: false }; + const result = projectHostReadiness(snapshot, { nemoclawVersion: "0.1.0", now: () => NOW }); + + expect(result.status).toBe("inconclusive"); + expect(result.evidence.map(({ id }) => id)).toContain("host.probe.stale"); + expect( + result.capabilities.every(({ state: capabilityState }) => capabilityState === "unknown"), + ).toBe(true); + }); +}); diff --git a/src/lib/readiness/host.ts b/src/lib/readiness/host.ts new file mode 100644 index 00000000000..0872e7edc0a --- /dev/null +++ b/src/lib/readiness/host.ts @@ -0,0 +1,386 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import type { HostAssessment } from "../onboard/preflight.js"; +import { assessHost } from "../onboard/preflight.js"; +import { + SYSTEM_READINESS_SCHEMA_VERSION, + type EvidenceScalar, + type FindingSeverity, + type ReadinessCapability, + type ReadinessEvidence, + type ReadinessFinding, + type ReadinessObservation, + type ReadinessState, + type SystemReadinessReport, +} from "./types.js"; + +const DEFAULT_MAX_AGE_MS = 30_000; +const MAX_EVIDENCE_LENGTH = 1024; +const SECRET_PATTERN = + /\b(?:bearer\s+)?(?:gh[opusr]_[a-z0-9_]{20,}|nvapi-[a-z0-9_-]{16,}|sk-[a-z0-9_-]{16,}|(?:api[_-]?key|token|password|secret)\s*[=:]\s*[^\s,;]+)/gi; + +export interface HostObservations { + platform: string; + architecture: string; + isWsl: boolean; + isHeadlessLikely: boolean; + dockerInstalled: boolean; + dockerReachable: boolean; + runtime: string; + dockerCgroupVersion?: string; + dockerDefaultCgroupnsMode?: string; + dockerStorageDriver?: string; + dockerUsesContainerdSnapshotter?: boolean; + dockerCpus?: number; + dockerMemTotalBytes?: number; + isContainerRuntimeUnderProvisioned: boolean; + hasNestedOverlayConflict: boolean; + isUnsupportedRuntime: boolean; + nodeInstalled: boolean; + openshellInstalled: boolean; + hasNvidiaGpu: boolean; + nvidiaContainerToolkitInstalled: boolean; + dockerCdiSpecDirs: readonly string[]; + cdiNvidiaGpuSpecMissing: boolean; + cdiNvidiaGpuSpecStale?: boolean; + cdiNvidiaGpuSpecNeedsRepair?: boolean; +} + +export interface HostObservationSnapshot { + observedAt: string; + observations?: Readonly; + failure?: string; + reusable?: boolean; +} + +export interface CollectHostObservationsOptions { + assess?: () => HostAssessment; + architecture?: string; + now?: () => Date; +} + +export interface CreateHostReadinessReportOptions { + nemoclawVersion: string; + sourceRevision?: string; + now?: () => Date; + maxObservationAgeMs?: number; +} + +function safeEvidence(value: string): string { + return value.replace(SECRET_PATTERN, "[REDACTED]").slice(0, MAX_EVIDENCE_LENGTH); +} + +function adaptHostAssessment( + host: Readonly, + architecture: string, +): HostObservations { + return { + platform: host.platform, + architecture, + isWsl: host.isWsl, + isHeadlessLikely: host.isHeadlessLikely, + dockerInstalled: host.dockerInstalled, + dockerReachable: host.dockerReachable, + runtime: host.runtime, + dockerCgroupVersion: host.dockerCgroupVersion, + dockerDefaultCgroupnsMode: host.dockerDefaultCgroupnsMode, + dockerStorageDriver: host.dockerStorageDriver, + dockerUsesContainerdSnapshotter: host.dockerUsesContainerdSnapshotter, + dockerCpus: host.dockerCpus, + dockerMemTotalBytes: host.dockerMemTotalBytes, + isContainerRuntimeUnderProvisioned: host.isContainerRuntimeUnderProvisioned, + hasNestedOverlayConflict: host.hasNestedOverlayConflict, + isUnsupportedRuntime: host.isUnsupportedRuntime, + nodeInstalled: host.nodeInstalled, + openshellInstalled: host.openshellInstalled, + hasNvidiaGpu: host.hasNvidiaGpu, + nvidiaContainerToolkitInstalled: host.nvidiaContainerToolkitInstalled, + dockerCdiSpecDirs: [...host.dockerCdiSpecDirs], + cdiNvidiaGpuSpecMissing: host.cdiNvidiaGpuSpecMissing, + cdiNvidiaGpuSpecStale: host.cdiNvidiaGpuSpecStale, + cdiNvidiaGpuSpecNeedsRepair: host.cdiNvidiaGpuSpecNeedsRepair, + }; +} + +export function collectHostObservations( + options: CollectHostObservationsOptions = {}, +): HostObservationSnapshot { + const observedAt = (options.now ?? (() => new Date()))().toISOString(); + try { + const assessment = (options.assess ?? assessHost)(); + return { + observedAt, + observations: adaptHostAssessment(assessment, options.architecture ?? process.arch), + reusable: false, + }; + } catch (error) { + return { + observedAt, + failure: safeEvidence(error instanceof Error ? error.message : String(error)), + reusable: false, + }; + } +} + +function observation(id: string, value: EvidenceScalar | undefined): ReadinessObservation { + if (value === undefined || value === null || value === "unknown") return { id, state: "unknown" }; + if (typeof value === "boolean") return { id, state: value ? "present" : "absent", value }; + return { id, state: "present", value }; +} + +function capability(id: string, state: ReadinessState): ReadinessCapability { + return { id, state }; +} + +function finding( + id: string, + severity: FindingSeverity, + summary: string, + capabilityIds: readonly string[], +): ReadinessFinding { + return { id, severity, summary, capabilityIds }; +} + +function stateOf(value: boolean | undefined): ReadinessState { + return value === undefined ? "unknown" : value ? "present" : "absent"; +} + +function unknownProjection(evidenceIds: readonly string[]): { + observations: ReadinessObservation[]; + capabilities: ReadinessCapability[]; + findings: ReadinessFinding[]; +} { + const observationIds = [ + "host.os.platform", + "host.os.architecture", + "host.os.wsl", + "host.session.headless", + "host.docker.installed", + "host.docker.reachable", + "host.docker.runtime", + "host.docker.cpus", + "host.docker.memory_bytes", + "host.docker.cgroup_version", + "host.docker.cgroupns_mode", + "host.docker.storage_driver", + "host.docker.containerd_snapshotter", + "host.toolchain.node", + "host.toolchain.openshell", + "host.gpu.nvidia", + "host.gpu.container_toolkit", + "host.gpu.cdi", + "host.gpu.cdi_stale", + ]; + const capabilityIds = [ + "host.docker.available", + "host.docker.daemon_reachable", + "host.docker.runtime_supported", + "host.docker.resources_sufficient", + "host.docker.storage_compatible", + "host.toolchain.node_available", + "host.toolchain.openshell_available", + "host.gpu.nvidia_available", + "host.gpu.container_toolkit_available", + "host.gpu.cdi_healthy", + ]; + return { + observations: observationIds.map((id) => ({ id, state: "unknown", evidenceIds })), + capabilities: capabilityIds.map((id) => ({ id, state: "unknown", evidenceIds })), + findings: [ + { + id: "host.probe.inconclusive", + severity: "warning", + summary: "Host observations could not be collected safely.", + evidenceIds, + }, + ], + }; +} + +export function projectHostReadiness( + snapshot: Readonly, + options: CreateHostReadinessReportOptions, +): SystemReadinessReport { + const now = (options.now ?? (() => new Date()))(); + const age = now.getTime() - Date.parse(snapshot.observedAt); + const stale = + !Number.isFinite(age) || age < 0 || age > (options.maxObservationAgeMs ?? DEFAULT_MAX_AGE_MS); + const unsafeReuse = stale && snapshot.reusable !== true; + const evidence: ReadinessEvidence[] = []; + if (snapshot.failure) { + evidence.push({ id: "host.probe.failure", summary: safeEvidence(snapshot.failure) }); + } + if (unsafeReuse) { + evidence.push({ + id: "host.probe.stale", + summary: "Host observations exceeded their safe reuse window.", + }); + } + + let observations: ReadinessObservation[]; + let capabilities: ReadinessCapability[]; + let findings: ReadinessFinding[]; + const host = snapshot.observations; + if (!host || snapshot.failure || unsafeReuse) { + const projected = unknownProjection(evidence.map(({ id }) => id)); + ({ observations, capabilities, findings } = projected); + } else { + const cdiApplies = + host.platform === "linux" && host.hasNvidiaGpu && host.dockerCdiSpecDirs.length > 0; + const cdiHealthy = cdiApplies + ? !host.cdiNvidiaGpuSpecMissing && !host.cdiNvidiaGpuSpecNeedsRepair + : undefined; + observations = [ + observation("host.os.platform", host.platform), + observation("host.os.architecture", host.architecture), + observation("host.os.wsl", host.isWsl), + observation("host.session.headless", host.isHeadlessLikely), + observation("host.docker.installed", host.dockerInstalled), + observation("host.docker.reachable", host.dockerReachable), + observation("host.docker.runtime", host.dockerReachable ? host.runtime : undefined), + observation("host.docker.cpus", host.dockerReachable ? host.dockerCpus : undefined), + observation( + "host.docker.memory_bytes", + host.dockerReachable ? host.dockerMemTotalBytes : undefined, + ), + observation( + "host.docker.cgroup_version", + host.dockerReachable ? host.dockerCgroupVersion : undefined, + ), + observation( + "host.docker.cgroupns_mode", + host.dockerReachable ? host.dockerDefaultCgroupnsMode : undefined, + ), + observation( + "host.docker.storage_driver", + host.dockerReachable ? host.dockerStorageDriver : undefined, + ), + observation( + "host.docker.containerd_snapshotter", + host.dockerReachable ? host.dockerUsesContainerdSnapshotter : undefined, + ), + observation("host.toolchain.node", host.nodeInstalled), + observation("host.toolchain.openshell", host.openshellInstalled), + observation("host.gpu.nvidia", host.hasNvidiaGpu), + observation( + "host.gpu.container_toolkit", + host.hasNvidiaGpu ? host.nvidiaContainerToolkitInstalled : undefined, + ), + observation("host.gpu.cdi", cdiHealthy), + observation("host.gpu.cdi_stale", cdiApplies ? host.cdiNvidiaGpuSpecStale : undefined), + ]; + capabilities = [ + capability("host.docker.available", stateOf(host.dockerInstalled)), + capability( + "host.docker.daemon_reachable", + host.dockerInstalled ? stateOf(host.dockerReachable) : "absent", + ), + capability( + "host.docker.runtime_supported", + host.dockerReachable ? stateOf(!host.isUnsupportedRuntime) : "unknown", + ), + capability( + "host.docker.resources_sufficient", + host.dockerReachable ? stateOf(!host.isContainerRuntimeUnderProvisioned) : "unknown", + ), + capability( + "host.docker.storage_compatible", + host.dockerReachable ? stateOf(!host.hasNestedOverlayConflict) : "unknown", + ), + capability("host.toolchain.node_available", stateOf(host.nodeInstalled)), + capability("host.toolchain.openshell_available", stateOf(host.openshellInstalled)), + capability("host.gpu.nvidia_available", stateOf(host.hasNvidiaGpu)), + capability( + "host.gpu.container_toolkit_available", + host.hasNvidiaGpu ? stateOf(host.nvidiaContainerToolkitInstalled) : "unknown", + ), + capability("host.gpu.cdi_healthy", stateOf(cdiHealthy)), + ]; + findings = []; + if (!host.dockerInstalled) + findings.push( + finding("host.docker.unavailable", "blocking", "Docker is not installed.", [ + "host.docker.available", + ]), + ); + else if (!host.dockerReachable) + findings.push( + finding("host.docker.daemon_unreachable", "blocking", "The Docker daemon is unreachable.", [ + "host.docker.daemon_reachable", + ]), + ); + if (host.isContainerRuntimeUnderProvisioned) + findings.push( + finding( + "host.docker.resources_insufficient", + "warning", + "Container runtime resources are below recommendations.", + ["host.docker.resources_sufficient"], + ), + ); + if (host.isUnsupportedRuntime) + findings.push( + finding( + "host.docker.runtime_unsupported", + "warning", + "The detected container runtime is unsupported.", + ["host.docker.runtime_supported"], + ), + ); + if (host.hasNvidiaGpu && !host.nvidiaContainerToolkitInstalled) + findings.push( + finding( + "host.gpu.container_toolkit_missing", + "blocking", + "NVIDIA Container Toolkit is missing.", + ["host.gpu.container_toolkit_available"], + ), + ); + if (cdiApplies && host.cdiNvidiaGpuSpecMissing) + findings.push( + finding("host.gpu.cdi_missing", "blocking", "The NVIDIA CDI specification is missing.", [ + "host.gpu.cdi_healthy", + ]), + ); + if (cdiApplies && host.cdiNvidiaGpuSpecStale) + findings.push( + finding("host.gpu.cdi_stale", "blocking", "The NVIDIA CDI specification is stale.", [ + "host.gpu.cdi_healthy", + ]), + ); + } + + const hasBlocking = findings.some( + ({ severity }) => severity === "blocking" || severity === "fatal", + ); + const hasUnknown = capabilities.some(({ state }) => state === "unknown"); + const status = hasBlocking ? "incompatible" : hasUnknown ? "inconclusive" : "supported"; + return { + schemaVersion: SYSTEM_READINESS_SCHEMA_VERSION, + status, + exitCode: status === "supported" ? 0 : status === "incompatible" ? 2 : 3, + mutated: false, + provenance: { + nemoclawVersion: options.nemoclawVersion, + ...(options.sourceRevision ? { sourceRevision: options.sourceRevision } : {}), + observedAt: snapshot.observedAt, + }, + observations, + capabilities, + qualifications: [], + findings, + evidence, + }; +} + +export function createHostReadinessReport( + options: CreateHostReadinessReportOptions, + collectionOptions: CollectHostObservationsOptions = {}, +): SystemReadinessReport { + const now = options.now ?? collectionOptions.now ?? (() => new Date()); + return projectHostReadiness(collectHostObservations({ ...collectionOptions, now }), { + ...options, + now, + }); +} diff --git a/src/lib/readiness/index.ts b/src/lib/readiness/index.ts index 6551210d754..c29cd83256d 100644 --- a/src/lib/readiness/index.ts +++ b/src/lib/readiness/index.ts @@ -4,6 +4,17 @@ export type { SchemaCompatibility } from "./compatibility.js"; export { checkSystemReadinessSchemaVersion } from "./compatibility.js"; export { getSystemReadinessReferenceErrors } from "./references.js"; +export { + collectHostObservations, + createHostReadinessReport, + projectHostReadiness, +} from "./host.js"; +export type { + CollectHostObservationsOptions, + CreateHostReadinessReportOptions, + HostObservationSnapshot, + HostObservations, +} from "./host.js"; export { SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR, SYSTEM_READINESS_SCHEMA_VERSION, From e15776234d207acc53f510fd8be3c7446b21f8ae Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 13:41:59 +0000 Subject: [PATCH 12/33] fix(readiness): preserve host CDI exclusions Signed-off-by: Remy the Refactoror --- src/lib/readiness/host.test.ts | 44 +++++++++++++++++++++++++++++++--- src/lib/readiness/host.ts | 18 +++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/lib/readiness/host.test.ts b/src/lib/readiness/host.test.ts index f860aae330d..2f09f6d1409 100644 --- a/src/lib/readiness/host.test.ts +++ b/src/lib/readiness/host.test.ts @@ -39,9 +39,17 @@ function host(overrides: Partial = {}): HostAssessment { }; } -function report(overrides: Partial = {}) { +function report( + overrides: Partial = {}, + collectionOptions: { hostGpuPlatform?: string } = {}, +) { return projectHostReadiness( - collectHostObservations({ assess: () => host(overrides), architecture: "x64", now: () => NOW }), + collectHostObservations({ + assess: () => host(overrides), + architecture: "x64", + now: () => NOW, + ...collectionOptions, + }), { nemoclawVersion: "0.1.0", now: () => NOW }, ); } @@ -116,6 +124,21 @@ describe("host readiness projection (#7408)", () => { expect(findingIds(result)).toContain(findingId); }); + it.each([ + [{ cdiNvidiaGpuSpecMissing: true }, { hostGpuPlatform: "jetson" }], + [ + { isWsl: true, runtime: "docker-desktop", cdiNvidiaGpuSpecStale: true }, + { hostGpuPlatform: undefined }, + ], + ] as const)("preserves CDI enforcement exclusions for %s", (overrides, collectionOptions) => { + const result = report(overrides, collectionOptions); + + expect(state(result, "host.gpu.cdi_healthy")).toBe("unknown"); + expect(findingIds(result)).not.toContain("host.gpu.cdi_missing"); + expect(findingIds(result)).not.toContain("host.gpu.cdi_stale"); + expect(result.status).not.toBe("incompatible"); + }); + it("uses unknown for dependent facts when Docker is unreachable", () => { const result = report({ dockerReachable: false }); @@ -127,7 +150,7 @@ describe("host readiness projection (#7408)", () => { }); it("bounds and redacts failed probe evidence and projects unknown", () => { - const failure = `token=top-secret ${"x".repeat(1500)}`; + const failure = `Authorization: Bearer top-secret token=other-secret ${"x".repeat(1500)}`; const snapshot = collectHostObservations({ assess: () => { throw new Error(failure); @@ -141,6 +164,7 @@ describe("host readiness projection (#7408)", () => { result.capabilities.every(({ state: capabilityState }) => capabilityState === "unknown"), ).toBe(true); expect(result.evidence[0]?.summary).not.toContain("top-secret"); + expect(result.evidence[0]?.summary).not.toContain("other-secret"); expect(result.evidence[0]?.summary.length).toBeLessThanOrEqual(1024); }); @@ -155,4 +179,18 @@ describe("host readiness projection (#7408)", () => { result.capabilities.every(({ state: capabilityState }) => capabilityState === "unknown"), ).toBe(true); }); + + it.each([ + ["2026-06-01T11:00:00Z", true], + ["2026-06-01T11:59:30Z", false], + ] as const)("projects safe snapshot reuse at %s", (observedAt, reusable) => { + const current = collectHostObservations({ assess: () => host(), now: () => NOW }); + const result = projectHostReadiness( + { ...current, observedAt, reusable }, + { nemoclawVersion: "0.1.0", now: () => NOW }, + ); + + expect(result.status).toBe("supported"); + expect(result.evidence.map(({ id }) => id)).not.toContain("host.probe.stale"); + }); }); diff --git a/src/lib/readiness/host.ts b/src/lib/readiness/host.ts index 0872e7edc0a..71ef32efd2f 100644 --- a/src/lib/readiness/host.ts +++ b/src/lib/readiness/host.ts @@ -18,7 +18,7 @@ import { const DEFAULT_MAX_AGE_MS = 30_000; const MAX_EVIDENCE_LENGTH = 1024; const SECRET_PATTERN = - /\b(?:bearer\s+)?(?:gh[opusr]_[a-z0-9_]{20,}|nvapi-[a-z0-9_-]{16,}|sk-[a-z0-9_-]{16,}|(?:api[_-]?key|token|password|secret)\s*[=:]\s*[^\s,;]+)/gi; + /(?:\bauthorization\s*:\s*bearer\s+[^\s,;]+|\b(?:bearer\s+)?(?:gh[opusr]_[a-z0-9_]{20,}|nvapi-[a-z0-9_-]{16,}|sk-[a-z0-9_-]{16,}|(?:api[_-]?key|token|password|secret)\s*[=:]\s*[^\s,;]+))/gi; export interface HostObservations { platform: string; @@ -40,6 +40,7 @@ export interface HostObservations { nodeInstalled: boolean; openshellInstalled: boolean; hasNvidiaGpu: boolean; + hostGpuPlatform?: string; nvidiaContainerToolkitInstalled: boolean; dockerCdiSpecDirs: readonly string[]; cdiNvidiaGpuSpecMissing: boolean; @@ -57,6 +58,7 @@ export interface HostObservationSnapshot { export interface CollectHostObservationsOptions { assess?: () => HostAssessment; architecture?: string; + hostGpuPlatform?: string; now?: () => Date; } @@ -74,6 +76,7 @@ function safeEvidence(value: string): string { function adaptHostAssessment( host: Readonly, architecture: string, + hostGpuPlatform?: string, ): HostObservations { return { platform: host.platform, @@ -95,6 +98,7 @@ function adaptHostAssessment( nodeInstalled: host.nodeInstalled, openshellInstalled: host.openshellInstalled, hasNvidiaGpu: host.hasNvidiaGpu, + hostGpuPlatform, nvidiaContainerToolkitInstalled: host.nvidiaContainerToolkitInstalled, dockerCdiSpecDirs: [...host.dockerCdiSpecDirs], cdiNvidiaGpuSpecMissing: host.cdiNvidiaGpuSpecMissing, @@ -111,7 +115,11 @@ export function collectHostObservations( const assessment = (options.assess ?? assessHost)(); return { observedAt, - observations: adaptHostAssessment(assessment, options.architecture ?? process.arch), + observations: adaptHostAssessment( + assessment, + options.architecture ?? process.arch, + options.hostGpuPlatform, + ), reusable: false, }; } catch (error) { @@ -227,7 +235,11 @@ export function projectHostReadiness( ({ observations, capabilities, findings } = projected); } else { const cdiApplies = - host.platform === "linux" && host.hasNvidiaGpu && host.dockerCdiSpecDirs.length > 0; + host.platform === "linux" && + host.hasNvidiaGpu && + host.dockerCdiSpecDirs.length > 0 && + host.hostGpuPlatform !== "jetson" && + !(host.isWsl && host.runtime === "docker-desktop"); const cdiHealthy = cdiApplies ? !host.cdiNvidiaGpuSpecMissing && !host.cdiNvidiaGpuSpecNeedsRepair : undefined; From 737f517e79ae3365f20a663b1f6e81e7cdb1e1c4 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 16:02:54 -0400 Subject: [PATCH 13/33] fix(readiness): preserve report outcome pairing Signed-off-by: Julie Yaunches --- src/lib/readiness/host.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/readiness/host.ts b/src/lib/readiness/host.ts index 71ef32efd2f..2c83e480dfe 100644 --- a/src/lib/readiness/host.ts +++ b/src/lib/readiness/host.ts @@ -367,11 +367,14 @@ export function projectHostReadiness( ({ severity }) => severity === "blocking" || severity === "fatal", ); const hasUnknown = capabilities.some(({ state }) => state === "unknown"); - const status = hasBlocking ? "incompatible" : hasUnknown ? "inconclusive" : "supported"; + const outcome = hasBlocking + ? ({ status: "incompatible", exitCode: 2 } as const) + : hasUnknown + ? ({ status: "inconclusive", exitCode: 3 } as const) + : ({ status: "supported", exitCode: 0 } as const); return { schemaVersion: SYSTEM_READINESS_SCHEMA_VERSION, - status, - exitCode: status === "supported" ? 0 : status === "incompatible" ? 2 : 3, + ...outcome, mutated: false, provenance: { nemoclawVersion: options.nemoclawVersion, From cb2d07b1bc885982280e23b7e1304ef49851d6cf Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 14:47:38 +0000 Subject: [PATCH 14/33] feat(cli): add read-only host readiness probe Signed-off-by: Remy the Refactoror --- docs/reference/system-readiness.mdx | 64 +++++++++++++ docs/reference/troubleshooting.mdx | 10 ++ src/commands/host/probe.test.ts | 110 +++++++++++++++++++++ src/commands/host/probe.ts | 31 ++++++ src/lib/readiness/effects.test.ts | 81 ++++++++++++++++ src/lib/readiness/index.ts | 1 + src/lib/readiness/presentation.test.ts | 103 ++++++++++++++++++++ src/lib/readiness/presentation.ts | 128 +++++++++++++++++++++++++ 8 files changed, 528 insertions(+) create mode 100644 docs/reference/system-readiness.mdx create mode 100644 src/commands/host/probe.test.ts create mode 100644 src/commands/host/probe.ts create mode 100644 src/lib/readiness/effects.test.ts create mode 100644 src/lib/readiness/presentation.test.ts create mode 100644 src/lib/readiness/presentation.ts diff --git a/docs/reference/system-readiness.mdx b/docs/reference/system-readiness.mdx new file mode 100644 index 00000000000..042e04326e3 --- /dev/null +++ b/docs/reference/system-readiness.mdx @@ -0,0 +1,64 @@ +--- +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +title: "System Readiness" +sidebar-title: "System Readiness" +description: "Check host readiness before NemoClaw onboarding without changing system state." +description-agent: "Documents the read-only host readiness command, JSON contract, exit codes, redaction boundary, and mutation guarantees." +keywords: ["nemoclaw host probe", "system readiness", "readiness json", "pre-onboarding check"] +content: + type: "reference" +--- + +Use the system readiness report to inspect a host before you run onboarding. +The command works without a registered gateway or sandbox. + +## Run the readiness check + +Run the human-readable check from the host: + +```bash +nemoclaw host probe +``` + +Use JSON when another tool consumes the result: + +```bash +nemoclaw host probe --json +``` + +Both presentations use the same structured report. +The JSON report includes its schema version, result, exit code, observations, capabilities, findings, evidence, and provenance. +It also includes `mutated: false`. + +## Interpret exit codes + +The command uses deterministic exit codes: + +| Exit code | Status | Meaning | +| --- | --- | --- | +| `0` | `supported` | Required readiness checks passed. | +| `2` | `incompatible` | A blocking or fatal finding prevents onboarding. | +| `3` | `inconclusive` | NemoClaw could not determine a required capability. | + +The command writes a schema-valid JSON report for all three results. +Read the report before you handle a nonzero exit. + +## Use the compatibility contract + +The `schemaVersion` field uses `major.minor.patch` format. +Consumers must reject an unknown major version. +Consumers can ignore fields that they do not recognize within major version 1. +Use stable capability and finding IDs instead of parsing human summaries. +Treat bounded evidence as diagnostic context unless a capability or finding references its evidence ID. + +## Understand the read-only boundary + +`host probe` observes the host and does not run remediation. +Repeated runs do not change filesystem, service, Docker image or container, gateway, provider, credential, policy, or sandbox state. +A future command that changes the host must use a separate mutating mode. +That mode cannot run with `--json` probing. + +The public report removes process environments and unrecognized fields from internal probe results. +It redacts token-shaped values and credential-bearing URLs. +It also limits finding summaries and command evidence before either presentation receives the report. diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 4c4eb0055e2..f63fd69c175 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -72,6 +72,16 @@ If you cannot add memory, configure at least 8 GB of swap to work around the iss ### Docker is not running +Check the host before onboarding: + +```bash +$$nemoclaw host probe +``` + +The command does not start Docker or apply a repair. +A `host.docker.daemon_unreachable` finding means Docker is installed but NemoClaw cannot reach the daemon. +For JSON output and exit-code details, refer to [System Readiness](system-readiness). + The installer and onboard wizard require Docker to be running. If you see a Docker connection error, start the Docker daemon: diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts new file mode 100644 index 00000000000..6a806bc4173 --- /dev/null +++ b/src/commands/host/probe.test.ts @@ -0,0 +1,110 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import type { SystemReadinessReport } from "../../lib/readiness/types"; + +const mocks = vi.hoisted(() => ({ + createHostReadinessReport: vi.fn(), + createPublicReadinessReport: vi.fn(), + renderReadinessReport: vi.fn(), +})); + +vi.mock("../../lib/readiness/index", () => ({ + createHostReadinessReport: mocks.createHostReadinessReport, + createPublicReadinessReport: mocks.createPublicReadinessReport, + renderReadinessReport: mocks.renderReadinessReport, +})); + +import HostProbeCommand from "./probe"; + +function report( + status: SystemReadinessReport["status"], + exitCode: SystemReadinessReport["exitCode"], +): SystemReadinessReport { + return { + schemaVersion: "1.0.0", + status, + exitCode, + mutated: false, + provenance: { nemoclawVersion: "0.1.0", observedAt: "2026-06-01T12:00:00.000Z" }, + observations: [], + capabilities: [], + qualifications: [], + findings: [], + evidence: [], + }; +} + +describe("host probe command (#7412)", () => { + beforeEach(() => { + vi.clearAllMocks(); + mocks.createHostReadinessReport.mockReturnValue(report("supported", 0)); + mocks.createPublicReadinessReport.mockImplementation((value) => value); + mocks.renderReadinessReport.mockReturnValue("System readiness: supported"); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it.each([ + ["supported", 0], + ["incompatible", 2], + ["inconclusive", 3], + ] as const)("returns the deterministic %s exit code", async (status, exitCode) => { + const previousExitCode = process.exitCode; + process.exitCode = undefined; + mocks.createHostReadinessReport.mockReturnValueOnce(report(status, exitCode)); + + try { + await HostProbeCommand.run([], process.cwd()); + expect(process.exitCode).toBe(exitCode); + } finally { + process.exitCode = previousExitCode; + } + }); + + it("emits the public report as JSON on a nonzero exit", async () => { + const incompatible = report("incompatible", 2); + mocks.createHostReadinessReport.mockReturnValueOnce(incompatible); + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + const previousExitCode = process.exitCode; + process.exitCode = undefined; + + try { + await HostProbeCommand.run(["--json"], process.cwd()); + expect(JSON.parse(String(log.mock.calls.at(-1)?.[0]))).toEqual(incompatible); + expect(process.exitCode).toBe(2); + expect(mocks.renderReadinessReport).not.toHaveBeenCalled(); + } finally { + process.exitCode = previousExitCode; + } + }); + + it("runs before gateway or sandbox registration and uses one report for human output", async () => { + const publicReport = report("supported", 0); + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + mocks.createPublicReadinessReport.mockReturnValueOnce(publicReport); + + await HostProbeCommand.run([], process.cwd()); + + expect(mocks.createHostReadinessReport).toHaveBeenCalledWith({ nemoclawVersion: "0.1.0" }); + expect(mocks.createPublicReadinessReport).toHaveBeenCalledWith( + mocks.createHostReadinessReport.mock.results[0]?.value, + ); + expect(mocks.renderReadinessReport).toHaveBeenCalledWith(publicReport); + expect(log).toHaveBeenCalledWith("System readiness: supported"); + }); + + it("repeats through the observation-only dependency graph", async () => { + vi.spyOn(console, "log").mockImplementation(() => undefined); + + await HostProbeCommand.run([], process.cwd()); + await HostProbeCommand.run(["--json"], process.cwd()); + + expect(mocks.createHostReadinessReport).toHaveBeenCalledTimes(2); + expect(mocks.createPublicReadinessReport).toHaveBeenCalledTimes(2); + expect(mocks.renderReadinessReport).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/commands/host/probe.ts b/src/commands/host/probe.ts new file mode 100644 index 00000000000..4fc0a10c11a --- /dev/null +++ b/src/commands/host/probe.ts @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command"; +import { + createHostReadinessReport, + createPublicReadinessReport, + renderReadinessReport, +} from "../../lib/readiness"; + +export default class HostProbeCommand extends NemoClawCommand { + static id = "host:probe"; + static strict = true; + static enableJsonFlag = true; + static summary = "Report host readiness without changing the system"; + static description = + "Inspect host capabilities before onboarding. The command does not remediate findings or change host, Docker, gateway, credential, policy, or sandbox state."; + static usage = ["host probe [--json]"]; + static examples = ["<%= config.bin %> host probe", "<%= config.bin %> host probe --json"]; + static flags = {}; + + public async run(): Promise { + await this.parse(HostProbeCommand); + const report = createPublicReadinessReport( + createHostReadinessReport({ nemoclawVersion: this.config.version }), + ); + this.setExitCode(report.exitCode); + if (this.jsonEnabled()) return report; + this.log(renderReadinessReport(report)); + } +} diff --git a/src/lib/readiness/effects.test.ts b/src/lib/readiness/effects.test.ts new file mode 100644 index 00000000000..37558377aac --- /dev/null +++ b/src/lib/readiness/effects.test.ts @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { assessHost } from "../onboard/preflight"; +import { describe, expect, it, vi } from "vitest"; +import { createHostReadinessReport } from "./host"; + +const NOW = new Date("2026-06-01T12:00:00Z"); +const DOCKER_INFO = JSON.stringify({ + CgroupVersion: "2", + Driver: "overlay2", + DriverStatus: [], + NCPU: 8, + MemTotal: 16 * 1024 ** 3, + OperatingSystem: "Docker Engine", +}); + +describe("readiness process effects (#7412)", () => { + it("repeats the host probe without invoking a mutating dependency", () => { + const commands: string[][] = []; + const reads: string[] = []; + const directories: string[] = []; + const runCaptureImpl = vi.fn((command: readonly string[]) => { + commands.push([...command]); + if (command[0] === "sh" && command[4]) return `/usr/bin/${command[4]}`; + if (command[0] === "docker") return DOCKER_INFO; + if (command[0] === "systemctl") return command[1] === "is-active" ? "active" : "enabled"; + return ""; + }); + const readFileImpl = vi.fn((path: string) => { + reads.push(path); + return path === "/proc/version" ? "Linux version 6.8" : "{}"; + }); + const readdirImpl = vi.fn((path: string) => { + directories.push(path); + return []; + }); + const assess = vi.fn(() => + assessHost({ + gpuProbeImpl: () => false, + platform: "linux", + readFileImpl, + readdirImpl, + runCaptureImpl, + }), + ); + const options = { nemoclawVersion: "0.1.0", now: () => NOW }; + const collectionOptions = { assess, now: () => NOW }; + + const first = createHostReadinessReport(options, collectionOptions); + const second = createHostReadinessReport(options, collectionOptions); + + expect(first).toEqual(second); + expect(first.mutated).toBe(false); + expect(assess).toHaveBeenCalledTimes(2); + expect(commands.length).toBeGreaterThan(0); + expect( + commands.every(([command]) => ["sh", "docker", "systemctl"].includes(command ?? "")), + ).toBe(true); + expect( + commands + .filter(([command]) => command === "systemctl") + .every(([, operation]) => operation === "is-active" || operation === "is-enabled"), + ).toBe(true); + expect( + commands + .filter(([command]) => command === "docker") + .every(([, operation]) => operation === "info"), + ).toBe(true); + expect( + reads.every((path) => + [ + "/proc/version", + "/etc/docker/daemon.json", + "/home/rootless/.config/docker/daemon.json", + ].includes(path), + ), + ).toBe(true); + expect(directories.every((path) => path === "/etc/cdi" || path === "/var/run/cdi")).toBe(true); + }); +}); diff --git a/src/lib/readiness/index.ts b/src/lib/readiness/index.ts index c29cd83256d..247025f6f3c 100644 --- a/src/lib/readiness/index.ts +++ b/src/lib/readiness/index.ts @@ -15,6 +15,7 @@ export type { HostObservationSnapshot, HostObservations, } from "./host.js"; +export { createPublicReadinessReport, renderReadinessReport } from "./presentation.js"; export { SUPPORTED_SYSTEM_READINESS_SCHEMA_MAJOR, SYSTEM_READINESS_SCHEMA_VERSION, diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts new file mode 100644 index 00000000000..0b871b237f4 --- /dev/null +++ b/src/lib/readiness/presentation.test.ts @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; +import { describe, expect, it } from "vitest"; +import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { + type: "json", +}; +import { createPublicReadinessReport, renderReadinessReport } from "./presentation"; +import type { SystemReadinessReport } from "./types"; + +function report(overrides: Partial = {}): SystemReadinessReport { + return { + schemaVersion: "1.0.0", + status: "supported", + exitCode: 0, + mutated: false, + provenance: { + nemoclawVersion: "0.1.0", + observedAt: "2026-06-01T12:00:00.000Z", + }, + observations: [], + capabilities: [], + qualifications: [], + findings: [], + evidence: [], + ...overrides, + }; +} + +describe("public readiness presentation (#7412)", () => { + it.each([ + ["incompatible", 2], + ["inconclusive", 3], + ] as const)("emits a schema-valid %s report for exit %i", (status, exitCode) => { + const ajv = new Ajv2020({ strict: true }); + ajv.addFormat("date-time", { + type: "string", + validate: (value: string) => !Number.isNaN(Date.parse(value)), + }); + const validate = ajv.compile(systemReadinessSchema as AnySchema); + const publicReport = createPublicReadinessReport(report({ status, exitCode })); + + expect(validate(publicReport), JSON.stringify(validate.errors)).toBe(true); + }); + + it("renders human output from the same public report used for JSON", () => { + const publicReport = createPublicReadinessReport( + report({ + status: "incompatible", + exitCode: 2, + findings: [ + { + id: "host.docker.unavailable", + severity: "blocking", + summary: "Docker is not installed.", + }, + ], + }), + ); + + expect(renderReadinessReport(publicReport)).toContain("System readiness: incompatible"); + expect(renderReadinessReport(publicReport)).toContain( + "[blocking] host.docker.unavailable: Docker is not installed.", + ); + }); + + it("redacts secrets and excludes process environments at the public boundary", () => { + const token = `nvapi-${"a".repeat(24)}`; + const publicReport = createPublicReadinessReport( + report({ + findings: [ + { + id: "host.probe.failure", + severity: "warning", + summary: `token=${token}`, + processEnv: { NVIDIA_API_KEY: token }, + }, + ], + evidence: [ + { + id: "host.probe.output", + summary: `https://user:${token}@example.test/path?token=${token}${"x".repeat(1200)}`, + details: { + stderr: `${token}${"x".repeat(1200)}`, + processEnv: `NVIDIA_API_KEY=${token}`, + "processEnv.PATH": "/usr/bin", + environmentDump: "HOME=/home/user", + }, + }, + ], + }), + ); + const serialized = JSON.stringify(publicReport); + + expect(serialized).not.toContain(token); + expect(serialized).not.toContain("user:"); + expect(serialized).not.toContain("NVIDIA_API_KEY"); + expect(serialized).not.toContain("processEnv"); + expect(publicReport.evidence[0]?.summary.length).toBeLessThanOrEqual(1024); + expect(String(publicReport.evidence[0]?.details?.stderr).length).toBeLessThanOrEqual(1024); + }); +}); diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts new file mode 100644 index 00000000000..b33ab9ecddc --- /dev/null +++ b/src/lib/readiness/presentation.ts @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { redactForLog } from "../security/redact.js"; +import type { + EvidenceScalar, + ReadinessCapability, + ReadinessEvidence, + ReadinessFinding, + ReadinessObservation, + ReadinessQualification, + SystemReadinessReport, +} from "./types.js"; + +const MAX_SUMMARY_LENGTH = 512; +const MAX_EVIDENCE_LENGTH = 1024; + +function bounded(value: string, maxLength: number): string { + return String(redactForLog(value)) + .replace(/([a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/gi, "$1@") + .slice(0, maxLength); +} + +function scalar(value: EvidenceScalar): EvidenceScalar { + return typeof value === "string" ? bounded(value, MAX_EVIDENCE_LENGTH) : value; +} + +function observation(entry: ReadinessObservation): ReadinessObservation { + return { + id: entry.id, + state: entry.state, + ...(entry.value !== undefined ? { value: scalar(entry.value) } : {}), + ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + }; +} + +function capability(entry: ReadinessCapability): ReadinessCapability { + return { + id: entry.id, + state: entry.state, + ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + }; +} + +function qualification(entry: ReadinessQualification): ReadinessQualification { + return { + id: entry.id, + status: entry.status, + ...(entry.capabilityIds ? { capabilityIds: [...entry.capabilityIds] } : {}), + }; +} + +function finding(entry: ReadinessFinding): ReadinessFinding { + return { + id: entry.id, + severity: entry.severity, + summary: bounded(entry.summary, MAX_SUMMARY_LENGTH), + ...(entry.capabilityIds ? { capabilityIds: [...entry.capabilityIds] } : {}), + ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + }; +} + +function evidence(entry: ReadinessEvidence): ReadinessEvidence { + const redactedDetails = entry.details + ? (redactForLog(entry.details) as Record) + : undefined; + return { + id: entry.id, + summary: bounded(entry.summary, MAX_EVIDENCE_LENGTH), + ...(redactedDetails + ? { + details: Object.fromEntries( + Object.entries(redactedDetails) + .filter( + ([key]) => + !/(?:^|[._-])(?:env|environment)(?:$|[._-])/i.test(key) && + !/(?:processEnv|processEnvironment)/i.test(key), + ) + .slice(0, 16) + .map(([key, value]) => [key, scalar(value)]), + ), + } + : {}), + }; +} + +export function createPublicReadinessReport( + report: Readonly, +): SystemReadinessReport { + return { + schemaVersion: report.schemaVersion, + status: report.status, + exitCode: report.exitCode, + mutated: false, + provenance: { + nemoclawVersion: bounded(report.provenance.nemoclawVersion, 128), + ...(report.provenance.sourceRevision + ? { sourceRevision: report.provenance.sourceRevision } + : {}), + observedAt: report.provenance.observedAt, + }, + observations: report.observations.slice(0, 256).map(observation), + capabilities: report.capabilities.slice(0, 256).map(capability), + qualifications: report.qualifications.slice(0, 128).map(qualification), + findings: report.findings.slice(0, 256).map(finding), + evidence: report.evidence.slice(0, 256).map(evidence), + }; +} + +export function renderReadinessReport(report: Readonly): string { + const lines = [ + `System readiness: ${report.status}`, + `Schema: ${report.schemaVersion}`, + `Observed: ${report.provenance.observedAt}`, + "Mutation performed: no", + ]; + + if (report.findings.length === 0) { + lines.push("Findings: none"); + } else { + lines.push("Findings:"); + for (const entry of report.findings) { + lines.push(`- [${entry.severity}] ${entry.id}: ${entry.summary}`); + } + } + + return lines.join("\n"); +} From 6714d639a42111750043bda9e70ce0422ae5aee9 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 14:55:03 +0000 Subject: [PATCH 15/33] fix(cli): satisfy readiness probe CI contracts Signed-off-by: Remy the Refactoror --- src/commands/host/probe.ts | 10 ++++++++++ src/lib/readiness/effects.test.ts | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/commands/host/probe.ts b/src/commands/host/probe.ts index 4fc0a10c11a..10232a63567 100644 --- a/src/commands/host/probe.ts +++ b/src/commands/host/probe.ts @@ -18,6 +18,16 @@ export default class HostProbeCommand extends NemoClawCommand { static usage = ["host probe [--json]"]; static examples = ["<%= config.bin %> host probe", "<%= config.bin %> host probe --json"]; static flags = {}; + static publicDisplay = [ + { + usage: "nemoclaw host probe", + description: "Report host readiness without changing the system", + flags: "[--json]", + group: "Troubleshooting", + scope: "global", + order: 37.5, + }, + ] as const; public async run(): Promise { await this.parse(HostProbeCommand); diff --git a/src/lib/readiness/effects.test.ts b/src/lib/readiness/effects.test.ts index 37558377aac..8be83f3923c 100644 --- a/src/lib/readiness/effects.test.ts +++ b/src/lib/readiness/effects.test.ts @@ -14,6 +14,19 @@ const DOCKER_INFO = JSON.stringify({ MemTotal: 16 * 1024 ** 3, OperatingSystem: "Docker Engine", }); +const COMMAND_OUTPUTS: Record = { + "sh -lc command -v node": "/usr/bin/node", + "sh -lc command -v openshell": "/usr/bin/openshell", + "sh -lc command -v nvidia-container-cli": "/usr/bin/nvidia-container-cli", + "docker info --format {{json .}}": DOCKER_INFO, + "systemctl is-active docker": "active", + "systemctl is-enabled docker": "enabled", +}; +const FILE_CONTENTS: Record = { + "/proc/version": "Linux version 6.8", + "/etc/docker/daemon.json": "{}", + "/home/rootless/.config/docker/daemon.json": "{}", +}; describe("readiness process effects (#7412)", () => { it("repeats the host probe without invoking a mutating dependency", () => { @@ -22,14 +35,11 @@ describe("readiness process effects (#7412)", () => { const directories: string[] = []; const runCaptureImpl = vi.fn((command: readonly string[]) => { commands.push([...command]); - if (command[0] === "sh" && command[4]) return `/usr/bin/${command[4]}`; - if (command[0] === "docker") return DOCKER_INFO; - if (command[0] === "systemctl") return command[1] === "is-active" ? "active" : "enabled"; - return ""; + return COMMAND_OUTPUTS[command.join(" ")] ?? ""; }); const readFileImpl = vi.fn((path: string) => { reads.push(path); - return path === "/proc/version" ? "Linux version 6.8" : "{}"; + return FILE_CONTENTS[path] ?? ""; }); const readdirImpl = vi.fn((path: string) => { directories.push(path); From 28f9cabf5a5aff3e0989c13f22446720eccd135d Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:02:31 +0000 Subject: [PATCH 16/33] test(cli): include host in command registry contract Signed-off-by: Remy the Refactoror --- test/package-contract/cli/command-registry.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/package-contract/cli/command-registry.test.ts b/test/package-contract/cli/command-registry.test.ts index 787e929ba27..a1f19adff2c 100644 --- a/test/package-contract/cli/command-registry.test.ts +++ b/test/package-contract/cli/command-registry.test.ts @@ -189,11 +189,12 @@ describe("command-registry", () => { }); describe("globalCommandTokens()", () => { - it("returns the exact set of 27 tokens matching the global dispatch commands", () => { + it("returns the exact set of 28 tokens matching the global dispatch commands", () => { const tokens = globalCommandTokens(); const expected = new Set([ "agents", "completion", + "host", "onboard", "update", "list", From f3f1d85ab78ca73a269dc2fb8978ce0388295351 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:13:01 +0000 Subject: [PATCH 17/33] fix(readiness): harden public report boundary Signed-off-by: Remy the Refactoror --- src/lib/readiness/effects.test.ts | 19 +++++++++++------ src/lib/readiness/presentation.test.ts | 28 ++++++++++++++++++++++++++ src/lib/readiness/presentation.ts | 24 ++++++++++++++++------ 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/lib/readiness/effects.test.ts b/src/lib/readiness/effects.test.ts index 8be83f3923c..c3d9f3e7bce 100644 --- a/src/lib/readiness/effects.test.ts +++ b/src/lib/readiness/effects.test.ts @@ -15,9 +15,16 @@ const DOCKER_INFO = JSON.stringify({ OperatingSystem: "Docker Engine", }); const COMMAND_OUTPUTS: Record = { - "sh -lc command -v node": "/usr/bin/node", - "sh -lc command -v openshell": "/usr/bin/openshell", - "sh -lc command -v nvidia-container-cli": "/usr/bin/nvidia-container-cli", + 'sh -c command -v "$1" -- docker': "/usr/bin/docker", + 'sh -c command -v "$1" -- node': "/usr/bin/node", + 'sh -c command -v "$1" -- openshell': "/usr/bin/openshell", + 'sh -c command -v "$1" -- nvidia-ctk': "/usr/bin/nvidia-ctk", + 'sh -c command -v "$1" -- apt-get': "", + 'sh -c command -v "$1" -- dnf': "", + 'sh -c command -v "$1" -- yum': "", + 'sh -c command -v "$1" -- brew': "", + 'sh -c command -v "$1" -- pacman': "", + 'sh -c command -v "$1" -- systemctl': "/usr/bin/systemctl", "docker info --format {{json .}}": DOCKER_INFO, "systemctl is-active docker": "active", "systemctl is-enabled docker": "enabled", @@ -64,9 +71,9 @@ describe("readiness process effects (#7412)", () => { expect(first.mutated).toBe(false); expect(assess).toHaveBeenCalledTimes(2); expect(commands.length).toBeGreaterThan(0); - expect( - commands.every(([command]) => ["sh", "docker", "systemctl"].includes(command ?? "")), - ).toBe(true); + expect(commands.every((command) => Object.hasOwn(COMMAND_OUTPUTS, command.join(" ")))).toBe( + true, + ); expect( commands .filter(([command]) => command === "systemctl") diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 0b871b237f4..49573363262 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -44,6 +44,31 @@ describe("public readiness presentation (#7412)", () => { expect(validate(publicReport), JSON.stringify(validate.errors)).toBe(true); }); + it.each([ + [`nvapi-${"a".repeat(24)}`, undefined], + ["not-a-source-revision", undefined], + ["a".repeat(40), "a".repeat(40)], + ])("publishes only schema-valid source revisions", (sourceRevision, expected) => { + const ajv = new Ajv2020({ strict: true }); + ajv.addFormat("date-time", { + type: "string", + validate: (value: string) => !Number.isNaN(Date.parse(value)), + }); + const validate = ajv.compile(systemReadinessSchema as AnySchema); + const publicReport = createPublicReadinessReport( + report({ + provenance: { + nemoclawVersion: "0.1.0", + observedAt: "2026-06-01T12:00:00.000Z", + sourceRevision, + }, + }), + ); + + expect(publicReport.provenance.sourceRevision).toBe(expected); + expect(validate(publicReport), JSON.stringify(validate.errors)).toBe(true); + }); + it("renders human output from the same public report used for JSON", () => { const publicReport = createPublicReadinessReport( report({ @@ -86,6 +111,7 @@ describe("public readiness presentation (#7412)", () => { processEnv: `NVIDIA_API_KEY=${token}`, "processEnv.PATH": "/usr/bin", environmentDump: "HOME=/home/user", + envVars: `NVIDIA_API_KEY=${token}`, }, }, ], @@ -97,6 +123,8 @@ describe("public readiness presentation (#7412)", () => { expect(serialized).not.toContain("user:"); expect(serialized).not.toContain("NVIDIA_API_KEY"); expect(serialized).not.toContain("processEnv"); + expect(serialized).not.toContain("environmentDump"); + expect(serialized).not.toContain("envVars"); expect(publicReport.evidence[0]?.summary.length).toBeLessThanOrEqual(1024); expect(String(publicReport.evidence[0]?.details?.stderr).length).toBeLessThanOrEqual(1024); }); diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts index b33ab9ecddc..00e1abb2057 100644 --- a/src/lib/readiness/presentation.ts +++ b/src/lib/readiness/presentation.ts @@ -14,6 +14,16 @@ import type { const MAX_SUMMARY_LENGTH = 512; const MAX_EVIDENCE_LENGTH = 1024; +const SOURCE_REVISION_PATTERN = /^[0-9a-f]{40,64}$/; +const ENVIRONMENT_DETAIL_KEYS = new Set([ + "env", + "environment", + "environmentdump", + "environmentvariables", + "envvars", + "processenv", + "processenvironment", +]); function bounded(value: string, maxLength: number): string { return String(redactForLog(value)) @@ -25,6 +35,11 @@ function scalar(value: EvidenceScalar): EvidenceScalar { return typeof value === "string" ? bounded(value, MAX_EVIDENCE_LENGTH) : value; } +function isEnvironmentDetail(key: string): boolean { + const segments = key.split(/[._-]/).filter(Boolean); + return segments.some((segment) => ENVIRONMENT_DETAIL_KEYS.has(segment.toLowerCase())); +} + function observation(entry: ReadinessObservation): ReadinessObservation { return { id: entry.id, @@ -71,11 +86,7 @@ function evidence(entry: ReadinessEvidence): ReadinessEvidence { ? { details: Object.fromEntries( Object.entries(redactedDetails) - .filter( - ([key]) => - !/(?:^|[._-])(?:env|environment)(?:$|[._-])/i.test(key) && - !/(?:processEnv|processEnvironment)/i.test(key), - ) + .filter(([key]) => !isEnvironmentDetail(key)) .slice(0, 16) .map(([key, value]) => [key, scalar(value)]), ), @@ -94,7 +105,8 @@ export function createPublicReadinessReport( mutated: false, provenance: { nemoclawVersion: bounded(report.provenance.nemoclawVersion, 128), - ...(report.provenance.sourceRevision + ...(report.provenance.sourceRevision && + SOURCE_REVISION_PATTERN.test(report.provenance.sourceRevision) ? { sourceRevision: report.provenance.sourceRevision } : {}), observedAt: report.provenance.observedAt, From 5d54a714af2b4d1d42fc7085c39d2c4433e3f68f Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:31:11 +0000 Subject: [PATCH 18/33] chore(readiness): normalize effects test imports Signed-off-by: Remy the Refactoror --- src/lib/readiness/effects.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/readiness/effects.test.ts b/src/lib/readiness/effects.test.ts index c3d9f3e7bce..e6f52c75342 100644 --- a/src/lib/readiness/effects.test.ts +++ b/src/lib/readiness/effects.test.ts @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { assessHost } from "../onboard/preflight"; import { describe, expect, it, vi } from "vitest"; +import { assessHost } from "../onboard/preflight"; import { createHostReadinessReport } from "./host"; const NOW = new Date("2026-06-01T12:00:00Z"); From 4b99325ed9bc014a3911c2fa79581272cf6bfad9 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:38:18 +0000 Subject: [PATCH 19/33] test(readiness): assert presentation behavior Signed-off-by: Remy the Refactoror --- src/lib/readiness/presentation.test.ts | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 49573363262..9f1e5c67118 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -1,11 +1,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; import { describe, expect, it } from "vitest"; -import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { - type: "json", -}; import { createPublicReadinessReport, renderReadinessReport } from "./presentation"; import type { SystemReadinessReport } from "./types"; @@ -32,29 +28,17 @@ describe("public readiness presentation (#7412)", () => { it.each([ ["incompatible", 2], ["inconclusive", 3], - ] as const)("emits a schema-valid %s report for exit %i", (status, exitCode) => { - const ajv = new Ajv2020({ strict: true }); - ajv.addFormat("date-time", { - type: "string", - validate: (value: string) => !Number.isNaN(Date.parse(value)), - }); - const validate = ajv.compile(systemReadinessSchema as AnySchema); + ] as const)("preserves %s status and exit code %i", (status, exitCode) => { const publicReport = createPublicReadinessReport(report({ status, exitCode })); - expect(validate(publicReport), JSON.stringify(validate.errors)).toBe(true); + expect(publicReport).toMatchObject({ status, exitCode, mutated: false }); }); it.each([ [`nvapi-${"a".repeat(24)}`, undefined], ["not-a-source-revision", undefined], ["a".repeat(40), "a".repeat(40)], - ])("publishes only schema-valid source revisions", (sourceRevision, expected) => { - const ajv = new Ajv2020({ strict: true }); - ajv.addFormat("date-time", { - type: "string", - validate: (value: string) => !Number.isNaN(Date.parse(value)), - }); - const validate = ajv.compile(systemReadinessSchema as AnySchema); + ])("publishes only immutable source revisions", (sourceRevision, expected) => { const publicReport = createPublicReadinessReport( report({ provenance: { @@ -66,7 +50,6 @@ describe("public readiness presentation (#7412)", () => { ); expect(publicReport.provenance.sourceRevision).toBe(expected); - expect(validate(publicReport), JSON.stringify(validate.errors)).toBe(true); }); it("renders human output from the same public report used for JSON", () => { From 05ad4447a935da79d6cf74221c52b8b98685b304 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:51:29 +0000 Subject: [PATCH 20/33] test(cli): validate nonzero readiness JSON Signed-off-by: Remy the Refactoror --- src/commands/host/probe.test.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 6a806bc4173..257a11d64cb 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -1,7 +1,11 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import Ajv2020, { type AnySchema } from "ajv/dist/2020.js"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import systemReadinessSchema from "../../../schemas/system-readiness.schema.json" with { + type: "json", +}; import type { SystemReadinessReport } from "../../lib/readiness/types"; const mocks = vi.hoisted(() => ({ @@ -65,17 +69,26 @@ describe("host probe command (#7412)", () => { } }); - it("emits the public report as JSON on a nonzero exit", async () => { - const incompatible = report("incompatible", 2); - mocks.createHostReadinessReport.mockReturnValueOnce(incompatible); + it.each([ + ["incompatible", 2], + ["inconclusive", 3], + ] as const)("emits schema-valid JSON for %s hosts", async (status, exitCode) => { + const expectedReport = report(status, exitCode); + mocks.createHostReadinessReport.mockReturnValueOnce(expectedReport); const log = vi.spyOn(console, "log").mockImplementation(() => undefined); const previousExitCode = process.exitCode; process.exitCode = undefined; try { await HostProbeCommand.run(["--json"], process.cwd()); - expect(JSON.parse(String(log.mock.calls.at(-1)?.[0]))).toEqual(incompatible); - expect(process.exitCode).toBe(2); + const output = JSON.parse(String(log.mock.calls.at(-1)?.[0])); + const ajv = new Ajv2020({ allErrors: true, strict: true }); + ajv.addFormat("date-time", true); + const validate = ajv.compile(systemReadinessSchema as AnySchema); + + expect(output).toEqual(expectedReport); + expect(validate(output), JSON.stringify(validate.errors)).toBe(true); + expect(process.exitCode).toBe(exitCode); expect(mocks.renderReadinessReport).not.toHaveBeenCalled(); } finally { process.exitCode = previousExitCode; From 0e40fda44a4f9fb8c5507a6b3a5d0b040ab465bf Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 15:57:26 +0000 Subject: [PATCH 21/33] test(cli): keep schema assertion behavioral Signed-off-by: Remy the Refactoror --- src/commands/host/probe.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 257a11d64cb..b99dc8fd4b3 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -22,6 +22,13 @@ vi.mock("../../lib/readiness/index", () => ({ import HostProbeCommand from "./probe"; +function assertSchemaValid(value: unknown): void { + const ajv = new Ajv2020({ allErrors: true, strict: true }); + ajv.addFormat("date-time", true); + const validate = ajv.compile(systemReadinessSchema as AnySchema); + if (!validate(value)) throw new Error(JSON.stringify(validate.errors)); +} + function report( status: SystemReadinessReport["status"], exitCode: SystemReadinessReport["exitCode"], @@ -82,12 +89,9 @@ describe("host probe command (#7412)", () => { try { await HostProbeCommand.run(["--json"], process.cwd()); const output = JSON.parse(String(log.mock.calls.at(-1)?.[0])); - const ajv = new Ajv2020({ allErrors: true, strict: true }); - ajv.addFormat("date-time", true); - const validate = ajv.compile(systemReadinessSchema as AnySchema); + expect(() => assertSchemaValid(output)).not.toThrow(); expect(output).toEqual(expectedReport); - expect(validate(output), JSON.stringify(validate.errors)).toBe(true); expect(process.exitCode).toBe(exitCode); expect(mocks.renderReadinessReport).not.toHaveBeenCalled(); } finally { From 7c3164da717dc2d436adb6aa04611cb63401f782 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 16:00:28 +0000 Subject: [PATCH 22/33] test(cli): keep readiness schema helper linear Signed-off-by: Remy the Refactoror --- src/commands/host/probe.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index b99dc8fd4b3..0b009495b0f 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -22,11 +22,15 @@ vi.mock("../../lib/readiness/index", () => ({ import HostProbeCommand from "./probe"; +function throwSchemaErrors(errors: unknown): never { + throw new Error(JSON.stringify(errors)); +} + function assertSchemaValid(value: unknown): void { const ajv = new Ajv2020({ allErrors: true, strict: true }); ajv.addFormat("date-time", true); const validate = ajv.compile(systemReadinessSchema as AnySchema); - if (!validate(value)) throw new Error(JSON.stringify(validate.errors)); + validate(value) || throwSchemaErrors(validate.errors); } function report( From 897303d6ff5d206f2ecb643b41a51d85ccfe5b69 Mon Sep 17 00:00:00 2001 From: Remy the Refactoror Date: Thu, 23 Jul 2026 16:11:30 +0000 Subject: [PATCH 23/33] test(cli): invoke readiness schema assertion directly Signed-off-by: Remy the Refactoror --- src/commands/host/probe.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 0b009495b0f..9981f2faceb 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -94,7 +94,7 @@ describe("host probe command (#7412)", () => { await HostProbeCommand.run(["--json"], process.cwd()); const output = JSON.parse(String(log.mock.calls.at(-1)?.[0])); - expect(() => assertSchemaValid(output)).not.toThrow(); + assertSchemaValid(output); expect(output).toEqual(expectedReport); expect(process.exitCode).toBe(exitCode); expect(mocks.renderReadinessReport).not.toHaveBeenCalled(); From 50678c435679edc24c3e1087303037e5761f2aff Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 16:03:23 -0400 Subject: [PATCH 24/33] fix(readiness): preserve public outcome pairing Signed-off-by: Julie Yaunches --- src/lib/readiness/presentation.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts index 00e1abb2057..9c1ed0171cf 100644 --- a/src/lib/readiness/presentation.ts +++ b/src/lib/readiness/presentation.ts @@ -98,10 +98,15 @@ function evidence(entry: ReadinessEvidence): ReadinessEvidence { export function createPublicReadinessReport( report: Readonly, ): SystemReadinessReport { + const outcome = + report.status === "supported" + ? ({ status: report.status, exitCode: report.exitCode } as const) + : report.status === "incompatible" + ? ({ status: report.status, exitCode: report.exitCode } as const) + : ({ status: report.status, exitCode: report.exitCode } as const); return { schemaVersion: report.schemaVersion, - status: report.status, - exitCode: report.exitCode, + ...outcome, mutated: false, provenance: { nemoclawVersion: bounded(report.provenance.nemoclawVersion, 128), From 0ad09b38d340e6a0f959336f99f8176eefede370 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 16:09:37 -0400 Subject: [PATCH 25/33] test(readiness): preserve outcome fixture pairing Signed-off-by: Julie Yaunches --- src/commands/host/probe.test.ts | 47 ++++++++++++---------- src/lib/readiness/presentation.test.ts | 54 ++++++++++++++++---------- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 9981f2faceb..301330995da 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -22,6 +22,22 @@ vi.mock("../../lib/readiness/index", () => ({ import HostProbeCommand from "./probe"; +type ReadinessOutcome = + | { status: "supported"; exitCode: 0 } + | { status: "incompatible"; exitCode: 2 } + | { status: "inconclusive"; exitCode: 3 }; + +const READINESS_OUTCOMES = [ + { status: "supported", exitCode: 0 }, + { status: "incompatible", exitCode: 2 }, + { status: "inconclusive", exitCode: 3 }, +] as const satisfies readonly ReadinessOutcome[]; + +const NON_SUPPORTED_OUTCOMES = [ + { status: "incompatible", exitCode: 2 }, + { status: "inconclusive", exitCode: 3 }, +] as const satisfies readonly ReadinessOutcome[]; + function throwSchemaErrors(errors: unknown): never { throw new Error(JSON.stringify(errors)); } @@ -33,14 +49,10 @@ function assertSchemaValid(value: unknown): void { validate(value) || throwSchemaErrors(validate.errors); } -function report( - status: SystemReadinessReport["status"], - exitCode: SystemReadinessReport["exitCode"], -): SystemReadinessReport { +function report(outcome: ReadinessOutcome): SystemReadinessReport { return { schemaVersion: "1.0.0", - status, - exitCode, + ...outcome, mutated: false, provenance: { nemoclawVersion: "0.1.0", observedAt: "2026-06-01T12:00:00.000Z" }, observations: [], @@ -54,7 +66,7 @@ function report( describe("host probe command (#7412)", () => { beforeEach(() => { vi.clearAllMocks(); - mocks.createHostReadinessReport.mockReturnValue(report("supported", 0)); + mocks.createHostReadinessReport.mockReturnValue(report(READINESS_OUTCOMES[0])); mocks.createPublicReadinessReport.mockImplementation((value) => value); mocks.renderReadinessReport.mockReturnValue("System readiness: supported"); }); @@ -63,28 +75,21 @@ describe("host probe command (#7412)", () => { vi.restoreAllMocks(); }); - it.each([ - ["supported", 0], - ["incompatible", 2], - ["inconclusive", 3], - ] as const)("returns the deterministic %s exit code", async (status, exitCode) => { + it.each(READINESS_OUTCOMES)("returns the deterministic $status exit code", async (outcome) => { const previousExitCode = process.exitCode; process.exitCode = undefined; - mocks.createHostReadinessReport.mockReturnValueOnce(report(status, exitCode)); + mocks.createHostReadinessReport.mockReturnValueOnce(report(outcome)); try { await HostProbeCommand.run([], process.cwd()); - expect(process.exitCode).toBe(exitCode); + expect(process.exitCode).toBe(outcome.exitCode); } finally { process.exitCode = previousExitCode; } }); - it.each([ - ["incompatible", 2], - ["inconclusive", 3], - ] as const)("emits schema-valid JSON for %s hosts", async (status, exitCode) => { - const expectedReport = report(status, exitCode); + it.each(NON_SUPPORTED_OUTCOMES)("emits schema-valid JSON for $status hosts", async (outcome) => { + const expectedReport = report(outcome); mocks.createHostReadinessReport.mockReturnValueOnce(expectedReport); const log = vi.spyOn(console, "log").mockImplementation(() => undefined); const previousExitCode = process.exitCode; @@ -96,7 +101,7 @@ describe("host probe command (#7412)", () => { assertSchemaValid(output); expect(output).toEqual(expectedReport); - expect(process.exitCode).toBe(exitCode); + expect(process.exitCode).toBe(outcome.exitCode); expect(mocks.renderReadinessReport).not.toHaveBeenCalled(); } finally { process.exitCode = previousExitCode; @@ -104,7 +109,7 @@ describe("host probe command (#7412)", () => { }); it("runs before gateway or sandbox registration and uses one report for human output", async () => { - const publicReport = report("supported", 0); + const publicReport = report(READINESS_OUTCOMES[0]); const log = vi.spyOn(console, "log").mockImplementation(() => undefined); mocks.createPublicReadinessReport.mockReturnValueOnce(publicReport); diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 9f1e5c67118..52627f8d0ab 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -5,11 +5,27 @@ import { describe, expect, it } from "vitest"; import { createPublicReadinessReport, renderReadinessReport } from "./presentation"; import type { SystemReadinessReport } from "./types"; -function report(overrides: Partial = {}): SystemReadinessReport { +type ReadinessOutcome = + | { status: "supported"; exitCode: 0 } + | { status: "incompatible"; exitCode: 2 } + | { status: "inconclusive"; exitCode: 3 }; + +type ReportOverrides = Partial< + Omit, "status" | "exitCode"> +>; + +const NON_SUPPORTED_OUTCOMES = [ + { status: "incompatible", exitCode: 2 }, + { status: "inconclusive", exitCode: 3 }, +] as const satisfies readonly ReadinessOutcome[]; + +function report( + overrides: ReportOverrides = {}, + outcome: ReadinessOutcome = { status: "supported", exitCode: 0 }, +): SystemReadinessReport { return { schemaVersion: "1.0.0", - status: "supported", - exitCode: 0, + ...outcome, mutated: false, provenance: { nemoclawVersion: "0.1.0", @@ -25,13 +41,10 @@ function report(overrides: Partial = {}): SystemReadiness } describe("public readiness presentation (#7412)", () => { - it.each([ - ["incompatible", 2], - ["inconclusive", 3], - ] as const)("preserves %s status and exit code %i", (status, exitCode) => { - const publicReport = createPublicReadinessReport(report({ status, exitCode })); + it.each(NON_SUPPORTED_OUTCOMES)("preserves $status status and exit code $exitCode", (outcome) => { + const publicReport = createPublicReadinessReport(report({}, outcome)); - expect(publicReport).toMatchObject({ status, exitCode, mutated: false }); + expect(publicReport).toMatchObject({ ...outcome, mutated: false }); }); it.each([ @@ -54,17 +67,18 @@ describe("public readiness presentation (#7412)", () => { it("renders human output from the same public report used for JSON", () => { const publicReport = createPublicReadinessReport( - report({ - status: "incompatible", - exitCode: 2, - findings: [ - { - id: "host.docker.unavailable", - severity: "blocking", - summary: "Docker is not installed.", - }, - ], - }), + report( + { + findings: [ + { + id: "host.docker.unavailable", + severity: "blocking", + summary: "Docker is not installed.", + }, + ], + }, + { status: "incompatible", exitCode: 2 }, + ), ); expect(renderReadinessReport(publicReport)).toContain("System readiness: incompatible"); From 9d04090bd6f271b5faa7dadbdb3c525a517d5bbb Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 17:50:22 -0400 Subject: [PATCH 26/33] docs(readiness): publish host probe reference Signed-off-by: Julie Yaunches --- docs/index.yml | 9 +++++++++ docs/reference/system-readiness.mdx | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/index.yml b/docs/index.yml index 9a6a6fe6613..349f0cbc6f7 100644 --- a/docs/index.yml +++ b/docs/index.yml @@ -381,6 +381,9 @@ navigation: - page: "Troubleshoot MCP Servers" path: _build/agent-variants/reference/troubleshoot-mcp-servers.openclaw.generated.mdx slug: troubleshoot-mcp-servers + - page: "System Readiness" + path: _build/agent-variants/reference/system-readiness.openclaw.generated.mdx + slug: system-readiness - page: "Troubleshooting" path: _build/agent-variants/reference/troubleshooting.openclaw.generated.mdx slug: troubleshooting @@ -657,6 +660,9 @@ navigation: - page: "Troubleshoot MCP Servers" path: _build/agent-variants/reference/troubleshoot-mcp-servers.deepagents.generated.mdx slug: troubleshoot-mcp-servers + - page: "System Readiness" + path: _build/agent-variants/reference/system-readiness.deepagents.generated.mdx + slug: system-readiness - page: "Troubleshooting" path: _build/agent-variants/reference/troubleshooting.deepagents.generated.mdx slug: troubleshooting @@ -1027,6 +1033,9 @@ navigation: - page: "Troubleshoot MCP Servers" path: _build/agent-variants/reference/troubleshoot-mcp-servers.hermes.generated.mdx slug: troubleshoot-mcp-servers + - page: "System Readiness" + path: _build/agent-variants/reference/system-readiness.hermes.generated.mdx + slug: system-readiness - page: "Troubleshooting" path: _build/agent-variants/reference/troubleshooting.hermes.generated.mdx slug: troubleshooting diff --git a/docs/reference/system-readiness.mdx b/docs/reference/system-readiness.mdx index 042e04326e3..3581c89b426 100644 --- a/docs/reference/system-readiness.mdx +++ b/docs/reference/system-readiness.mdx @@ -4,7 +4,7 @@ title: "System Readiness" sidebar-title: "System Readiness" description: "Check host readiness before NemoClaw onboarding without changing system state." -description-agent: "Documents the read-only host readiness command, JSON contract, exit codes, redaction boundary, and mutation guarantees." +description-agent: "Documents the read-only host readiness command, JSON contract, exit codes, redaction boundary, and mutation guarantees. Use when checking a host before onboarding or consuming readiness JSON." keywords: ["nemoclaw host probe", "system readiness", "readiness json", "pre-onboarding check"] content: type: "reference" @@ -18,13 +18,13 @@ The command works without a registered gateway or sandbox. Run the human-readable check from the host: ```bash -nemoclaw host probe +$$nemoclaw host probe ``` Use JSON when another tool consumes the result: ```bash -nemoclaw host probe --json +$$nemoclaw host probe --json ``` Both presentations use the same structured report. From 871d4b1d3094ef9cdcbc465085ae8fb749292708 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 18:13:31 -0400 Subject: [PATCH 27/33] fix(readiness): handle non-applicable GPU checks Signed-off-by: Julie Yaunches --- src/lib/readiness/host.test.ts | 70 +++++++++++++++++++++++++++++----- src/lib/readiness/host.ts | 33 ++++++++-------- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/lib/readiness/host.test.ts b/src/lib/readiness/host.test.ts index 2f09f6d1409..70d5cda3093 100644 --- a/src/lib/readiness/host.test.ts +++ b/src/lib/readiness/host.test.ts @@ -1,9 +1,16 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { NvidiaPlatform } from "../inference/nim"; import type { HostAssessment } from "../onboard/preflight"; -import { collectHostObservations, projectHostReadiness } from "./host"; +import { collectHostObservations, createHostReadinessReport, projectHostReadiness } from "./host"; + +const { detectNvidiaPlatform } = vi.hoisted(() => ({ + detectNvidiaPlatform: vi.fn<() => NvidiaPlatform>(() => "linux"), +})); + +vi.mock("../inference/nim", () => ({ detectNvidiaPlatform })); const NOW = new Date("2026-06-01T12:00:00Z"); @@ -41,7 +48,7 @@ function host(overrides: Partial = {}): HostAssessment { function report( overrides: Partial = {}, - collectionOptions: { hostGpuPlatform?: string } = {}, + collectionOptions: { detectHostGpuPlatform?: () => NvidiaPlatform } = {}, ) { return projectHostReadiness( collectHostObservations({ @@ -63,6 +70,11 @@ function findingIds(result: ReturnType) { } describe("host readiness projection (#7408)", () => { + beforeEach(() => { + detectNvidiaPlatform.mockReset(); + detectNvidiaPlatform.mockReturnValue("linux"); + }); + it("keeps collection dependency-injected and separate from pure evaluation", () => { const assess = vi.fn(() => host()); const snapshot = collectHostObservations({ assess, now: () => NOW }); @@ -125,18 +137,56 @@ describe("host readiness projection (#7408)", () => { }); it.each([ - [{ cdiNvidiaGpuSpecMissing: true }, { hostGpuPlatform: "jetson" }], - [ - { isWsl: true, runtime: "docker-desktop", cdiNvidiaGpuSpecStale: true }, - { hostGpuPlatform: undefined }, - ], + [{ cdiNvidiaGpuSpecMissing: true }, { detectHostGpuPlatform: () => "jetson" as const }], + [{ isWsl: true, runtime: "docker-desktop", cdiNvidiaGpuSpecStale: true }, {}], ] as const)("preserves CDI enforcement exclusions for %s", (overrides, collectionOptions) => { const result = report(overrides, collectionOptions); - expect(state(result, "host.gpu.cdi_healthy")).toBe("unknown"); + expect(state(result, "host.gpu.cdi_healthy")).toBe("present"); expect(findingIds(result)).not.toContain("host.gpu.cdi_missing"); expect(findingIds(result)).not.toContain("host.gpu.cdi_stale"); - expect(result.status).not.toBe("incompatible"); + expect(result.status).toBe("supported"); + }); + + it("uses canonical platform detection in the default report creator", () => { + detectNvidiaPlatform.mockReturnValue("jetson"); + + const result = createHostReadinessReport( + { nemoclawVersion: "0.1.0", now: () => NOW }, + { + assess: () => host({ cdiNvidiaGpuSpecMissing: true }), + architecture: "arm64", + }, + ); + + expect(detectNvidiaPlatform).toHaveBeenCalledOnce(); + expect(state(result, "host.gpu.cdi_healthy")).toBe("present"); + expect(findingIds(result)).not.toContain("host.gpu.cdi_missing"); + expect(result.status).toBe("supported"); + }); + + it("supports CPU-only hosts without requiring GPU tooling", () => { + const result = report({ + hasNvidiaGpu: false, + nvidiaContainerToolkitInstalled: false, + dockerCdiSpecDirs: [], + cdiNvidiaGpuSpecMissing: true, + cdiNvidiaGpuSpecNeedsRepair: true, + }); + + expect(detectNvidiaPlatform).not.toHaveBeenCalled(); + expect(state(result, "host.gpu.nvidia_available")).toBe("absent"); + expect(state(result, "host.gpu.container_toolkit_available")).toBe("present"); + expect(state(result, "host.gpu.cdi_healthy")).toBe("present"); + expect(findingIds(result)).not.toContain("host.gpu.container_toolkit_missing"); + expect(findingIds(result)).not.toContain("host.gpu.cdi_missing"); + expect(result.status).toBe("supported"); + }); + + it("projects nested overlay conflicts as incompatible storage", () => { + const result = report({ hasNestedOverlayConflict: true }); + + expect(state(result, "host.docker.storage_compatible")).toBe("absent"); }); it("uses unknown for dependent facts when Docker is unreachable", () => { diff --git a/src/lib/readiness/host.ts b/src/lib/readiness/host.ts index 2c83e480dfe..31bed77cb42 100644 --- a/src/lib/readiness/host.ts +++ b/src/lib/readiness/host.ts @@ -1,10 +1,11 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import { detectNvidiaPlatform, type NvidiaPlatform } from "../inference/nim.js"; import type { HostAssessment } from "../onboard/preflight.js"; import { assessHost } from "../onboard/preflight.js"; +import { redactFull } from "../security/redact.js"; import { - SYSTEM_READINESS_SCHEMA_VERSION, type EvidenceScalar, type FindingSeverity, type ReadinessCapability, @@ -12,13 +13,12 @@ import { type ReadinessFinding, type ReadinessObservation, type ReadinessState, + SYSTEM_READINESS_SCHEMA_VERSION, type SystemReadinessReport, } from "./types.js"; const DEFAULT_MAX_AGE_MS = 30_000; const MAX_EVIDENCE_LENGTH = 1024; -const SECRET_PATTERN = - /(?:\bauthorization\s*:\s*bearer\s+[^\s,;]+|\b(?:bearer\s+)?(?:gh[opusr]_[a-z0-9_]{20,}|nvapi-[a-z0-9_-]{16,}|sk-[a-z0-9_-]{16,}|(?:api[_-]?key|token|password|secret)\s*[=:]\s*[^\s,;]+))/gi; export interface HostObservations { platform: string; @@ -40,7 +40,7 @@ export interface HostObservations { nodeInstalled: boolean; openshellInstalled: boolean; hasNvidiaGpu: boolean; - hostGpuPlatform?: string; + hostGpuPlatform?: NvidiaPlatform; nvidiaContainerToolkitInstalled: boolean; dockerCdiSpecDirs: readonly string[]; cdiNvidiaGpuSpecMissing: boolean; @@ -58,7 +58,7 @@ export interface HostObservationSnapshot { export interface CollectHostObservationsOptions { assess?: () => HostAssessment; architecture?: string; - hostGpuPlatform?: string; + detectHostGpuPlatform?: () => NvidiaPlatform; now?: () => Date; } @@ -70,13 +70,13 @@ export interface CreateHostReadinessReportOptions { } function safeEvidence(value: string): string { - return value.replace(SECRET_PATTERN, "[REDACTED]").slice(0, MAX_EVIDENCE_LENGTH); + return redactFull(value).slice(0, MAX_EVIDENCE_LENGTH); } function adaptHostAssessment( host: Readonly, architecture: string, - hostGpuPlatform?: string, + hostGpuPlatform?: NvidiaPlatform, ): HostObservations { return { platform: host.platform, @@ -118,7 +118,9 @@ export function collectHostObservations( observations: adaptHostAssessment( assessment, options.architecture ?? process.arch, - options.hostGpuPlatform, + assessment.hasNvidiaGpu + ? (options.detectHostGpuPlatform ?? detectNvidiaPlatform)() + : undefined, ), reusable: false, }; @@ -240,9 +242,8 @@ export function projectHostReadiness( host.dockerCdiSpecDirs.length > 0 && host.hostGpuPlatform !== "jetson" && !(host.isWsl && host.runtime === "docker-desktop"); - const cdiHealthy = cdiApplies - ? !host.cdiNvidiaGpuSpecMissing && !host.cdiNvidiaGpuSpecNeedsRepair - : undefined; + const cdiHealthy = + !cdiApplies || (!host.cdiNvidiaGpuSpecMissing && !host.cdiNvidiaGpuSpecNeedsRepair); observations = [ observation("host.os.platform", host.platform), observation("host.os.architecture", host.architecture), @@ -277,10 +278,10 @@ export function projectHostReadiness( observation("host.gpu.nvidia", host.hasNvidiaGpu), observation( "host.gpu.container_toolkit", - host.hasNvidiaGpu ? host.nvidiaContainerToolkitInstalled : undefined, + host.hasNvidiaGpu ? host.nvidiaContainerToolkitInstalled : false, ), - observation("host.gpu.cdi", cdiHealthy), - observation("host.gpu.cdi_stale", cdiApplies ? host.cdiNvidiaGpuSpecStale : undefined), + observation("host.gpu.cdi", cdiApplies ? cdiHealthy : false), + observation("host.gpu.cdi_stale", cdiApplies ? host.cdiNvidiaGpuSpecStale : false), ]; capabilities = [ capability("host.docker.available", stateOf(host.dockerInstalled)), @@ -305,9 +306,9 @@ export function projectHostReadiness( capability("host.gpu.nvidia_available", stateOf(host.hasNvidiaGpu)), capability( "host.gpu.container_toolkit_available", - host.hasNvidiaGpu ? stateOf(host.nvidiaContainerToolkitInstalled) : "unknown", + host.hasNvidiaGpu ? stateOf(host.nvidiaContainerToolkitInstalled) : "present", ), - capability("host.gpu.cdi_healthy", stateOf(cdiHealthy)), + capability("host.gpu.cdi_healthy", cdiApplies ? stateOf(cdiHealthy) : "present"), ]; findings = []; if (!host.dockerInstalled) From ecdcd0b92ed74176d2ba7978f7ff4bb1dfda6b4d Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 18:15:29 -0400 Subject: [PATCH 28/33] fix(readiness): enforce public report boundaries Signed-off-by: Julie Yaunches --- src/commands/host/probe.test.ts | 7 +---- src/lib/readiness/presentation.test.ts | 43 ++++++++++++++++++++++++++ src/lib/readiness/presentation.ts | 22 ++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 301330995da..08118733492 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -33,11 +33,6 @@ const READINESS_OUTCOMES = [ { status: "inconclusive", exitCode: 3 }, ] as const satisfies readonly ReadinessOutcome[]; -const NON_SUPPORTED_OUTCOMES = [ - { status: "incompatible", exitCode: 2 }, - { status: "inconclusive", exitCode: 3 }, -] as const satisfies readonly ReadinessOutcome[]; - function throwSchemaErrors(errors: unknown): never { throw new Error(JSON.stringify(errors)); } @@ -88,7 +83,7 @@ describe("host probe command (#7412)", () => { } }); - it.each(NON_SUPPORTED_OUTCOMES)("emits schema-valid JSON for $status hosts", async (outcome) => { + it.each(READINESS_OUTCOMES)("emits schema-valid JSON for $status hosts", async (outcome) => { const expectedReport = report(outcome); mocks.createHostReadinessReport.mockReturnValueOnce(expectedReport); const log = vi.spyOn(console, "log").mockImplementation(() => undefined); diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 52627f8d0ab..25c63d3e8e1 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -41,6 +41,14 @@ function report( } describe("public readiness presentation (#7412)", () => { + it("rejects reports that claim host mutation", () => { + const mutatedReport = { ...report(), mutated: true } as unknown as SystemReadinessReport; + + expect(() => createPublicReadinessReport(mutatedReport)).toThrow( + "Readiness reports must be observation-only.", + ); + }); + it.each(NON_SUPPORTED_OUTCOMES)("preserves $status status and exit code $exitCode", (outcome) => { const publicReport = createPublicReadinessReport(report({}, outcome)); @@ -125,4 +133,39 @@ describe("public readiness presentation (#7412)", () => { expect(publicReport.evidence[0]?.summary.length).toBeLessThanOrEqual(1024); expect(String(publicReport.evidence[0]?.details?.stderr).length).toBeLessThanOrEqual(1024); }); + + it("retains a final required finding at the public boundary", () => { + const warnings = Array.from({ length: 256 }, (_, index) => ({ + id: `host.boundary.${index}`, + severity: "warning" as const, + summary: `Warning ${index}`, + })); + const blocker = { + id: "host.boundary.blocker", + severity: "fatal" as const, + summary: "A final required finding.", + }; + + const publicReport = createPublicReadinessReport( + report({ findings: [...warnings, blocker] }, { status: "incompatible", exitCode: 2 }), + ); + + expect(publicReport.findings).toHaveLength(256); + expect(publicReport.findings).toContainEqual(blocker); + expect(publicReport.findings).not.toContainEqual(warnings.at(-1)); + }); + + it("fails closed when required findings exceed the public boundary", () => { + const blockers = Array.from({ length: 257 }, (_, index) => ({ + id: `host.blocker.${index}`, + severity: "blocking" as const, + summary: `Blocker ${index}`, + })); + + expect(() => + createPublicReadinessReport( + report({ findings: blockers }, { status: "incompatible", exitCode: 2 }), + ), + ).toThrow("Readiness report exceeds the public boundary for required findings."); + }); }); diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts index 9c1ed0171cf..f5eaa00131f 100644 --- a/src/lib/readiness/presentation.ts +++ b/src/lib/readiness/presentation.ts @@ -14,6 +14,7 @@ import type { const MAX_SUMMARY_LENGTH = 512; const MAX_EVIDENCE_LENGTH = 1024; +const MAX_FINDINGS = 256; const SOURCE_REVISION_PATTERN = /^[0-9a-f]{40,64}$/; const ENVIRONMENT_DETAIL_KEYS = new Set([ "env", @@ -75,6 +76,22 @@ function finding(entry: ReadinessFinding): ReadinessFinding { }; } +function boundedFindings(entries: readonly ReadinessFinding[]): ReadinessFinding[] { + const required = entries.filter( + ({ severity }) => severity === "blocking" || severity === "fatal", + ); + if (required.length > MAX_FINDINGS) { + throw new Error("Readiness report exceeds the public boundary for required findings."); + } + + const selected = new Set(required); + for (const entry of entries) { + if (selected.size >= MAX_FINDINGS) break; + selected.add(entry); + } + return entries.filter((entry) => selected.has(entry)).map(finding); +} + function evidence(entry: ReadinessEvidence): ReadinessEvidence { const redactedDetails = entry.details ? (redactForLog(entry.details) as Record) @@ -98,6 +115,9 @@ function evidence(entry: ReadinessEvidence): ReadinessEvidence { export function createPublicReadinessReport( report: Readonly, ): SystemReadinessReport { + if (report.mutated !== false) { + throw new Error("Readiness reports must be observation-only."); + } const outcome = report.status === "supported" ? ({ status: report.status, exitCode: report.exitCode } as const) @@ -119,7 +139,7 @@ export function createPublicReadinessReport( observations: report.observations.slice(0, 256).map(observation), capabilities: report.capabilities.slice(0, 256).map(capability), qualifications: report.qualifications.slice(0, 128).map(qualification), - findings: report.findings.slice(0, 256).map(finding), + findings: boundedFindings(report.findings), evidence: report.evidence.slice(0, 256).map(evidence), }; } From b8f4381600de7f214347f8ab5c6d3761bd3c9492 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 18:31:45 -0400 Subject: [PATCH 29/33] docs(readiness): document host probe command Signed-off-by: Julie Yaunches --- docs/reference/commands.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index 261d5e4b8ff..1779fe735a2 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -170,6 +170,18 @@ $$nemoclaw resources [--json] If the gateway is not running, Kubernetes allocatable fields are omitted and host CPU/RAM totals are still shown. +### `$$nemoclaw host probe` + +Inspect host readiness before onboarding without changing host, Docker, gateway, credential, policy, or sandbox state. +Use `--json` for the schema-versioned report. +The command exits with `0` for `supported`, `2` for `incompatible`, and `3` for `inconclusive`. + +```bash +$$nemoclaw host probe [--json] +``` + +For capability IDs, evidence bounds, and compatibility guidance, refer to [System Readiness](system-readiness). + ### `$$nemoclaw agents list` List the installed agent runtimes that can be selected with `$$nemoclaw onboard --agent `. From 4e40724b2595dab64f84efd09bf02a20fd9e5aba Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 18:37:25 -0400 Subject: [PATCH 30/33] fix(readiness): preserve public report references Signed-off-by: Julie Yaunches --- src/lib/readiness/presentation.test.ts | 41 +++++++++++++ src/lib/readiness/presentation.ts | 80 +++++++++++++++++++++++--- 2 files changed, 114 insertions(+), 7 deletions(-) diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 25c63d3e8e1..edb3cc1d59c 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -155,6 +155,47 @@ describe("public readiness presentation (#7412)", () => { expect(publicReport.findings).not.toContainEqual(warnings.at(-1)); }); + it("retains evidence referenced by a finding beyond the initial evidence boundary", () => { + const evidence = Array.from({ length: 257 }, (_, index) => ({ + id: `host.boundary.evidence.${index}`, + summary: `Evidence ${index}`, + })); + const blocker = { + id: "host.boundary.blocker", + severity: "blocking" as const, + summary: "A blocker with late evidence.", + evidenceIds: [evidence.at(-1)?.id ?? ""], + }; + + const publicReport = createPublicReadinessReport( + report({ evidence, findings: [blocker] }, { status: "incompatible", exitCode: 2 }), + ); + + expect(publicReport.evidence).toHaveLength(256); + expect(publicReport.evidence.map(({ id }) => id)).toContain(evidence.at(-1)?.id); + expect(publicReport.evidence.map(({ id }) => id)).not.toContain(evidence.at(-2)?.id); + }); + + it("retains capabilities referenced by a qualification beyond the initial boundary", () => { + const capabilities = Array.from({ length: 257 }, (_, index) => ({ + id: `host.boundary.capability.${index}`, + state: "present" as const, + })); + const qualification = { + id: "host.boundary.qualification", + status: "qualified" as const, + capabilityIds: [capabilities.at(-1)?.id ?? ""], + }; + + const publicReport = createPublicReadinessReport( + report({ capabilities, qualifications: [qualification] }), + ); + + expect(publicReport.capabilities).toHaveLength(256); + expect(publicReport.capabilities.map(({ id }) => id)).toContain(capabilities.at(-1)?.id); + expect(publicReport.capabilities.map(({ id }) => id)).not.toContain(capabilities.at(-2)?.id); + }); + it("fails closed when required findings exceed the public boundary", () => { const blockers = Array.from({ length: 257 }, (_, index) => ({ id: `host.blocker.${index}`, diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts index f5eaa00131f..fc5a80ee346 100644 --- a/src/lib/readiness/presentation.ts +++ b/src/lib/readiness/presentation.ts @@ -14,7 +14,11 @@ import type { const MAX_SUMMARY_LENGTH = 512; const MAX_EVIDENCE_LENGTH = 1024; +const MAX_OBSERVATIONS = 256; +const MAX_CAPABILITIES = 256; +const MAX_QUALIFICATIONS = 128; const MAX_FINDINGS = 256; +const MAX_EVIDENCE = 256; const SOURCE_REVISION_PATTERN = /^[0-9a-f]{40,64}$/; const ENVIRONMENT_DETAIL_KEYS = new Set([ "env", @@ -76,7 +80,7 @@ function finding(entry: ReadinessFinding): ReadinessFinding { }; } -function boundedFindings(entries: readonly ReadinessFinding[]): ReadinessFinding[] { +function boundedFindings(entries: readonly ReadinessFinding[]): readonly ReadinessFinding[] { const required = entries.filter( ({ severity }) => severity === "blocking" || severity === "fatal", ); @@ -89,7 +93,37 @@ function boundedFindings(entries: readonly ReadinessFinding[]): ReadinessFinding if (selected.size >= MAX_FINDINGS) break; selected.add(entry); } - return entries.filter((entry) => selected.has(entry)).map(finding); + return entries.filter((entry) => selected.has(entry)); +} + +function addReferences(target: Set, references: readonly string[] | undefined): void { + for (const id of references ?? []) target.add(id); +} + +function boundedReferencedEntries( + entries: readonly T[], + requiredIds: ReadonlySet, + maxEntries: number, + entityName: string, +): readonly T[] { + if (requiredIds.size > maxEntries) { + throw new Error( + `Readiness report exceeds the public boundary for referenced ${entityName} entries.`, + ); + } + + const entriesById = new Map(entries.map((entry) => [entry.id, entry])); + const missingIds = [...requiredIds].filter((id) => !entriesById.has(id)); + if (missingIds.length > 0) { + throw new Error(`Readiness report contains unresolved ${entityName} references.`); + } + + const selected = new Set([...requiredIds].map((id) => entriesById.get(id) as T)); + for (const entry of entries) { + if (selected.size >= maxEntries) break; + selected.add(entry); + } + return entries.filter((entry) => selected.has(entry)); } function evidence(entry: ReadinessEvidence): ReadinessEvidence { @@ -124,6 +158,38 @@ export function createPublicReadinessReport( : report.status === "incompatible" ? ({ status: report.status, exitCode: report.exitCode } as const) : ({ status: report.status, exitCode: report.exitCode } as const); + const selectedObservations = report.observations.slice(0, MAX_OBSERVATIONS); + const selectedQualifications = report.qualifications.slice(0, MAX_QUALIFICATIONS); + const selectedFindings = boundedFindings(report.findings); + const requiredCapabilityIds = new Set(); + for (const entry of selectedQualifications) { + addReferences(requiredCapabilityIds, entry.capabilityIds); + } + for (const entry of selectedFindings) { + addReferences(requiredCapabilityIds, entry.capabilityIds); + } + const selectedCapabilities = boundedReferencedEntries( + report.capabilities, + requiredCapabilityIds, + MAX_CAPABILITIES, + "capability", + ); + const requiredEvidenceIds = new Set(); + for (const entry of selectedObservations) { + addReferences(requiredEvidenceIds, entry.evidenceIds); + } + for (const entry of selectedCapabilities) { + addReferences(requiredEvidenceIds, entry.evidenceIds); + } + for (const entry of selectedFindings) { + addReferences(requiredEvidenceIds, entry.evidenceIds); + } + const selectedEvidence = boundedReferencedEntries( + report.evidence, + requiredEvidenceIds, + MAX_EVIDENCE, + "evidence", + ); return { schemaVersion: report.schemaVersion, ...outcome, @@ -136,11 +202,11 @@ export function createPublicReadinessReport( : {}), observedAt: report.provenance.observedAt, }, - observations: report.observations.slice(0, 256).map(observation), - capabilities: report.capabilities.slice(0, 256).map(capability), - qualifications: report.qualifications.slice(0, 128).map(qualification), - findings: boundedFindings(report.findings), - evidence: report.evidence.slice(0, 256).map(evidence), + observations: selectedObservations.map(observation), + capabilities: selectedCapabilities.map(capability), + qualifications: selectedQualifications.map(qualification), + findings: selectedFindings.map(finding), + evidence: selectedEvidence.map(evidence), }; } From 858a040ee2fb3b8d37a3ac417171d15b018ecbe7 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Mon, 27 Jul 2026 21:20:26 -0400 Subject: [PATCH 31/33] docs(readiness): align host probe contract Signed-off-by: Julie Yaunches --- docs/reference/system-readiness.mdx | 4 ++-- src/commands/host/probe.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/reference/system-readiness.mdx b/docs/reference/system-readiness.mdx index 3581c89b426..5b681266690 100644 --- a/docs/reference/system-readiness.mdx +++ b/docs/reference/system-readiness.mdx @@ -28,7 +28,7 @@ $$nemoclaw host probe --json ``` Both presentations use the same structured report. -The JSON report includes its schema version, result, exit code, observations, capabilities, findings, evidence, and provenance. +The JSON report includes its `schemaVersion`, `status`, `exitCode`, `observations`, `capabilities`, `qualifications`, `findings`, `evidence`, and `provenance`. It also includes `mutated: false`. ## Interpret exit codes @@ -50,7 +50,7 @@ The `schemaVersion` field uses `major.minor.patch` format. Consumers must reject an unknown major version. Consumers can ignore fields that they do not recognize within major version 1. Use stable capability and finding IDs instead of parsing human summaries. -Treat bounded evidence as diagnostic context unless a capability or finding references its evidence ID. +Treat bounded evidence as diagnostic context unless an observation, capability, or finding references that evidence ID. ## Understand the read-only boundary diff --git a/src/commands/host/probe.test.ts b/src/commands/host/probe.test.ts index 08118733492..8fbe21cb582 100644 --- a/src/commands/host/probe.test.ts +++ b/src/commands/host/probe.test.ts @@ -103,7 +103,7 @@ describe("host probe command (#7412)", () => { } }); - it("runs before gateway or sandbox registration and uses one report for human output", async () => { + it("uses one readiness report for human output (#7412)", async () => { const publicReport = report(READINESS_OUTCOMES[0]); const log = vi.spyOn(console, "log").mockImplementation(() => undefined); mocks.createPublicReadinessReport.mockReturnValueOnce(publicReport); From 7e3b601fec49c12453ed4d22080a4213d57fd2c9 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Tue, 28 Jul 2026 08:08:42 -0400 Subject: [PATCH 32/33] fix(readiness): harden public report boundary --- src/lib/readiness/presentation.test.ts | 113 +++++++++++++++++++++++++ src/lib/readiness/presentation.ts | 78 +++++++++++++++-- 2 files changed, 185 insertions(+), 6 deletions(-) diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index edb3cc1d59c..2665575cfbd 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -134,6 +134,26 @@ describe("public readiness presentation (#7412)", () => { expect(String(publicReport.evidence[0]?.details?.stderr).length).toBeLessThanOrEqual(1024); }); + it("excludes camel-cased and suffixed process environment keys", () => { + const publicReport = createPublicReadinessReport( + report({ + evidence: [ + { + id: "host.probe.output", + summary: "Probe output", + details: { + processEnvironmentVariables: "HOME=/private/home PATH=/private/bin", + processEnvDumpV2: "USER=private-user", + stderr: "Docker is unavailable.", + }, + }, + ], + }), + ); + + expect(publicReport.evidence[0]?.details).toEqual({ stderr: "Docker is unavailable." }); + }); + it("retains a final required finding at the public boundary", () => { const warnings = Array.from({ length: 256 }, (_, index) => ({ id: `host.boundary.${index}`, @@ -209,4 +229,97 @@ describe("public readiness presentation (#7412)", () => { ), ).toThrow("Readiness report exceeds the public boundary for required findings."); }); + + it("fails closed when a finding exceeds its capability-reference boundary", () => { + const capabilities = Array.from({ length: 65 }, (_, index) => ({ + id: `host.capability.${index}`, + state: "present" as const, + })); + const blocker = { + id: "host.boundary.blocker", + severity: "blocking" as const, + summary: "A blocker with too many capability references.", + capabilityIds: capabilities.map(({ id }) => id), + }; + + expect(() => + createPublicReadinessReport( + report({ capabilities, findings: [blocker] }, { status: "incompatible", exitCode: 2 }), + ), + ).toThrow("Readiness report exceeds the public boundary for finding capability references."); + }); + + it("fails closed when an observation exceeds its evidence-reference boundary", () => { + const evidence = Array.from({ length: 33 }, (_, index) => ({ + id: `host.evidence.${index}`, + summary: `Evidence ${index}`, + })); + const observation = { + id: "host.observation", + state: "present" as const, + evidenceIds: evidence.map(({ id }) => id), + }; + + expect(() => + createPublicReadinessReport(report({ evidence, observations: [observation] })), + ).toThrow("Readiness report exceeds the public boundary for observation evidence references."); + }); + + it("fails closed when a retained reference array contains duplicate IDs", () => { + const evidence = [{ id: "host.evidence", summary: "Evidence" }]; + const observation = { + id: "host.observation", + state: "present" as const, + evidenceIds: [evidence[0].id, evidence[0].id], + }; + + expect(() => + createPublicReadinessReport(report({ evidence, observations: [observation] })), + ).toThrow("Readiness report contains duplicate observation evidence references."); + }); + + it("fails closed when required capability references exceed the collection boundary", () => { + const capabilities = Array.from({ length: 257 }, (_, index) => ({ + id: `host.capability.${index}`, + state: "present" as const, + })); + const blocker = { + id: "host.boundary.blocker", + severity: "blocking" as const, + summary: "A blocker with too many required capabilities.", + capabilityIds: capabilities.map(({ id }) => id), + }; + + expect(() => + createPublicReadinessReport( + report({ capabilities, findings: [blocker] }, { status: "incompatible", exitCode: 2 }), + ), + ).toThrow("Readiness report exceeds the public boundary for referenced capability entries."); + }); + + it("fails closed when a required capability reference does not resolve", () => { + const blocker = { + id: "host.boundary.blocker", + severity: "blocking" as const, + summary: "A blocker with a missing capability.", + capabilityIds: ["host.capability.missing"], + }; + + expect(() => + createPublicReadinessReport( + report({ findings: [blocker] }, { status: "incompatible", exitCode: 2 }), + ), + ).toThrow("Readiness report contains unresolved capability references."); + }); + + it("rejects conflicting capabilities that use the same stable ID", () => { + const capabilities = [ + { id: "host.capability", state: "present" as const }, + { id: "host.capability", state: "absent" as const }, + ]; + + expect(() => createPublicReadinessReport(report({ capabilities }))).toThrow( + "Readiness report contains duplicate capability IDs.", + ); + }); }); diff --git a/src/lib/readiness/presentation.ts b/src/lib/readiness/presentation.ts index fc5a80ee346..a1208a4dd66 100644 --- a/src/lib/readiness/presentation.ts +++ b/src/lib/readiness/presentation.ts @@ -19,6 +19,8 @@ const MAX_CAPABILITIES = 256; const MAX_QUALIFICATIONS = 128; const MAX_FINDINGS = 256; const MAX_EVIDENCE = 256; +const MAX_CAPABILITY_REFERENCES = 64; +const MAX_EVIDENCE_REFERENCES = 32; const SOURCE_REVISION_PATTERN = /^[0-9a-f]{40,64}$/; const ENVIRONMENT_DETAIL_KEYS = new Set([ "env", @@ -41,42 +43,87 @@ function scalar(value: EvidenceScalar): EvidenceScalar { } function isEnvironmentDetail(key: string): boolean { - const segments = key.split(/[._-]/).filter(Boolean); + const segments = key + .replace(/([a-z0-9])([A-Z])/g, "$1.$2") + .replace(/([A-Za-z])([0-9])/g, "$1.$2") + .replace(/([0-9])([A-Za-z])/g, "$1.$2") + .split(/[._-]/) + .filter(Boolean); return segments.some((segment) => ENVIRONMENT_DETAIL_KEYS.has(segment.toLowerCase())); } +function boundedReferences( + references: readonly string[] | undefined, + maxReferences: number, + referenceName: string, +): readonly string[] | undefined { + if (!references) return undefined; + if (references.length > maxReferences) { + throw new Error(`Readiness report exceeds the public boundary for ${referenceName}.`); + } + if (new Set(references).size !== references.length) { + throw new Error(`Readiness report contains duplicate ${referenceName}.`); + } + return [...references]; +} + function observation(entry: ReadinessObservation): ReadinessObservation { + const evidenceIds = boundedReferences( + entry.evidenceIds, + MAX_EVIDENCE_REFERENCES, + "observation evidence references", + ); return { id: entry.id, state: entry.state, ...(entry.value !== undefined ? { value: scalar(entry.value) } : {}), - ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + ...(evidenceIds ? { evidenceIds } : {}), }; } function capability(entry: ReadinessCapability): ReadinessCapability { + const evidenceIds = boundedReferences( + entry.evidenceIds, + MAX_EVIDENCE_REFERENCES, + "capability evidence references", + ); return { id: entry.id, state: entry.state, - ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + ...(evidenceIds ? { evidenceIds } : {}), }; } function qualification(entry: ReadinessQualification): ReadinessQualification { + const capabilityIds = boundedReferences( + entry.capabilityIds, + MAX_CAPABILITY_REFERENCES, + "qualification capability references", + ); return { id: entry.id, status: entry.status, - ...(entry.capabilityIds ? { capabilityIds: [...entry.capabilityIds] } : {}), + ...(capabilityIds ? { capabilityIds } : {}), }; } function finding(entry: ReadinessFinding): ReadinessFinding { + const capabilityIds = boundedReferences( + entry.capabilityIds, + MAX_CAPABILITY_REFERENCES, + "finding capability references", + ); + const evidenceIds = boundedReferences( + entry.evidenceIds, + MAX_EVIDENCE_REFERENCES, + "finding evidence references", + ); return { id: entry.id, severity: entry.severity, summary: bounded(entry.summary, MAX_SUMMARY_LENGTH), - ...(entry.capabilityIds ? { capabilityIds: [...entry.capabilityIds] } : {}), - ...(entry.evidenceIds ? { evidenceIds: [...entry.evidenceIds] } : {}), + ...(capabilityIds ? { capabilityIds } : {}), + ...(evidenceIds ? { evidenceIds } : {}), }; } @@ -100,6 +147,19 @@ function addReferences(target: Set, references: readonly string[] | unde for (const id of references ?? []) target.add(id); } +function assertUniqueIds( + entries: readonly T[], + entityName: string, +): void { + const ids = new Set(); + for (const entry of entries) { + if (ids.has(entry.id)) { + throw new Error(`Readiness report contains duplicate ${entityName} IDs.`); + } + ids.add(entry.id); + } +} + function boundedReferencedEntries( entries: readonly T[], requiredIds: ReadonlySet, @@ -152,6 +212,12 @@ export function createPublicReadinessReport( if (report.mutated !== false) { throw new Error("Readiness reports must be observation-only."); } + assertUniqueIds(report.observations, "observation"); + assertUniqueIds(report.capabilities, "capability"); + assertUniqueIds(report.qualifications, "qualification"); + assertUniqueIds(report.findings, "finding"); + assertUniqueIds(report.evidence, "evidence"); + // Keep these branches so TypeScript preserves the correlation between status and exitCode. const outcome = report.status === "supported" ? ({ status: report.status, exitCode: report.exitCode } as const) From 9d29ff5cf5e5ed4e9db319d4c705550d5420f9e5 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Tue, 28 Jul 2026 08:19:59 -0400 Subject: [PATCH 33/33] test(readiness): isolate reference boundary case --- src/lib/readiness/presentation.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/readiness/presentation.test.ts b/src/lib/readiness/presentation.test.ts index 2665575cfbd..bc56cd0af38 100644 --- a/src/lib/readiness/presentation.test.ts +++ b/src/lib/readiness/presentation.test.ts @@ -283,16 +283,16 @@ describe("public readiness presentation (#7412)", () => { id: `host.capability.${index}`, state: "present" as const, })); - const blocker = { - id: "host.boundary.blocker", + const blockers = Array.from({ length: 5 }, (_, index) => ({ + id: `host.boundary.blocker.${index}`, severity: "blocking" as const, - summary: "A blocker with too many required capabilities.", - capabilityIds: capabilities.map(({ id }) => id), - }; + summary: "A blocker with required capabilities.", + capabilityIds: capabilities.slice(index * 64, (index + 1) * 64).map(({ id }) => id), + })); expect(() => createPublicReadinessReport( - report({ capabilities, findings: [blocker] }, { status: "incompatible", exitCode: 2 }), + report({ capabilities, findings: blockers }, { status: "incompatible", exitCode: 2 }), ), ).toThrow("Readiness report exceeds the public boundary for referenced capability entries."); });