Files
ARCADIA-Studio/harness/experiments/text-diagnostics-20260913/native-preparation/candidate-oracle.py
T
sorokin.oleg.edu 9fd76aef3a Add current-draft diagnostic underlines and passive hover
Preserve raw include diagnostic provenance and derive bands from the existing shaped editor. Retain deferred tooltip paragraphs through rendering. Include source, regression, failure and native-trial evidence; corrected native acceptance remains pending.
2026-09-13 01:43:22 -07:00

101 lines
6.0 KiB
Python

"""Prepared saved syntax-variant oracle; not a GUI or unsaved-model evaluator."""
from pathlib import Path
import argparse, hashlib, importlib.util, json, os, re, shutil, subprocess, sys
BASE = Path(__file__).resolve().parent
CORE_SHA = '6491786c2d4752ffa7718d99e3eb9e3f068eb78e3b96917bffc37c8ed47a0c1a'
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--oracle-result', required=True)
ap.add_argument('--oracle-sha', required=True)
ap.add_argument('--label', required=True)
args = ap.parse_args()
helper = BASE / 'current-oracle.py'
assert hashlib.sha256(helper.read_bytes()).hexdigest() == CORE_SHA
spec = importlib.util.spec_from_file_location('saved_oracle', helper)
core = importlib.util.module_from_spec(spec)
spec.loader.exec_module(core)
assert os.name == 'nt' and re.fullmatch('candidate-oracle-[a-z0-9-]+', args.label)
prior_path = Path(args.oracle_result)
core.pin(prior_path, args.oracle_sha)
prior = core.read(prior_path)
assert prior['passed'] is True
build_pin, source_pin = prior['buildResult'], prior['sourceResult']
build, rows = core.gate(Path(build_pin['path']), build_pin['sha256'])
source, source_rows = core.gate(Path(source_pin['path']), source_pin['sha256'])
assert rows == source_rows and build['inputs'] == prior['sourceInputs']
matches = [a for a in build['artifacts'] if a['cargo']['target']['name'] == 'arcadia'
and a['cargo']['target']['kind'] == ['bin'] and a['cargo']['profile']['test'] is False]
assert len(matches) == 1 and matches[0] == prior['artifact']
binary = Path(prior['binaryPath'])
assert core.ident(binary) == prior['binary'] == matches[0]['readback']
dll = BASE / 'runtime/libunwind.dll'
assert core.ident(dll)['sha256'] == core.DLL_SHA
fixtures = core.tree(BASE / 'fixtures')
assert fixtures == prior['fixtures']
complete = prior_path.parent / 'complete'
assert core.tree(complete) == prior['preparedFixtures']['complete']
assert (complete / 'functions.arcadia').read_bytes() == (BASE / 'fixtures/functions-to-discover.arcadia').read_bytes()
bindings = {str(p):core.ident(p) for p in [helper, prior_path, binary, dll,
*[Path(pin['path']).parent / name for pin in [build_pin, source_pin]
for name in ['result.json','inputs.json','inputs.zip','stdout.log','stderr.log']]]}
out = BASE / args.label
out.mkdir()
record = {'started':core.now(), 'passed':False, 'scope':'Saved private syntax candidates only; no GUI or unsaved-model acceptance.',
'helper':core.ident(Path(__file__)), 'priorOracle':{'path':str(prior_path),'sha256':args.oracle_sha},
'bindings':bindings, 'sourceInputs':build['inputs'], 'runs':[]}
try:
for name in ['cwd','profile','tmp']: (out / name).mkdir()
system = os.environ['SYSTEMROOT']
env = {'SystemRoot':system,'WINDIR':system,'SystemDrive':os.environ['SYSTEMDRIVE'],
'PATH':str(binary.parent)+';'+str(dll.parent)+';'+system+'\\System32;'+system,
'USERPROFILE':str(out/'profile'),'TEMP':str(out/'tmp'),'TMP':str(out/'tmp')}
record['environment'] = env
for label, suffix in [('token', b'\n}'), ('eof', b'\nsa_function unfinished "Unfinished" {')]:
folder = out / label
shutil.copytree(complete, folder)
source_file = folder / 'functions.arcadia'
raw = source_file.read_bytes() + suffix
source_file.write_bytes(raw)
before = core.tree(folder)
command = [str(binary),'lint',str(folder/'project.arcadia'),'--json']
run = {'label':label,'started':core.now(),'command':command,'inputFiles':before,
'suffixHex':suffix.hex(),'expectedExitCode':1}
record['runs'].append(run)
stdout_path, stderr_path = out/(label+'.stdout.json'), out/(label+'.stderr.log')
with stdout_path.open('xb') as stdout, stderr_path.open('xb') as stderr:
try:
result = subprocess.run(command,cwd=out/'cwd',env=env,stdout=stdout,stderr=stderr,
timeout=55,creationflags=subprocess.CREATE_NO_WINDOW)
run['exitCode'] = result.returncode
finally: run['finished'] = core.now()
report = core.read(stdout_path)
run['report'] = report
assert result.returncode == report['exit_code'] == 1
assert report['status'] == 'invalid' and report['operation'] == 'check'
assert report['written'] is False and report['changes'] == []
errors = [d for d in report['diagnostics'] if d['severity'] == 'error' and d.get('location')
and Path(d['location']['path']).name == 'functions.arcadia']
expected = (len(raw)-1,len(raw)) if label == 'token' else (len(raw),len(raw))
assert any((d['location']['start'],d['location']['end']) == expected for d in errors), (label, expected, errors)
run['expectedSpan'] = list(expected)
assert core.tree(folder) == before
record['passed'] = True
except Exception as error:
record['failure'] = repr(error)
finally:
record['finished'] = core.now()
record['originalsUnchanged'] = all(core.ident(Path(p)) == value for p,value in bindings.items()) and core.tree(BASE/'fixtures') == fixtures and core.tree(complete) == prior['preparedFixtures']['complete']
record['passed'] = record['passed'] and record['originalsUnchanged']
for run in record['runs']:
for suffix, key in [('.stdout.json','stdout'),('.stderr.log','stderr')]:
p = out / (run['label']+suffix)
if p.exists(): run[key] = core.ident(p)
with (out/'result.json').open('x',encoding='utf-8',newline='\n') as f:
json.dump(record,f,indent=2); f.write('\n')
print(json.dumps({'output':str(out),'passed':record['passed'],'receipt':core.ident(out/'result.json')}))
return 0 if record['passed'] else 1
if __name__ == '__main__': sys.exit(main())