hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / tools / check-ask-route.sh
| 1 | #!/bin/sh |
| 2 | # Negative controls for Ask's own-model-first rows (Sources/AskRouteChecks.swift). |
| 3 | # Usage: tools/check-ask-route.sh [mutant-name ...] (no names: all of them) |
| 4 | # |
| 5 | # First the rows must pass on this tree (build/Hop.app, built by ./build.sh). Then, for each mutant, a copy of the |
| 6 | # tree with ONE rule changed is built with ./build.sh (signed ad-hoc) and `Hop --selftest-ask` must exit non-zero |
| 7 | # with the named row reported FAIL. A mutant whose text is not found in the source is a failure of this script, |
| 8 | # not a pass. Every run uses a fresh HOP_CONFIG_DIR under the system's temporary folder; the rows talk only to stub |
| 9 | # servers on this Mac's loopback address. Builds run one at a time under nice. Prints ASK-ROUTE-MUTANTS PASS n. |
| 10 | set -u |
| 11 | cd "$(dirname "$0")/.." |
| 12 | ROOT=$PWD |
| 13 | T=$(mktemp -d "${TMPDIR:-/tmp}/hop-ask-route.XXXXXX") |
| 14 | trap 'rm -rf "$T"' EXIT |
| 15 | fails=0 passes=0 |
| 16 | pass() { echo "PASS $*"; passes=$((passes + 1)); } |
| 17 | fail() { echo "FAIL $*"; fails=$((fails + 1)); } |
| 18 | |
| 19 | rows() { # rows APP LOG: run the rows alone with a throwaway settings folder; echoes the exit code |
| 20 | d=$(mktemp -d "$T/cfg.XXXXXX") |
| 21 | HOP_CONFIG_DIR="$d" "$1/Contents/MacOS/Hop" --selftest-ask --no-global-hotkey > "$2" 2>&1 |
| 22 | echo $? |
| 23 | } |
| 24 | |
| 25 | # Control: the unchanged tree passes every row. |
| 26 | if [ ! -x build/Hop.app/Contents/MacOS/Hop ]; then fail "control: build/Hop.app is missing (run ./build.sh first)" |
| 27 | else |
| 28 | rc=$(rows build/Hop.app "$T/control.log") |
| 29 | if [ "$rc" = 0 ] && grep -q '^ASK-ROUTE PASS 9$' "$T/control.log"; then pass "control: unchanged tree, $(tail -n 1 "$T/control.log")" |
| 30 | else fail "control: unchanged tree, Hop exit $rc"; cat "$T/control.log"; fi |
| 31 | fi |
| 32 | |
| 33 | # name | file | text to find | replacement | row that must FAIL |
| 34 | MUTANTS='own-first-removed|Sources/AskRoute.swift|(cfg.preferOwnModel ?? true) && !ownModels(cfg).isEmpty }|false }|Ask uses your own model when it answers |
| 35 | fresh-install-changed|Sources/AskRoute.swift|(cfg.preferOwnModel ?? true) && !ownModels(cfg).isEmpty }|(cfg.preferOwnModel ?? true) }|Ask on a fresh install is unchanged |
| 36 | fallback-line-removed|Sources/AskRoute.swift|note: fallbackNote(silent, using: previous(cfg)))|note: nil)|Your own model silent: Ask falls back and says so in one line |
| 37 | default-ignored|Sources/AskRoute.swift|if let d = cfg.defaultModel { return Choice(name: d, note: nil) }|_ = 0|An explicit defaultModel always wins |
| 38 | switch-ignored|Sources/AskRoute.swift|(cfg.preferOwnModel ?? true) &&|true &&|"preferOwnModel": false switches it off |
| 39 | online-counted|Sources/AskRoute.swift|$0.kind == "openai" && $0.place != .online|$0.kind == "openai"|Only a model on this Mac or your network counts as your own |
| 40 | stream-id-dropped|Sources/Runners.swift|if out.model == nil { out.model = AskRoute.reportedModel(j) }|_ = 0|Under an answer: the model the server named, and where it ran |
| 41 | reported-id-ignored|Sources/AskRoute.swift|!r.isEmpty { return "answered by \(r)" }|!r.isEmpty, r.isEmpty { return "answered by \(r)" }|Under an answer: the model the server named, and where it ran |
| 42 | configured-label-dropped|Sources/AskRoute.swift| (the configured name; \(teller) reported no model id)"|" + (teller.isEmpty ? "" : "")|No model id reported: the configured name, said to be that |
| 43 | cli-id-dropped|Sources/AskRoute.swift|let found: [Any?] = [j["model"], |let found: [Any?] = [nil, |Claude CLI answers name the model it reported' |
| 44 | |
| 45 | echo "$MUTANTS" > "$T/mutants" |
| 46 | while IFS='|' read -r name file from to row; do |
| 47 | if [ $# -gt 0 ]; then case " $* " in *" $name "*) ;; *) continue ;; esac; fi |
| 48 | M="$T/$name"; mkdir -p "$M" |
| 49 | (cd "$ROOT" && tar cf - --exclude ./build --exclude ./.git --exclude ./dist .) | (cd "$M" && tar xf -) |
| 50 | FROM="$from" TO="$to" perl -0pi -e '$n = s/\Q$ENV{FROM}\E/$ENV{TO}/g; END { exit($n == 1 ? 0 : 3) }' "$M/$file" |
| 51 | if [ $? -ne 0 ] || cmp -s "$ROOT/$file" "$M/$file"; then fail "mutant $name: the text to change was not found exactly once in $file"; continue; fi |
| 52 | if ! (cd "$M" && HOP_SIGN=adhoc nice -n 15 ./build.sh > "$T/$name.build.log" 2>&1); then |
| 53 | fail "mutant $name: did not build"; tail -n 8 "$T/$name.build.log"; rm -rf "$M"; continue |
| 54 | fi |
| 55 | rc=$(rows "$M/build/Hop.app" "$T/$name.log") |
| 56 | if [ "$rc" != 0 ] && grep -qF "FAIL $row:" "$T/$name.log"; then |
| 57 | pass "negative control: $name is caught (Hop exit $rc, FAIL $row)" |
| 58 | else |
| 59 | fail "mutant $name was not caught (Hop exit $rc)"; cat "$T/$name.log" |
| 60 | fi |
| 61 | rm -rf "$M" |
| 62 | done < "$T/mutants" |
| 63 | |
| 64 | if [ "$fails" = 0 ]; then echo "ASK-ROUTE-MUTANTS PASS $passes"; exit 0; fi |
| 65 | echo "ASK-ROUTE-MUTANTS FAIL $fails"; exit 1 |