interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / golden / check.sh

139 lines · 8184 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# om/golden/check.sh: host arms for the golden-token harness (Core #853, DRA-52).
4# Usage: OMC=/path/to/omega-mv/seed/out/omc bash om/golden/check.sh
5# Every engine reply here comes from fake.om on a random 127.0.0.1 port and every record it makes is
6# labelled FAKE. No live engine, model or GPU is touched. Exit 0 all arms as expected, 1 an arm
7# failed, 3 omc missing or not pinned (NOT_RUN).
8set -u
9here=$(cd "$(dirname "$0")" && pwd)
10fx=$here/fixtures
11t=$(mktemp -d)
12trap 'rm -rf "$t"' EXIT
13bash "$here/build.sh" "$t/golden" || exit $?
14bash "$here/build.sh" "$t/fake" "$here/fake.om" || exit $?
15G=$t/golden
16fail=0
17ok() { echo "PASS $1"; }
18bad() { echo "FAIL $1: $2"; fail=1; }
19# arm NAME WANT_RC WANT_GREP cmd...: exit code must be WANT_RC; stdout+stderr must contain WANT_GREP
20arm() {
21 local name=$1 want=$2 pat=$3; shift 3
22 "$@" > "$t/out" 2>&1; local rc=$?
23 if [ "$rc" != "$want" ]; then bad "$name" "exit $rc, want $want: $(cat "$t/out")"; return; fi
24 if [ -n "$pat" ] && ! grep -qxF -- "$pat" "$t/out"; then bad "$name" "no line '$pat' in: $(cat "$t/out")"; return; fi
25 ok "$name (exit $rc${pat:+, '$pat'})"
26}
27
28echo "== comparator, synthetic fixtures"
29arm cmp-match 0 'golden-cmp prompts=2 match=2 diverge=0' "$G" cmp "$fx/synthetic-ref.json" "$fx/synthetic-match.json"
30arm cmp-diverge-1-token 1 'DIVERGE p1 index=1 ref=20 cand=21' "$G" cmp "$fx/synthetic-ref.json" "$fx/synthetic-diverge.json"
31arm cmp-header-engine 3 "NOTCOMPARABLE engine_sha256 ref=\"$(printf 'e%.0s' $(seq 64))\" cand=\"$(printf 'f%.0s' $(seq 64))\"" "$G" cmp "$fx/synthetic-ref.json" "$fx/synthetic-header.json"
32sed 's/"model_rev":"0000000000000000000000000000000000000000"/"model_rev":"1111111111111111111111111111111111111111"/' "$fx/synthetic-match.json" > "$t/rev.json"
33arm cmp-header-model-rev 3 'NOTCOMPARABLE model_rev ref="0000000000000000000000000000000000000000" cand="1111111111111111111111111111111111111111"' "$G" cmp "$fx/synthetic-ref.json" "$t/rev.json"
34sed 's/"ids":\[10,20,30\]/"ids":[10,20]/' "$fx/synthetic-match.json" > "$t/short.json"
35arm cmp-prefix-ends-early 1 'DIVERGE p1 index=2 ref=30 cand=end' "$G" cmp "$fx/synthetic-ref.json" "$t/short.json"
36head -c 100 "$fx/synthetic-match.json" > "$t/trunc.json"
37arm cmp-malformed-json 4 'golden: refused 4 json' "$G" cmp "$fx/synthetic-ref.json" "$t/trunc.json"
38sed 's/"temperature":0,/"temperature":0.7,/' "$fx/synthetic-match.json" > "$t/temp.json"
39arm cmp-not-greedy-record 4 'golden: refused 4 record-schema' "$G" cmp "$fx/synthetic-ref.json" "$t/temp.json"
40sed 's/"label":"SYNTHETIC",/"label":"SYNTHETIC","extra":1,/' "$fx/synthetic-match.json" > "$t/extra.json"
41arm cmp-unknown-key 4 'golden: refused 4 record-schema' "$G" cmp "$fx/synthetic-ref.json" "$t/extra.json"
42arm usage 2 '' "$G" cmp "$fx/synthetic-ref.json"
43
44echo "== recorder against fake.om (FAKE replies, random 127.0.0.1 port)"
45# canned DIR K STATUS BODY: one full HTTP/1.1 response for connection K
46canned() {
47 mkdir -p "$1"
48 printf 'HTTP/1.1 %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s' \
49 "$3" "${#4}" "$4" > "$1/$2.http"
50}
51reply() { printf '{"id":"FAKE","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"FAKE"},"finish_reason":"length"}],"usage":{"prompt_tokens":3,"completion_tokens":3,"total_tokens":6,"aien_token_ids":[%s],"aien_sampling":{"mode":"%s","temperature":0.0}}}' "$1" "$2"; }
52# serve NAME N: start fake for N connections on canned dir $t/NAME.c, capture to $t/NAME.cap; sets port
53serve() {
54 mkdir -p "$t/$1.cap"
55 timeout 60 "$t/fake" "$t/$1.port" "$t/$1.c" "$t/$1.cap" "$2" 2> "$t/$1.fakeerr" &
56 for _ in $(seq 100); do [ -s "$t/$1.port" ] && break; sleep 0.1; done
57 port=$(cat "$t/$1.port")
58}
59eng=$(printf 'e%.0s' $(seq 64))
60rev=0000000000000000000000000000000000000000
61printf 'Authorization: Bearer synthetic-test-token\n' > "$t/hdr"
62rec() { # rec NAME OUT
63 GOLDEN=$G bash "$here/record.sh" --url "http://127.0.0.1:$port" --prompts "$fx/synthetic-prompts.json" \
64 --model-repo synthetic/not-a-model --model-rev $rev --max-tokens 8 --engine-sha256 "$eng" \
65 --host-id fake-host --label FAKE --out "$2" --header-file "$t/hdr" --timeout 20
66}
67canned "$t/a.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)"
68canned "$t/a.c" 1 '200 OK' "$(reply 10,20,30 greedy)"
69serve a 2
70before=$(date -u +%s)
71arm rec-fake-success 0 '' rec a "$t/a.json"
72after=$(date -u +%s)
73wait
74if [ -s "$t/a.json" ]; then
75 grep -qxF '{"id":"p0","ids":[1,2,3,4,5]},' "$t/a.json" && grep -qxF '{"id":"p1","ids":[10,20,30]}' "$t/a.json" \
76 && ok "rec-ids-taken-from-usage" || bad rec-ids-taken-from-usage "$(cat "$t/a.json")"
77 grep -qF '"label":"FAKE"' "$t/a.json" && ok "rec-record-says-FAKE" || bad rec-record-says-FAKE "no FAKE label"
78 ps=$(sha256sum "$fx/synthetic-prompts.json" | cut -c1-64)
79 grep -qF "\"prompts_sha256\":\"$ps\"" "$t/a.json" && ok "rec-prompts-sha256 = sha256sum ($ps)" || bad rec-prompts-sha256 "want $ps"
80 utc=$(grep -o '"utc":"[^"]*"' "$t/a.json" | cut -d'"' -f4); us=$(date -u -d "$utc" +%s)
81 [ "$us" -ge "$before" ] && [ "$us" -le "$after" ] && ok "rec-utc $utc within [$before,$after]" || bad rec-utc "$utc not within [$before,$after]"
82 "$G" req "$fx/synthetic-prompts.json" synthetic/not-a-model 8 "$(mkdir "$t/rq" && echo "$t/rq")" > /dev/null
83 for i in 0 1; do
84 tail -c "$(stat -c %s "$t/rq/$i.json")" "$t/a.cap/$i.http" | cmp -s - "$t/rq/$i.json" \
85 && ok "rec-request-body-$i byte-equal to golden req" || bad "rec-request-body-$i" "differs"
86 done
87 grep -qaF 'Authorization: Bearer synthetic-test-token' "$t/a.cap/0.http" && ok "rec-header-file-sent" || bad rec-header-file-sent "missing"
88fi
89canned "$t/b.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)"
90canned "$t/b.c" 1 '200 OK' "$(reply 10,20,31 greedy)"
91serve b 2
92arm rec-fake-rerecord 0 '' rec b "$t/b.json"
93wait
94arm rec-then-cmp-divergence 1 'DIVERGE p1 index=2 ref=30 cand=31' "$G" cmp "$t/a.json" "$t/b.json"
95canned "$t/c.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)"
96canned "$t/c.c" 1 '200 OK' "$(reply 10,20,30 sampled)"
97serve c 2
98arm rec-sampled-reply-refused 5 'golden: refused 5 not-greedy' rec c "$t/c.json"
99wait
100[ ! -e "$t/c.json" ] && ok "rec-refusal-leaves-no-record" || bad rec-refusal-leaves-no-record "$t/c.json written"
101canned "$t/d.c" 0 '200 OK' '{"choices":[],"usage":{"prompt_tokens":3}}'
102canned "$t/d.c" 1 '200 OK' "$(reply 10,20,30 greedy)"
103serve d 2
104arm rec-missing-token-ids-refused 5 'golden: refused 5 no-usage-aien_token_ids' rec d "$t/d.json"
105wait
106canned "$t/e.c" 0 '500 Internal Server Error' '{"error":{"message":"FAKE"}}'
107serve e 1
108arm rec-http-500-transport 6 'record: refused 6 transport prompt 0' rec e "$t/e.json"
109wait
110arm rec-existing-out-refused 2 "record: refused 2 $t/a.json exists" rec x "$t/a.json"
111
112echo "== negative controls: mutants of golden.om must fail their arm"
113mutant() { # mutant NAME FROM TO: replace exactly one source line, build, set M
114 awk -v f="$2" -v r="$3" '$0 == f { $0 = r; n++ } { print } END { if (n != 1) exit 9 }' "$here/golden.om" > "$t/$1.om" \
115 || { bad "$1" "line '$2' not unique"; return 1; }
116 bash "$here/build.sh" "$t/$1" "$t/$1.om" || { bad "$1" "mutant did not build"; return 1; }
117 M=$t/$1
118}
119mflip() { # mflip NAME CHECK-CMD...: the arm must now fail
120 "${@:2}" > "$t/mout" 2>&1 && bad "$1" "mutant survived" || ok "$1 killed"
121}
122if mutant M1-ignore-header 'if gt bad 0' 'if gt bad 99'; then
123 mflip M1-ignore-header bash -c '"$0" cmp "$1" "$2"; [ $? = 3 ]' "$M" "$fx/synthetic-ref.json" "$fx/synthetic-header.json"
124fi
125if mutant M2-index-off-by-one 'ret k' 'ret add k 1'; then
126 mflip M2-index-off-by-one bash -c '"$0" cmp "$1" "$2" | grep -qxF "DIVERGE p1 index=1 ref=20 cand=21"' "$M" "$fx/synthetic-ref.json" "$fx/synthetic-diverge.json"
127fi
128if mutant M3-accept-sampled 'die 5 tsampled' 'ret'; then
129 canned "$t/m.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)"
130 canned "$t/m.c" 1 '200 OK' "$(reply 10,20,30 sampled)"
131 serve m 2
132 G0=$G; G=$M
133 m3() { rec m "$t/m.json" > /dev/null 2>&1; [ $? = 5 ]; }
134 mflip M3-accept-sampled m3
135 G=$G0
136 wait
137fi
138[ "$fail" = 0 ] && echo "golden check: all arms as expected" || echo "golden check: FAILED"
139exit "$fail"