interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / json / tests / consumers.py

131 lines · 7465 bytes Raw Blame History
1#!/usr/bin/env python3
2# Test instrument: compile concrete JSON compositions documented by the repository, not runtime
3# replacements. --base compares the base tree with the candidate; newer test-only applications
4# absent at that base are held identical while their JSON library inputs come from each tree.
5import argparse
6import hashlib
7import json
8import re
9from pathlib import Path
10import subprocess
11import sys
12sys.dont_write_bytecode=True
13import field
14
15
16def require(ok, message):
17 if not ok:
18 raise RuntimeError(message)
19
20p=argparse.ArgumentParser()
21p.add_argument('omc');p.add_argument('out');p.add_argument('--base')
22p.add_argument('--wrong-expectation',action='store_true')
23a=p.parse_args()
24root=Path(__file__).resolve().parents[3]
25out=Path(a.out).resolve();out.mkdir(parents=True,exist_ok=True)
26omc=str(Path(a.omc).resolve())
27head=subprocess.check_output(['git','-C',str(root),'rev-parse','HEAD'],text=True).strip()
28base=subprocess.check_output(['git','-C',str(root),'rev-parse',a.base],text=True).strip() if a.base else None
29J='seed/json/'
30N='seed/node/'
31D=N+'tests/'
32H='seed/net/'
33common=[J+'json.om',D+'drv.om']
34node=common+[D+'nodedrv.om']
35lib=[J+'json.om',J+'jsonw.om',J+'jsonf.om']
36main='fn main to int\nret 0\nend\n'
37# The input lists are acceptance cases, each linked to an actual documented build command.
38# Aliased D in the Node README is expanded from that README, rather than inferred from names.
39node_readme=(root/N/'README.md').read_text()
40require('D="'+ ' '.join(node)+'"' in node_readme,'documented Node D composition changed')
41cases=[]
42def add(name, paths, citation, om2=True, suffix=''):
43 document=(root/citation).read_text()
44 require(all(path in document for path in paths) or citation=='seed/json/tests/field.py',
45 'composition citation missing an input: '+name)
46 cases.append(dict(name=name,paths=paths,citation=citation,om2=om2,suffix=suffix))
47
48add('bench-chat',[J+'json.om',J+'jsonw.om','bench/inference_cost/chat.om'],'bench/inference_cost/chat.om')
49add('bench-fake-model',[J+'json.om',J+'jsonw.om',H+'http.om',H+'notls.om','bench/inference_cost/fake_model.om'],'bench/inference_cost/fake_model.om')
50add('agent',[J+'json.om',J+'jsonw.om',H+'http.om',H+'notls.om','seed/agent/path.om','seed/agent/agent.om'],'seed/agent/README.md')
51for name,paths in [
52 ('infer',[J+'json.om',J+'jsonw.om',H+'http.om',H+'notls.om',N+'infer.om']),
53 ('tool-replay',common+[D+'tool-replay.om']),('drv-test',common+[D+'drv-test.om']),
54 ('qual',['om/tls/sha2.om']+common+[D+'qual.om']),
55 ('receipt',[J+'json.om',J+'jsonw.om','om/tls/sha2.om',D+'drv.om',D+'receipt.om']),
56 ('live-test',[J+'json.om','om/tls/sha2.om',N+'live-test.om']),
57 ('view-prep',node+[D+'view-prep.om']),('view-accept',node+[D+'view-accept.om']),
58 ('release-accept',['om/tls/sha2.om']+node+[D+'release-accept.om']),
59 ('release-gate',common+[D+'release-gate.om']),
60]:
61 add('node-'+name,paths,'seed/node/README.md')
62add('node-schedrcpt',[N+'schedrcpt.om',J+'json.om'],'seed/node/README.md',om2=False)
63# Gate compositions use aliases J/$1; their exact source clauses supply provenance.
64for name,paths,suffix,clause in [
65 ('json-lib',lib,main,'cat "$J/json.om" "$J/jsonw.om" "$J/jsonf.om"'),
66 ('json-driver',lib+[J+'tests/jsdrv.om'],'','"$J/tests/jsdrv.om"'),
67]:
68 doc=(root/'seed/json/tests/gate-json.sh').read_text()
69 require(clause in doc,'JSON gate composition changed: '+name)
70 cases.append(dict(name=name,paths=paths,citation='seed/json/tests/gate-json.sh',om2=True,suffix=suffix))
71doc=(root/'seed/semhash/check.sh').read_text()
72require('cat "$J/json.om" "$J/jsonw.om";' in doc,'semhash no-float composition changed')
73cases.append(dict(name='json-nof',paths=lib[:2],citation='seed/semhash/check.sh',om2=True,suffix=main))
74doc=(root/'seed/json/tests/growing.py').read_text()
75require("units={u:(j/u).read_text() for u in ('json.om','jsonw.om','jsonf.om')}" in doc,'growth composition changed')
76cases.append(dict(name='json-big',paths=lib+[J+'tests/big.om'],citation='seed/json/tests/growing.py',om2=True,suffix=''))
77for name,wrapper in field.WRAPPERS.items():
78 cases.append(dict(name='field-'+name,paths=lib,citation='seed/json/tests/field.py',om2=True,suffix=wrapper))
79
80cache={}
81fallbacks=[]
82def text(path, ref):
83 key=(path,ref)
84 if key in cache:
85 return cache[key]
86 if ref is None:
87 result=(root/path).read_text()
88 else:
89 r=subprocess.run(['git','-C',str(root),'show',ref+':'+path],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
90 if r.returncode:
91 require(path in (J+'tests/big.om',),'base lacks a non-test composition input: '+path)
92 result=(root/path).read_text()
93 fallbacks.append(path)
94 else:
95 result=r.stdout.decode()
96 cache[key]=result
97 return result
98
99results=[]
100for case in cases:
101 statuses=[]
102 for label,ref in ([('base',base)] if base else [])+[('head',None)]:
103 program=('om2\n' if case['om2'] else '')+''.join(text(path,ref) for path in case['paths'])+case['suffix']
104 path=out/(case['name']+'-'+label)
105 path.with_suffix('.om').write_text(program)
106 r=subprocess.run([omc],input=program.encode(),stdout=subprocess.PIPE,stderr=subprocess.PIPE,timeout=120)
107 path.write_bytes(r.stdout)
108 path.with_suffix('.err').write_bytes(r.stderr)
109 statuses.append(r.returncode)
110 results.append(dict(name=case['name'],tree=label,exit=r.returncode,input_sha256=hashlib.sha256(program.encode()).hexdigest(),citation=case['citation'],paths=case['paths']))
111 expected=23 if a.wrong_expectation and case['name']=='bench-chat' else 0
112 require(all(status==expected for status in statuses) and len(set(statuses))==1,
113 'composition expectation mismatch: '+case['name']+' '+repr(statuses))
114 print('PASS composition/'+case['name']+' statuses='+','.join(map(str,statuses)),flush=True)
115# A library-sized buffer-type regression must be a compile refusal, not a passing parity record.
116for case in [c for c in cases if c['name'] in ('node-view-prep','node-view-accept','node-release-accept')]:
117 sources=[]
118 for path in case['paths']:
119 value=text(path,None)
120 if path==D+'nodedrv.om':
121 declaration=re.findall(r'^const ndjsz ulong [0-9]+$',value,re.M)
122 require(len(declaration)==1,'Node width declaration is not unique')
123 library_width=re.findall(r'^const jsmaxn ulong ([0-9]+)$',text(J+'json.om',None),re.M)
124 require(len(library_width)==1,'library width declaration is not unique')
125 value=value.replace(declaration[0],'const ndjsz ulong '+library_width[0])
126 sources.append(value)
127 r=subprocess.run([omc],input=('om2\n'+''.join(sources)).encode(),stdout=subprocess.DEVNULL,stderr=subprocess.PIPE,timeout=120)
128 require(r.returncode==23,(case['name'],'width mutant not refused',r.returncode,r.stderr))
129 print('PASS composition/'+case['name']+' width-mutant=23',flush=True)
130(out/'manifest.json').write_text(json.dumps(dict(head=head,base=base,cases=cases,results=results,base_application_fallbacks=sorted(set(fallbacks)),excluded_templates=["seed/json/README.md app.om is a placeholder, not a repository program","seed/net/README.md optional JSON addition is not a concrete additional program","seed/text and seed/equiv mention copied routines, not JSON composition"]),indent=2)+'\n')
131print('CONSUMERS PASS compositions='+str(len(cases))+' base='+str(base)+' head='+head+' width-mutants=3',flush=True)