# Build and verify

The library and the standalone validator are written in MoonBit. The conversion CLI uses Node.js. The independent comparisons use Python 3.12 with pinned reference readers. CI exercises MoonBit `1.0.0-rc1+3c0520448` on Windows and Linux, including native x86-64 and AArch64 Ubuntu builds.

```sh
moon version --all
moon fmt --check
moon check --target all --deny-warn
moon test --target js --deny-warn
moon test --target wasm --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target native --deny-warn
moon run examples/records --target js
moon build bridge --target js --release --deny-warn
node tools/bundle-cli.cjs _build/js/release/build/bridge/bridge.js dist/steimpack.cjs
node --test tests/cli.test.cjs tests/cli.integration.test.cjs tests/linux-files.test.cjs tests/stream-selection.test.cjs
```

## Independent comparisons

```sh
python -m pip install -r tests/requirements.txt
python tests/interop.py --report _build/interop.json
python tests/scale.py
python tests/stations.py
```

The first run of `interop.py` fetches the official sinusoid examples and legacy reference records. It verifies each file's SHA-256 before decoding. The default cache is `_build/reference-data`. For offline use, point `--cache` at a directory containing the files named in `tests/reference_data.py`. The station segment is included in the repository.

| Input or experiment | Independent checks |
| --- | --- |
| FDSN Steim-1 and Steim-2 sinusoids | Compare all 500 and 499 samples with FDSN JSON. Their shared prefix is identical. Repacking the 500-point example as Steim-2 yields records of 499 and 1 because its final difference is 556,206,272. |
| Four miniSEED 2.4 fixtures from libmseed 3.6.0 | Both payload byte orders for both codecs. Compare all samples and each record's header, start and byte extent against libmseed. |
| IU.ANMO.00.BHZ, five minutes at 20 Hz | Compare all 6,000 samples across 15 source records. Convert v2 to v3 with each codec and decode with libmseed and SimpleMSeed. Check the identity, flags, original starts and translated extra headers. |
| Mixed IU.ANMO and IU.COLA channels | Interleave 15 original v2 records with 16 COLA records encoded as v3 by libmseed. Compare each channel's full 6,000-sample output and original offsets. Check that both independent readers recover each filtered conversion. Recover the three original 1 µs timing deviations and, in a separate stream, a 21.4 s missing span and a 19.05 s overlap. |
| Producer interoperability | libmseed and SimpleMSeed each generate v3 records in both codecs. SteimPack reads all four streams and compares every integer with the original. |
| Million-sample stream, 37 Hz | Encode and decode a 4,000,000-byte deterministic signal with each codec. Compare exact PCM bytes and every libmseed-decoded value. Check CRCs and each UTC start against an integer nanosecond oracle across leap-day midnight. |
| Corrupt or incomplete input | Tests cover mismatched CRC and Xn, reserved words, bad blockette offsets, impossible sample counts, incomplete records and partial int32 input. CLI tests also check that a failed file conversion preserves an existing destination. |

`tests/scale.py` prints machine-readable counts, encoded bytes, timings and input SHA-256. Timings depend on the machine. CI uploads the comparison results for each operating system.

## Native Linux and released assets

Build the checker and use the executable path printed in the build artifact JSON. These process and scale tests use only the Python standard library.

```sh
moon build cmd/steimcheck --target native --release --deny-warn --output-json > _build/native-build.jsonl
exe=$(jq -r 'select(."$message_type" == "artifact" and .target_backend == "native") | .path' _build/native-build.jsonl)
python3 tests/native_check.py "$exe" -v
python3 tests/native_scale.py "$exe"
```

The process tests exercise files, stdin, fragmented records, an open FIFO, exact record-size bounds, corrupt CRCs and a wrong Xn with a valid CRC. The scale tests stream 120 MiB of repeated real records and locate a damaged signature exactly 4 GiB into a separate pipe. A single compressed record expands to 16,777,216 samples, a 64 MiB int32 array. Its waveform check must stay within a 56 MiB process RSS budget on both Linux runners. Each job records the observed peak and elapsed time. CLI file tests cover restrictive umasks, preservation of regular permission bits, relative symlinks, FIFOs and output rollback.

Both native build jobs extract the archive and run the binary as an unprivileged user inside a read-only minimal Debian container with networking disabled. After publication, a fresh Ubuntu runner for each architecture fetches the public tarball and CLI, checks their digests, repeats the same Debian test, and compares a filtered channel with the libmseed PCM digest. It also installs the exact MoonCakes version into an empty project and runs a native example that calls the codec and timeline APIs. [Native build jobs](https://github.com/kent131452777/steimpack/actions/workflows/native.yml) · [Published install jobs](https://github.com/kent131452777/steimpack/actions/workflows/published.yml)

The reference readers are `pymseed` (libmseed bindings) and the independent Python implementation SimpleMSeed. Short byte-order excerpts in codec tests come from EarthScope libmseed's Apache-2.0 test fixtures. The standalone CLI includes the MoonBit core license and notices. [pymseed](https://github.com/EarthScope/pymseed) · [SimpleMSeed](https://github.com/crotwell/simplemseed) · [libmseed license](https://github.com/EarthScope/libmseed/blob/v3.6.0/LICENSE) · [Station provenance and FDSN fixtures](../tests/data/README.md)
