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-index-rebuild.sh
| 1 | #!/bin/sh |
| 2 | # Checks the command Hop uses to rebuild another machine's file list (Sources/RemoteIndex.swift) where it runs: on a |
| 3 | # Linux machine with GNU find. Builds the command here, runs five cases there in a scratch folder under /tmp. |
| 4 | # Usage: tools/check-index-rebuild.sh SSH_HOST |
| 5 | set -eu |
| 6 | cd "$(dirname "$0")/.." |
| 7 | host=${1:?usage: tools/check-index-rebuild.sh SSH_HOST} |
| 8 | work=$(mktemp -d "${TMPDIR:-/tmp}/hop-index-check.XXXXXXXX") |
| 9 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 10 | sed "s#HOP_DIR#$PWD#" toolchain/overlay.yaml > "$work/overlay.yaml" |
| 11 | swiftc -swift-version 5 -vfsoverlay "$work/overlay.yaml" -Xcc -ivfsoverlay -Xcc "$work/overlay.yaml" \ |
| 12 | Sources/RemoteIndex.swift tests/RemoteIndexChecks.swift -o "$work/print" |
| 13 | T=/tmp/hop-index-check.$$ |
| 14 | { |
| 15 | echo "T=$T" |
| 16 | echo "CMD=$("$work/print" "$T/root")" |
| 17 | echo "NONE=$("$work/print" "$T/missing")" |
| 18 | cat <<'REMOTE' |
| 19 | set -u |
| 20 | fail=0 |
| 21 | mkdir -p "$T/root/a" "$T/root/locked" "$T/root/node_modules/x" |
| 22 | i=0; while [ $i -lt 300 ]; do : > "$T/root/a/file-with-a-long-enough-name-to-fill-the-list-$i"; i=$((i + 1)); done |
| 23 | chmod 000 "$T/root/locked" |
| 24 | check() { # NAME WANT(new|old) SCRIPT |
| 25 | H="$T/home-$1"; mkdir -p "$H/.cache/hop/building" "$H/.cache/hop/shards"; echo old > "$H/.cache/hop/shards/s00" |
| 26 | HOME="$H" sh -c "$3" 2>/dev/null |
| 27 | if [ "$(cat "$H/.cache/hop/shards/s00")" = old ]; then got=old; else got=new; fi |
| 28 | left=$(cd "$H/.cache/hop" && ls -d index.tmp index.err building shards.new 2>/dev/null | tr '\n' ' ') |
| 29 | if [ "$2" = new ] && ! cat "$H"/.cache/hop/shards/s* | grep -q "^$T/root/locked/\$"; then got="$got-without-locked"; fi |
| 30 | if [ "$2" = new ] && cat "$H"/.cache/hop/shards/s* | grep -q node_modules/x; then got="$got-with-pruned"; fi |
| 31 | if [ "$got" = "$2" ] && [ -z "$left" ]; then echo "PASS $1"; else echo "FAIL $1: want $2, got $got, left [$left]"; fail=1; fi |
| 32 | } |
| 33 | check unreadable-folder new "$CMD" |
| 34 | check plain-folder new "chmod 755 '$T/root/locked'; $CMD; chmod 000 '$T/root/locked'" |
| 35 | check write-error old "trap '' XFSZ; ulimit -f 4; $CMD" |
| 36 | check killed-find old "ulimit -f 4; $CMD" |
| 37 | check no-root old "$NONE" |
| 38 | chmod 755 "$T/root/locked"; rm -rf "$T" |
| 39 | [ $fail = 0 ] && echo "INDEX REBUILD PASS" || { echo "INDEX REBUILD FAIL"; exit 1; } |
| 40 | REMOTE |
| 41 | } | ssh -o BatchMode=yes "$host" sh -s |