Files
ARCADIA-Studio/harness/experiments/runtime-notices-20260913/tools/rerun-runtime-notice-contract-20260913.py
T

20 lines
2.3 KiB
Python

from pathlib import Path
import hashlib,json,subprocess,datetime,time,os
R=Path(__file__).resolve().parent.parent;Q=R/'.local/runtime-notices-integration-20260913/module-isolated-r1';Q.mkdir()
def identity(p):
b=p.read_bytes();return {'path':str(p),'bytes':len(b),'sha256':hashlib.sha256(b).hexdigest()}
shell=Path(os.environ['SystemRoot'])/'System32/WindowsPowerShell/v1.0/powershell.exe'
module_root=shell.parent/'Modules';utility=module_root/'Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1'
assert utility.is_file()
test=R/'scripts/test-windows-notices.ps1';collector=R/'scripts/windows-notices.ps1';manifest=R/'scripts/windows-notices/manifest.json'
inputs=[identity(p) for p in [test,collector,manifest,utility]]
env=os.environ.copy();prior=env.get('PSModulePath');env['PSModulePath']=str(module_root)
wrapper=Q/'run.ps1'
wrapper.write_text("$ErrorActionPreference = 'Stop'\nImport-Module '"+str(utility)+"' -ErrorAction Stop\nWrite-Output ('PowerShell: ' + $PSVersionTable.PSVersion.ToString())\nWrite-Output ('Hash command: ' + (Get-Command Get-FileHash).Source)\n& '"+str(test)+"'\n",encoding='utf-8')
command=[str(shell),'-NoProfile','-ExecutionPolicy','Bypass','-File',str(wrapper)]
start=datetime.datetime.now(datetime.timezone.utc).isoformat();clock=time.monotonic()
with (Q/'stdout.log').open('xb') as out,(Q/'stderr.log').open('xb') as err:p=subprocess.run(command,cwd=R,env=env,stdout=out,stderr=err)
result={'start_utc':start,'end_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'elapsed_seconds':time.monotonic()-clock,'command':command,'exit':p.returncode,'diagnosed_correction':'Child-only PSModulePath restricted to Windows PowerShell5.1 built-in modules; explicitly import its Utility module, avoiding inherited PowerShell7 module selection. Same unchanged contract test. No machine/user env changes.','prior_PSModulePath':prior,'child_PSModulePath':env['PSModulePath'],'powershell':identity(shell),'wrapper':identity(wrapper),'inputs':inputs,'inputs_unchanged':inputs==[identity(x) for x in [test,collector,manifest,utility]],'stdout':identity(Q/'stdout.log'),'stderr':identity(Q/'stderr.log')}
with (Q/'result.json').open('x',encoding='utf-8') as f:json.dump(result,f,indent=2)
print(json.dumps(result,indent=2));assert result['inputs_unchanged'];assert p.returncode==0;assert b'PASS:' in (Q/'stdout.log').read_bytes()