Files
Jarvis/scripts/test-check-no-evaluate-javascript.sh
james.maes a63d521d38 feat(02-04): add bus parity + HUD-04 lint + harness-parity pre-build scripts
Three build-breaking check scripts + two smoke test harnesses + two fixture dirs:

- scripts/check-bus-protocol-version.sh: greps Swift vs TS BUS_PROTOCOL_VERSION
  constants, diffs the two fixture directories (packages/Bus/Tests/BusTests/
  Fixtures/ vs webview/packages/bus/fixtures/). Fails build on any drift.
- scripts/check-no-evaluate-javascript.sh: scans App/ + packages/ for
  `.evaluateJavaScript(` outside test dirs; HUD-04 architectural lint.
- scripts/check-bus-harness-parity.sh: byte-identical check between
  canonical webview/bus-harness.html and bundle copy (Plan 02-03 provides
  the bundle copy; this script enforces no-drift going forward).
- scripts/test-check-bus-protocol-version.sh + bus-mismatch/ fixture:
  drives the protocol-version checker against a v2.0.0/v1.9.0 mismatch,
  asserts exit 1 + both versions in error text.
- scripts/test-check-no-evaluate-javascript.sh + bus-evaluate-js/ fixture:
  drives HUD-04 lint against bad.swift (evaluateJavaScript) + good.swift
  (callAsyncJavaScript). Asserts bad.swift flagged, good.swift not flagged.
  Fixture is copied to a temp dir to bypass the production */test-fixtures/*
  path-skip rule.

[Rule 3 - Blocking] Normalized Swift-side fixtures to drop trailing newlines.
The 14 JSON files under packages/Bus/Tests/BusTests/Fixtures/ had stray
trailing \n while the TS mirror at webview/packages/bus/fixtures/ did not.
Plan 02-02's SUMMARY documented the no-trailing-newline convention (matches
Swift JSONEncoder default) but Plan 02-01's fixtures were authored via a
text editor that added them. Stripping \n lets check-bus-protocol-version.sh
pass without relaxing the byte-equality invariant. Swift CodableRoundTripTests
remain green (24/24) because JSONSerialization ignores trailing whitespace.
2026-04-23 17:51:56 -05:00

51 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# test-check-no-evaluate-javascript.sh — fault-injection smoke test.
#
# Drives scripts/check-no-evaluate-javascript.sh against a fixture directory
# containing a deliberately-bad bad.swift (uses evaluateJavaScript) and a
# control good.swift (uses callAsyncJavaScript). Asserts:
# * the checker exits non-zero
# * the failure names bad.swift
# * good.swift is NOT flagged
#
# Hazard: the production checker skips any path matching `*/test-fixtures/*`,
# so running it with REPO pointing at scripts/test-fixtures would no-op the
# test (the bad.swift is inside a test-fixtures path component). Workaround:
# copy the fixture dir to a temp location whose path does not contain the
# string `test-fixtures`, then invoke the checker against that.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CHECKER="$SCRIPT_DIR/check-no-evaluate-javascript.sh"
FIX_DIR="$SCRIPT_DIR/test-fixtures/bus-evaluate-js"
[[ -x "$CHECKER" ]] || { echo "FAIL: checker not executable: $CHECKER" >&2; exit 1; }
[[ -d "$FIX_DIR" ]] || { echo "FAIL: fixture dir missing: $FIX_DIR" >&2; exit 1; }
workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT
cp -R "$FIX_DIR" "$workdir/bus-evaluate-js"
tmp="$workdir/out.log"
if env REPO="$workdir" SEARCH_ROOTS="bus-evaluate-js" \
"$CHECKER" >"$tmp" 2>&1; then
echo "FAIL: check-no-evaluate-javascript.sh accepted a bad fixture" >&2
cat "$tmp" >&2
exit 1
fi
if ! grep -q "bad.swift" "$tmp"; then
echo "FAIL: error should mention bad.swift" >&2
cat "$tmp" >&2
exit 1
fi
if grep -q "good.swift" "$tmp"; then
echo "FAIL: good.swift was falsely flagged" >&2
cat "$tmp" >&2
exit 1
fi
echo "check-no-evaluate-javascript.sh correctly rejected bad fixture"