feat(wasm): examples/wasm-viewer, an HDF5/NetCDF-4 viewer page

Drop a file (or pass ?file=<url>&path=<object>), browse the tree lazily,
see a dataset's type, shape, max shape and attributes, and page through
its values as 50x12 hyperslab windows (leading dims of 3-D+ data held
at chosen indices). build.sh produces pkg/ (not committed) with
wasm-bindgen --target web and checks the CLI matches the crate version.

test/run.sh builds it and runs test.mjs under Node against the h5py/
netCDF4 fixture (250 checks: every dataset whole and as a strided
hyperslab, listings, attributes, error paths, the page's DOM-free
helpers), then browser.sh renders the page in headless Chromium for
eight objects and checks the DOM. The fixture gains LZ4 (read) and Zstd
(refused: links C) datasets and a compound attribute (value null plus
its type). ci-test.sh runs it when node and wasm-bindgen exist; the CI
container has neither, so CI relies on the native h5py_interop test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
osobh
2026-09-26 00:05:34 -05:00
co-authored by Claude Opus 5.5
parent a42b646689
commit 1abd93e0f8
11 changed files with 800 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Build the wasm package (../build.sh), test it under Node against files
# written by h5py and netCDF4 (make_fixture.py), then load the viewer page
# in headless Chromium if one is found (browser.sh).
#
# Needs node, the wasm-bindgen CLI (see ../build.sh) and a Python with h5py,
# netCDF4 and numpy: CLAWHDF5_PYTHON names it (default python3). Without that
# Python the test is skipped, unless CLAWHDF5_REQUIRE_INTEROP=1.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
PY="${CLAWHDF5_PYTHON:-python3}"
command -v node >/dev/null || { echo "node not found" >&2; exit 1; }
if ! "$PY" -c "import h5py, netCDF4, numpy" >/dev/null 2>&1; then
if [ "${CLAWHDF5_REQUIRE_INTEROP:-0}" = "1" ]; then
echo "CLAWHDF5_REQUIRE_INTEROP=1 but $PY lacks h5py/netCDF4/numpy" >&2
exit 1
fi
echo "SKIP: $PY lacks h5py/netCDF4/numpy"
exit 0
fi
bash "$HERE/../build.sh"
fix="$(mktemp -d)"
trap 'rm -rf "$fix"' EXIT
"$PY" "$HERE/make_fixture.py" "$fix"
node "$HERE/test.mjs" "$HERE/../pkg" "$fix"
# The page itself, in headless Chromium when one is available.
status=0
bash "$HERE/browser.sh" "$fix" || status=$?
if [ "$status" = 3 ]; then
echo "SKIP: viewer page in a browser (no Chromium; set CHROME)"
elif [ "$status" != 0 ]; then
exit "$status"
fi