"""Publish the eventual native DMA component outcome. Watches only the explicitly supplied owned queue; no VM is started here. """ from pathlib import Path import datetime,hashlib,json,os,re,shutil,subprocess,sys,tempfile,time root=Path.cwd().resolve();queue=Path(sys.argv[1]);out=Path(tempfile.mkdtemp(prefix='K2155-dma-publication-watch-',dir=root/'reports/os-implementation')) def read(p):return json.loads(Path(p).read_bytes()) def art(p): p=Path(p);return dict(path=str(p.relative_to(root)) if p.is_absolute() else str(p),sha256=hashlib.sha256(p.read_bytes()).hexdigest()) def save(status,**fields): report.update(status=status,**fields);p=out/'report.json';temp=p.with_suffix('.tmp');temp.write_text(json.dumps(report,indent=2)+'\n');temp.replace(p) def run(name,args): with (out/(name+'.log')).open('w')as log:r=subprocess.run(args,stdout=log,stderr=subprocess.STDOUT) assert r.returncode==0,name+' failed; see '+str(out/(name+'.log')) return (out/(name+'.log')).read_text() report=dict(status='DMA_PUBLICATION_WAITING',guestAccepted=False,productAccepted=False,pid=os.getpid(),queuePath=str(queue)) try: shutil.copyfile(__file__,out/'harness.py.txt');save('DMA_PUBLICATION_WAITING') while True: r=read(queue) if r['status'] in ['DMA_COMPONENT_COMPLETED','DMA_COMPONENT_FAILED','DMA_COMPONENT_QUEUE_FAILED']:break time.sleep(30) files=[queue];execution_ref=r.get('execution');execution=read(execution_ref['path']) if execution_ref else None if execution: assert art(execution_ref['path'])==execution_ref;files.append(execution_ref['path']) for step in execution['steps']: files.append(step['log']['path']) if 'proof'in step:files.append(step['proof']['path']) # Include failed matrix evidence too: the runner prints its owned directory # before any guest starts, including when the command later fails. log=Path(step['log']['path']).read_text() for matrix in re.findall(r'^MATRIX-DIRECTORY (reports/os-implementation/K2155-shutdown-dma-component-matrix-[A-Za-z0-9]+)$',log,re.M): life=Path(matrix)/'scoped-lifecycle.json' if life.exists(): files.append(life) for profile in read(life).get('profiles',[]): files.append(Path(matrix)/profile['profile']['id']/'result.json');files.append(profile['serial']['path']) summary=dict(status='DMA_COMPONENT_PASSED' if r['status']=='DMA_COMPONENT_COMPLETED' else 'DMA_COMPONENT_FAILED', guestAccepted=False,productAccepted=False,physicalDmaVerified=r.get('physicalDmaVerified',False),queue=art(queue),files=[art(p)for p in files], scope='Native twelve-page disk/network DMA component only; no IRQ, worker or EL0 integration and no full K2155 acceptance. Failed outcomes remain failed.') summary_path=out/'component-summary.json';summary_path.write_text(json.dumps(summary,indent=2)+'\n');Path('/tmp/turkos-k2155-dma-result.txt').write_text(str(summary_path.relative_to(root))+'\n') save('DMA_PUBLICATION_READY',componentSummary=art(summary_path)) while (root/'reports/site-publication/publish.lock').exists():time.sleep(15) run('registry',['python3','/tmp/turkos-k2100-site-experiments.py']) text=run('publication',['node','scripts/publish-development-site.mjs','--deploy']) match=re.search(r'SITE REPORT (.+)',text);assert match publication=Path(match[1].strip());p=read(publication);assert p['status']=='PUBLISHED_AND_PRODUCTION_VERIFIED' and p['productionVerified'] is True state_path=root/'reports/os-implementation/active-development-continuation.json';state=read(state_path) state['K2155']['dmaComponentPublication']=str(publication.relative_to(root));state['K2155']['dmaComponentPublicationVerified']=True state['site'].update(report=str(publication.relative_to(root)),status=p['status'],reports=p['progress']['evidenceReports'],downloads=p['progress']['textDownloads'],preparationAndComponentReports=p['progress']['experimentReports']) ledger=read(root/'reports/os-implementation/supplement-progress.json');state['supplement'].update(counts=ledger['counts'],publishedCounts=p['supplement']['counts']) if ledger['counts']==p['supplement']['counts']:state['supplement']['pendingPublicationMoves']=[] state['updatedAt']=datetime.datetime.now(datetime.timezone.utc).isoformat();tmp=state_path.with_suffix('.dma-publish');tmp.write_text(json.dumps(state,indent=2)+'\n');tmp.replace(state_path) save('DMA_COMPONENT_PRODUCTION_PUBLISHED',publication=art(publication)) except BaseException: import traceback save('DMA_PUBLICATION_FAILED',error=traceback.format_exc());raise finally:print(json.dumps({'status':report['status'],'report':str((out/'report.json').relative_to(root))}),flush=True)