Files

22 lines
4.1 KiB
Python

from pathlib import Path
import json,hashlib,shutil
R=Path('/Users/korizatou114/Projects/とりにく工房ゲーム制作部');A=R/'artifacts/original-completion-2026-10-02';P=A/'p04-idempotency-paid-midnight-prep-r01';assert not P.exists();P.mkdir();base=A/'p04-paid-shift-midnight-prep-r01/paid-shift-midnight.gd';s=base.read_text().replace('var _expected_daily_wages := 0','var _expected_daily_wages := 0\nvar _duplicate_results: Array[Dictionary] = []')
old='\t_expect(_cmd(&"create_service_request", {&"facility_id": _facility_id, &"request_id": _request_id, &"guest_ids": [_guest_id]}).is_success(), "actual request original price/duration")';assert old in s;s=s.replace(old,'\t_expect(_target_request().is_success(), "original public service request with explicit idempotency key")\n\t_assert_request_resend("queued-same-minute")')
old='\tvar paused: Dictionary = _runtime.create_snapshot()';s=s.replace(old,'\t_assert_request_resend("paused-00-01")\n'+old);old='\tvar after: Dictionary = _runtime.create_snapshot()';s=s.replace(old,'\t_assert_request_resend("completed-00-02")\n'+old)
pos=s.index('func _setup_paid_reception()');s=s[:pos]+'''func _target_request() -> CommandResult:
return _runtime.submit_command(&"create_service_request", {&"facility_id": _facility_id, &"request_id": _request_id, &"guest_ids": [_guest_id]}, &"player", &"", 10, -1, &"p04.same-minute.service.request")
func _assert_request_resend(label: String) -> void:
var before: Dictionary = _runtime.create_snapshot()
var result: CommandResult = _target_request()
_expect(result.code == CommandResult.Code.DUPLICATE_IDEMPOTENCY_KEY, "normal repeated processed request reports its original duplicate-key contract " + label)
var after: Dictionary = _runtime.create_snapshot()
_expect(var_to_bytes(before) == var_to_bytes(after), "same-minute request resend preserves all typed Runtime state " + label)
_write_var("duplicate-" + label + "-before", before)
_write_var("duplicate-" + label + "-after", after)
_duplicate_results.append({&"label": label, &"minute": _clock.absolute_minute, &"command_result": result.to_dictionary(), &"request_id": _request_id, &"idempotency_key": &"p04.same-minute.service.request"})
''' +s[pos:]
s=s.replace('&"first_summary": _first_summary,','&"first_summary": _first_summary, &"duplicate_results": _duplicate_results,');s=s.replace('P04-01 existing paid catalog DAY/NIGHT reception handover and real nonzero payroll with approved dependency closure across midnight','P04-01 same-minute public request resend before admission, during dependency pause and after completion, with paid catalog DAY/NIGHT handover and nonzero payroll across midnight');Q=P/'idempotency-paid-midnight.gd';Q.write_text(s)
w=(A/'p04-paid-shift-midnight-native-r01.py').read_text().replace('p04-paid-shift-midnight-native-r01','p04-idempotency-paid-midnight-native-r01').replace('p04-paid-shift-midnight-prep-r01','p04-idempotency-paid-midnight-prep-r01').replace('/paid-shift-midnight.gd','/idempotency-paid-midnight.gd').replace('P04-01 existing catalog paid DAY/NIGHT actors with actual nonzero payroll and dependency pause/resume across midnight on current source','P04-01 same-minute public service request resends with full typed state equality and existing paid catalog midnight/dependency scenario');W=A/'p04-idempotency-paid-midnight-native-r01.py';compile(w,str(W),'exec');W.write_text(w);shutil.copyfile(A/'p04-paid-shift-midnight-prep-r01/SOURCE_MAP.json',P/'SOURCE_MAP.json');floor=1024**3+Path('/Applications/Godot.app/Contents/MacOS/Godot').stat().st_size+136*1024**2;free=shutil.disk_usage(A).free;assert free>=floor;sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest();(P/'ADMISSION.json').write_text(json.dumps({'scope':'Root QA exact same-minute request replay contract; no product or worker edits; catalog values are observed test inputs','base_probe_sha256':sha(base),'probe_sha256':sha(Q),'wrapper_sha256':sha(W),'estimated_seconds':90,'free_before':free,'required_free':floor,'planned_native_phases':['import','parse','repro'],'original_acceptance_credit':0},indent=2)+'\n');print('idempotency probe prepared on preserved native pattern')