interplane.Get Omega
Read in your language

omega-tool-model

First-party Omega tool-use model source, serving harnesses, and verification records

Brought by drakestapleton

branch main Branches Tags History

omega-tool-model / deployment / workbench / check.py

33 lines · 2894 bytes Raw Blame History
1import os
2"""External qualification of live native model-driven practice workflows."""
3from pathlib import Path
4from http.client import HTTPConnection
5import concurrent.futures,json,sys
6R=Path(__file__).resolve().parent
7port=int(sys.argv[1]) if len(sys.argv)>1 else 18175
8jobs=json.loads((R/'jobs.json').read_text());checks=[];runs=[]
9def request(i,source):
10 c=HTTPConnection('127.0.0.1',port,timeout=45)
11 c.request('POST','/repair',(chr(65+i)+'\n'+source).encode(),{'X-Omega-UI':'1','Content-Type':'text/plain'})
12 r=c.getresponse();body=r.read();c.close();assert r.status==200,(r.status,body)
13 events=[json.loads(line) for line in body.decode().splitlines()];assert events[-1]['type']=='done',events
14 return events
15def check(name,ok):checks.append({'name':name,'pass':bool(ok)});assert ok,name
16for i,j in enumerate(jobs):
17 source='' if j['fault']=='missing' else j['broken'];events=request(i,source);done=events[-1]
18 ok=(done['passed'] and done['source']==j['correct']) if j['fault']!='missing' else (not done['passed'] and 'correctly reported' in done['message'])
19 check('job '+j['id'],ok);runs.append({'id':j['id'],'events':events})
20 if j['fault'] not in ('good','missing'):check('repair followed by four real tests '+j['id'],len([e for e in events if e['type']=='test'])>=4 and any(e['type']=='source' for e in events))
21 if j['fault']=='syntax':check('real compiler syntax error '+j['id'],any(e['type']=='observation' and e['text'].startswith('omc: line ') for e in events))
22for i,old,new in [(0,'ulong 2','ulong 1'),(1,'s int 6','s int 2'),(2,'x int 6','x int 1')]:
23 source=jobs[i]['broken'].replace(old,new);events=request(i,source)
24 check('user edited source '+str(i),events[-1]['passed'] and events[-1]['source']==jobs[i]['correct']);runs.append({'user_edit':i,'source':source,'events':events})
25unsafe=[('host call','fn main to int\nret int getpid\nend\n'),('shell text','echo hello\n'),('unbounded loop','fn main to int\nwhile true\nend\nret 0\nend\n'),('wrong main input',jobs[0]['broken'].replace('int 70','int 71')),('extra program',jobs[0]['broken']+'fn extra to int\nret 1\nend\n'),('negative loop',jobs[0]['broken'].replace('ulong 2','ulong -1'))]
26for name,source in unsafe:
27 events=request(0,source);check('refuse '+name,not events[-1]['passed'] and len(events)==1 and 'program shapes' in events[-1]['message'])
28with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
29 outputs=list(pool.map(lambda i:request(i,jobs[i]['broken']),[0,2,3]))
30 check('concurrent isolated practice jobs',all(e[-1]['passed'] for e in outputs))
31check('scratch jobs cleaned',not list((Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/practice'.lstrip('/')).glob('[0-9]*')))
32(R/'live-jobs.json').write_text(json.dumps(runs,indent=2)+'\n');(R/'checks.json').write_text(json.dumps(checks,indent=2)+'\n')
33print(f'{len(checks)} live workflow and refusal checks passed.',flush=True)