import assert from'node:assert/strict';import{readFileSync,writeFileSync,mkdirSync,mkdtempSync,copyFileSync}from'node:fs';import{spawnSync}from'node:child_process';import{createHash}from'node:crypto'; const d=mkdtempSync('reports/os-implementation/K2100-running-clock-preparation-'),art=p=>({path:p,sha256:createHash('sha256').update(readFileSync(p)).digest('hex')}); const input='scripts/os-acceptance/k2100-running-clock.mjs',tests='scripts/os-acceptance/k2100-running-clock-tests.mjs',before=[art(input),art(tests)],source=readFileSync(input,'utf8'),test=readFileSync(tests,'utf8');copyFileSync('/tmp/turkos-k2100-running-clock-preparation.mjs',d+'/harness.mjs.txt'); let status='RUNNING_CLOCK_PREPARATION_FAILED',error=null;const commands=[]; function run(name,text){const p=d+'/'+name;mkdirSync(p);writeFileSync(p+'/k2100-running-clock.mjs',text);writeFileSync(p+'/test.mjs',test);const r=spawnSync('node',[p+'/test.mjs'],{encoding:'utf8',timeout:10000});writeFileSync(p+'/test.log',(r.stdout??'')+(r.stderr??''));const v={name,exitCode:r.status,source:art(p+'/k2100-running-clock.mjs'),tests:art(p+'/test.mjs'),log:art(p+'/test.log')};commands.push(v);return v;} try{ assert.equal(run('source',source).exitCode,0); for(const[name,a,b]of[ ['paused-time-counts','runningMilliseconds >= K2100_MIN_RUNNING_MS','wallMilliseconds >= K2100_MIN_RUNNING_MS'], ['paused-snapshot-counts',"this.#phase === 'running' ? now - this.#started : 0","this.#phase === 'running' ? now - this.#started : now - this.#last"], ['clock-regression','now >= this.#last','true'], ['lost-segment','this.#elapsed = total;','this.#elapsed = 0;'], ['shortened-boundary','7_200_000','3_600_000'], ['synthetic-default','performance.now()','0'], ]){assert.equal(source.split(a).length,2,a);const r=run(name,source.replace(a,b));assert.equal(r.exitCode,1,name);assert.match(readFileSync(r.log.path,'utf8'),/AssertionError/,name);} assert.deepEqual([art(input),art(tests)],before);status='RUNNING_CLOCK_PREPARATION_PASSED'; }catch(e){error=e.stack;} writeFileSync(d+'/report.json',JSON.stringify({status,guestAccepted:false,productAccepted:false,scope:'Host utility and modeled boundary tests only. Real default monotonic clock smoke verifies that paused capture intervals do not increase running time. Full 7200 seconds and guest integration remain unperformed. Caller must pause before requesting QMP stop and resume only after confirmed running.',source:commands[0]?.source,tests:commands[0]?.tests,sourceMutantsRejected:commands.filter(r=>r.name!=='source'&&r.exitCode===1).length,commands,inputsBefore:before,inputsAfter:[art(input),art(tests)],harness:art(d+'/harness.mjs.txt'),error},null,2)+'\n');console.log(JSON.stringify({status,report:d+'/report.json',mutants:commands.length-1,error}));if(error)process.exitCode=1;