tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

shipped_compiler.py (3477B)


      1 #!/usr/bin/env python3
      2 """Verify shipped bytes/snapshots and exact DAG equality to the published compiler.
      3 
      4 No Git history, compilation, tree expansion or generation. This checks a retained
      5 acceptance record, not a new proof of compiler correctness or publisher identity.
      6 """
      7 import hashlib
      8 import json
      9 from pathlib import Path
     10 from bundle_dag import read, Intern
     11 from fixture_sources import verify as verify_fixtures
     12 from bootstrap_inputs import load_kit
     13 
     14 ROOT = Path(__file__).resolve().parent.parent
     15 
     16 
     17 def verify(root=ROOT):
     18     metadata = json.loads((root / 'bootstrap/stable-compiler.json').read_text())
     19     assert metadata['schema'] == 'tricu.shipped-stable-compiler.v1'
     20     assert metadata['backend'] == 'stable'
     21     for path, digest in [(metadata['bundle'], metadata['sha256']),
     22                          (metadata['source_map'], metadata['source_map_sha256'])] + [
     23                              (row['snapshot'], row['sha256']) for row in metadata['sources']]:
     24         assert hashlib.sha256((root / path).read_bytes()).hexdigest() == digest, path
     25     rows = verify_fixtures(root / 'test/fixtures')
     26     recorded = {row['alias']: row for row in metadata['sources']}
     27     compiler_rows = [row for row in rows if row[0] == 'compiler-library']
     28     assert set(recorded) == {row[2] for row in compiler_rows}
     29     for _, _, alias, path, pin in compiler_rows:
     30         assert recorded[alias]['path'] == path
     31         assert recorded[alias]['snapshot'] == 'test/fixtures/reference-source/' + pin + '.tri'
     32     for line in (root / metadata['source_map']).read_text().splitlines()[1:]:
     33         _, alias, _, path, _ = line.split('\t')
     34         assert recorded[alias]['path'] == path
     35     interner = Intern()
     36     _, _, nodes, exports, _ = read(root / metadata['bundle'])
     37     assert set(exports) == {metadata['export']}
     38     shipped = interner.graph(nodes)[exports[metadata['export']]]
     39     _, _, nodes, exports, _ = read(root / 'test/fixtures/compiler-library.arboricx')
     40     published = interner.graph(nodes)[exports[metadata['published_fixture_export']]]
     41     assert shipped == published, 'shipped stable builder differs from published accepted tree'
     42     raw, _, _ = load_kit(root / 'bootstrap/rebuild', 'stable')
     43     kit = json.loads(raw)
     44     assert kit['accepted_source'] == metadata['accepted_source']
     45     assert kit['source_map_sha256'] == metadata['source_map_sha256']
     46     # Acceptance summaries must describe these bytes, not an older publication.
     47     acceptance = metadata['acceptance']
     48     assert acceptance['fresh_generations'] == 2
     49     assert acceptance['matching_manifests'] == len(compiler_rows)
     50     assert acceptance['matching_bundle_sha256'] == metadata['sha256']
     51     assert acceptance['matching_artifacts']['build-stable.arboricx'] == metadata['sha256']
     52     assert acceptance['matching_artifacts']['rebuilt-compiler.arboricx'] == kit['artifacts']['compiler']['sha256']
     53     _, _, kit_nodes, kit_exports, _ = read(root / 'bootstrap/rebuild/rebuilt-compiler.arboricx')
     54     assert set(kit_exports) == {'sourceMapBuildStable'}
     55     assert interner.graph(kit_nodes)[kit_exports['sourceMapBuildStable']] == interner.graph(nodes)[exports['source_map.sourceMapBuildStable']]
     56     _, _, _, adapter_exports, _ = read(root / 'bootstrap/rebuild/io-adapter.arboricx')
     57     assert set(adapter_exports) == {'main'}
     58     return metadata
     59 
     60 
     61 if __name__ == '__main__':
     62     verify()
     63     print('Shipped stable compiler: bytes, source snapshots, and published executable trees and rebuild kit verified.')