Files
Jarvis/scripts/check-bus-harness-parity.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

54 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# check-bus-harness-parity.sh — Xcode pre-build phase.
#
# Asserts the canonical `webview/bus-harness.html` (authored) and the bundled
# copy at `App/Resources/webview/bus-harness.html` (shipped, committed by
# Plan 02-03) are byte-identical. Prevents silent drift between the two.
#
# If you changed the canonical file, re-copy it to the bundle location.
# If you changed the bundle copy directly — don't. Edit the canonical file.
#
# Usage:
# scripts/check-bus-harness-parity.sh # production
# REPO=/tmp/fix scripts/check-bus-harness-parity.sh # test mode
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${REPO:=$(cd "$SCRIPT_DIR/.." && pwd)}"
CANONICAL="$REPO/webview/bus-harness.html"
BUNDLE="$REPO/App/Resources/webview/bus-harness.html"
if [[ ! -f "$CANONICAL" ]]; then
echo "FAIL: canonical bus-harness.html missing: $CANONICAL" >&2
exit 1
fi
if [[ ! -f "$BUNDLE" ]]; then
{
echo "FAIL: bundle bus-harness.html missing: $BUNDLE"
echo " Copy from $CANONICAL to $BUNDLE and commit."
} >&2
exit 1
fi
if ! /usr/bin/diff -q "$CANONICAL" "$BUNDLE" >/dev/null 2>&1; then
{
echo "FAIL: bus-harness.html drift between canonical and bundle copy"
echo " Canonical: $CANONICAL"
echo " Bundle: $BUNDLE"
echo ""
echo "If you changed the canonical file, copy it:"
echo " cp \"$CANONICAL\" \"$BUNDLE\""
echo ""
echo "If you changed the bundle copy directly: don't. Edit the canonical file."
echo ""
echo "Diff:"
/usr/bin/diff "$CANONICAL" "$BUNDLE" || true
} >&2
exit 1
fi
echo "bus-harness.html parity OK"