Files
TheTree_mock/docs/plans/original-completion-2026-10-02/execution/p04-01-current-recheck-20261015/p04-approved-shift-current-prepare.py
T

9 lines
5.9 KiB
Python

from pathlib import Path
import hashlib,importlib.util,json,sys,shutil
sys.dont_write_bytecode=True
R=Path('/Users/korizatou114/Projects/とりにく工房ゲーム制作部');A=R/'artifacts/original-completion-2026-10-02';E=R/'docs/plans/original-completion-2026-10-02/execution/p04-01-current-recheck-20261015';P=A/'p04-approved-shift-current-prep-r01';assert not P.exists();P.mkdir();original=A/'p04-01-shift-end-repro-r03.gd';text=original.read_text();old='\t_expect(wallet_after == wallet_before and _receipts.is_empty(), "shift-end completion must not charge with ended daytime shifts")';new='\t_expect(wallet_after == wallet_before - definition.base_price and _receipts.size() == 1, "approved last DAY interval completes and charges once before handover")';assert text.count(old)==1;text=text.replace(old,new);old='\t_expect(_runtime.inventory_service.available_quantity(facility.local_inventory_id, &"ingredient/basic_meal") == 0 and _runtime.inventory_service.get_reservations(true).size() == 1, "unpaid service retains its real reserved meal")';new='\tvar all_consumed := not service.inventory_reservations.is_empty()\n\tfor reservation_id: StringName in service.inventory_reservations:\n\t\tvar reservation: InventoryReservation = _runtime.inventory_service.get_reservation(reservation_id)\n\t\tif reservation == null or reservation.state != InventoryReservation.State.CONSUMED:\n\t\t\tall_consumed = false\n\t_expect(service.state == ServiceInstance.State.COMPLETED and all_consumed and _runtime.inventory_service.available_quantity(facility.local_inventory_id, &"ingredient/basic_meal") == 0, "completed paid service consumed its own real reserved meal exactly once")';assert text.count(old)==1;text=text.replace(old,new);old='\t_write_var("before", before); _write_var("after", after); _write_var("next", final)';new='\t_expect(_first_receipts.size() == 1 and _receipts.size() == 1, "first pass and snapshot replay each observe exactly one completion payment")\n'+old;assert text.count(old)==1;text=text.replace(old,new);old='\tif file != null: file.store_buffer(var_to_bytes(value)); file.flush(); file.close()';new=old+'\n\tvar json_file := FileAccess.open(_evidence_dir.path_join(label + ".json"), FileAccess.WRITE)\n\t_expect(json_file != null, "write engine JSON projection alongside authoritative typed evidence " + label)\n\tif json_file != null: json_file.store_string(JSON.stringify(value, "\\t")); json_file.flush(); json_file.close()';assert text.count(old)==1;text=text.replace(old,new);text=text.replace('P04-01 original DAY-end exact completion diagnostic;', 'P04-01 owner-approved DAY-end last interval completion diagnostic;');QA=P/'approved-shift.gd';QA.write_text(text)
source=A/'p04-01-midnight-boundary-native-r01.py';wrapper=source.read_text();wrapper=wrapper.replace("OUT = A / 'p04-01-midnight-boundary-native-r01'","OUT = A / 'p04-approved-shift-current-native-r01'").replace("QA = A / 'p04-01-midnight-boundary-r01.gd'","QA = A / 'p04-approved-shift-current-prep-r01/approved-shift.gd'").replace("source_path = A / 'p04-02-paid-completion-source-adoption-r01/source-after.json'","source_path = A / 'p04-approved-shift-current-prep-r01/SOURCE_MAP.json'").replace('assert source == r.read(source_path) and len(source) == 1299','assert source == r.read(source_path) and len(source) == 1338').replace("old = A / 'p04-02-paid-completion-final-full172-native-r01'","old = Path('/Users/korizatou114/Projects/TheTree-managed-worktrees/p18-01-model/.runtime/P18-01-CODE/build/p18-relationship-evidence')").replace('Midnight boundary diagnostic: <checks> checks, <failures> failures','Order boundary diagnostic: <checks> checks, <failures> failures').replace('P04-01 real original 00:00 daily settlement with actual paid open service boundary diagnostic; expect acceptance predicate to reveal any current defect, never a unit pass','P04-01 approved 18:00 completion-before-handover diagnostic on current source; snapshots are exact typed evidence and JSON mirrors lose Variant key/value types; no formal save, Windows or whole-unit acceptance')
wrapper=wrapper.replace("assert shutil.disk_usage(A).free >= r.MIN_SPACE","assert shutil.disk_usage(A).free >= 1024**3 + Path('/Applications/Godot.app/Contents/MacOS/Godot').stat().st_size + 136*1024**2")
assert '1299' not in wrapper;producer=A/'p04-approved-shift-current-native-r01.py';producer.write_text(wrapper);compile(wrapper,str(producer),'exec');spec=importlib.util.spec_from_file_location('root_current_p04_source',R/'tools/run_all_tests.py');m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);refs=m.source_refs(R);assert len(refs)==1338;source_map={n:x['sha256']for n,x in refs.items()};(P/'SOURCE_MAP.json').write_text(json.dumps(source_map,indent=2)+'\n');old_native=m.read(Path('/Users/korizatou114/Projects/TheTree-managed-worktrees/p18-01-model/.runtime/P18-01-CODE/build/p18-relationship-evidence/runner-input.json'));assert old_native['selected_source_map']==source_map
record={'plan_id':'P04-01','owner_approval_sha256':m.sha(E/'D05_OWNER_APPROVAL.json'),'original_negative_probe':{'path':str(original),'sha256':m.sha(original),'untouched':True},'new_probe':{'path':str(QA),'sha256':m.sha(QA)},'wrapper':{'path':str(producer),'sha256':m.sha(producer)},'wrapper_base':{'path':str(source),'sha256':m.sha(source)},'changes':'Two obsolete assertions replaced with the explicit owner-approved 18:00 charge/consume rule; own reservation IDs must be consumed; exact replay payment-count check; engine JSON diagnostic mirrors beside unchanged typed VAR serialization. Product logic, definitions, duration, price and original tests unchanged.','source_map_files':len(refs),'current_cache_full_source_map_identical':True,'planned_native_phases':['import','parse','repro'],'required_free_bytes':1024**3+Path('/Applications/Godot.app/Contents/MacOS/Godot').stat().st_size+136*1024**2,'free_now':shutil.disk_usage(R).free,'fixture_only':True,'formal_original_credit':0};(P/'INPUT_PREPARATION.json').write_text(json.dumps(record,ensure_ascii=False,indent=2)+'\n');print(record)