# 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 tests/archive-queries.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
python tests/archive_queries.py
python tests/numeric_pipeline.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. |
| Shuffled and retransmitted station records | Compare final UTC spans and physical durations with an independent interval union. A 31,745-record input fills a missing ANMO interval on its last record. Compare a ten-second cut with all 200 libmseed sample values and the raw enclosing records byte for byte. |
| Eleven EarthScope archive fixtures | Check time-window selection on both versions of a 107-record, three-channel archive, mixed lengths including 128 bytes, 1080 Hz sampling, floating-point records and a legacy clock correction. Compare detection and timing extras in converted header-only records with libmseed. |
| Seventeen numeric and calibration files | Compare 90 records and 17,469 samples with libmseed and SimpleMSeed, including all six numeric encodings and IU.KIEV step, sine and pseudo-random calibrations. Compare encoded sample bits, header fields, clipped binary64 values and timestamped CSV. Check all eight combinations of IEEE width, header order and payload order using signed zeros, infinities, subnormals and NaN payloads. |
| A continuous CSV export across leap-day midnight | Check all 65,537 data rows against a 37 Hz integer nanosecond clock and their original amplitudes. The first row is at 23:59:59.123456789 UTC on 29 February 2024. The last is at 00:29:30.366700032 UTC on 1 March. |
| Three samples from a large Steim-2 record | Decode a UTC window near the end of a 16,777,216-sample ramp. Check the three signed int32 values and their digest. |
| 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 executables 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 downloads the public tarball and CLI, verifies their digests, and repeats the Debian test. It checks a full channel and a ten-second window against libmseed PCM digests, compares raw channel extraction byte for byte, and checks coverage across duplicate records. It installs the exact MoonCakes version into an empty project and runs a native consumer of the codec, time-window and coverage 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 Windows build packages an x86-64 PE executable and the redistribution notices in a ZIP. A separate Windows Server 2022 installation job downloads the public ZIP, verifies SHA-256, extracts the executable and runs it with only Windows system directories on PATH. It exercises a Unicode file path, standard input and a malformed floating-point record after a valid prefix. Both Linux architectures and Windows also check the downloaded CLI against known binary64 bits, a CSV time window and byte-exact v3 migration. To exercise a downloaded archive on Windows, run `python tests/windows_package.py steimcheck-windows-x86_64.zip`. [Windows build](https://github.com/kent131452777/steimpack/actions/workflows/ci.yml) · [Public install tests](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)
