hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Omega / tests / check-core.sh
| 1 | #!/bin/sh |
| 2 | # macOS arm64 check of the matching core as Hop runs it (no app build, no install, nothing started but the core). |
| 3 | # Usage, from the Hop tree: sh Omega/tests/check-core.sh |
| 4 | # 1. Generated/hopcore and Omega/hopcore.om match Generated/CORE-SHA256SUMS. |
| 5 | # 2. The core, signed ad hoc in a temp dir, answers every case as the Swift code Hop shipped up to 0.4.0 |
| 6 | # (names: Omega/tests/FuzzyReference.swift; paths: Omega/tests/FileScoreReference.swift; text decisions: |
| 7 | # Omega/tests/TextReference.swift), through the same |
| 8 | # host code Hop uses (Sources/OmegaCore.swift, Sources/OmegaText.swift, Sources/SwarmCore.swift and Sources/SmartRank.swift). |
| 9 | # 3. Negative controls: thirteen cores built from a source with one changed rule (Omega/tests/mutant/: a name |
| 10 | # prefix scores 161, not 160; a term found only in the folders scores 6, not 5; a question needs two |
| 11 | # words, not three; a fix may replace two words, not three; a board line keeps three senders, not four; "@all" is marked as a |
| 12 | # channel; workers, not the others, follow every channel; a name without |
| 13 | # its lane joins any of several agents; a member is stuck after 601 seconds, not 600; a named screen scores 231, not 230; a thing just copied scores 131, not 130; a habit lifts by 61, not 60; one of the sixteen reductions of the tag is off by one) must each be told apart, in its own part only. |
| 14 | # Last line: HOPCORE-MACOS PASS or FAIL n; only PASS exits 0. |
| 15 | set -eu |
| 16 | cd "$(dirname "$0")/../.." |
| 17 | export LC_ALL=C |
| 18 | [ "$(uname -sm)" = "Darwin arm64" ] || { echo "HOPCORE-MACOS NOT_RUN (host is $(uname -sm))"; exit 1; } |
| 19 | B=$(mktemp -d "${TMPDIR:-/tmp}/hopcore.XXXXXX") |
| 20 | fails=0 |
| 21 | pass() { echo "PASS $1"; } |
| 22 | fail() { echo "FAIL $1"; fails=$((fails + 1)); } |
| 23 | if shasum -a 256 -c Generated/CORE-SHA256SUMS > "$B/sums.log" 2>&1; then pass "Generated/hopcore and Omega/hopcore.om match Generated/CORE-SHA256SUMS" |
| 24 | else fail "CORE-SHA256SUMS mismatch"; cat "$B/sums.log"; fi |
| 25 | EXTRA="" |
| 26 | if [ -f /Library/Developer/CommandLineTools/usr/include/swift/module.modulemap ] && \ |
| 27 | [ -f /Library/Developer/CommandLineTools/usr/include/swift/bridging.modulemap ]; then |
| 28 | sed "s#HOP_DIR#$PWD#" toolchain/overlay.yaml > "$B/overlay.yaml" |
| 29 | EXTRA="-vfsoverlay $B/overlay.yaml -Xcc -ivfsoverlay -Xcc $B/overlay.yaml" |
| 30 | fi |
| 31 | # shellcheck disable=SC2086 |
| 32 | swiftc -O -swift-version 5 $EXTRA -o "$B/parity" Sources/OmegaCore.swift Sources/OmegaText.swift Sources/SwarmCore.swift Sources/SmartRank.swift Omega/tests/SwarmReference.swift Omega/tests/SmartRankReference.swift Omega/tests/SuggestReference.swift Omega/tests/FuzzyReference.swift Omega/tests/FileScoreReference.swift Omega/tests/TextReference.swift Omega/tests/core-parity/main.swift 2> "$B/swiftc.log" \ |
| 33 | || { fail "swiftc"; cat "$B/swiftc.log"; } |
| 34 | sign() { cp "$1" "$2"; chmod 755 "$2"; codesign --force --sign - "$2" 2> /dev/null; } |
| 35 | sign Generated/hopcore "$B/core" |
| 36 | sign Omega/tests/mutant/hopcore-names "$B/mut-names" |
| 37 | sign Omega/tests/mutant/hopcore-paths "$B/mut-paths" |
| 38 | sign Omega/tests/mutant/hopcore-text "$B/mut-text" |
| 39 | sign Omega/tests/mutant/hopcore-words "$B/mut-words" |
| 40 | sign Omega/tests/mutant/hopcore-board "$B/mut-board" |
| 41 | sign Omega/tests/mutant/hopcore-spans "$B/mut-spans" |
| 42 | sign Omega/tests/mutant/hopcore-addr "$B/mut-addr" |
| 43 | sign Omega/tests/mutant/hopcore-asm "$B/mut-asm" |
| 44 | sign Omega/tests/mutant/hopcore-status "$B/mut-status" |
| 45 | sign Omega/tests/mutant/hopcore-rank "$B/mut-rank" |
| 46 | sign Omega/tests/mutant/hopcore-suggest "$B/mut-suggest" |
| 47 | sign Omega/tests/mutant/hopcore-lifts "$B/mut-lifts" |
| 48 | sign Omega/tests/mutant/hopcore-gcm "$B/mut-gcm" |
| 49 | if HOP_CORE="$B/core" "$B/parity" > "$B/core.log" 2>&1; then pass "core equals the Swift reference: $(grep '^CORE-PARITY names' "$B/core.log"); $(grep '^CORE-PARITY paths' "$B/core.log"); $(grep '^CORE-PARITY text' "$B/core.log"); $(grep '^CORE-PARITY words' "$B/core.log") ($(grep '^fields ' "$B/core.log")); $(grep '^CORE-PARITY board' "$B/core.log"); $(grep '^CORE-PARITY status' "$B/core.log")" |
| 50 | else fail "core differs from the Swift reference"; tail -n 14 "$B/core.log"; fi |
| 51 | # A mutant is told apart only when the harness itself ran and counted differences in that part, and none in the |
| 52 | # other part (a harness that cannot run proves nothing). |
| 53 | ctl() { # ctl CORE PART [ALSO]: differences in PART, perhaps in ALSO (a part that builds on PART), in no other part |
| 54 | HOP_CORE="$B/$1" "$B/parity" > "$B/$1.log" 2>&1 || true |
| 55 | others=$(grep -E '^CORE-PARITY (names|paths|text|words|board|status) ' "$B/$1.log" | grep -v "^CORE-PARITY $2 " | grep -v "^CORE-PARITY ${3:-none} " | grep -Evc ' different 0$' || true) |
| 56 | if grep -Eq "^CORE-PARITY $2 same [0-9]+ different [1-9][0-9]*\$" "$B/$1.log" && [ "$(grep -Ec '^CORE-PARITY (names|paths|text|words|board|status) ' "$B/$1.log")" = 6 ] && [ "$others" = 0 ] |
| 57 | then pass "negative control: a changed $2 rule is told apart ($(grep "^CORE-PARITY $2" "$B/$1.log"))" |
| 58 | else fail "the $2 mutant $1 was not told apart"; tail -n 5 "$B/$1.log"; fi |
| 59 | } |
| 60 | ctl mut-names names |
| 61 | ctl mut-paths paths |
| 62 | ctl mut-text text |
| 63 | ctl mut-words words |
| 64 | ctl mut-board board |
| 65 | ctl mut-spans board status |
| 66 | ctl mut-addr board status |
| 67 | ctl mut-asm board |
| 68 | ctl mut-status status |
| 69 | ctl mut-rank status |
| 70 | ctl mut-suggest status |
| 71 | ctl mut-lifts status |
| 72 | ctl mut-gcm status |
| 73 | rm -rf "$B" |
| 74 | if [ $fails -eq 0 ]; then echo "HOPCORE-MACOS PASS"; else echo "HOPCORE-MACOS FAIL $fails"; exit 1; fi |