Data pipeline sanity tests #
Run make test. It automatically runs make setup to create .venv/ and
install requirements.txt, then runs the full suite with that environment.
Dependency installation needs network access on first use (or when requirements
change); subsequent runs reuse the environment.
make setup is also available separately, and all make data-* targets use the
same environment. Override PYTHON to select the bootstrap interpreter or VENV
to select the environment directory:
make setup
make test
make test PYTHON=python3.12 VENV=/tmp/hanzi-venv
To run core checks without installing dependencies, use
python3 -m unittest discover -s test -v directly. Language integration checks
report explicit skips if their packages are missing.
The progress-index test stubs simplification because simplified text is excluded from its fingerprint. A separate OpenCC integration test checks the real converter.
fixtures/indexes.json contains counts and SHA-256 hashes generated exclusively
from clean Python subject and progress builds using the checked-in source data.
It is a Python regression baseline, not a Rust migration-parity check. Progress
simplification is stubbed during baseline generation, just as in the test, because
that field is excluded from the projection. Tests do not read ignored local files
under www/static/gen/.
The subject projection covers ordered IDs, slugs, types, levels, positions, SRS
IDs, hidden timestamps, card types, prerequisites, components, similar subjects,
and readings. Progress projections include everything except simplified text.
JSON formatting, audio order, meanings, hints, and examples are not pinned.
From the repository root, check or regenerate the snapshot reproducibly:
.venv/bin/python test/index_snapshot.py --check
.venv/bin/python test/index_snapshot.py --update
The script shares its clean-build setup and projection logic with the tests.
--check never writes and exits nonzero on differences; --update explicitly
replaces test/fixtures/indexes.json. Both build only in temporary directories,
without reading local generated subjects or audio, or requiring language packages.
Review the printed changes and git diff -- test/fixtures/indexes.json before
committing an update. Tests never update snapshots automatically.
An intentional curriculum change will require updating the baseline after reviewing the index changes, not simply accepting a new hash. Existing generated subject JSON is an input to the build: it preserves retired subjects, their IDs, and manually maintained content. The test separately seeds an active subject with manual content and a retired subject, then checks ID/card/content preservation, unhiding, retirement, and repeat-build stability. Clean-build fingerprints are not a promise that deleting generated subject files in production is safe.
Additional checks cover game-card schemas/order, all dispatcher commands, dictionary update preservation/idempotence, sort preservation, pronunciation dependency APIs, lazy-quoted sentence parsing, curriculum-level calculation, audio filename/region contracts, and the license schema with a mocked fetch.