from __future__ import annotations
import importlib.util
from pathlib import Path
ROOT=Path(__file__).resolve().parent
spec=importlib.util.spec_from_file_location('controller_v7',ROOT/'launch_controller_v7.py')
assert spec and spec.loader
c=importlib.util.module_from_spec(spec);spec.loader.exec_module(c)
def test_exact_actual_profile_preflight_is_read_only():
 before=c.tree_snapshot(c.PROFILE); proof=c.exact_profile_preflight_proof(); after=c.tree_snapshot(c.PROFILE)
 assert before==after
 assert proof['status']=='PASS_READ_ONLY'
 assert proof['config_mode']==proof['env_mode']=='0600'
 assert proof['credential_resolved'] is True and proof['credential_output'] is False
 assert proof['sessions_absent'] is True and proof['authority_tree_mutations']==0
def test_0664_fixture_fails_closed_exactly():
 proof=c.mode_0664_fixture_proof()
 assert proof=={'status':'PASS_FAIL_CLOSED','mode':'0664','exception':'GatewayPreflightError','reason':'untrusted profile input: config.yaml','reason_code':'UNTRUSTED_PROFILE_INPUT_CONFIG_YAML','credential_output':False}
def test_v7_never_calls_mutating_gateway_loader():
 text=(ROOT/'launch_controller_v7.py').read_text()
 assert 'load_gateway_'+'config' not in text
 assert 'load_gateway_preflight_inputs' in text
def test_v7_permission_is_fresh_and_binds_incident():
 text=(ROOT/'launch_controller_v7.py').read_text()
 assert 'AUTHORIZED_ONE_USE_V7' in text
 assert 'AUTHORIZED_ONE_USE_V6' not in text
 assert 'b2df5bb3a8c553bb785247b86fa7b96e0633025c598123458d19684b3bafa564' in text
