omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tools / gen / abstract / probe
| 1 | #!/usr/bin/env bash |
| 2 | # tools/gen/abstract/probe [--root <repo>] <build dir> <records dir> |
| 3 | # |
| 4 | # GEN-3 (aien-spark/omega#478) local transfer probes, functional (run in the harness runner, not just parsed). |
| 5 | # The probe tasks are the corpus tasks named in corpus/PROBES; the extractor never reads their helpers, so no |
| 6 | # abstraction record descends from them (checked first). For each PROBES line `<task> positive|negative <name>` |
| 7 | # with the abstraction record whose entry is <name> (taken from MANIFEST, digests checked): |
| 8 | # positive the task's own solution with its helper <name> replaced by the record body passes the task's |
| 9 | # public tests: the record fits a task it was not extracted from |
| 10 | # negative the record body plus tasks/<task>/misuse.<name>.omegese (the entry a model might write with the |
| 11 | # record) passes the reader chain but FAILS the task's public tests: the record looks related but |
| 12 | # does not apply, and the tests catch its misuse |
| 13 | # Prints `PROBE <task> <polarity> <name> PASS|FAIL <detail>` lines and a summary; exit 1 if any probe fails. |
| 14 | set -euo pipefail |
| 15 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 16 | . "$HERE/genabs.sh" |
| 17 | ROOT="$(cd "$HERE/../../.." && pwd)" |
| 18 | if [ "${1:-}" = --root ]; then ROOT="$(cd "$2" && pwd)"; shift 2; fi |
| 19 | [ $# -eq 2 ] || { echo "usage: probe [--root <repo>] <build dir> <records dir>" >&2; exit 2; } |
| 20 | B="$(cd "$1" && pwd)" RS="$(cd "$2" && pwd)" |
| 21 | W="$(mktemp -d "${TMPDIR:-/tmp}/gen-probe.XXXXXXXX")" |
| 22 | trap 'rm -rf "$W"' EXIT |
| 23 | ga_init "$B" "$ROOT" "$W" || exit 2 |
| 24 | CR="$ROOT/$GA_CORPUS" |
| 25 | (cd "$RS" && sha256sum --quiet -c MANIFEST) || { echo "probe: MANIFEST digests do not match the record files" >&2; exit 1; } |
| 26 | pass=0 fail=0 |
| 27 | res() { echo "PROBE $1 $2 $3 $4 $5"; if [ "$4" = PASS ]; then pass=$((pass + 1)); else fail=$((fail + 1)); fi; } |
| 28 | |
| 29 | # probe tasks are withheld: no abstraction record may name one in its ancestry |
| 30 | probes="$(grep -v '^#' "$CR/PROBES" | cut -d' ' -f1 | sort -u)" |
| 31 | leak="$(for f in $(awk '$2 ~ /^abstraction\// { print $2 }' "$RS/MANIFEST"); do sed -n 's/^ancestry \([^ ]*\) .*/\1/p' "$RS/$f"; done | sort -u | comm -12 - <(printf '%s\n' "$probes"))" |
| 32 | if [ -z "$leak" ]; then echo "probe: withheld ok: no abstraction record descends from a probe task"; else echo "probe: LEAK: probe tasks in ancestry: $leak"; fail=$((fail + 1)); fi |
| 33 | |
| 34 | while read -r t pol name; do |
| 35 | d="$CR/tasks/$t" |
| 36 | rec="$(for f in $(awk '$2 ~ /^abstraction\// { print $2 }' "$RS/MANIFEST"); do grep -qx "entry $name" "$RS/$f" && echo "$RS/$f"; done | head -n 1 || true)" |
| 37 | [ -n "$rec" ] || { res "$t" "$pol" "$name" FAIL "no abstraction record named $name in the manifest"; continue; } |
| 38 | sed '1,/^body$/d' "$rec" > "$W/rb" |
| 39 | p="$(sed -n 's/^params//p' "$d/requirement")" ret="$(sed -n 's/^ret //p' "$d/requirement")" |
| 40 | if [ "$pol" = positive ]; then |
| 41 | fns="$("$GA_GABS" split "$d/solution.omegese" "$W/p.$t")" |
| 42 | printf '%s\n' "$fns" | awk -v n="$name" '$3 == n { f = 1 } END { exit !f }' || { res "$t" "$pol" "$name" FAIL "the probe solution has no helper $name"; continue; } |
| 43 | while read -r _ k fname _; do |
| 44 | if [ "$fname" = "$name" ]; then cat "$W/rb"; else cat "$W/p.$t.$k.omegese"; fi |
| 45 | done <<< "$fns" > "$W/prog.omegese" |
| 46 | ga_chain "$W/prog.omegese" "$W/prog" || { res "$t" "$pol" "$name" FAIL "$GA_ERR"; continue; } |
| 47 | v="$("$GA_GABS" run "$GA_RUNNER" "$W/scratch" "$W/prog.ir" "$t" "$ret" "$d/inputs" "$d/expected" $p 2>&1)" || true |
| 48 | case "$v" in "ACCEPT n="*) res "$t" "$pol" "$name" PASS "record body in the probe solution: $v";; |
| 49 | *) res "$t" "$pol" "$name" FAIL "record body in the probe solution: $v";; esac |
| 50 | else |
| 51 | m="$d/misuse.$name.omegese" |
| 52 | [ -f "$m" ] || { res "$t" "$pol" "$name" FAIL "no misuse.$name.omegese"; continue; } |
| 53 | cat "$W/rb" "$m" > "$W/prog.omegese" |
| 54 | ga_chain "$W/prog.omegese" "$W/prog" || { res "$t" "$pol" "$name" FAIL "misuse program must pass the reader chain: $GA_ERR"; continue; } |
| 55 | v="$("$GA_GABS" run "$GA_RUNNER" "$W/scratch" "$W/prog.ir" "$t" "$ret" "$d/inputs" "$d/expected" $p 2>&1)" || true |
| 56 | case "$v" in "REJECT wrong_result"*|"REJECT unexpected_trap"*|"REJECT missing_trap"*|"REJECT wrong_trap"*) |
| 57 | res "$t" "$pol" "$name" PASS "record misused, tests catch it: $v";; |
| 58 | *) res "$t" "$pol" "$name" FAIL "record misuse not caught by the tests: $v";; esac |
| 59 | fi |
| 60 | done < <(grep -v '^#' "$CR/PROBES") |
| 61 | echo "probe: $pass pass, $fail fail" |
| 62 | [ "$fail" = 0 ] |