#!/usr/bin/env python3
from pathlib import Path
import hashlib, json, platform, sys

HERE = Path(__file__).resolve().parent
root = HERE / 'workspace'
if not (root / '.tol001-owned').exists():
    raise SystemExit('Run setup_fixture.py first')

workspace_file = root / 'workspace.json'
workspace_bytes = workspace_file.read_bytes()
workspace = json.loads(workspace_bytes.decode('utf-8'))

environment_identity = {
    'python_implementation': platform.python_implementation(),
    'python_version': platform.python_version(),
    'resolved_executable': str(Path(sys.executable).resolve()),
    'platform_system': platform.system(),
    'platform_machine': platform.machine(),
    'fixture_schema': workspace.get('schema', 'UNKNOWN'),
    'workspace_declaration_sha256': hashlib.sha256(workspace_bytes).hexdigest(),
}
observation_boundary = {
    'inspection_mode': 'STATIC_DECLARATION_MANIFEST_CONFIG_INSPECTION',
    'build_or_install_executed': False,
    'observed_build_state': 'UNKNOWN_NOT_OBSERVED',
    'claim_boundary': 'Architecture declaration evidence only; no build/reproducibility claim.',
}
print(json.dumps({'environment_identity': environment_identity}, ensure_ascii=False, indent=2))
print(json.dumps({'observation_boundary': observation_boundary}, ensure_ascii=False, indent=2))
print(json.dumps({'workspace_declaration': workspace}, ensure_ascii=False, indent=2))
for p in sorted(root.rglob('package.json')):
    print(json.dumps({'manifest_path': str(p.relative_to(root)), 'manifest': json.load(open(p, encoding='utf-8'))}, ensure_ascii=False, indent=2))
for p in sorted(root.rglob('*.policy.json')):
    print(json.dumps({'config_path': str(p.relative_to(root)), 'config': json.load(open(p, encoding='utf-8'))}, ensure_ascii=False, indent=2))
