Skip to content

Commit 6b789cc

Browse files
committed
fix(tests): harden docker-run.sh argument and image-hash handling
Two papercuts hit while regenerating baselines for the fix in this PR: - `vitest --run -u <filter>` parses <filter> as the *value* of `-u`, so the filter is dropped and the whole suite runs in update mode. The `e2e:updateSnaps` script ends in `-u`, so any filter a caller appends (as CLAUDE.md instructs) lands in exactly that trap - which silently rewrote an unrelated, flaky `deleteShallowerBlock` baseline. `-u` / `--update` is now always passed last. - wasm-pack emits `packages/xl-typst-compiler/pkg/package.json`, which the image content hash globbed, so building the wasm that docker-run.sh itself requires invalidated the image. A fresh clone paid two full image builds. `pkg` is now pruned alongside `dist`.
1 parent cc3431b commit 6b789cc

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

.claude/skills/testing-skill/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bash tests/docker-run.sh -e CI=1 -- --run [filters]
5555

5656
A specific test file may be targeted by appending (part of) its name as a filter. A single browser may be targeted with `--project "e2e (chromium)"`. Individual tests in a file may be disabled using `skip`, i.e. `test.skip("Test name", ...)` (remember to revert this once all tests pass).
5757

58-
Screenshot baselines can be regenerated with the `-u` argument, which must come **after** the filters (`--run <filters> -u`): written as `--run -u <filter>`, the filter is parsed as the flag's value and the **whole** suite runs in update mode, silently rewriting unrelated baselines. Note that `-u` only rewrites baselines whose comparison **fails** — a small intended change (e.g. a short text edit) that fits inside the suite's 2% pixel tolerance leaves the baseline stale while the test passes. To force a fresh capture, delete the baseline file first. Baselines are per-browser (`<name>-<browser>-linux.png`); after regenerating, always inspect the images before committing them.
58+
Screenshot baselines can be regenerated with the `-u` argument. Vitest parses `--run -u <filter>` with the filter as the _value_ of `-u`, which drops the filter and runs the **whole** suite in update mode; `docker-run.sh` now normalizes this by always passing `-u`/`--update` last, so either order is safe through the script (invoking vitest directly still is not). Note that `-u` only rewrites baselines whose comparison **fails** — a small intended change (e.g. a short text edit) that fits inside the suite's 2% pixel tolerance leaves the baseline stale while the test passes. To force a fresh capture, delete the baseline file first. Baselines are per-browser (`<name>-<browser>-linux.png`); after regenerating, always inspect the images before committing them.
5959

6060
When testing a visual change, prefer writing screenshots to verify that the change is working as expected.
6161

tests/docker-run.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,28 @@ done
2626
[ "$#" -gt 0 ] && shift
2727
entrypoint_args=("$@")
2828

29+
# `vitest --run -u <filter>` parses <filter> as the *value* of `-u`, so the
30+
# filter is dropped and the whole suite runs in update mode, silently rewriting
31+
# unrelated baselines. The `e2e:updateSnaps` package script ends in `-u`, which
32+
# puts any filter a caller appends into exactly that trap. Re-order defensively
33+
# so `-u`/`--update` is always passed last, after the filters.
34+
update_flags=()
35+
filtered_args=()
36+
for arg in "${entrypoint_args[@]}"; do
37+
case "$arg" in
38+
-u | --update) update_flags+=("$arg") ;;
39+
*) filtered_args+=("$arg") ;;
40+
esac
41+
done
42+
entrypoint_args=("${filtered_args[@]}" "${update_flags[@]}")
43+
2944
# Auto-rebuild the image if its content hash label doesn't match the current
3045
# repo state. The hash covers every file that affects the image's contents: the
3146
# Dockerfile itself, plus everything it bakes in — the lockfile, workspace file,
32-
# all package.json files, patches, and example sources. When they differ the
47+
# all package.json files, patches, and example sources. Generated output dirs
48+
# are pruned: `pkg/` is wasm-pack's, and it emits a package.json, so without
49+
# that prune, building the wasm this script *requires* would itself invalidate
50+
# the image and force a second full rebuild. When they differ the
3351
# image is rebuilt in place
3452
# (Docker's layer cache makes this fast when only a leaf changed).
3553
_dep_files() {
@@ -42,7 +60,8 @@ _dep_files() {
4260
find . -name package.json \
4361
-not -path '*/node_modules/*' \
4462
-not -path '*/.git/*' \
45-
-not -path '*/dist/*'
63+
-not -path '*/dist/*' \
64+
-not -path '*/pkg/*'
4665
} | sort -u
4766
}
4867
_content_hash() {

0 commit comments

Comments
 (0)