import assert from 'node:assert/strict'; import {readFileSync, writeFileSync, existsSync, mkdtempSync, copyFileSync, statfsSync, renameSync} from 'node:fs'; import {spawn} from 'node:child_process'; import {createHash} from 'node:crypto'; import {join, resolve, relative} from 'node:path'; import {fileURLToPath} from 'node:url'; import {setTimeout as delay} from 'node:timers/promises'; // Sequential, source-bound collection of the eighteen requested components. // This never accepts K2100 or changes the numeric roadmap. It stops on the // first guest/proof/source failure and preserves all completed evidence. const [candidatePath, resumePath] = process.argv.slice(2); assert.ok(candidatePath && resumePath, 'candidate and stopped sequence report are required'); const read = path => JSON.parse(readFileSync(path)); const artifact = path => ({path, sha256: createHash('sha256').update(readFileSync(path)).digest('hex')}); const check = a => {assert.equal(artifact(a.path).sha256, a.sha256, a.path); return read(a.path);}; const directory = mkdtempSync('reports/os-implementation/K2100-long-profile-sequence-'); copyFileSync(fileURLToPath(import.meta.url), join(directory, 'harness.mjs.txt')); const statePath = 'reports/os-implementation/active-development-continuation.json'; const candidate = read(candidatePath), candidateArtifact = artifact(candidatePath); assert.equal(candidate.status, 'COMPILED_K2100_DURATION_LONG_CANDIDATE'); const pins = [candidateArtifact, ...Object.values(candidate.artifacts), ...[ '/tmp/turkos-k2100-duration-continuous-clock-v2-smoke.mjs', 'scripts/os-acceptance/.k2100-duration-long-continuous-clock-generated.mjs', 'scripts/os-acceptance/k2100-host-continuity-v2.mjs', 'scripts/os-acceptance/k2100-continuous-clock.c', "/reports/os-implementation/K2100-continuous-clock-recovery-s0uvw0ef/continuous-clock", 'scripts/os-acceptance/k2100-duration-long-capture.mjs', 'scripts/os-acceptance/k2100-duration-capture.mjs', 'scripts/os-acceptance/k2100-profile-capture.mjs', 'scripts/os-acceptance/k2100-running-clock.mjs', 'scripts/os-acceptance/k2100-duration-window-check.mjs', 'scripts/os-acceptance/k2100-duration-window-proof.mjs', 'scripts/os-acceptance/k2100-duration-provenance-proof.mjs', 'scripts/os-acceptance/k2100-duration-service-replay.mjs', 'scripts/os-acceptance/k2100-completed-profile-dedup.py', ].map(artifact)]; const profiles = []; for (const route of ['direct', 'uefi']) for (const memoryMiB of [256, 512, 1024]) for (const cpuCount of [4, 2, 1]) profiles.push({cpuCount, memoryMiB, route, id: `${route}-${memoryMiB}-cpu-${cpuCount}`}); assert.equal(profiles.length, 18); const resume = read(resumePath); assert.equal(resume.status, 'LONG_WORKLOAD_PROFILE_SEQUENCE_FAILED'); assert.deepEqual(resume.candidate, candidateArtifact); assert.deepEqual(resume.sameImage, candidate.artifacts.image); assert.ok(resume.completed.length > 0 && resume.completed.length < 18); for (const a of resume.pins) assert.deepEqual(artifact(a.path), a); assert.deepEqual(resume.requestedProfiles, profiles); const completed = structuredClone(resume.completed); let active = null; for (const [i, entry] of completed.entries()) { assert.deepEqual(entry.profile, profiles[i]); assert.deepEqual(artifact(entry.review.path), entry.review); assert.deepEqual(artifact(entry.proof.path), entry.proof); const validated = validateCompletedEvidence(entry.profile, entry.review.path, entry.proof.path); for (const [key, value] of Object.entries(validated)) assert.deepEqual(entry[key], value); assert.equal(check(entry.publication).status, 'PUBLISHED_AND_PRODUCTION_VERIFIED'); } const seedCount = completed.length; const resumedFrom = artifact(resumePath); writeFileSync('/tmp/turkos-k2100-long-profile-sequence.txt', directory); let pipeline = 'PROFILE_COLLECTION_ACTIVE'; function atomic(path, value) {writeFileSync(path + '.resume-tmp', JSON.stringify(value, null, 2) + '\n'); renameSync(path + '.resume-tmp', path);} function verifyPins() {for (const a of pins) assert.equal(artifact(a.path).sha256, a.sha256, 'source frozen: ' + a.path);} function save(extra = {}) { const report = {schema: 'turkos-k2100-long-profile-sequence/v1', status: pipeline, updatedAt: new Date().toISOString(), guestAccepted: false, productAccepted: false, scope: 'Sequential source-bound two-hour profile components. Each must pass raw-memory/protocol/service replay checks before another starts. Complete milestone native proof and roadmap admission remain separate.', candidate: candidateArtifact, sameImage: candidate.artifacts.image, pins, requestedProfiles: profiles, completed, active, resumedFrom, retainedCompletedProfiles: seedCount, ...extra}; atomic(join(directory, 'progress.json'), report); const state = read(statePath); state.K2100.longProfileSequence = join(directory, 'progress.json'); state.K2100.longProfilesCompleted = completed.length; state.K2100.longProfileSequenceStatus = pipeline; state.updatedAt = report.updatedAt; atomic(statePath, state); return report; } async function command(executable, args, env, log) { const child = spawn(executable, args, {env: {...process.env, ...env}, stdio: ['ignore', 'pipe', 'pipe']}); let output = ''; for (const stream of [child.stdout, child.stderr]) stream.on('data', chunk => {output += chunk; writeFileSync(log, output);}); const exitCode = await new Promise((done, fail) => {child.once('error', fail); child.once('exit', done);}); assert.equal(exitCode, 0, 'see preserved command log: ' + log); return output; } function validateCompletedEvidence(profile, reviewPath, proofPath) { const review = read(reviewPath), physical = check(review.physical), proof = read(proofPath); assert.equal(review.status, 'LONG_WORKLOAD_GUEST_RETURNED'); for (const key of ['cpuCount', 'memoryMiB', 'route']) assert.equal(review[key], profile[key]); assert.deepEqual(review.candidate, candidateArtifact); const life = check(review.lifecycle); assert.equal(life.status, 'RUNNER_PASSED'); assert.equal(life.allOwnedGuestsStopped, true); assert.equal(proof.status, 'DURATION_WINDOW_PHYSICAL_COMPONENT_PASSED'); assert.equal(proof.longInput, true); assert.deepEqual(proof.image, candidate.artifacts.image); assert.ok(physical.workloadMeasurement.durationMet && physical.workloadMeasurement.runningMilliseconds >= 7200000); assert.ok(proof.guestElapsedSeconds >= 7200); return {profile, review: artifact(reviewPath), proof: artifact(proofPath), matrix: relative('.', resolve(review.lifecycle.path, '..')), hostRunningMilliseconds: physical.workloadMeasurement.runningMilliseconds, guestElapsedSeconds: proof.guestElapsedSeconds, windows: physical.windowCheckpoints.length, actualRequests: profile.cpuCount * physical.windowCheckpoints.length, actualReplies: 2 * profile.cpuCount * physical.windowCheckpoints.length}; } try { verifyPins(); const adopted = save(); const seedSnapshot = join(directory, 'completed-' + completed.length + '.json'); atomic(seedSnapshot, {...adopted, status: 'LONG_WORKLOAD_PROFILE_PROGRESS_PASSED', completeMatrix: false}); writeFileSync('/tmp/turkos-k2100-long-profile-progress.txt', seedSnapshot); console.log('SEQUENCE-DIRECTORY ' + directory); for (const [index, profile] of profiles.entries()) { if (index < seedCount) continue; verifyPins(); active = {...profile, matrix: null}; save(); let reviewPath; { const space = statfsSync('.'); assert.ok(space.bavail * space.bsize > 1.5 * 1024 ** 3, 'insufficient free space for next preserved profile'); // The wrapper independently requires that no QEMU remains alive and // checks the accepted predecessor and source hashes before booting. await command('node', ['/tmp/turkos-k2100-duration-continuous-clock-v2-smoke.mjs'], { TURKOS_K2100_CPUS: String(profile.cpuCount), TURKOS_K2100_RAM: String(profile.memoryMiB), TURKOS_K2100_ROUTE: profile.route, }, join(directory, profile.id + '-guest.log')); reviewPath = read(statePath).K2100.durationLongReview; } verifyPins(); const output = await command('node', ['scripts/os-acceptance/k2100-duration-window-check.mjs', reviewPath], {}, join(directory, profile.id + '-proof.log')); const terminal = JSON.parse(output.trim().split('\n').at(-1)); assert.equal(terminal.status, 'DURATION_WINDOW_PHYSICAL_COMPONENT_PASSED'); const entry = validateCompletedEvidence(profile, reviewPath, terminal.report); const dedupOutput = await command('python3', ['scripts/os-acceptance/k2100-completed-profile-dedup.py', entry.matrix], {}, join(directory, profile.id + '-storage.log')); const dedup = JSON.parse(dedupOutput.trim().split('\n').at(-1)); assert.equal(dedup.status, 'IMMUTABLE_EVIDENCE_DEDUPLICATED_AND_VERIFIED'); entry.storage = artifact(dedup.report); completed.push(entry); active = null; const progress = save(); const completedPath = join(directory, 'completed-' + completed.length + '.json'); writeFileSync(completedPath, JSON.stringify({...progress, status: 'LONG_WORKLOAD_PROFILE_PROGRESS_PASSED', completeMatrix: completed.length === profiles.length, active: null}, null, 2) + '\n'); writeFileSync('/tmp/turkos-k2100-long-profile-progress.txt', completedPath); console.log(JSON.stringify({completedProfiles: completed.length, profile: profile.id, review: reviewPath, proof: terminal.report})); // Publish only the completed, validated subset. The K2100 acceptance count // remains unchanged even when all eighteen component runs have returned. let publication; for (let attempt = 1; attempt <= 3; attempt++) { for (const deadline = Date.now() + 1800000; existsSync('reports/site-publication/publish.lock');) { assert.ok(Date.now() < deadline, 'publication lock deadline'); await delay(5000); } try { await command('python3', ['/tmp/turkos-k2100-site-experiments.py'], {}, join(directory, profile.id + '-registry-' + attempt + '.log')); const output = await command('node', ['scripts/publish-development-site.mjs', '--deploy'], {}, join(directory, profile.id + '-publication-' + attempt + '.log')); const match = output.match(/SITE REPORT (.+)/); assert.ok(match); const reportPath = relative('.', resolve(match[1].trim())), report = read(reportPath); assert.equal(report.status, 'PUBLISHED_AND_PRODUCTION_VERIFIED'); publication = artifact(reportPath); break; } catch (error) { writeFileSync(join(directory, profile.id + '-publication-error-' + attempt + '.txt'), error.stack + '\n'); if (attempt === 3) throw error; await delay(30000); } } entry.publication = publication; save(); const published = read(publication.path), registry = read('scripts/os-development-experiments.json'), state = read(statePath); state.site = {...state.site, report: publication.path, status: published.status, reports: published.progress.evidenceReports, downloads: published.progress.textDownloads, preparationAndComponentReports: published.progress.experimentReports, preparationDownloads: registry.reduce((n, row) => n + row.files.length, 0)}; state.K2100.componentPublication = publication.path; state.updatedAt = new Date().toISOString(); atomic(statePath, state); } pipeline = 'LONG_WORKLOAD_PROFILE_COMPONENTS_PASSED'; active = null; const report = save(); writeFileSync(join(directory, 'report.json'), JSON.stringify(report, null, 2) + '\n'); console.log(JSON.stringify({status: pipeline, completedProfiles: completed.length, report: join(directory, 'report.json')})); } catch (error) { pipeline = 'LONG_WORKLOAD_PROFILE_SEQUENCE_FAILED'; const report = save({error: error.stack}); writeFileSync(join(directory, 'report.json'), JSON.stringify(report, null, 2) + '\n'); console.error(error.stack); process.exitCode = 1; }