import assert from 'node:assert/strict'; import {readFileSync, writeFileSync, copyFileSync, mkdtempSync} from 'node:fs'; import {createHash} from 'node:crypto'; import {join, resolve} from 'node:path'; import {fileURLToPath} from 'node:url'; import {frozenSnapshot} from './boot-contract-report.mjs'; // Admit only the four local engineering steps. Long guest admission is separate. assert.equal(process.argv.length, 6, 'pass candidate, host preparation, native index and wake refusal proof'); const [candidatePath, preparationPath, indexPath, wakePath] = process.argv.slice(2); const directory = mkdtempSync('reports/os-implementation/K2100-smp-workload-local-'); copyFileSync(fileURLToPath(import.meta.url), join(directory, 'harness.mjs.txt')); const root = process.cwd(); const artifact = path => ({path, sha256: createHash('sha256').update(readFileSync(path)).digest('hex')}); const read = path => JSON.parse(readFileSync(path)); const verified = new Map(); function checked(a) { assert.ok(resolve(a.path).startsWith(root + '/'), 'artifact belongs to workspace'); if (!verified.has(a.path)) verified.set(a.path, artifact(a.path).sha256); assert.equal(verified.get(a.path), a.sha256, a.path); return readFileSync(a.path); } function verifyNested(value) { if (!value || typeof value !== 'object') return; if (typeof value.path === 'string' && typeof value.sha256 === 'string') checked(value); for (const child of Object.values(value)) verifyNested(child); } try { const frozenBefore = frozenSnapshot(root); const predecessorPath = 'reports/os-implementation/K2095-cpu-watchdog-readiness.json'; const predecessor = read(predecessorPath); assert.equal(predecessor.status, 'ACCEPTED_AND_PRODUCTION_PUBLISHED'); assert.equal(read(predecessor.publication).status, 'PUBLISHED_AND_PRODUCTION_VERIFIED'); const candidate = read(candidatePath), preparation = read(preparationPath); const index = read(indexPath), wake = read(wakePath); assert.equal(candidate.status, 'COMPILED_K2100_DURATION_LONG_CANDIDATE'); assert.equal(preparation.status, 'STAGING_LOCAL_PASSED'); assert.equal(preparation.tests, 17); assert.equal(preparation.mutationsRejected, 44); assert.equal(preparation.mutants.length, 44); assert.equal(preparation.commands.length, 46); assert.deepEqual(preparation.frozenBefore, preparation.frozenAfter); assert.deepEqual(preparation.frozenBefore, frozenBefore); verifyNested(preparation); verifyNested(candidate.artifacts); const preflight = JSON.parse(checked(candidate.preflight)); assert.equal(preflight.status, 'NATIVE_MODELS_COMPILED'); assert.equal(preflight.exitCode, 0); assert.deepEqual(preflight.artifacts.image, candidate.artifacts.image); assert.equal(candidate.imageSpan.bytes, checked(candidate.artifacts.image).length); assert.ok(candidate.imageSpan.bytes <= 8 * 1024 * 1024); for (const [i, command] of preparation.commands.entries()) { const text = checked(command.log).toString(); assert.equal(command.exitCode, i < 2 ? 0 : 101); assert.doesNotMatch(text, /error\[E\d+\]|could not compile/); if (i === 0) assert.match(text, /17 passed; 0 failed; 0 ignored/); if (i >= 2) assert.match(text, /test os_smp_workload_\w+ \.\.\. FAILED/); } const model = preparation.sources.find(a => a.path.endsWith('/src/workload.rs')); const contract = preparation.sources.find(a => a.path.endsWith('/kernel/SMP_WORKLOAD_CONTRACT.md')); assert.ok(model && contract); const nativeModel = artifact(join(candidate.sourceDirectory, 'kernel/src/runtime/smp_workload.rs')); assert.equal(nativeModel.sha256, model.sha256, 'tested Rust model is the compiled model'); assert.equal(artifact('kernel/SMP_WORKLOAD_CONTRACT.md').sha256, contract.sha256); assert.equal(index.status, 'COMPILED_AND_SHORT_PHYSICAL_COMPONENT_INDEX_VERIFIED'); assert.deepEqual(index.image, candidate.artifacts.image); assert.deepEqual(index.preflight, candidate.preflight); assert.equal(Object.keys(index.components).length, 8); assert.equal(index.hostPredicateCases, 3915); assert.equal(index.actualInstructionMutantsRejected, 8); assert.equal(index.shortPhysicalBadRecordsRejected, 58); verifyNested(index); for (const component of Object.values(index.components)) { const report = JSON.parse(checked(component.report)); assert.equal(report.status, component.status); assert.equal(report.guestAccepted, false); assert.equal(report.productAccepted, false); assert.deepEqual(report.image, candidate.artifacts.image); verifyNested(report); } const correction = JSON.parse(checked(index.hostControlCorrection)); assert.equal(correction.status, 'SINGLE_CPU_HOST_CONTROLS_CORRECTED_AND_TESTED'); verifyNested(correction); assert.equal(wake.status, 'NATIVE_WAKE_EARLY_REFUSAL_COMPONENT_PASSED'); assert.equal(wake.cases, 158); assert.deepEqual(wake.coverage, {selectedInstructions: 39, visitedInstructions: 39, entireFunctionInstructions: 432}); assert.deepEqual(wake.image, candidate.artifacts.image); assert.deepEqual(wake.preflight, candidate.preflight); verifyNested(wake); for (const report of [candidate, preparation, index, wake]) { assert.equal(report.guestAccepted, false); assert.equal(report.productAccepted, false); } const short = JSON.parse(checked(candidate.shortComponent)); assert.equal(short.status, 'DURATION_COMPONENT_GUEST_RETURNED'); assert.deepEqual(short.sourceBefore, short.sourceAfter); const librarySources = short.sourceBefore; assert.ok(librarySources.length > 0); for (const a of librarySources) { assert.ok(a.path.startsWith(candidate.sourceDirectory + '/')); checked(a); } const frozenAfter = frozenSnapshot(root); assert.deepEqual(frozenAfter, frozenBefore); const report = { schema: 'turkos-k2100-smp-workload-local/v1', status: 'K2096_K2099_LOCAL_VALIDATED', guestAccepted: false, productAccepted: false, scope: 'Local validation of the combined SMP contract, actual Rust ownership implementation, positive/boundary host tests and rejection/transaction controls. The tested Monitor source is byte-identical to the compiled model. Eight compiled/short-physical components and the bounded wake-token return path retain their documented scopes. This report does not admit K2100: all eighteen measured long CPU/RAM/boot profiles and consolidated native/physical acceptance remain required.', predecessor: artifact(predecessorPath), predecessorPublication: artifact(predecessor.publication), candidate: artifact(candidatePath), preparation: artifact(preparationPath), nativeIndex: artifact(indexPath), wakeRefusal: artifact(wakePath), image: candidate.artifacts.image, sources: {contract, model, nativeModel}, librarySources, commands: preparation.commands, mutants: preparation.mutants, tests: {hostTests: 17, sourceMutantsRejected: 44, compiledPredicateCases: 4073, compiledInstructionMutantsRejected: 8, shortPhysicalBadRecordsRejected: 58, nativeWakeSelectedInstructions: 39}, checkedArtifacts: verified.size, frozenBefore, frozenAfter, harness: artifact(join(directory, 'harness.mjs.txt')), }; const path = join(directory, 'report.json'); writeFileSync(path, JSON.stringify(report, null, 2) + '\n'); console.log(JSON.stringify({status: report.status, report: path, checkedArtifacts: verified.size, tests: report.tests})); } catch (error) { const path = join(directory, 'report.json'); writeFileSync(path, JSON.stringify({status: 'SMP_WORKLOAD_LOCAL_REVIEW_FAILED', guestAccepted: false, productAccepted: false, error: error.stack, harness: artifact(join(directory, 'harness.mjs.txt'))}, null, 2) + '\n'); console.error(path); throw error; }