Datasets:
Download scripts/evaluate_candidate_pnpm_v4_a03.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 37.1 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/evaluate_candidate_pnpm_v4_a03.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/evaluate_candidate_pnpm_v4_a03.py
-
curl -L -o evaluate_candidate_pnpm_v4_a03.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/evaluate_candidate_pnpm_v4_a03.py
37.1 kB
| """Versioned v4 image profile over the exact reviewed batch06 candidate API. | |
| No baseline execution, gold selection, score writes or publication. PNPM requires | |
| an externally SHA-bound completed v4 formal receipt before input preparation or | |
| candidate dispatch. Import/help/check-only never create outputs or use Docker. | |
| """ | |
| import argparse | |
| import collections | |
| import copy | |
| import hashlib | |
| import importlib.util | |
| import json | |
| from pathlib import Path | |
| import sys | |
| HERE=Path(__file__).resolve().parent | |
| PARENT='evaluate_candidate_batch06_v1.py';PARENT_SHA='4c0ba175d2d0f6af6f409ec90853f9acb4c52d8307d1b94552d93958dbf507fc' | |
| PARSER='batch06_candidate_case_reports_v1.py';PARSER_SHA='9d42cd5aa901366cacea886560cb9487ea3d912c5ed72001144a216258b7999d' | |
| IID='buildpkg-pnpm-11330';OWNER='native-candidate-pnpm-v4-a03' | |
| DIGEST='sha256:f35465cc119d326935b3bf47aad741c84f66acc8536eebe2bb891c381db66af0' | |
| CONFIG='sha256:946c0bba28290b4a42687e6d542fe79580a3ebbd7b8b2db4ac2d2a38a22a9ef0' | |
| BASELINE_ATTEMPT='agent-ready-v4-mem64-a01';BASELINE_STATE='RUNTIME_AND_AGENT_VALIDATED_PENDING_PUBLICATION' | |
| BASELINE_CONTROLLER_SHA='f029b122705fdc73adc409146a37b8d4066e8d46fa939dd6b8f1d586d7ee4434' | |
| BASELINE_PLAN_SHA='5f7ec90df531d8f3571d8654c20ca4409e45bcf4b3cd20b4abd28b7defa54a18' | |
| BASELINE_REVIEWER_SHA='1d2f5f76a49546d95e4675c1a7e019a319437dc359f60ee129dff6b67bf35b34' | |
| ORIGINAL_BASELINE_REVIEWER_SHA='a8ed487ee178641b6c5c602634404ae65bb2b809dfe1afb8d2ae82c9321a962d' | |
| PUBLIC_RECEIPT_SHA='351432cd6213417a757cfb37c8e297182babd53f70b32789f9c113c6accd5cc8' | |
| RECOVERY_REVIEWER='reparse_pnpm11330_native_inventory_v4_a02.py' | |
| RECOVERY_KIND='PNPM_V4_NATIVE_UNICODE_INVENTORY_RECOVERY_V2' | |
| RECOVERY_PLAN_KIND='PNPM_V4_NATIVE_UNICODE_INVENTORY_RECOVERY_PLAN_V2' | |
| RECOVERY_ROOT=Path('/root/silinchen/silin_repo/crossrepo-work/docker171-build-20261015') | |
| def _recovery_pin(relative,size,sha): | |
| return {'path':str(RECOVERY_ROOT/relative),'bytes':size,'sha256':sha} | |
| # Exact twelve actual plan references plus the actual plan itself. The | |
| # original paths remain evidence identities and resolve only via BaselinePaths. | |
| RECOVERY_REFERENCE_PINS={ | |
| 'reviewed_controller':_recovery_pin('control/code/agent-readiness/pnpm11330-native-v4-mem64-overlay-reparse-a01/code/restore_validate_pnpm_v4_mem64_a01.py',43339,BASELINE_CONTROLLER_SHA), | |
| 'reviewed_plan':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-repair-v4-mem64-a01-plan.json',9128,BASELINE_PLAN_SHA), | |
| 'original_review_tool':_recovery_pin('control/code/agent-readiness/pnpm11330-native-v4-mem64-overlay-reparse-a01/code/finalize_pnpm_v4_mem64_a01.py',9483,ORIGINAL_BASELINE_REVIEWER_SHA), | |
| 'review_tool':_recovery_pin('control/code/agent-readiness/pnpm11330-native-inventory-recovery-a02/code/reparse_pnpm11330_native_inventory_v4_a02.py',53254,BASELINE_REVIEWER_SHA), | |
| 'original_controller_error':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/recovery-validation-agent-ready-v4-mem64-a01.json',22744,'7a0ad37a6c16dee74378f926c8146ba10069b159b00a679b435a082628a610c8'), | |
| 'native_status':_recovery_pin('validation/buildpkg-pnpm-11330/agent-ready-v4-mem64-a01/status.json',13595,'721fe8d705c42aa314fe87beccf454b7473be26ff27a93399da1bef2a5fe0751'), | |
| 'merkle_proof':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-terminal-source-review-diagnostic-a01/base-commit-unicode-merkle-proof.json',13509,'4bec9c0a7f08cb6326c2d659ca70f6b492b3ef93fbc164d06b3d1592e8d2477c'), | |
| 'source_difference':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-terminal-source-review-diagnostic-a01/inventory-difference.json',3076,'36900b2b4ffe2e0ed5971d74396758169de8b8cc39ea9781b92089c056fa76d2'), | |
| 'lifecycle_output_proof':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-inventory-recovery-a02/lifecycle-output-proof.json',10276,'dbb667c85e863c785ebf3c22bf9fdc4fde00a38d5a0319aeda5eb3dd11d31d48'), | |
| 'prior_review_tool':_recovery_pin('control/code/agent-readiness/pnpm11330-native-inventory-recovery-a01/code/reparse_pnpm11330_native_inventory_v4_a01.py',31855,'75a6a012fde84e33ccf3ce0b257e07a610512d385045e0920bb05f0f426e55b3'), | |
| 'prior_supplement_plan':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-inventory-recovery-a01/supplement-plan.json',2884,'868fab52ed4af1b0e8025a5046b4d52babd59b78a69fc200a9c8f04704e4a5f5'), | |
| 'prior_review_result':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-inventory-recovery-a01/check-only-a01-result.json',3349,'35df4a1dcef540a59dc5ef298478856a0deb1d12512fbf7cc22d79ff3b37157f'), | |
| 'supplement_plan':_recovery_pin('control/agent-readiness/buildpkg-pnpm-11330/native-inventory-recovery-a02/supplement-plan.json',4162,'e6d56cdcd5b9145394f81fc8e424d8fe74ef3a31864a8634cef72af868d21261'), | |
| } | |
| LIFECYCLE_PREDICATE_PROVENANCE={ | |
| 'original_source_sha256':'3f2d553028bc979c996c6f47a2b69e45156c995030446cb72459dcbc2e920274', | |
| 'original_function_source_sha256':'73482c44c11dde511be64fa784025e68a163a87a600130f37f33f67f7ed1ece4', | |
| 'adapted_function_ast_sha256':'077b2dba00e20d6ab756191d6bcad078ceac48e6170621467066cfc210125742', | |
| 'transforms':{'memory_literal_24_to_64':1,'final_stdout_predicate':1}, | |
| 'normal_stdout_predicate':'stdout.read_text().strip() == exact_owned_name', | |
| 'additional_stop_stdout_exact':'Flag --time has been deprecated, use --timeout instead\n<exact_owned_name>\n', | |
| 'original_checks_preserved':True,'raw_normalized_or_changed':False, | |
| } | |
| def require(ok,message): | |
| if not ok:raise ValueError(message) | |
| def digest(path): | |
| value=hashlib.sha256() | |
| with Path(path).open('rb')as stream: | |
| for block in iter(lambda:stream.read(1024*1024),b''):value.update(block) | |
| return value.hexdigest() | |
| def regular(path): | |
| path=Path(path).absolute();require(path==path.resolve()and path.is_file()and not path.is_symlink(),'Missing/linked versioned input: '+str(path));return path | |
| def ref(path): | |
| path=regular(path);return {'path':str(path),'bytes':path.stat().st_size,'sha256':digest(path)} | |
| def bound(path,sha): | |
| path=regular(path);require(digest(path)==sha,'Pinned source/evidence SHA differs: '+str(path));return path | |
| def source_module(name,path): | |
| """Compile actual source bytes; a timestamp-matched .pyc is never consulted.""" | |
| path=regular(path);spec=importlib.util.spec_from_file_location(name,path);module=importlib.util.module_from_spec(spec) | |
| exec(compile(path.read_bytes(),str(path),'exec'),module.__dict__);return module | |
| def load_adapter(parent=HERE/PARENT): | |
| parent=bound(parent,PARENT_SHA);parser=bound(parent.with_name(PARSER),PARSER_SHA) | |
| previous=sys.modules.get('batch06_candidate_case_reports_v1');old_bytecode=sys.dont_write_bytecode | |
| try: | |
| sys.dont_write_bytecode=True;sys.modules['batch06_candidate_case_reports_v1']=source_module('_pnpm_v4_exact_parser',parser) | |
| module=source_module('_pnpm_v4_exact_candidate_parent',parent) | |
| finally: | |
| sys.dont_write_bytecode=old_bytecode | |
| if previous is None:sys.modules.pop('batch06_candidate_case_reports_v1',None) | |
| else:sys.modules['batch06_candidate_case_reports_v1']=previous | |
| module.PROFILES=copy.deepcopy(module.PROFILES) | |
| module.PROFILES[IID].update(registry_digest=DIGEST,config_digest=CONFIG) | |
| module.OWNER=OWNER | |
| # Original support pins run before these loads. This I/O-only replacement | |
| # prevents cached bytecode from replacing any already checked source bytes. | |
| module.import_file=source_module | |
| return module | |
| _PUBLIC_ADAPTER=load_adapter() | |
| PROFILES=copy.deepcopy(_PUBLIC_ADAPTER.PROFILES) | |
| DEFAULT_SUPPORT=_PUBLIC_ADAPTER.DEFAULT_SUPPORT | |
| def __getattr__(name): | |
| """Keep the original parser/patch/classification/support read API available.""" | |
| return getattr(_PUBLIC_ADAPTER,name) | |
| class PendingBaseline(ValueError): | |
| def __init__(self,detail): | |
| self.detail={'state':'PENDING_MATCHING_PNPM_V4_BASELINE','no_dispatch':True,'runtime_validation':'NOT_RUN',**detail} | |
| super().__init__(self.detail['state']) | |
| class BaselinePaths: | |
| """Explicit original-directory locator; it never rewrites evidence bytes.""" | |
| def __init__(self,path,module): | |
| self.locator=ref(path)if path is not None else None;self.members={};self.module=module | |
| if path is not None: | |
| for original,target in module.read_json(path).items(): | |
| require(isinstance(original,str)and Path(original).is_absolute()and '..'not in Path(original).parts | |
| and str(Path(original))==original and isinstance(target,str)and target,'Invalid baseline locator member') | |
| supplied=Path(target);require('..'not in supplied.parts,'Escaping baseline locator target') | |
| resolved=supplied if supplied.is_absolute()else Path(path).resolve().parent/supplied | |
| require(resolved==resolved.resolve(),'Linked baseline locator target');self.members[Path(original)]=resolved | |
| def resolve(self,original): | |
| original=Path(original);require(original.is_absolute()and '..'not in original.parts,'Invalid original baseline path') | |
| matches=[source for source in self.members if original.is_relative_to(source)] | |
| if not matches:return original | |
| source=max(matches,key=lambda item:len(item.parts));return self.members[source]/original.relative_to(source) | |
| def load_recovery_reviewer(path=HERE/RECOVERY_REVIEWER): | |
| """Load only the approved pure proof API from checked actual source bytes.""" | |
| path=bound(path,BASELINE_REVIEWER_SHA) | |
| require(path.name==RECOVERY_REVIEWER,'Recovery reviewer source name differs') | |
| previous=sys.dont_write_bytecode | |
| try: | |
| sys.dont_write_bytecode=True | |
| return source_module('_pnpm_v4_exact_recovery_proofs',path) | |
| finally:sys.dont_write_bytecode=previous | |
| def same_json(left,right): | |
| """Exact JSON types keep bool/int lookalikes out of new provenance.""" | |
| if type(left)is not type(right):return False | |
| if isinstance(left,dict):return set(left)==set(right)and all(same_json(left[key],right[key])for key in left) | |
| if isinstance(left,list):return len(left)==len(right)and all(same_json(a,b)for a,b in zip(left,right)) | |
| return left==right | |
| def operator_sources(module,support_dir): | |
| """The original twelve source files plus the approved pure recovery API.""" | |
| values={Path(__file__).name:ref(Path(__file__).resolve()),PARENT:ref(bound(module.__file__,PARENT_SHA)), | |
| PARSER:ref(bound(Path(module.__file__).with_name(PARSER),PARSER_SHA)), | |
| RECOVERY_REVIEWER:ref(bound(HERE/RECOVERY_REVIEWER,BASELINE_REVIEWER_SHA))} | |
| values.update({name:ref(bound(Path(support_dir)/name,expected))for name,expected in module.SUPPORT_SHA256.items()}) | |
| require(len(values)==13,'Candidate operator must retain all thirteen checked source files') | |
| return values | |
| def verify_recovery_provenance(receipt,module,locator,referenced): | |
| """Verify the exact V2 correction over retained small files only. | |
| ``referenced`` is baseline_raw's existing retained-reference reader. It | |
| resolves every new file through the explicit locator and adds it to the | |
| same returned closure/end-rehash as the original native RAW. Neither the | |
| full collector nor cold OCI evidence is called or opened here. | |
| """ | |
| pins=RECOVERY_REFERENCE_PINS;fields=set(pins)-{'supplement_plan'} | |
| require(type(receipt.get('schema_version'))is int and receipt['schema_version']==1 | |
| and receipt.get('kind')==RECOVERY_KIND and receipt.get('derived')is True,'Baseline is not the exact derived V2 review') | |
| provenance=receipt.get('review_provenance') | |
| expected_provenance={'kind':RECOVERY_KIND,'derived':True,'original_controller_state':'RECOVERY_OR_VALIDATION_ERROR', | |
| **pins,'lifecycle_predicate_derivation':LIFECYCLE_PREDICATE_PROVENANCE} | |
| require(same_json(provenance,expected_provenance),'Recovery provenance or exact pinned reference differs') | |
| require(all(type(receipt.get(key))is int and receipt[key]==0 for key in ('native_commands_executed_by_review','native_commands_repeated')) | |
| and receipt.get('old_failed_baseline_reused')is False and receipt.get('cleanup_performed_by_review')is False, | |
| 'Recovery review execution history differs') | |
| require(same_json(receipt.get('controller'),pins['original_controller_error'])and same_json(receipt.get('native_status'),pins['native_status']) | |
| and all(same_json(receipt.get(key),pins[key])for key in ('reviewed_controller','reviewed_plan','review_tool')), | |
| 'Recovery final/original terminal references differ') | |
| files={key:referenced(pins[key])for key in sorted(pins)} | |
| core=load_recovery_reviewer(files['review_tool']) | |
| plan=module.read_json(files['supplement_plan']) | |
| require(isinstance(plan,dict)and set(plan)=={'schema_version','kind','instance_id','attempt','image_digest','config_digest',*fields} | |
| and type(plan['schema_version'])is int and plan['schema_version']==1 and plan['kind']==RECOVERY_PLAN_KIND | |
| and plan['instance_id']==IID and plan['attempt']==BASELINE_ATTEMPT and plan['image_digest']==DIGEST and plan['config_digest']==CONFIG | |
| and all(same_json(plan[key],pins[key])for key in fields),'Exact V2 supplement plan identity or twelve-reference closure differs') | |
| original_plan=module.read_json(files['reviewed_plan']) | |
| require(same_json(original_plan.get('finalizer'),pins['original_review_tool'])and same_json(original_plan.get('controller'),pins['reviewed_controller']), | |
| 'Original execution plan/finalizer binding differs') | |
| prior=module.read_json(files['prior_supplement_plan']);first_fields=fields-{'lifecycle_output_proof','prior_review_tool','prior_supplement_plan','prior_review_result'} | |
| require(isinstance(prior,dict)and set(prior)=={'schema_version','kind','instance_id','attempt','image_digest','config_digest',*first_fields} | |
| and type(prior['schema_version'])is int and prior['schema_version']==1 | |
| and prior['kind']=='PNPM_V4_NATIVE_UNICODE_INVENTORY_RECOVERY_PLAN_V1' | |
| and all(prior[key]==plan[key]for key in ('instance_id','attempt','image_digest','config_digest')) | |
| and same_json(prior['review_tool'],pins['prior_review_tool'])and all(same_json(prior[key],pins[key])for key in first_fields-{'review_tool'}), | |
| 'Prior failed supplement plan original bindings differ') | |
| prior_result=module.read_json(files['prior_review_result']) | |
| require(prior_result.get('schema')=='crossswe-root-completed-native-review-execution-v1' | |
| and prior_result.get('state')=='READ_ONLY_REVIEW_ERROR'and type(prior_result.get('returncode'))is int and prior_result['returncode']==1 | |
| and prior_result.get('ledger_append')is False and type(prior_result.get('native_commands_repeated'))is int and prior_result['native_commands_repeated']==0 | |
| and all(prior_result.get(key)is True for key in ('native_status_unchanged','original_error_unchanged','repair_ledger_unchanged')) | |
| and isinstance(prior_result.get('terminal_error'),str) | |
| and prior_result['terminal_error'].endswith('.ReviewError: Native lifecycle stdout differs: stop\n'), | |
| 'Actual prior failed review history differs') | |
| controller=module.read_json(files['original_controller_error']);native=module.read_json(files['native_status']) | |
| core.verify_terminal_statuses(controller,native,pins['reviewed_plan']) | |
| require(controller['validation_path']==pins['native_status']['path']and controller['validation_sha256']==pins['native_status']['sha256'], | |
| 'Original controller/native reference scope differs') | |
| merkle=module.read_json(files['merkle_proof']);objects={} | |
| for row in merkle['objects']: | |
| oid=row['git_oid'];value=row['file'] | |
| require(isinstance(oid,str)and oid not in objects | |
| and Path(value['path'])==Path(pins['merkle_proof']['path']).parent/'base-git-objects'/(oid+'.raw'), | |
| 'Git proof object escaped its fixed retained namespace') | |
| objects[oid]=referenced(value).read_bytes() | |
| git=core.verify_merkle_payload(merkle,objects) | |
| require(git['objects_verified']==15,'Complete fifteen typed Git object proof missing') | |
| difference=module.read_json(files['source_difference']) | |
| expected_extra=[{'path':name,'value':value['sha256']}for name,value in core.UNICODE_FILES.items()] | |
| require(difference.get('schema')=='crossswe-pnpm-v4-readonly-source-fingerprint-difference-v1' | |
| and difference.get('source_changed')is False and type(difference.get('tests_repeated'))is int and difference['tests_repeated']==0 | |
| and isinstance(difference.get('worlds'),list)and [row.get('world')for row in difference['worlds']]==list(core.WORLDS), | |
| 'Source difference correction history differs') | |
| for row in difference['worlds']: | |
| require(type(row['cache_count'])is int and row['cache_count']==core.ORIGINAL_NODE_COUNT | |
| and type(row['actual_count'])is int and row['actual_count']==core.ORIGINAL_NODE_COUNT+4 | |
| and row['missing']==row['changed']==[]and row['extra']==expected_extra | |
| and row['native_before_after_equal']is True and row['git_before_after_equal']is True, | |
| 'Source difference is not exactly the four proven fixed UTF8 files') | |
| expected_inventory={**git,'original_cache_proof':controller['cache_preflight'], | |
| 'original_expected_counts':{world:core.ORIGINAL_NODE_COUNT for world in core.WORLDS}, | |
| 'completed_expected_counts':{world:core.ORIGINAL_NODE_COUNT+4 for world in core.WORLDS}, | |
| 'original_cache_proof_unchanged':True,'only_expected_maps_supplemented':True} | |
| require(same_json(receipt.get('source_inventory_supplement'),expected_inventory) | |
| and same_json(receipt.get('cache_preflight',{}).get('receipt'),controller['cache_preflight']), | |
| 'Complete fixed inventory supplement or unchanged original cache proof differs') | |
| lifecycle=module.read_json(files['lifecycle_output_proof']) | |
| top=('native_status','original_controller_error','prior_review_result','prior_review_tool','prior_supplement_plan') | |
| require(all(same_json(lifecycle.get(key),pins[key])for key in top),'Lifecycle proof/supplement original or prior reference differs') | |
| references=[lifecycle[key]for key in top] | |
| for world in lifecycle['worlds']: | |
| references += [world['create_stdout'],world['final_inspect']] | |
| references += [world[label][stream]for label in ('start','stop','remove')for stream in ('execution','stdout','stderr')] | |
| raw={} | |
| for value in references: | |
| require(value['path']not in raw,'Duplicate lifecycle proof reference') | |
| raw[value['path']]=referenced(value).read_bytes() | |
| verified_lifecycle=core.verify_lifecycle_payload(lifecycle,raw) | |
| require(len(verified_lifecycle['reference_refs'])==27,'Complete 27-reference lifecycle proof missing') | |
| expected_lifecycle={'kind':'PNPM_V4_EXACT_STOP_STDOUT_COMPATIBILITY_V1','proof':pins['lifecycle_output_proof'], | |
| **{key:pins[key]for key in ('prior_review_tool','prior_supplement_plan','prior_review_result')}, | |
| 'worlds':verified_lifecycle['worlds'],'reference_refs':verified_lifecycle['reference_refs'], | |
| 'predicate_derivation':LIFECYCLE_PREDICATE_PROVENANCE,'native_commands_repeated':0,'raw_files_changed':False, | |
| 'original_lifecycle_checks_preserved':True} | |
| require(same_json(receipt.get('lifecycle_output_compatibility'),expected_lifecycle),'Exact lifecycle correction/derivation proof differs') | |
| return {'controller':controller,'native_original':Path(pins['native_status']['path']), | |
| 'native_file':files['native_status'],'native':native,'review':{'kind':RECOVERY_KIND,'derived':True, | |
| 'reviewer_source':ref(files['review_tool']),'references':copy.deepcopy(pins), | |
| 'git_objects_verified':git['objects_verified'],'git_raw_object_bytes':git['raw_object_bytes'], | |
| 'lifecycle_references_verified':len(verified_lifecycle['reference_refs']), | |
| 'original_controller_state':controller['state'],'native_commands_executed':0}} | |
| def baseline_raw(receipt,module,reports,locator): | |
| """Reparse only eight native groups and their small SavedEvidence closure.""" | |
| refs=receipt.get('retained_evidence') | |
| if not isinstance(refs,list):raise PendingBaseline({'missing':['retained_native_raw_references']}) | |
| retained={item['path']:item for item in refs};require(len(retained)==len(refs),'Duplicate retained baseline reference') | |
| used={} | |
| def member(original,expected_sha=None): | |
| original=str(original) | |
| if original not in retained:raise PendingBaseline({'missing':['actual_native_reference:'+original]}) | |
| item=retained[original] | |
| require(expected_sha is None or item['sha256']==expected_sha,'Retained native reference SHA contradicts its binding') | |
| translated=locator.resolve(original) | |
| if not translated.exists():raise PendingBaseline({'missing':['actual_native_file:'+original]}) | |
| actual=bound(translated,item['sha256']);require(item['bytes']==actual.stat().st_size,'Retained native reference byte count differs') | |
| used[original]={'original':item,'resolved':ref(actual)};return actual | |
| def referenced(item): | |
| if not isinstance(item,dict)or not item.get('path')or not item.get('sha256'):raise PendingBaseline({'missing':['actual_native_provenance_ref']}) | |
| path=member(item['path'],item['sha256']);require('bytes'not in item or item['bytes']==path.stat().st_size,'Provenance reference byte count differs');return path | |
| for key,expected in (('reviewed_controller',BASELINE_CONTROLLER_SHA),('reviewed_plan',BASELINE_PLAN_SHA),('review_tool',BASELINE_REVIEWER_SHA)): | |
| require(receipt[key]['sha256']==expected,'Unapproved baseline reviewed source');referenced(receipt[key]) | |
| recovery=verify_recovery_provenance(receipt,module,locator,referenced) | |
| controller=recovery['controller'];native_original=recovery['native_original'] | |
| require(tuple(native_original.parts[-4:])==('validation',IID,BASELINE_ATTEMPT,'status.json'),'Baseline native namespace differs') | |
| native_file=member(native_original,controller['validation_sha256']);native=module.read_json(native_file) | |
| require(native['state']=='LOCAL_VALIDATED'and native['instance_id']==IID and native['image']==DIGEST and native['attempt']==BASELINE_ATTEMPT | |
| and native['issues']==[]and native.get('ended_utc')and not native.get('active')and native['effective_policy']=={'worlds':['all_buggy','all_fixed'],'repeat_count':1} | |
| and native['contract_sha256']==module.PROFILES[IID]['contract_sha256'],'Actual native result is incomplete or mismatched') | |
| require([(world['world'],world['repeat'])for world in native['worlds']]==[('all_buggy',1),('all_fixed',1)],'Actual native worlds differ') | |
| original_root=native_original.parents[3];inputs=original_root/'control/inputs'/IID/'current' | |
| task=module.read_json(member(inputs/'task.json',module.PROFILES[IID]['task_sha256'])) | |
| relative=Path(task['evaluation']['path']);require(not relative.is_absolute()and '..'not in relative.parts,'Escaping baseline contract reference') | |
| contract=module.read_json(member(inputs/relative,module.PROFILES[IID]['contract_sha256'])) | |
| require(contract.get('network')=='none'and task['instance_id']==IID,'Actual baseline task/network differs') | |
| commands={item['repository']:item for item in contract['commands']};require(set(commands)=={'pnpm','node'}and len(contract['commands'])==2,'Actual native command repository inventory differs') | |
| reviewed=receipt['frozen_native_review'];groups=reviewed.get('commands') | |
| if not isinstance(groups,list):raise PendingBaseline({'missing':['eight_actual_native_group_references']}) | |
| indexed={(item['world'],item['repository'],item['kind']):item for item in groups} | |
| expected={(world,repo,kind)for world in ('all_buggy','all_fixed')for repo in ('pnpm','node')for kind in ('pass_to_pass','fail_to_pass')} | |
| require(len(groups)==len(indexed)==8 and set(indexed)==expected,'Actual eight-group reference inventory differs') | |
| recorded={item['path']:item['sha256']for item in reviewed['all_recorded_commands']};actual_rows=[];original_saved=reports.SavedEvidence | |
| for world in native['worlds']: | |
| world_name=world['world'];original_cell=native_original.parent/world_name/'repeat-1';cell=locator.resolve(original_cell) | |
| require(cell.is_dir()and cell==cell.resolve(),'Missing/linked exported native cell') | |
| require(module.read_json(member(original_cell/'result.json'))==world and world['issues']==[]and world['container_image_id']==DIGEST,'Actual world result/image differs') | |
| require(len(world['commands'])==4 and {(row['repository'],row['kind'])for row in world['commands']}=={(repo,kind)for repo in ('pnpm','node')for kind in ('pass_to_pass','fail_to_pass')},'Actual four-group world inventory differs') | |
| class BoundSavedEvidence(original_saved): | |
| def __init__(self,actual_cell): | |
| require(Path(actual_cell)==cell,'Parser escaped actual native cell');super().__init__(actual_cell) | |
| def file(self,relative): | |
| actual=super().file(relative);require(member(original_cell/'native-artifacts'/relative)==regular(actual),'Exported artifact locator is incoherent');return actual | |
| def source(self): | |
| for name in ('source-files.json','source-files-after.json'):require(member(original_cell/name)==regular(cell/name),'Exported source locator is incoherent') | |
| return super().source() | |
| reports.SavedEvidence=BoundSavedEvidence | |
| try: | |
| for row in world['commands']: | |
| repo,kind=row['repository'],row['kind'];proof=indexed[world_name,repo,kind];label=repo+'-'+kind;original_execution=original_cell/(label+'.execution.json') | |
| require(proof['execution']['path']==str(original_execution)and recorded.get(str(original_execution))==proof['execution']['sha256'],'Native execution ref escaped its actual group') | |
| execution=module.read_json(referenced(proof['execution']));frozen=commands[repo];env={**module.ENVIRONMENT,**frozen.get('environment',{})} | |
| argv=['docker','exec','-w',frozen.get('test_cwd')or frozen['container_path']] | |
| for key,value in env.items():argv+=['-e',key+'='+value] | |
| name=('d171-'+IID+'-'+BASELINE_ATTEMPT+'-'+world_name).lower().replace('_','-');argv += [name,'bash','-lc',frozen[kind]] | |
| require(execution['argv']==argv and row['command']==frozen[kind]and row['issues']==[]and type(execution['returncode'])is int | |
| and execution['returncode']==row['returncode']and not execution.get('timed_out')and not execution.get('error'),'Actual native command/exit/error differs') | |
| streams={} | |
| for stream in ('stdout','stderr'): | |
| sha=execution[stream+'_sha256'];require(proof[stream+'_sha256']==sha,'Group/command RAW SHA differs') | |
| streams[stream]=member(original_cell/(label+'.'+stream+'.log'),sha).read_text() | |
| cases,issues,metadata=reports.parse_report(IID,repo,kind,streams['stdout'],streams['stderr'],row['returncode'],cell) | |
| require(not issues and cases and cases==row['cases']and metadata==row['report_metadata']and metadata['native_case_receipts_verified']==len(cases) | |
| and row['passed']==sum(case['passed']for case in cases)and row['failed']==sum(not case['passed']for case in cases),'Actual frozen parser/case metadata differs') | |
| require(proof['actual_cases']==proof['native_case_receipts_verified']==len(cases),'Reviewed group case count differs') | |
| actual_rows += [{'world':world_name,'repeat':1,'repository':repo,'kind':kind,**case}for case in cases] | |
| finally:reports.SavedEvidence=original_saved | |
| require(actual_rows==reviewed['actual_case_rows'],'Final receipt case rows differ from actual native RAW reparse') | |
| for original,entry in used.items():require(ref(bound(locator.resolve(original),entry['original']['sha256']))==entry['resolved'],'Native RAW changed during baseline reparse') | |
| return {'native_status':{'original':retained[str(native_original)],'resolved':ref(native_file)},'native_groups_reparsed':8,'actual_cases_reparsed':50, | |
| 'parser_sha256':module.SUPPORT_SHA256['reusable_support/batch06_case_reports.py'],'path_map':locator.locator, | |
| 'verified_small_references':[used[key]for key in sorted(used)],'large_retained_objects_read':False,'recovery_provenance':recovery['review']} | |
| def baseline_proof(path,sha,module,support_dir=DEFAULT_SUPPORT,path_map=None): | |
| if path is None or sha is None:raise PendingBaseline({'missing':['baseline_receipt','baseline_receipt_sha256']}) | |
| if not Path(path).exists():raise PendingBaseline({'missing':['actual_completed_baseline_receipt']}) | |
| receipt=module.read_json(bound(path,sha)) | |
| if isinstance(receipt,dict)and receipt.get('schema')=='crossswe-frozen-native-behavior-case-review-v1'and receipt.get('state')=='BEHAVIOR_CASES_VERIFIED_FULL_LIFECYCLE_REVIEW_PENDING': | |
| require(same_json(receipt.get('native_status'),RECOVERY_REFERENCE_PINS['native_status']) | |
| and same_json(receipt.get('original_controller_error'),RECOVERY_REFERENCE_PINS['original_controller_error']) | |
| and receipt.get('full_delivery')is False,'Partial baseline original terminal bindings differ') | |
| raise PendingBaseline({'baseline_state':receipt['state'],'missing':['completed_full_lifecycle_baseline_review']}) | |
| require(isinstance(receipt,dict)and receipt.get('instance_id')==IID and receipt.get('registry_digest',receipt.get('image_digest'))==DIGEST | |
| and receipt.get('config_digest',receipt.get('image_config_digest'))==CONFIG,'Baseline receipt has a nonmatching v4 identity') | |
| if receipt['state']!=BASELINE_STATE:raise PendingBaseline({'baseline_state':receipt['state']}) | |
| require(receipt['repair_identity']==BASELINE_ATTEMPT and receipt['new_formal_instances']==receipt['model_calls']==receipt['score_writes']==0 | |
| and receipt['effective_policy']=={'worlds':['all_buggy','all_fixed'],'repeat_count':1,'network':'none'} | |
| and receipt['reviewed_controller']['sha256']==BASELINE_CONTROLLER_SHA and receipt['reviewed_plan']['sha256']==BASELINE_PLAN_SHA | |
| and receipt['review_tool']['sha256']==BASELINE_REVIEWER_SHA,'Baseline receipt is not the reviewed once-only v4 result') | |
| require(all(receipt[key]==module.PROFILES[IID][key]for key in ('task_sha256','contract_sha256')),'Baseline frozen task/contract differs') | |
| profile=receipt['resource_profile'];require(profile['cpus']==8 and profile['memory_bytes']==profile['memory_swap_bytes']==64*1024**3 | |
| and profile['minimum_host_available_bytes']==80_000_000_000,'Baseline v4 resource profile differs') | |
| public=receipt['public_tests'];require(public['image_requested']==DIGEST and public['receipt_sha256']==PUBLIC_RECEIPT_SHA | |
| and public['status']=='AGENT_PUBLIC_TESTS_READY_WITH_REVIEW','Actual v4 public proof differs') | |
| require(receipt['workspace_overlay']['state']=='SUCCESS_WITH_POSTPROCESS_CORRECTION' | |
| and receipt['workspace_overlay']['reader']['sha256']=='183363d70b8781034fd03db104e27cfbe4f742854214c825f2c1b9c447705639','Actual corrected overlay proof differs') | |
| native=receipt['frozen_native_review'];require(native['actual_cases_per_world']=={'all_buggy':25,'all_fixed':25},'Baseline full25 cases/world missing') | |
| inventories=module.load_support(support_dir).reports.INVENTORIES[IID] | |
| expected=collections.Counter((world,1,repo,kind,case)for world in ('all_buggy','all_fixed')for repo in ('pnpm','node') | |
| for kind,phase in (('pass_to_pass','p2p'),('fail_to_pass','f2p'))for case in inventories[repo][phase]) | |
| rows=native['actual_case_rows'];require(collections.Counter((row['world'],row['repeat'],row['repository'],row['kind'],row['id'])for row in rows)==expected | |
| and all(type(row['passed'])is bool for row in rows),'Baseline complete frozen case identities differ') | |
| totals={} | |
| for world in ('all_buggy','all_fixed'): | |
| totals[world]={} | |
| for kind,phase in (('pass_to_pass','p2p'),('fail_to_pass','f2p')): | |
| cases=[row for row in rows if row['world']==world and row['kind']==kind];passed=sum(row['passed']for row in cases);failed=len(cases)-passed | |
| require(not failed if phase=='p2p'or world=='all_fixed'else failed>0,'Baseline frozen endpoint outcomes differ') | |
| totals[world][phase]={'passed':passed,'failed':failed} | |
| require(native['totals']==totals,'Baseline actual case totals disagree') | |
| small=baseline_raw(receipt,module,module.load_support(support_dir).reports,BaselinePaths(path_map,module)) | |
| return {'receipt':ref(path),'state':receipt['state'],'repair_identity':receipt['repair_identity'],'image_digest':DIGEST,'config_digest':CONFIG, | |
| 'actual_cases_per_world':native['actual_cases_per_world'],'small_raw_review':small,'basis':'externally SHA-bound final receipt plus original frozen parser over actual native RAW; no baseline commands executed'} | |
| def prepare_inputs(bench_root,iid,mapping_file,output_dir,support_dir=DEFAULT_SUPPORT,evaluator_resource_dir=None,*,baseline_receipt=None,baseline_receipt_sha256=None,baseline_path_map=None): | |
| module=load_adapter();require(iid in module.PROFILES,'Unsupported candidate instance') | |
| proof=baseline_proof(baseline_receipt,baseline_receipt_sha256,module,support_dir,baseline_path_map)if iid==IID else None | |
| prepared=module.prepare_inputs(bench_root,iid,mapping_file,output_dir,support_dir,evaluator_resource_dir) | |
| binding={'wrapper':ref(Path(__file__).resolve()),'parent':ref(Path(module.__file__)),'parser':ref(Path(module.__file__).with_name(PARSER)), | |
| 'namespace':OWNER,'profile':copy.deepcopy(module.PROFILES[iid]),'baseline':proof,'operator_sources':operator_sources(module,support_dir)} | |
| prepared['input_provenance']={**prepared['input_provenance'],'versioned_adapter':binding} | |
| prepared['_versioned_module']=module;prepared['_versioned_support_dir']=Path(support_dir);prepared['_baseline_path_map']=baseline_path_map | |
| return prepared | |
| def evaluate(prepared,runner=None): | |
| module=prepared['_versioned_module'];binding=prepared['input_provenance']['versioned_adapter'];iid=prepared['iid'] | |
| bound(module.__file__,PARENT_SHA);bound(Path(module.__file__).with_name(PARSER),PARSER_SHA) | |
| require(binding['wrapper']==ref(Path(__file__).resolve())and binding['namespace']==module.OWNER==OWNER and module.PROFILES[iid]==binding['profile'] | |
| and binding['profile']==load_adapter().PROFILES[iid]and all(prepared['image'][key]==value for key,value in binding['profile'].items()),'Prepared versioned profile/source binding differs') | |
| require(same_json(binding.get('operator_sources'),operator_sources(module,prepared['_versioned_support_dir'])),'Prepared thirteen-file operator source closure differs') | |
| if iid==IID: | |
| proof=binding['baseline'];require(proof is not None,'Completed v4 baseline proof missing') | |
| require(baseline_proof(proof['receipt']['path'],proof['receipt']['sha256'],module,prepared['_versioned_support_dir'],prepared['_baseline_path_map'])==proof,'Completed baseline drift after preparation') | |
| return module.evaluate(prepared,runner) | |
| def main(argv=None): | |
| parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--bench-root',type=Path,required=True);parser.add_argument('--support-dir',type=Path,default=DEFAULT_SUPPORT) | |
| parser.add_argument('--instance-id',required=True,choices=sorted(PROFILES));parser.add_argument('--candidate-patches',type=Path,required=True);parser.add_argument('--output-dir',type=Path,required=True) | |
| parser.add_argument('--evaluator-resource-dir',type=Path);parser.add_argument('--baseline-receipt',type=Path);parser.add_argument('--baseline-receipt-sha256');parser.add_argument('--baseline-path-map',type=Path);parser.add_argument('--check-only',action='store_true');args=parser.parse_args(argv) | |
| try: | |
| prepared=prepare_inputs(args.bench_root,args.instance_id,args.candidate_patches,args.output_dir,args.support_dir,args.evaluator_resource_dir, | |
| baseline_receipt=args.baseline_receipt,baseline_receipt_sha256=args.baseline_receipt_sha256,baseline_path_map=args.baseline_path_map) | |
| if args.check_only: | |
| print(json.dumps({'instance_id':args.instance_id,'state':'INPUTS_VERIFIED','world':'candidate','image':prepared['image']['image_ref'],'patches':prepared['patches'], | |
| 'evaluator_resources':prepared['resource'],'versioned_adapter':prepared['input_provenance']['versioned_adapter'],'model_calls':0,'score_writes':0,'runtime_validation':'NOT_RUN'}));return 0 | |
| status=evaluate(prepared);print(json.dumps({'instance_id':args.instance_id,'state':status['state'],'resolved':status.get('resolved',False),'receipt':str(prepared['out']/'status.json'), | |
| 'receipt_persisted':status.get('receipt_persisted',False),'issues':status['issues'],'logging_errors':status['logging_errors']}));return 2 if status['state']=='EVALUATION_ERROR'else 0 | |
| except PendingBaseline as error:print(json.dumps(error.detail,sort_keys=True));return 2 | |
| except(ValueError,OSError,KeyError,TypeError)as error:print(type(error).__name__+': '+str(error),file=sys.stderr);return 2 | |
| if __name__=='__main__':raise SystemExit(main()) | |