tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

shipped_compiler.py (3596B)


      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.v2'
     20     assert metadata['io_version'] == 2
     21     assert metadata['backend'] == 'stable'
     22     for path, digest in [(metadata['bundle'], metadata['sha256']),
     23                          (metadata['source_map'], metadata['source_map_sha256'])] + [
     24                              (row['snapshot'], row['sha256']) for row in metadata['sources']]:
     25         assert hashlib.sha256((root / path).read_bytes()).hexdigest() == digest, path
     26     rows = verify_fixtures(root / 'test/fixtures')
     27     recorded = {row['alias']: row for row in metadata['sources']}
     28     compiler_rows = [row for row in rows if row[0] == 'compiler-library']
     29     assert set(recorded) == {row[2] for row in compiler_rows}
     30     for _, _, alias, path, pin in compiler_rows:
     31         assert recorded[alias]['path'] == path
     32         assert recorded[alias]['snapshot'] == 'test/fixtures/reference-source/' + pin + '.tri'
     33     for line in (root / metadata['source_map']).read_text().splitlines()[1:]:
     34         _, alias, _, path, _ = line.split('\t')
     35         assert recorded[alias]['path'] == path
     36     interner = Intern()
     37     _, _, nodes, exports, _ = read(root / metadata['bundle'])
     38     assert set(exports) == {metadata['export']}
     39     shipped = interner.graph(nodes)[exports[metadata['export']]]
     40     _, _, nodes, exports, _ = read(root / 'test/fixtures/compiler-library.arboricx')
     41     published = interner.graph(nodes)[exports[metadata['published_fixture_export']]]
     42     assert shipped == published, 'shipped stable builder differs from published accepted tree'
     43     raw, _, _ = load_kit(root / 'bootstrap/rebuild', 'stable')
     44     kit = json.loads(raw)
     45     assert kit['schema'] == 'tricu.bootstrap-kit.v2' and kit['io_version'] == 2
     46     assert kit['accepted_source'] == metadata['accepted_source']
     47     assert kit['source_map_sha256'] == metadata['source_map_sha256']
     48     # Acceptance summaries must describe these bytes, not an older publication.
     49     acceptance = metadata['acceptance']
     50     assert acceptance['fresh_generations'] == 2
     51     assert acceptance['matching_manifests'] == len(compiler_rows)
     52     assert acceptance['matching_bundle_sha256'] == metadata['sha256']
     53     assert acceptance['matching_artifacts']['build-stable.arboricx'] == metadata['sha256']
     54     assert acceptance['matching_artifacts']['rebuilt-compiler.arboricx'] == kit['artifacts']['compiler']['sha256']
     55     _, _, kit_nodes, kit_exports, _ = read(root / 'bootstrap/rebuild/rebuilt-compiler.arboricx')
     56     assert set(kit_exports) == {'sourceMapBuildStable'}
     57     assert interner.graph(kit_nodes)[kit_exports['sourceMapBuildStable']] == interner.graph(nodes)[exports['source_map.sourceMapBuildStable']]
     58     _, _, _, adapter_exports, _ = read(root / 'bootstrap/rebuild/io-adapter.arboricx')
     59     assert set(adapter_exports) == {'main'}
     60     return metadata
     61 
     62 
     63 if __name__ == '__main__':
     64     verify()
     65     print('Shipped stable compiler: bytes, source snapshots, and published executable trees and rebuild kit verified.')