justintsus-experiment Public
#!/usr/bin/env bash# Runs the hidden search-query tests against one builder's worktree.## hidden-tests/run.sh <worktree path> [--tap <file>]## 1. makes the worktree-local node_modules links (@duragit/*, @tsus/runtime) if they are missing;# 2. compiles the worktree's .tsus files (npm run tsus:web; a no-op for a plain-TypeScript build);# 3. runs every hidden-tests/*.test.mjs with SEARCH_WORKTREE set, printing the spec report and a# final "pass N / total M" line (and the TAP stream to --tap <file> when given).# Exit status: 0 when every test passes, 1 otherwise, 2 for a setup failure.set -uo pipefailhere="$(cd "$(dirname "$0")" && pwd)"wt="${1:?usage: run.sh <worktree path> [--tap <file>]}"wt="$(cd "$wt" && pwd)" || exit 2tap=""if [ "${2:-}" = --tap ]; then tap="${3:?--tap needs a file}"; fiif [ ! -f "$wt/apps/web/src/search/api.ts" ]; then echo "run.sh: $wt/apps/web/src/search/api.ts is missing" >&2 exit 2fimkdir -p "$wt/node_modules/@duragit" "$wt/node_modules/@tsus"for p in actions:apps/actions cli:packages/cli deadman:apps/deadman git:packages/git shared:packages/shared ssh:apps/ssh web:apps/web; do name="${p%%:*}"; target="${p#*:}" [ -e "$wt/node_modules/@duragit/$name" ] || ln -sfn "../../$target" "$wt/node_modules/@duragit/$name"done[ -e "$wt/node_modules/@tsus/runtime" ] || { [ -d "$wt/tools/tsus/packages/runtime" ] && ln -sfn ../../tools/tsus/packages/runtime "$wt/node_modules/@tsus/runtime"; }if [ -f "$wt/scripts/tsus-web.mjs" ]; then if ! (cd "$wt" && node scripts/tsus-web.mjs build); then echo "run.sh: the .tsus build failed; every test counts as failed" >&2 exit 2 fifiout="$(mktemp -t hidden-tap.XXXXXX)"SEARCH_WORKTREE="$wt" node --test --test-concurrency=1 --test-timeout=60000 \ --test-reporter=spec --test-reporter-destination=stdout \ --test-reporter=tap --test-reporter-destination="$out" \ "$here"/*.test.mjsstatus=$?# Suites (describe blocks) report as ok/not ok lines too; count only the leaf tests.leaf_pass=$(node -e 'const t = require("fs").readFileSync(process.argv[1], "utf8").split("\n");let pass = 0, fail = 0;for (let i = 0; i < t.length; i++) { const m = /^( *)(not ok|ok) \d+ - /.exec(t[i]); if (!m) continue; // A suite line is followed by its own yaml block with type: suite. let suite = false; for (let j = i + 1; j < Math.min(t.length, i + 6); j++) { if (/type: .suite./.test(t[j])) { suite = true; break; } if (/^ *(not ok|ok) \d+ - /.test(t[j])) break; } if (suite) continue; if (m[2] === "ok") pass++; else fail++;}console.log(pass + " " + (pass + fail));' "$out")[ -n "$tap" ] && cp "$out" "$tap"rm -f "$out"echo "hidden tests: pass ${leaf_pass% *} / total ${leaf_pass#* } (worktree $wt)"[ "$status" = 0 ] && exit 0 || exit 1