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
aien-sovereign-core-mv / om / golden / check.sh
| 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). |
| 8 | set -u |
| 9 | here=$(cd "$(dirname "$0")" && pwd) |
| 10 | fx=$here/fixtures |
| 11 | t=$(mktemp -d) |
| 12 | trap 'rm -rf "$t"' EXIT |
| 13 | bash "$here/build.sh" "$t/golden" || exit $? |
| 14 | bash "$here/build.sh" "$t/fake" "$here/fake.om" || exit $? |
| 15 | G=$t/golden |
| 16 | fail=0 |
| 17 | ok() { echo "PASS $1"; } |
| 18 | bad() { 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 |
| 20 | arm() { |
| 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 | |
| 28 | echo "== comparator, synthetic fixtures" |
| 29 | arm cmp-match 0 'golden-cmp prompts=2 match=2 diverge=0' "$G" cmp "$fx/synthetic-ref.json" "$fx/synthetic-match.json" |
| 30 | arm cmp-diverge-1-token 1 'DIVERGE p1 index=1 ref=20 cand=21' "$G" cmp "$fx/synthetic-ref.json" "$fx/synthetic-diverge.json" |
| 31 | arm 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" |
| 32 | sed 's/"model_rev":"0000000000000000000000000000000000000000"/"model_rev":"1111111111111111111111111111111111111111"/' "$fx/synthetic-match.json" > "$t/rev.json" |
| 33 | arm cmp-header-model-rev 3 'NOTCOMPARABLE model_rev ref="0000000000000000000000000000000000000000" cand="1111111111111111111111111111111111111111"' "$G" cmp "$fx/synthetic-ref.json" "$t/rev.json" |
| 34 | sed 's/"ids":\[10,20,30\]/"ids":[10,20]/' "$fx/synthetic-match.json" > "$t/short.json" |
| 35 | arm cmp-prefix-ends-early 1 'DIVERGE p1 index=2 ref=30 cand=end' "$G" cmp "$fx/synthetic-ref.json" "$t/short.json" |
| 36 | head -c 100 "$fx/synthetic-match.json" > "$t/trunc.json" |
| 37 | arm cmp-malformed-json 4 'golden: refused 4 json' "$G" cmp "$fx/synthetic-ref.json" "$t/trunc.json" |
| 38 | sed 's/"temperature":0,/"temperature":0.7,/' "$fx/synthetic-match.json" > "$t/temp.json" |
| 39 | arm cmp-not-greedy-record 4 'golden: refused 4 record-schema' "$G" cmp "$fx/synthetic-ref.json" "$t/temp.json" |
| 40 | sed 's/"label":"SYNTHETIC",/"label":"SYNTHETIC","extra":1,/' "$fx/synthetic-match.json" > "$t/extra.json" |
| 41 | arm cmp-unknown-key 4 'golden: refused 4 record-schema' "$G" cmp "$fx/synthetic-ref.json" "$t/extra.json" |
| 42 | arm usage 2 '' "$G" cmp "$fx/synthetic-ref.json" |
| 43 | |
| 44 | echo "== 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 |
| 46 | canned() { |
| 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 | } |
| 51 | reply() { 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 |
| 53 | serve() { |
| 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 | } |
| 59 | eng=$(printf 'e%.0s' $(seq 64)) |
| 60 | rev=0000000000000000000000000000000000000000 |
| 61 | printf 'Authorization: Bearer synthetic-test-token\n' > "$t/hdr" |
| 62 | rec() { # 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 | } |
| 67 | canned "$t/a.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)" |
| 68 | canned "$t/a.c" 1 '200 OK' "$(reply 10,20,30 greedy)" |
| 69 | serve a 2 |
| 70 | before=$(date -u +%s) |
| 71 | arm rec-fake-success 0 '' rec a "$t/a.json" |
| 72 | after=$(date -u +%s) |
| 73 | wait |
| 74 | if [ -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" |
| 88 | fi |
| 89 | canned "$t/b.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)" |
| 90 | canned "$t/b.c" 1 '200 OK' "$(reply 10,20,31 greedy)" |
| 91 | serve b 2 |
| 92 | arm rec-fake-rerecord 0 '' rec b "$t/b.json" |
| 93 | wait |
| 94 | arm rec-then-cmp-divergence 1 'DIVERGE p1 index=2 ref=30 cand=31' "$G" cmp "$t/a.json" "$t/b.json" |
| 95 | canned "$t/c.c" 0 '200 OK' "$(reply 1,2,3,4,5 greedy)" |
| 96 | canned "$t/c.c" 1 '200 OK' "$(reply 10,20,30 sampled)" |
| 97 | serve c 2 |
| 98 | arm rec-sampled-reply-refused 5 'golden: refused 5 not-greedy' rec c "$t/c.json" |
| 99 | wait |
| 100 | [ ! -e "$t/c.json" ] && ok "rec-refusal-leaves-no-record" || bad rec-refusal-leaves-no-record "$t/c.json written" |
| 101 | canned "$t/d.c" 0 '200 OK' '{"choices":[],"usage":{"prompt_tokens":3}}' |
| 102 | canned "$t/d.c" 1 '200 OK' "$(reply 10,20,30 greedy)" |
| 103 | serve d 2 |
| 104 | arm rec-missing-token-ids-refused 5 'golden: refused 5 no-usage-aien_token_ids' rec d "$t/d.json" |
| 105 | wait |
| 106 | canned "$t/e.c" 0 '500 Internal Server Error' '{"error":{"message":"FAKE"}}' |
| 107 | serve e 1 |
| 108 | arm rec-http-500-transport 6 'record: refused 6 transport prompt 0' rec e "$t/e.json" |
| 109 | wait |
| 110 | arm rec-existing-out-refused 2 "record: refused 2 $t/a.json exists" rec x "$t/a.json" |
| 111 | |
| 112 | echo "== negative controls: mutants of golden.om must fail their arm" |
| 113 | mutant() { # 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 | } |
| 119 | mflip() { # mflip NAME CHECK-CMD...: the arm must now fail |
| 120 | "${@:2}" > "$t/mout" 2>&1 && bad "$1" "mutant survived" || ok "$1 killed" |
| 121 | } |
| 122 | if 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" |
| 124 | fi |
| 125 | if 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" |
| 127 | fi |
| 128 | if 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 |
| 137 | fi |
| 138 | [ "$fail" = 0 ] && echo "golden check: all arms as expected" || echo "golden check: FAILED" |
| 139 | exit "$fail" |