Preserve production code, regression fixtures, audio assets and provenance, test infrastructure, and the original-completion plan and progress ledger. Final game and Windows acceptance remain pending; excluded local artifacts and native experiments are not part of this snapshot.
119 lines
9.0 KiB
Python
119 lines
9.0 KiB
Python
"""Strict proof gates. Synthetic self tests never count as engine evidence."""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import math
|
|
|
|
CASES = {'paused_success_exact_once', 'actual_duplicate_refusal', 'actual_public_authority_replay_silent', 'actual_noop_silent', 'two_actual_enqueue_validation_refusals', 'two_actual_empty_executor_refusals'}
|
|
PAIRED = {'paused_success_exact_once', 'actual_public_authority_replay_silent', 'two_actual_empty_executor_refusals'}
|
|
TEARDOWN_TESTS = {'tests/ui/test_ui_audio_feedback.gd', 'tests/ui/test_main_dashboard.gd', 'tests/ui/test_supply_management.gd', 'tests/ui/test_business_management.gd', 'tests/ui/test_elevator_management.gd'}
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def pin_file(pin, directory):
|
|
path = Path(pin['path'])
|
|
assert path.parent == directory and path.is_file() and not path.is_symlink()
|
|
assert sha(path) == pin['sha256'] and path.stat().st_size == pin['bytes'] > 0
|
|
assert pin['field_deletions'] == 0
|
|
return path, {'sha256': sha(path), 'bytes': path.stat().st_size}
|
|
|
|
|
|
def dto_tree(value):
|
|
if isinstance(value, dict):
|
|
if {'code', 'command_id', 'is_replay'} <= set(value):
|
|
assert set(value) == {'code', 'command_id', 'details', 'is_replay', 'message', 'resolution_hints', 'target_id'}
|
|
assert isinstance(value['is_replay'], bool) and isinstance(value['command_id'], int)
|
|
for item in value.values(): dto_tree(item)
|
|
elif isinstance(value, list):
|
|
for item in value: dto_tree(item)
|
|
|
|
|
|
def command_gate(proof_path, out, pid):
|
|
proof = json.loads(proof_path.read_text())
|
|
dto_tree(proof)
|
|
assert proof['Godot_pid'] == pid
|
|
assert proof['gameplay_snapshot_field_deletions'] == 0 and proof['buffer_CommandResult_objects_recorded_as_full_DTO'] is True
|
|
assert proof['source_fallback'] is False and proof['formal_P22_P25_acceptance'] is False
|
|
cases = {case['case']: case for case in proof['cases']}
|
|
assert len(cases) == len(proof['cases']) == 6 and set(cases) == CASES
|
|
pins = {}
|
|
for name, case in cases.items():
|
|
assert set(case['snapshots']) == ({'before', 'after', 'direct_control'} if name in PAIRED else {'before', 'after'})
|
|
for part, pin in case['snapshots'].items():
|
|
assert pin['full_gameplay_dictionary'] is True
|
|
path, digest = pin_file(pin, out / 'actual-command-result-buffer-proof-typed')
|
|
assert path.name == name + '-' + part + '.varbytes'
|
|
pins[str(path.relative_to(out))] = digest
|
|
if name in PAIRED:
|
|
assert case['extra']['direct_control_pair_verified'] is True
|
|
assert case['snapshots']['after']['sha256'] == case['snapshots']['direct_control']['sha256']
|
|
success = cases['paused_success_exact_once']; duplicate = cases['actual_duplicate_refusal']
|
|
replay = cases['actual_public_authority_replay_silent']; noop = cases['actual_noop_silent']
|
|
invalid = cases['two_actual_enqueue_validation_refusals']; empty = cases['two_actual_empty_executor_refusals']
|
|
assert success['returned_result']['code'] == 'OK' and success['returned_result']['is_replay'] is False and success['cues'] == ['success']
|
|
assert duplicate['returned_result']['code'] == 'DUPLICATE_IDEMPOTENCY_KEY' and duplicate['returned_result']['is_replay'] is False and duplicate['cues'] == ['refusal']
|
|
assert duplicate['snapshots']['before']['sha256'] == duplicate['snapshots']['after']['sha256']
|
|
assert replay['returned_result']['code'] == 'OK' and replay['returned_result']['is_replay'] is True and replay['cues'] == []
|
|
assert replay['after_audio_state']['armed'] == {} and replay['after_audio_state']['active_submissions'] == []
|
|
assert replay['extra']['public_command_type'] == 'report_authority_incident' and replay['extra']['fabricated_result_fields'] == 0
|
|
assert replay['extra']['setup_result']['code'] == 'OK' and replay['extra']['setup_result']['is_replay'] is False
|
|
assert replay['extra']['observed_queue_replay_copy']['code'] == 'OK' and replay['extra']['observed_queue_replay_copy']['is_replay'] is True
|
|
assert replay['extra']['stored_result'] == replay['returned_result'] == replay['extra']['direct_control_result']
|
|
completions = [event for event in replay['events'] if event['kind'] == 'command_completed']
|
|
assert len(completions) == 1 and completions[0]['result'] == replay['returned_result'] and len(completions[0]['audio_state']['active_submissions']) == 1
|
|
assert noop['returned_result']['code'] == 'OK' and noop['returned_result']['is_replay'] is False and noop['returned_result']['details']['unchanged'] is True and noop['cues'] == []
|
|
for case in (invalid, empty):
|
|
assert case['returned_result']['code'] == case['extra']['first_result']['code'] == 'INVALID_COMMAND'
|
|
assert case['returned_result']['is_replay'] is False and case['extra']['first_result']['is_replay'] is False and case['cues'] == ['refusal', 'refusal']
|
|
assert invalid['extra']['command_type'] == 'audio_test_ok' and 0 <= invalid['extra']['execute_at'] < invalid['extra']['issued_tick']
|
|
assert invalid['returned_result']['command_id'] == invalid['extra']['first_result']['command_id']
|
|
assert not [event for event in invalid['events'] if event['kind'] == 'command_completed']
|
|
assert invalid['snapshots']['before']['sha256'] == invalid['snapshots']['after']['sha256']
|
|
assert empty['extra']['command_type'] == '' and empty['returned_result']['command_id'] == empty['extra']['first_result']['command_id'] + 1
|
|
assert empty['snapshots']['before']['sha256'] != empty['snapshots']['after']['sha256']
|
|
assert empty['extra']['direct_control_first_result'] == empty['extra']['first_result'] and empty['extra']['direct_control_second_result'] == empty['returned_result']
|
|
completions = [event for event in empty['events'] if event['kind'] == 'command_completed']
|
|
assert len(completions) == 2 and [event['result'] for event in completions] == [empty['extra']['first_result'], empty['returned_result']]
|
|
assert len(pins) == 15
|
|
return {'verified': True, 'report_sha256': sha(proof_path), 'full_typed_snapshot_files': pins}
|
|
|
|
|
|
def teardown_gate(directory, pid, out):
|
|
paths = sorted(directory.glob('owner_*.json'))
|
|
assert len(paths) == 1
|
|
proof_path = paths[0]; proof = json.loads(proof_path.read_text())
|
|
assert proof['owned_engine_pid'] == pid and proof['owner_instance_id'] > 0 and proof['passed'] is True
|
|
assert proof['maximum_wait_us'] == 500000 and 0 < proof['waited_actual_us'] < 500000 and proof['deadline_reached'] is False
|
|
assert proof['owner_freed'] is True and proof['all_owned_targets_released'] is True and proof['whole_runtime_unchanged'] is True
|
|
assert proof['bus_deleted'] is False and proof['cues_muted_for_test'] is False and proof['actual_human_hearing'] is False and proof['WindowQuit_verified'] is False and proof['formal_acceptance'] is False
|
|
assert len(proof['initial_targets']) == len(proof['final_targets']) >= 8
|
|
assert all(row['alive'] is True for row in proof['initial_targets']) and all(row['alive'] is False for row in proof['final_targets'])
|
|
for kind in ('stream', 'packet_sequence'):
|
|
assert {row['role'] for row in proof['initial_targets'] if row['kind'] == kind} == {'click', 'success', 'refusal', 'notification'}
|
|
pins = {}
|
|
assert set(proof['full_typed_snapshots']) == {'before', 'after'}
|
|
for part, pin in proof['full_typed_snapshots'].items():
|
|
path, digest = pin_file(pin, directory)
|
|
assert path.name == proof_path.stem + '-' + part + '.varbytes'
|
|
pins[str(path.relative_to(out))] = digest
|
|
assert proof['full_typed_snapshots']['before']['sha256'] == proof['full_typed_snapshots']['after']['sha256']
|
|
assert set(directory.iterdir()) == {proof_path, *(Path(pin['path']) for pin in proof['full_typed_snapshots'].values())}
|
|
return {'verified': True, 'report_sha256': sha(proof_path), 'waited_actual_us': proof['waited_actual_us'], 'deadline_reached': False, 'full_typed_snapshot_files': pins}
|
|
|
|
|
|
def ogg_gate(proof_path, pid, overlay):
|
|
proof = json.loads(proof_path.read_text())
|
|
assert proof['Godot_pid'] == pid and proof['human_hearing_verified'] is False and proof['native_Windows'] == 'pending'
|
|
roles = {'click': 'click_001.ogg', 'success': 'confirmation_001.ogg', 'refusal': 'error_008.ogg', 'notification': 'bong_001.ogg'}
|
|
rows = {row['role']: row for row in proof['rows']}
|
|
assert len(rows) == len(proof['rows']) == 4 and set(rows) == set(roles)
|
|
for role, row in rows.items():
|
|
assert row['encoded_source_sha256'] == overlay['assets/audio/ui/' + roles[role]] and row['class'] == 'AudioStreamOggVorbis'
|
|
assert row['mix_rate'] > 0 and 0 < row['mixed_frames'] <= row['mix_rate'] * 2 and row['stream_seconds'] > 0
|
|
assert row['finite'] is True and math.isfinite(row['sample_peak']) and 0 < row['sample_peak'] < 1
|
|
assert row['one_shot_ended'] is True and row['player_playing_after_request'] is True and row['player_stopped_on_loaded_epoch'] is True
|
|
return {'verified': True, 'report_sha256': sha(proof_path), 'actual_roles': sorted(rows), 'audio_driver': proof['audio_driver'], 'human_hearing_verified': False, 'native_Windows': 'pending'}
|