import assert from 'node:assert/strict'; import {readFileSync, writeFileSync, existsSync, copyFileSync, mkdtempSync, renameSync} from 'node:fs'; import {createHash} from 'node:crypto'; import {spawn} from 'node:child_process'; import {join, relative} from 'node:path'; import {fileURLToPath} from 'node:url'; import {setTimeout as delay} from 'node:timers/promises'; assert.equal(process.argv.length, 6, 'pass profile sequence, local report, native stack report and closure seed list'); const [sequencePath, localPath, stackPath, seedPath] = process.argv.slice(2); const read = p => JSON.parse(readFileSync(p)); const artifact = path => ({path, sha256: createHash('sha256').update(readFileSync(path)).digest('hex')}); const directory = mkdtempSync('reports/os-implementation/K2100-acceptance-sequence-'); copyFileSync(fileURLToPath(import.meta.url), join(directory, 'harness.mjs.txt')); const local = read(localPath), nativeStack = read(stackPath), initial = read(sequencePath); assert.equal(local.status, 'K2096_K2099_LOCAL_VALIDATED'); assert.equal(nativeStack.status, 'NATIVE_STACK_RELEASE_COMPONENT_PASSED'); assert.deepEqual(initial.sameImage, local.image); assert.deepEqual(nativeStack.image, local.image); const pins = [localPath, stackPath, seedPath, ...[ 'k2100-profile-closure-check.mjs', 'k2100-profile-closure-proof.mjs', 'k2100-duration-window-proof.mjs', 'smp-workload-matrix-check.mjs', 'smp-workload-guest-progress-update.mjs', 'k2100-progress-reconcile.mjs', ].map(p => 'scripts/os-acceptance/' + p)].map(artifact); const verifyPins = () => {for (const a of pins) assert.deepEqual(artifact(a.path), a);}; const statePath = 'reports/os-implementation/active-development-continuation.json'; const seeds = read(seedPath), completed = []; let status = 'PROFILE_CLOSURE_COLLECTION_ACTIVE'; function atomic(path, value) {writeFileSync(path + '.tmp', JSON.stringify(value, null, 2) + '\n'); renameSync(path + '.tmp', path);} function save(extra = {}) { const progress = {status, guestAccepted: false, productAccepted: false, image: local.image, scope: 'Independent closure checks of already stopped long profiles. The collection alone never accepts K2100.', pins, sequencePath, completed, ...extra}; atomic(join(directory, 'closure-progress.json'), progress); const state = read(statePath); state.K2100.acceptanceSequence = join(directory, 'closure-progress.json'); state.K2100.closureProfilesCompleted = completed.length; state.updatedAt = new Date().toISOString(); atomic(statePath, state); } async function command(executable, args, log) { const child = spawn(executable, args, {stdio: ['ignore', 'pipe', 'pipe']}); let output = ''; for (const stream of [child.stdout, child.stderr]) stream.on('data', bytes => {output += bytes; writeFileSync(log, output);}); const code = await new Promise((done, fail) => {child.once('error', fail); child.once('exit', done);}); assert.equal(code, 0, 'preserved log: ' + log); return output; } const lastJson = output => JSON.parse(output.trim().split('\n').at(-1)); try { verifyPins(); save(); console.log('ACCEPTANCE-SEQUENCE ' + directory); while (true) { verifyPins(); const sequence = read(sequencePath); assert.ok(['PROFILE_COLLECTION_ACTIVE', 'LONG_WORKLOAD_PROFILE_COMPONENTS_PASSED'].includes(sequence.status), sequence.status); assert.deepEqual(sequence.sameImage, local.image); assert.deepEqual(sequence.candidate, local.candidate); assert.ok(sequence.completed.length <= 18); for (const entry of sequence.completed) { if (completed.some(c => c.id === entry.profile.id)) continue; // The duration coordinator may still be publishing this entry. Closure // reads stopped evidence only, and does not depend on that publication. assert.deepEqual(artifact(entry.review.path), entry.review); assert.deepEqual(artifact(entry.proof.path), entry.proof); let reportPath = seeds.find(p => read(p).proof.path === entry.proof.path); if (!reportPath) { const result = lastJson(await command('node', ['scripts/os-acceptance/k2100-profile-closure-check.mjs', entry.proof.path], join(directory, entry.profile.id + '-closure.log'))); assert.equal(result.status, 'PROFILE_CLOSURE_PHYSICAL_COMPONENT_PASSED'); reportPath = result.report; } const report = read(reportPath); assert.equal(report.status, 'PROFILE_CLOSURE_PHYSICAL_COMPONENT_PASSED'); assert.deepEqual(report.image, local.image); assert.deepEqual(report.proof, entry.proof); assert.deepEqual(report.review, entry.review); assert.equal(`${report.route}-${report.memoryMiB}-cpu-${report.cpuCount}`, entry.profile.id); assert.equal(report.guestAccepted, false); assert.equal(report.productAccepted, false); completed.push({id: entry.profile.id, report: artifact(reportPath)}); save(); const snapshot = join(directory, 'closure-completed-' + completed.length + '.json'); atomic(snapshot, {...read(join(directory, 'closure-progress.json')), status: 'PROFILE_CLOSURE_PROGRESS_PASSED'}); writeFileSync('/tmp/turkos-k2100-profile-closure-progress.txt', snapshot + '\n'); console.log(JSON.stringify({closedProfiles: completed.length, profile: entry.profile.id, report: reportPath})); } if (sequence.status === 'LONG_WORKLOAD_PROFILE_COMPONENTS_PASSED') {assert.equal(completed.length, 18); break;} await delay(30000); } status = 'PROFILE_CLOSURE_COLLECTION_PASSED'; save(); const collectionPath = join(directory, 'closure-collection.json'); atomic(collectionPath, read(join(directory, 'closure-progress.json'))); let matrixPath; for (const deadline = Date.now() + 3600000; !matrixPath;) { verifyPins(); const k = read(statePath).K2100; if (k.longMatrixIndependentlyVerified) { matrixPath = k.longMatrixProof; const matrix = read(matrixPath); assert.equal(matrix.status, 'LONG_PROFILE_MATRIX_COMPONENT_PASSED'); assert.equal(matrix.sequence.path, sequencePath); assert.deepEqual(artifact(sequencePath), matrix.sequence); } else {assert.ok(Date.now() < deadline, 'long matrix validator did not complete'); await delay(30000);} } verifyPins(); const accepted = lastJson(await command('node', ['scripts/os-acceptance/smp-workload-matrix-check.mjs', localPath, matrixPath, collectionPath, stackPath], join(directory, 'consolidated-matrix.log'))); assert.equal(accepted.status, 'K2100_SMP_WORKLOAD_DEVELOPMENT_MATRIX_VALIDATED'); const update = lastJson(await command('node', ['scripts/os-acceptance/smp-workload-guest-progress-update.mjs', accepted.report], join(directory, 'guest-progress.log'))); assert.equal(update.status, 'K2100_DEVELOPMENT_PROGRESS_RECONCILED'); let publication; for (let attempt = 1; attempt <= 3 && !publication; 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, 'registry-' + attempt + '.log')); const output = await command('node', ['scripts/publish-development-site.mjs', '--deploy'], join(directory, 'publication-' + attempt + '.log')); const match = output.match(/SITE REPORT (.+)/); assert.ok(match); publication = relative('.', match[1].trim()); const published = read(publication); assert.equal(published.status, 'PUBLISHED_AND_PRODUCTION_VERIFIED'); assert.equal(published.productionVerified, true); const current = read('reports/os-implementation/progress.json'); assert.equal(current.moves.find(m => m.id === 'K2100').status, 'DEVELOPMENT_GUEST_ACCEPTED'); assert.deepEqual(current.moves.find(m => m.id === 'K2100').evidence, artifact(accepted.report)); assert.equal(published.progress.lastAcceptedGuest, current.lastAcceptedGuest); assert.equal(published.progress.nextImplementation, current.nextImplementation); } catch (error) {publication = undefined; if (attempt === 3) throw error; await delay(10000);} } const readinessPath = 'reports/os-implementation/K2100-smp-workload-readiness.json'; const acceptedMatrix = read(accepted.report); atomic(readinessPath, {schema: 'turkos-development-readiness/v1', status: 'ACCEPTED_AND_PRODUCTION_PUBLISHED', milestone: 'K2100', matrixCheck: accepted.report, publication, profiles: 18, minimumHostRunningMilliseconds: acceptedMatrix.minimumHostRunningMilliseconds, minimumGuestElapsedSeconds: acceptedMatrix.minimumGuestElapsedSeconds, independentReviewAccepted: false, productAccepted: false, next: 'K2105'}); const state = read(statePath), published = read(publication); Object.assign(state.K2100, {status: 'ACCEPTED_AND_PRODUCTION_PUBLISHED', readiness: readinessPath, matrixCheck: accepted.report, publication, guestAccepted: true, productAccepted: false}); Object.assign(state.site, {report: publication, status: published.status, snapshotLastAccepted: published.progress.lastAcceptedGuest, snapshotNext: published.progress.nextImplementation, reports: published.progress.evidenceReports, downloads: published.progress.textDownloads, preparationAndComponentReports: published.progress.experimentReports}); state.updatedAt = new Date().toISOString(); atomic(statePath, state); atomic(join(directory, 'report.json'), {status: 'K2100_ACCEPTED_AND_PRODUCTION_PUBLISHED', guestAccepted: true, productAccepted: false, matrix: artifact(accepted.report), progress: artifact(update.report), publication: artifact(publication), readiness: artifact(readinessPath), pins}); console.log(JSON.stringify({status: 'K2100_ACCEPTED_AND_PRODUCTION_PUBLISHED', readiness: readinessPath, next: published.progress.nextImplementation})); } catch (error) { atomic(join(directory, 'failure.json'), {status: 'K2100_ACCEPTANCE_SEQUENCE_FAILED', guestAccepted: false, productAccepted: false, error: error.stack, completed, pins}); console.error(directory); throw error; }