interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / check-core.sh

74 lines · 5349 bytes Raw Blame History
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.
15set -eu
16cd "$(dirname "$0")/../.."
17export LC_ALL=C
18[ "$(uname -sm)" = "Darwin arm64" ] || { echo "HOPCORE-MACOS NOT_RUN (host is $(uname -sm))"; exit 1; }
19B=$(mktemp -d "${TMPDIR:-/tmp}/hopcore.XXXXXX")
20fails=0
21pass() { echo "PASS $1"; }
22fail() { echo "FAIL $1"; fails=$((fails + 1)); }
23if shasum -a 256 -c Generated/CORE-SHA256SUMS > "$B/sums.log" 2>&1; then pass "Generated/hopcore and Omega/hopcore.om match Generated/CORE-SHA256SUMS"
24else fail "CORE-SHA256SUMS mismatch"; cat "$B/sums.log"; fi
25EXTRA=""
26if [ -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"
30fi
31# shellcheck disable=SC2086
32swiftc -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"; }
34sign() { cp "$1" "$2"; chmod 755 "$2"; codesign --force --sign - "$2" 2> /dev/null; }
35sign Generated/hopcore "$B/core"
36sign Omega/tests/mutant/hopcore-names "$B/mut-names"
37sign Omega/tests/mutant/hopcore-paths "$B/mut-paths"
38sign Omega/tests/mutant/hopcore-text "$B/mut-text"
39sign Omega/tests/mutant/hopcore-words "$B/mut-words"
40sign Omega/tests/mutant/hopcore-board "$B/mut-board"
41sign Omega/tests/mutant/hopcore-spans "$B/mut-spans"
42sign Omega/tests/mutant/hopcore-addr "$B/mut-addr"
43sign Omega/tests/mutant/hopcore-asm "$B/mut-asm"
44sign Omega/tests/mutant/hopcore-status "$B/mut-status"
45sign Omega/tests/mutant/hopcore-rank "$B/mut-rank"
46sign Omega/tests/mutant/hopcore-suggest "$B/mut-suggest"
47sign Omega/tests/mutant/hopcore-lifts "$B/mut-lifts"
48sign Omega/tests/mutant/hopcore-gcm "$B/mut-gcm"
49if 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")"
50else 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).
53ctl() { # 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}
60ctl mut-names names
61ctl mut-paths paths
62ctl mut-text text
63ctl mut-words words
64ctl mut-board board
65ctl mut-spans board status
66ctl mut-addr board status
67ctl mut-asm board
68ctl mut-status status
69ctl mut-rank status
70ctl mut-suggest status
71ctl mut-lifts status
72ctl mut-gcm status
73rm -rf "$B"
74if [ $fails -eq 0 ]; then echo "HOPCORE-MACOS PASS"; else echo "HOPCORE-MACOS FAIL $fails"; exit 1; fi