tricu

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

io_v2_native_cli.py (4459B)


      1 #!/usr/bin/env python3
      2 """Actual production Zig boundary; private probes are not execution substitutes."""
      3 import argparse,json,hashlib,subprocess
      4 from pathlib import Path
      5 from source_order import Runner
      6 from bundle_dag import merge_bundles
      7 ROOT=Path(__file__).resolve().parent.parent
      8 
      9 def main():
     10     p=argparse.ArgumentParser(description=__doc__)
     11     p.add_argument('tricu',type=Path);p.add_argument('zig',type=Path);p.add_argument('--directory',type=Path,required=True)
     12     p.add_argument('--compiler-bundle',type=Path,help='also run an explicit v2 sourceBuildGraph worker through the production CLI')
     13     args=p.parse_args();d=args.directory.resolve();d.mkdir(parents=True,exist_ok=False)
     14     runner=Runner(args.tricu,d);bundle=d/'controls.arboricx'
     15     runner.run('compile',['compile','--file',ROOT/'test/io-v2/native-cli.tri','--store',runner.store,'--output',bundle])
     16     checks=[]
     17     def run(name,values=(),flags=(),expected=None,error=None):
     18         selected=d/(name+'.arboricx')
     19         merge_bundles(selected,[(bundle,[(name,'main')])],prune_unreachable=True)
     20         command=[str(args.zig.resolve()),'--io','--type','number',*flags,str(selected),*values]
     21         out=subprocess.run(command,capture_output=True,text=True,timeout=30)
     22         (d/(str(len(checks))+'-'+name+'.log')).write_text(out.stdout+out.stderr)
     23         if error:
     24             assert out.returncode!=0 and error in out.stderr,(command,out.stdout,out.stderr)
     25         else:
     26             assert out.returncode==0 and out.stdout==str(expected)+'\n',(command,out.stdout,out.stderr)
     27         checks.append(dict(name=name,command=command,returncode=out.returncode))
     28     for name,expected in [('pure',42),('unsupported',1),('inspect',1),('capabilities',1),('groups',1)]:run(name,['0'] if name in ['unsupported','inspect'] else [],expected=expected)
     29     run('legacy',error='UnsupportedIOVersion')
     30     run('legacy',flags=['--unsafe-io'],error='RetiredIOGrants')
     31     path=d/'output-λ😀.bin';run('write',['text:'+str(path)],expected=3)
     32     assert path.read_bytes()==bytes([0,255,65])
     33     denied=d/'must-not-exist'
     34     run('write',['text:'+str(denied)],['--unsafe-io'],error='RetiredIOGrants')
     35     assert not denied.exists()
     36     run('divergent',['0'],['--unsafe-io'],error='RetiredIOGrants')
     37     run('future',['0'],error='UnsupportedIOVersion')
     38     run('failed',['0'],error='IOV2Failed');run('cancelled',['0'],error='IOV2Cancelled')
     39     if args.compiler_bundle:
     40         worker=d/'worker.arboricx'
     41         merge_bundles(worker,[(args.compiler_bundle,[('sourceBuildGraph','main')])],prune_unreachable=True)
     42         selected=d/'compile.arboricx'
     43         merge_bundles(selected,[(bundle,[('compile','main')])],prune_unreachable=True)
     44         workspace=d/'workspace-λ';workspace.mkdir()
     45         (workspace/'dependency.tri').write_text('!export pick\npick [x | _] = x\npick _ = 0\n')
     46         (workspace/'main.tri').write_text('!import dependency as D\n!export main\n!export accent\nmain = D.pick [42 7]\naccent = "é"\n')
     47         store=d/'compiled';store.mkdir()
     48         identity=hashlib.sha256(args.compiler_bundle.read_bytes()).hexdigest()
     49         for label in ['cold','warm']:
     50             command=[str(args.zig.resolve()),'--io','--type','string',str(selected),str(worker),
     51                 'text:'+str(workspace),'text:'+str(store),'text:'+identity,'text:main']
     52             out=subprocess.run(command,capture_output=True,text=True,timeout=600)
     53             (d/('compiler-'+label+'.log')).write_text(out.stdout+out.stderr)
     54             manifest=out.stdout.strip()
     55             assert out.returncode==0 and len(manifest)==64 and all(c in '0123456789abcdef' for c in manifest),(out.stdout,out.stderr)
     56             from http_headers import number,tree_list
     57             old_store=runner.store;runner.store=store
     58             try:
     59                 assert runner.invoke('compiler-main-'+label,manifest,'main',[])==number(42)
     60                 assert runner.invoke('compiler-accent-'+label,manifest,'accent',[])==tree_list([number(101),number(769)])
     61             finally: runner.store=old_store
     62             checks.append(dict(name='compiler-'+label,command=command,manifest=manifest,compiler_sha256=identity))
     63         assert not list(store.rglob('.tricu-*'))
     64     (d/'report.json').write_text(json.dumps(dict(checks=checks,zig_sha256=hashlib.sha256(args.zig.read_bytes()).hexdigest()),indent=2)+'\n')
     65     print(f'PASS {len(checks)} production Zig v2 and retired-v1 CLI controls')
     66 if __name__=='__main__':main()