# Reference tools

Run these commands from this directory after installing dependencies with `npm ci` (or `npm ci --offline --no-audit --no-fund` when cached):

- `npm test`: portable consumer, validation, CLI, integrity and boundary checks on Node 22, 24 or 26; no host Unicode version requirement.
- `npm run test:mutations`: eighteen targeted mutations in disposable synthetic copies, including preservation of an owner-chosen health statement, deep unknown fields, selector rejection, unavailable-file handling, reading `"0.2"` profiles, including `visibility: public`, and the `quiet_hours` rules. It never mutates the working implementation.
- `npm run test:unicode`: exhaustive generator equivalence over all 1,114,112 code points. Requires `process.versions.unicode === '17.0'`, for example Node 24.21.0 or 26.10.0, and fails explicitly on another Unicode version. Allow about a second on a typical development machine; it is separate from `npm test` and never silently skipped.
- `node validate.mjs <files...> [--draft] [--expect-invalid]`: strict file validation; `--expect-invalid` asserts that each supplied file is available but invalid, including oversize and malformed UTF-8 inputs. Missing, unreadable and directory inputs fail even with this flag. These are the only accepted flags. Unknown flags, including every state selector form, fail with static `UNSUPPORTED_ARGUMENT` before profile file IO.
- `node ../tests/check-structure.mjs`: verify normative artifact hashes and vector structure on a Unicode 17.0 runtime. This separate artifact checker uses the schema's native Unicode expressions, unlike the portable consumer suite.

Put the selected Node binary's directory first in `PATH` before invoking `npm`, so its child `node` commands use the same runtime. The tests use synthetic fixtures; no model, network service, profile installation or telemetry is involved.

`validate.mjs` exports `parseProfile(string | Uint8Array, options)` and `loadProfile(path, mode, draft)`. The file entrance reads at most 24,590 bytes before decoding. Strict validation accepts only `humans: "0.3"` and rejects unknown fields; supported-version reading accepts `"0.3"` and `"0.2"` (read as `"0.3"`, with `visibility: public` read as `anyone_with_file`) and reconstructs recognized fields and ignores unknown enums only after checking supplied types, bounds and uniqueness. YAML collections are composed and converted iteratively within the existing byte bound, with no extra depth limit. Unknown subtrees still undergo syntax, key, duplicate and scalar checks before discard. Invalidity returns no profile and static diagnostics. Warnings do not fail validation. `--draft` skips only filename matching and reports that exemption.

The workshop's typed parser uses the same portable `reader-core.mjs` with separately generated standalone validators. `conformance.mjs` executes normative byte, profile and group vectors plus synthetic regressions in `regressions.mjs`. Differential tests compare complete parser results across the two validator paths and compare the independent merge implementations. They do not constitute independent parser algorithms or native adapter trials.

Plain-text category checks use generated Unicode 17.0 ranges, independent of the consumer's ICU tables. Regenerate with `node gen-unicode.mjs` on a Unicode 17.0 runtime, then run `npm run test:unicode`. The ordinary suite retains a pinned artifact digest and explicit category/parser boundary checks, including Unicode 17 additions on older hosts. Generated files must not be hand edited.

`merge(profiles, { today })` accepts already parsed, audience-authorized profiles; null denotes an unavailable recipient. Own `state` or `activeStates` properties throw `Error('UNSUPPORTED_ARGUMENT')` by presence, including null, empty and undefined values, before inspecting profiles. It excludes private profiles, never applies stored states and emits only the experimental group shape. `node merge.mjs <case.json>` rejects selectors in the case before loading members, and rejects CLI flags before reading the case; rejection exits 2 with only static `UNSUPPORTED_ARGUMENT` on stderr. Authorization remains the caller's responsibility. The reference tools do not provide an agent renderer; adapters must implement the normative frame and budgets separately.
