open-standards/wai/wai-audit/e2e/run.sh
Transaction Science 4627e02e04 wai-audit: the browser end to end, and what it found
e2e/run.sh builds the collector, installs the automation package and an
open-source web player from e2e/package-lock.json (npm ci, no install
scripts), runs the player integration's unit tests, then
e2e/audit.e2e.mjs: an HLS stream made with the host's media tool (H.264
and AAC in 2 s CMAF segments, a program time, a marked ad over two
segments) served from another origin with CMSD-Static exposed, played in
a real browser twice, once through the loader adapter and once through
the network tap, each session sent to a collector on loopback. It checks
the outcome, the acknowledged objects against the origin's own SHA-256
of what it served, the ad's claim, the CMSD notes, the unmetered energy,
the CMCD batches, the report, its recomputation by `wai-audit check`, a
replay stored once and a tampered record refused.

Three defects it found, fixed here:
- the player hands fragment buffers on (to a worker), emptying them
  after the loader's callback: the session now copies the bytes at once,
  and keeps each object in the order it was given;
- the tap read XMLHttpRequest responses after the player had moved them:
  it now listens from the request's construction, so it reads first;
- a stitched ad is entered between two observations, so its claim began
  past media time 0 and reached quartile 1: play that enters an ad
  continuously now starts its first span at 0 (stream-audit §6.3), as
  leaving it already ran the last span to the ad's end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 21:50:20 -04:00

38 lines
1.6 KiB
Shell
Executable file

#!/bin/bash
# Build the stream audit collector and run the kit's tests: the player integration's unit tests
# against the corpus, then the end-to-end run in a real browser (e2e/audit.e2e.mjs).
#
# e2e/run.sh [--runs N]
#
# Environment: CARGO_TARGET_DIR, BROWSER_BIN (an installed browser; otherwise the automation
# package's own, which PLAYWRIGHT_BROWSERS_PATH must then hold), AUDIT_E2E_OUT (where artifacts go),
# NPM_OFFLINE (set: install the packages from the local cache alone). The packages come from
# e2e/package-lock.json (`npm ci --ignore-scripts`: no install script runs). Nothing listens beyond
# loopback.
set -euo pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
CRATE=$(cd "$HERE/.." && pwd)
OUT=${AUDIT_E2E_OUT:-${TMPDIR:-/tmp}/wai-audit-e2e}
TARGET=${CARGO_TARGET_DIR:-$CRATE/target}
export CARGO_TARGET_DIR="$TARGET"
mkdir -p "$OUT"
echo "== the collector"
(cd "$CRATE" && cargo build --locked --release)
echo "== the packages"
PKG="$OUT/pkg"
mkdir -p "$PKG"
cp "$HERE/package.json" "$HERE/package-lock.json" "$PKG/"
(cd "$PKG" && npm ci --ignore-scripts --no-audit --no-fund ${NPM_OFFLINE:+--offline})
PLAYER="$PKG/node_modules/hls.js/dist/hls.min.js" # allow-name: the open-source web player's package and its script
echo "== the player integration's unit tests"
node --test "$CRATE/web/audit.test.mjs"
echo "== end to end"
browser=()
[ -n "${BROWSER_BIN:-}" ] && browser=(--browser "$BROWSER_BIN")
PLAYWRIGHT_HOST="$PKG/node_modules" node "$HERE/audit.e2e.mjs" \
--collector "$TARGET/release/wai-audit" --web "$CRATE/web" --page "$HERE/page" --player "$PLAYER" \
--out "$OUT/results" ${browser[@]+"${browser[@]}"} "$@"