#!/usr/bin/env python3 """Freeze only the bounded initialization lock fix; no target operations.""" import json import os from pathlib import Path import shutil import uuid import linux_updater_qualification as q ROOT=Path(__file__).resolve().parents[1] BASE=ROOT/'devstate/linux-updater-capability-build/9923a97f-4c8c-4e0a-bbad-4f1d88f0d43a' BASE_SHA='a41ad700b4b7527bf911bf00f2745914188760c631af0c3255364c05f1ef4fbc' CHANGED=['crates/privileged-helper/src/lib.rs','crates/privileged-helper/src/main.rs','crates/privileged-helper/src/tests.rs'] TEST='tests::startup_lock_waits_only_for_original_executor_and_times_out_without_effects' def main(): os.umask(0o077);q.require(q.sha((BASE/'manifest.json').read_bytes())==BASE_SHA,'exact original capability/tick derivative') old=json.loads((BASE/'manifest.json').read_text());case=ROOT/'devstate/linux-updater-helper-start-build'/str(uuid.uuid4());case.mkdir(mode=0o700,parents=True) fixed={n:(ROOT/n).read_bytes()for n in CHANGED};cache=case/'cache';cache.mkdir(mode=0o700);shutil.copytree(BASE/'cache/release',cache/'release') artifacts={};inputs={};unit=None for version in ('source0','source1'): expected=json.loads((BASE/(version+'-inputs.json')).read_text());names=sorted(expected);q.require(q.capture(BASE/version,names)==expected,'original snapshot unchanged') source=case/version;shutil.copytree(BASE/version,source) for name,raw in fixed.items(): target=source/name;target.chmod(0o600);target.write_bytes(raw);target.chmod(0o444) measured=q.capture(source,names);q.require({n for n in names if measured[n]!=expected[n]}==set(CHANGED),'exact three-file lock-only derivative');q.readonly(source);q.write(case/(version+'-inputs.json'),q.encode(measured));inputs[version]=q.sha((case/(version+'-inputs.json')).read_bytes()) q.run(case,source,cache,version+'-helper-clippy',['cargo','clippy','--locked','--offline','--release','--jobs','2','-p','rmm-privileged-helper','--all-targets','--','-D','warnings']) q.run(case,source,cache,version+'-helper-release',['cargo','build','--locked','--offline','--release','--jobs','2','-p','rmm-privileged-helper','--bin','rmm-privileged-helper']) helper=q.copy_artifact(cache/'release/rmm-privileged-helper',case/'artifacts'/version/'rmm-privileged-helper');artifacts[version]={**old['artifacts'][version],'helper':helper} if version=='source0': output=q.run(case,source,cache,'source0-startup-lock-unit-build',['cargo','test','--locked','--offline','--release','--jobs','2','-p','rmm-privileged-helper','--lib','--no-run','--message-format=json']) candidates=[] for line in output.splitlines(): try:item=json.loads(line) except ValueError:continue if item.get('reason')=='compiler-artifact'and item.get('executable')and item.get('target',{}).get('name')=='rmm_privileged_helper':candidates.append(item['executable']) q.require(len(candidates)==1,'one actual helper lib test executable');unit=q.copy_artifact(cache/Path(candidates[0]).relative_to('/target'),case/'artifacts/helper-startup-lock-unit');unit['filter']=TEST q.require(q.capture(source,names)==measured,'frozen helper source unchanged') for item in [old['stable_updater'],old['artifacts']['source0']['agent'],old['artifacts']['source1']['agent']]:q.require(q.sha(Path(item['path']).read_bytes())==item['sha256'],'original Agents/stable updater unchanged') q.require(artifacts['source0']['helper']['sha256']!=artifacts['source1']['helper']['sha256'],'real different-version helper bytes') manifest={'schema_version':1,'profile':'linux_compatible_helper_start_lock_derivative_v1','base_manifest_sha256':BASE_SHA,'base_manifest':str(BASE/'manifest.json'),'changed_modules':{n:q.sha(raw)for n,raw in fixed.items()},'source_input_hashes':inputs,'source0_version':'0.1.0','source1_version':'0.1.1','builder':q.BUILDER,'artifacts':artifacts,'stable_updater':old['stable_updater'],'units':old['units'],'native_startup_lock_unit':unit,'only_helpers_rebuilt':True,'original_artifacts_unchanged':True,'clippy_all_targets_passed':True,'native_vm_tested':False,'bootstrap_installed':False,'apply_executed':False} q.write(case/'manifest.json',q.encode(manifest));print(json.dumps({'manifest':str(case/'manifest.json'),'manifest_sha256':q.sha((case/'manifest.json').read_bytes()),'artifacts':artifacts,'native_unit':unit})) if __name__=='__main__':main()