interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / tests / passages.sh

126 lines · 5659 bytes Raw Blame History
1#!/bin/sh
2# Offline oracle: real sync/text -> build quote -> actual agent --gate --split.
3# --split exposes the same builder spans, including unselected passages (max three selected/work).
4# Python checks bytes/JSON; it neither implements splitting nor substitutes a passage builder.
5set -eu
6export LC_ALL=C
7cd "$(dirname "$0")/../.."
8OMC=$HOME/work/flux/omega-mv/seed/out/omc
9PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
10[ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'passages: compiler is not the pin'; exit 2; }
11T=$(mktemp -d /tmp/research-passages.XXXXXX)
12trap 'rm -rf "$T"' EXIT HUP INT TERM
13sh research/build-tools.sh "$T/bin"
14"$OMC" < research/build.om > "$T/build"
15"$OMC" < research/agent.om > "$T/agent"
16chmod 700 "$T/build" "$T/agent"
17python3 -I - "$T" <<'PY'
18from pathlib import Path
19import sys
20p=Path(sys.argv[1])
21# Each fixture produces at most three actual builder spans. ASCII and spaced fixtures score all
22# spans; exact requested UTF-8 fixture scores quantum only, so --split checks its unselected span too.
23for name,text,question in [
24 ('utf8','é'*800+' quantum '+'é'*1000,'quantum'),
25 ('ascii','a'*3609,'aaa'),
26 ('three','€'*1200+' quantum','quantum'),
27 ('four','😀'*900+' quantum','quantum'),
28 ('spaced','quantum '*450,'quantum'),
29]:
30 d=p/name; d.mkdir()
31 (d/'raw').write_bytes((text+'\n').encode('utf-8'))
32 (d/'question').write_text(question)
33PY
34for f in utf8 ascii three four spaced; do
35 "$T/bin/research-sync" text < "$T/$f/raw" > "$T/$f/text"
36 "$T/build" quote < "$T/$f/text" > "$T/$f/quoted"
37 { printf '@@\tpassage-fixture\tPassage fixture\n'; cat "$T/$f/quoted"; } > "$T/$f/corpus"
38done
39# Shared unchanged by the correct agent and both compiled source mutants.
40cat > "$T/check.py" <<'PY'
41import json,re,sys
42from pathlib import Path
43p=Path(sys.argv[1]); d=Path(sys.argv[2]); name=sys.argv[3]
44def fail(reason):
45 raise SystemExit(reason)
46def utf(data):
47 try: return data.decode('utf-8','strict')
48 except UnicodeDecodeError: fail('INVALID_UTF8')
49def load(data):
50 try: return json.loads(utf(data))
51 except json.JSONDecodeError: fail('INVALID_JSON')
52def nosep(data): return data.translate(None,b' \t\r\n')
53raw=(p/'raw').read_bytes(); admitted=(p/'text').read_bytes(); quoted=(p/'quoted').read_bytes()
54utf(admitted)
55if nosep(admitted)!=nosep(raw): fail('SYNC_LOST_BYTES')
56if quoted!=b''.join(b'> '+line for line in admitted.splitlines(keepends=True)): fail('QUOTE_LOST_BYTES')
57records=[load(line) for line in (d/'split.jsonl').read_bytes().splitlines()]
58if not 1<len(records)<=3: fail('FIXTURE_SPANS')
59corpus=(p/'corpus').read_bytes()
60start=corpus.index(b'\n')+1
61joined=b''
62for r in records:
63 text=r['text'].encode('utf-8')
64 if text!=corpus[r['s']:r['e']]: fail('DUMP_NOT_ACTUAL_SPAN')
65 if r['s']<start or nosep(corpus[start:r['s']]): fail('LOST_BYTES')
66 joined+=text
67 start=r['e']
68if nosep(corpus[start:]): fail('LOST_BYTES')
69if nosep(joined)!=nosep(quoted): fail('LOST_BYTES')
70req=load((d/'request.json').read_bytes())
71content=req['messages'][1]['content']
72# Selected spans come from the JSON-decoded actual request, never a second splitter.
73selected=re.findall(r'\[\d+\] Passage fixture\n(.*?)\n\n',content,re.S)
74if not selected: fail('NO_SELECTED_PASSAGES')
75texts=[r['text'].replace('\n',' ') for r in records]
76if any(t not in texts for t in selected): fail('SELECTED_NOT_BUILDER_SPAN')
77if name in ('ascii','spaced'):
78 if len(selected)!=len(records): fail('NOT_ALL_SELECTED')
79 if sorted(selected)!=sorted(texts): fail('LOST_BYTES')
80else:
81 if not any('quantum' in t for t in selected): fail('QUANTUM_NOT_SELECTED')
82answer=load(next((d/'ask').glob('*.json')).read_bytes())
83if answer['answer']!='Fixture answer. [1]': fail('NOT_GATE_ANSWER')
84print('PASSAGE_CHECK '+name+' spans='+str(len(records))+' selected='+str(len(selected))+' UTF8_JSON_RECONSTRUCT=PASS')
85PY
86run_case() {
87 bin=$1; tag=$2; f=$3
88 d=$T/$tag-$f
89 mkdir -p "$d/ask" "$d/state"
90 printf '10000000000000000000000000000001\t%s\n' "$(cat "$T/$f/question")" > "$d/ask/queue"
91 "$bin" "$d/ask/" "$T/$f/corpus" "$d/state/off" --gate --split > "$d/request.json" 2> "$d/split.jsonl"
92 python3 -I "$T/check.py" "$T/$f" "$d" "$f"
93}
94for f in utf8 ascii three four spaced; do run_case "$T/agent" good "$f"; done
95# Each mutant must compile/run. Only the byte oracle can kill it, not a compile error/missing output.
96python3 -I - research/agent.om "$T" <<'PY'
97from pathlib import Path
98import sys
99s=Path(sys.argv[1]).read_text(); p=Path(sys.argv[2])
100a='s = p\nif sep\ns = add p 1\nend'
101assert s.count(a)==1
102(p/'skip.om').write_text(s.replace(a,'s = add p 1'))
103a='while eq and get gc p 192 128 bound 4\np = sub p 1\nend'
104assert s.count(a)==1
105(p/'mid.om').write_text(s.replace(a,'p = add p 1'))
106PY
107for mutant in skip mid; do
108 "$OMC" < "$T/$mutant.om" > "$T/$mutant"
109 chmod 700 "$T/$mutant"
110done
111if run_case "$T/skip" skip ascii > "$T/skip.log" 2>&1; then
112 echo 'FAIL mutant skip survived'; exit 1
113fi
114grep -qx LOST_BYTES "$T/skip.log" || { cat "$T/skip.log"; echo 'FAIL skip wrong reason'; exit 1; }
115if run_case "$T/mid" mid utf8 > "$T/mid.log" 2>&1; then
116 echo 'FAIL mutant mid survived'; exit 1
117fi
118grep -qx INVALID_UTF8 "$T/mid.log" || { cat "$T/mid.log"; echo 'FAIL mid wrong reason'; exit 1; }
119echo 'PASSAGE_MUTANT skip=LOST_BYTES mid=INVALID_UTF8 compile=PASS'
120echo 'PASSAGES_RESULT cases=5 mutants=2 fail=0 model=NOT_RUN'
121# Entire sibling prompt module with the same compiled agent; no second build.
122pass=0; fail=0
123ok(){ pass=$((pass+1)); echo "PASS $*"; }
124bad(){ fail=$((fail+1)); echo "FAIL $*"; }
125. research/tests/prompt.sh
126[ "$fail" = 0 ]