omega-harness
Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories
Brought by drakestapleton
omega-harness / coder / eval / refcheck.sh
| 1 | #!/bin/sh |
| 2 | # Check the eval tasks and their held-out reference solutions at the pinned omc, before any run. |
| 3 | # usage: OMEGA_HOME=... sh refcheck.sh TASKDIR MANIFEST REFDIR |
| 4 | # TASKDIR ID/{spec.md,stdin,expected.out,expected.exit} |
| 5 | # MANIFEST tasks.json: [{id, spec, stdin_bytes, expected_sha256, exit, ref_sha256}, ...] |
| 6 | # REFDIR ID.om for every task (the references are not in this repository) |
| 7 | # Refuses unless the manifest ids are exactly the task directories, each task's files match the manifest, |
| 8 | # each reference's sha256 is the manifest's ref_sha256, and every reference passes its case line (the |
| 9 | # same line run.sh writes, from case.sh) through the om2 gate with the pinned omc. Prints REFCHECK PASS n=N (exit 0) or |
| 10 | # REFCHECK FAIL with the reasons (exit 1); exit 2 on a usage or pin error. |
| 11 | set -u |
| 12 | . "$(dirname "$0")/case.sh" |
| 13 | tasks=${1:?taskdir} |
| 14 | man=${2:?tasks.json} |
| 15 | refs=${3:?refdir} |
| 16 | home=${OMEGA_HOME:-$HOME/.local/share/aien-omega} |
| 17 | home=$(cd "$home" && pwd) || { echo "REFCHECK FAIL no OMEGA_HOME directory $home" >&2; exit 2; } |
| 18 | pin="$(cd "$(dirname "$0")/../.." && pwd)/PIN" |
| 19 | sha=$(sed -n 's/^omc-sha256 //p' "$pin") |
| 20 | [ -n "$sha" ] && [ "$(sha256sum "$home/omc" | cut -d' ' -f1)" = "$sha" ] || { echo "REFCHECK FAIL $home/omc is not the omc in $pin" >&2; exit 2; } |
| 21 | command -v jq > /dev/null || { echo "REFCHECK FAIL jq not on PATH" >&2; exit 2; } |
| 22 | command -v bwrap > /dev/null || { echo "REFCHECK FAIL bwrap not on PATH" >&2; exit 2; } |
| 23 | for d in "$tasks" "$refs"; do [ -d "$d" ] || { echo "REFCHECK FAIL no directory $d" >&2; exit 2; }; done |
| 24 | tasks=$(cd "$tasks" && pwd) |
| 25 | refs=$(cd "$refs" && pwd) |
| 26 | fail=0 |
| 27 | bad() { echo "REFCHECK FAIL $*"; fail=1; } |
| 28 | [ "$(jq -r '.[].id' "$man" | LC_ALL=C sort)" = "$(ls "$tasks" | LC_ALL=C sort)" ] || bad "manifest ids are not the task directories" |
| 29 | work=$(mktemp -d) |
| 30 | trap 'rm -rf "$work"' EXIT |
| 31 | # The gate sees copies of the tasks and references under $work/in, read-only, and nothing else of this machine |
| 32 | # (narrow_gate in case.sh). |
| 33 | mkdir "$work/in" "$work/sandbox" |
| 34 | cp -R "$tasks" "$work/in/tasks" |
| 35 | cp -R "$refs" "$work/in/refs" |
| 36 | echo "deadline $CASE_DEADLINE" > "$work/in/cases.txt" |
| 37 | n=0 |
| 38 | for id in $(jq -r '.[].id' "$man"); do |
| 39 | t="$tasks/$id" |
| 40 | [ -d "$t" ] || continue |
| 41 | n=$((n + 1)) |
| 42 | row=$(jq -c --arg id "$id" '.[] | select(.id == $id)' "$man") |
| 43 | [ "$(sha256sum < "$t/expected.out" | cut -d' ' -f1)" = "$(echo "$row" | jq -r .expected_sha256)" ] || bad "$id expected.out differs from expected_sha256" |
| 44 | [ "$(wc -c < "$t/stdin" | tr -d ' ')" = "$(echo "$row" | jq -r .stdin_bytes)" ] || bad "$id stdin size differs from stdin_bytes" |
| 45 | [ "$(cat "$t/expected.exit")" = "$(echo "$row" | jq -r .exit)" ] || bad "$id expected.exit differs from exit" |
| 46 | [ "$(cat "$t/spec.md")" = "$(echo "$row" | jq -r .spec)" ] || bad "$id spec.md differs from spec" |
| 47 | [ "$(wc -c < "$t/expected.out")" -lt $((CASE_FSIZE_BLOCKS * 256)) ] || |
| 48 | bad "$id expected.out is $(wc -c < "$t/expected.out" | tr -d ' ') bytes, half or more of the scorer's file-size limit (CASE_FSIZE_BLOCKS in case.sh): raise the limit" |
| 49 | if [ ! -f "$refs/$id.om" ]; then bad "$id no reference $refs/$id.om"; continue; fi |
| 50 | [ "$(sha256sum < "$refs/$id.om" | cut -d' ' -f1)" = "$(echo "$row" | jq -r .ref_sha256)" ] || bad "$id reference sha256 differs from ref_sha256" |
| 51 | caseline "$id" "$work/in/refs/$id.om" "$work/in/tasks/$id" >> "$work/in/cases.txt" |
| 52 | done |
| 53 | narrow_gate "$home" "$work/in" "$work/sandbox" "$home/omc" "$sha" "$work/in/cases.txt" "$work/sandbox/scratch" > "$work/gate.log" 2>&1 |
| 54 | grc=$? |
| 55 | notpass=$(grep '^VERDICT ' "$work/gate.log" | grep -v '^VERDICT [^ ]* PASS') |
| 56 | [ -z "$notpass" ] || bad "gate verdicts: $notpass" |
| 57 | [ "$grc" -eq 0 ] && grep -q "^OM2GATE PASS cases=$n " "$work/gate.log" || bad "gate rc $grc: $(grep '^OM2GATE ' "$work/gate.log")" |
| 58 | if [ "$fail" -eq 0 ]; then echo "REFCHECK PASS n=$n omc=$sha"; else exit 1; fi |