# Contributing to Datamonger

Datamonger accepts changes to clients, normative contracts, conformance data, registry records, and operational tooling. These surfaces have different review obligations because a small code or metadata edit can alter the data returned by every implementation. 

By contributing code or documentation, you agree that your contribution is licensed under the repository's MIT license. Upstream dataset artifacts are not part of that license and must not be committed to this repository; small, purpose-built conformance fixtures belong under `tests/conformance/artifacts`. 

<a id="development-environment"></a>

## Development environment

The supported environment is the repository's devenv shell. From the repository root, run: 

```console
devenv shell
task test
```

Entering the shell installs Git hooks for Ruff, nixfmt, and Prettier. The hooks format staged Python and Nix files and YAML under `.github`, plus `devenv.yaml` and `Taskfile.yml`. Generated registry files and conformance fixtures are outside the YAML formatter's scope. Run `prek run --all-files` to check all matching files; formatters may update files, so review and stage their changes before committing. `devenv test` also runs these hooks, and CI checks YAML formatting with Prettier. 

`task --list` lists focused checks and maintenance tasks from `Taskfile.yml`. `devenv test` delegates to `task test` after running the Git hooks. 

The quality gate checks formatting, lints Python, type-checks the package and tools, runs the Rust CLI and all three hermetic language client suites, checks generated registry data and shared fixture synchronization, builds the Python and R distributions, and runs a CRAN-style R package check. Focused commands from `packages/python` are: 

```console
uv run pytest
uv run pytest tests/test_decoder.py
ruff format . ../../tools ../../curation
ruff check . ../../tools ../../curation
uv run mypy
uv run python ../../tools/dm_index.py check
uv build
```

Python uses Maturin to build the private PyO3 extension. `uv sync` builds it against the local `crates/datamonger-core` path dependency, and `uv build` bundles that core in the source distribution and builds a wheel from it. After editing Rust code, run `uv sync --reinstall-package datamonger` before Python tests to rebuild the extension. The binding uses the repository's stable Rust toolchain; the core and R adapter retain their separate MSRV checks. Python source releases include the local core, so they do not require an earlier crates.io publication. Maturin includes the shared Cargo lockfile and trims unrelated workspace members from source distributions. Source builds allow Cargo to prune that lockfile; release wheel builds pass `--locked` explicitly. When changing the core's version, update the Python and C ABI bindings' Cargo requirements and the workspace lockfile in the same change. 

From `packages/python`, check the bindings and compare them with the independent Python implementation retained under `tests/reference`: 

```console
cargo fmt --check
cargo clippy --locked --all-targets -- -D warnings
uv run pytest tests/test_native.py
```

The Python oracle is test-only. Keep its parsing and canonical encoding independent of the native backend. The differential tests compare native and Python results against the shared conformance corpus, compressed inputs, malformed artifacts, and generated inputs before a backend change can ship. CI builds portable wheels for all supported platforms when the Python client, shared Rust core, packaging configuration, or shared conformance fixtures change. It tests installed wheels with Python 3.14 and 3.15 on all five platforms, and with Python 3.11 on Linux x86-64. Versionary release PRs skip the broad build and test matrices and the documentation build. They still check release versions, lockfiles, vendored Rust sources, and client bundles. Registry release PRs validate their pending snapshots, and release PRs run one Linux R check when the Rust adapter or vendor files change. Ordinary PRs and pushes to `main` run the Linux Python quality checks. Publishing tests installed wheels on all five platforms with all three Python versions. Run `Python distributions` manually to check the full matrix on a selected branch, commit, or tag before a release. 

Focused commands from `packages/r` are: 

```console
Rscript -e 'testthat::test_local(".")'
R CMD build .
R CMD check --as-cran datamonger_*.tar.gz
```

The core, C ABI, Python bindings, and CLI belong to the root Cargo workspace. They share `Cargo.lock` and `target/`, but retain independent versions, editions, and minimum Rust versions. From the repository root, run `cargo fmt --all --check` and `cargo test --locked --workspace`, or select packages with `cargo test --locked -p datamonger-core -p datamonger-ffi`. Dependabot updates the workspace as one dependency graph. The R adapter is excluded because it resolves and vendors a published core independently. 

Workspace commands use current stable Cargo to read the CLI's edition 2024 manifest. The core and C ABI still support Rust 1.82. The minimum toolchain is recorded in `rust-toolchain-msrv.toml`; `dm-core-cargo` combines current Cargo with that toolchain's compiler, documentation generator, and lint tools. CI also checks the core and C ABI with Rust 1.82. From the repository root: 

```console
dm-core-cargo test --locked --manifest-path crates/datamonger-core/Cargo.toml
dm-core-cargo clippy --locked --manifest-path crates/datamonger-core/Cargo.toml --all-targets -- -D warnings
dm-core-cargo doc --locked --manifest-path crates/datamonger-core/Cargo.toml --no-deps
```

The R adapter depends on a published `datamonger-core` version from crates.io. Use `dm-test-r` to test it against unpublished core edits. For other development scripts, use `dm-local-r` in place of `Rscript`; it sets `DM_R_CORE_PATH` and enables a local Cargo patch. These commands temporarily match the dependency pin to the local core version and restore the release manifest and lockfile afterward. For example, from `packages/r`, run: 

```console
dm-local-r -e 'pkgload::load_all(".")'
```

Normal source builds use the published version and compile offline with a locked dependency graph. Local builds use Cargo's usual cache and may download new dependencies. Release builds use at most two Cargo jobs. `DEBUG=1` selects a debug build; `NOT_CRAN=1` permits development without the vendor archive. 

Publish core changes before preparing an R release that needs them. Update the R adapter's version requirement when needed, then run `task r:vendor`. Its `r:catalog` dependency refreshes the compressed catalog offline from the currently bundled registry release. Run `task r:catalog` separately to regenerate only the R catalog. The vendor task resolves the published core, runs `rextendr::vendor_crates()`, and records the lockfile digest. Commit the compressed catalog, lockfile, vendor archive, vendor configuration, and digest. The core receives the same vendoring treatment as every other registry dependency. The R tarball must build with no checkout or Cargo network access. 

Run `python tools/dm_rust_sources.py` after shared conformance changes to update the core's fixture copy. `python tools/dm_rust_sources.py --check` checks fixtures and vendor metadata. Check changes with Rust 1.82. 

R package builds regenerate `R/extendr-wrappers.R` from extendr metadata using the `document` Cargo target introduced in rextendr 0.5.0. After changing Rust bindings, rebuild with `dm-test-r` or `pkgbuild::compile_dll(force = TRUE)` through `dm-local-r`, and commit the generated wrappers. 

Edit the roxygen2 comments in `packages/r/R` to update help topics, examples, and exports. Run `task r:document` and commit the generated Rd files and `NAMESPACE` with the source changes. The release tarball includes those generated files and does not require roxygen2 to build. 

Versionary manages core releases independently of the language clients. Merge its release PR after CI passes. Versionary creates a published GitHub Release with a `datamonger-core-v<version>` tag, which triggers `Publish Rust core`. That workflow verifies the tag and crate versions, tests and packages the crate with Rust 1.82, and publishes to crates.io through trusted publishing. 

After the crate is published, update the R lockfile and vendor archive: 

```console
dm-core-cargo update --manifest-path packages/r/src/rust/Cargo.toml -p datamonger-core
task r:vendor
```

The R release continues to use its committed dependency version until this refresh is reviewed and merged. 

Julia installs the published C ABI through `Datamonger_jll`. To test edits to the core or C ABI in this checkout, build a local library with Rust 1.82 or newer from the repository root: 

```console
julia tools/dm_julia_core.jl
```

The build uses the pinned core compiler in devenv and writes an ignored artifact binding under `packages/julia/deps`. Rebuild after native edits. Remove the local binding to return to the published JLL, or set `DM_JULIA_CORE_LIBRARY` to an absolute library path to select a specific build. Julia checks the ABI version on first use. 

The focused Julia command from `packages/julia` is: 

```console
julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.test()'
```

The original Julia decoder and canonical encoder live under `packages/julia/test/reference` and are test-only. Keep them independent of the native implementation. `test_native.jl` compares typed values, missingness, return types, canonical bytes, errors, compression behavior, and generated edge cases. The shared corpus remains the normative source for golden values. HTTP content decoding remains Julia's responsibility, separate from native artifact decompression. 

CI tests the published JLL outside the checkout on stable Julia for Linux x86-64 and ARM64, macOS Intel and Apple Silicon, and Windows x86-64. On Windows ARM64 it runs x64 Julia through Prism emulation. CI also tests Julia 1.10 on Linux x86-64 and runs the Julia suite against the checkout's native library on Linux x86-64. 

When a new decoder adds a native symbol, require its tests against the checkout's library and skip them in the published-JLL job until that JLL supplies the symbol. Publish the FFI release and its corresponding `Datamonger_jll`, then update Julia's JLL compatibility before merging the Julia release PR. The registration workflow checks the published JLL resolved by the saved release commit before requesting registration. 

Focused CLI commands from `packages/cli` are: 

```console
cargo fmt --check
cargo clippy --locked --all-targets -- -D warnings
cargo test --locked
cargo run --locked --example generate_cli_docs -- --check
```

The CLI publishes to crates.io as `datamonger`. Its package includes the source, bundled registry assets, README, and license. Integration tests use repository fixtures and run before publication. To verify the packaged crate locally, run `cargo publish --locked --dry-run` from `packages/cli` (add `--allow-dirty` when testing uncommitted changes). 

The CLI reference is generated from `packages/cli/src/cli.rs` with clapdown. After changing commands or help text, run `cargo run --locked --example generate_cli_docs` from `packages/cli` and commit `documentation/pages/cli-reference.md`. CI and `devenv test` check that it is current. 

From `packages/python`, run the live proof-registry test separately: 

```console
uv run pytest tests_live/test_proof_registry.py
```

Run the R and Julia `tests_live/test_candidate_registry.*` scripts separately from `packages/r` and `packages/julia`, respectively, to retrieve and verify every record in the published candidate registry. Pass `2026.09` as the first argument to audit the stable registry instead. 

Live-source tests and canaries require network access and healthy upstreams. They are not substitutes for deterministic tests and are not part of the routine hermetic gate. 

<a id="decoder-benchmarks"></a>

## Decoder benchmarks

Run the Criterion CSV comparison from the repository root in the development shell. 

```console
cargo bench --locked -p datamonger-core --bench csv
```

The benchmark compares Datamonger's decoder with the Rust `csv` crate on generated numeric tables of 100,000 × 4 and 10,000 × 40 rows by columns. Both readers decode the same in-memory bytes, use Datamonger's float parser, and produce matching typed columns with validity bits. Criterion reports elapsed time and byte throughput. Input generation and the output comparison happen before timing. 

Run the LIBSVM benchmarks from the repository root in the development shell. Prepare the inputs in a directory outside the working tree. Preparation uses the bundled registry and verifies the downloaded artifacts against their registered digests. It stages the training splits of `a9a` and `rcv1-binary` and the complete `cadata` dataset as uncompressed files. 

```sh
bench_dir="$HOME/.cache/datamonger-bench"
uv run --project packages/python python tools/dm_bench_libsvm.py prepare "$bench_dir"
```

Preparation prints the path, feature count, and label type for each case. Pass those arguments to both harnesses. For example, use `cadata` with these commands. 

```sh
cargo bench --locked -p datamonger-core --bench libsvm -- "$bench_dir/cadata.libsvm" 8 float64 7
uv run --project packages/python --with scikit-learn --with libsvm-official \
  python tools/dm_bench_libsvm.py read "$bench_dir/cadata.libsvm" 8 float64 --repeats 7
```

The Rust harness preloads the file and times parsing into the core's CSR and label components. The Python runner times local file reads through SciPy CSR and labels, with one warmup per reader. It checks normalized CSR values and labels after timing and records stored entries, index widths, dependency versions, and process peak RSS, including imports. The runner uses Unix resource accounting and supports Linux and macOS. If LIBSVM builds from source on Linux, use a C++ compiler with OpenMP support, such as `CC=gcc CXX=g++`. For inputs with explicit zeros, select Datamonger decoder v2 by appending `2` to the Rust arguments and passing `--decoder-version 2` to `read`. 

To measure the public fetch path, prepare with `--seed-fetch` to cache all required splits, then run `fetch`. The fetch runner uses the cache offline and reports timings with canonical verification enabled and disabled. 

```sh
uv run --project packages/python python tools/dm_bench_libsvm.py prepare "$bench_dir" --dataset cadata --seed-fetch
uv run --project packages/python python tools/dm_bench_libsvm.py fetch "$bench_dir" --dataset cadata
```

Omit `--dataset` to select all three cases. Seeding the fetch cache for `rcv1-binary` also retrieves its roughly 433 MiB compressed test split. For comparisons across revisions, reuse the prepared files and record the Git revisions, compiler, and machine. Timing runs are opt-in. 

<a id="code-changes"></a>

## Code changes

Prefer test-driven changes. Put deterministic tests under the affected client, reuse fixtures where possible, and simulate HTTP behavior rather than requiring network access. Put unavoidable network checks in a separately invoked live suite. 

When behavior is shared across languages, add or update a language-neutral case under `tests/conformance` before making a client-specific implementation pass it. A conformance case must identify the contract version it exercises and must contain language-neutral expected values or bytes. 

Public APIs must be typed, strict mypy must pass, and Python code must satisfy Ruff with the configured 88-character line limit. Comments should explain why a constraint exists, not narrate the code. 

<a id="adding-or-revising-a-dataset"></a>

## Adding or revising a dataset

Never commit downloaded upstream dataset artifacts. Manifests record upstream or reviewed mirror locations and the digests of the bytes served there. 

1. Choose a canonical `(source, name, version)` identity. For new curated datasets, follow the [curated dataset naming policy](<https://github.com/jolars/datamonger/blob/main/CONTRIBUTING.md#curated-dataset-names>). If artifact identity or the complete representation recipe differs from a published record, use a new dataset version.
2. Draft a YAML manifest from [`spec/schema/manifest-v5.schema.json`](<https://github.com/jolars/datamonger/blob/main/spec/schema/manifest-v5.schema.json>). Supply descriptive, provenance, license, artifact, location, decoder, and task metadata. Do not guess a license—use `status: unknown` when the evidence is insufficient. 
   
      Record [preprocessing](<https://github.com/jolars/datamonger/blob/main/registry/README.md#preprocessing>) separately for upstream and Datamonger preparation. Supply known steps, parameters, and evidence. Use `unknown` when the history is not established; reserve `none` for an absence of preprocessing supported by evidence.
3. Let `dm-add` retrieve every location, verify that they serve identical bytes, decode the data, and derive retrieval facts and candidate expectations: 
   
   ```console
   cd packages/python
   uv run python ../../tools/dm_add.py path/to/draft.yaml \
     --output ../../registry/datasets/<source>/<name>-<version>.yaml
   ```
   
      `dm-add` writes the completed manifest to stdout by default and a bounded review report to stderr. `--force` replaces an output only when that replacement is intentional. Generated verification is an authoring aid, not an independent attestation.
4. Review the upstream landing page, authorship and citation, version identity, license evidence, distribution and preservation status, every decoded name and shape, task roles, and the representative values printed by `dm-add`. Check for IDs or bookkeeping columns that should not silently become model features.
5. Add the quoted version to the dataset's `versions` list in `registry/collection.yaml`. The last entry becomes the default. Do not edit generated indexes or selectors, and do not alter a published release.
6. Commit the registry change with `feat(registry): ...` or `fix(registry): ...`. Versionary prepares the release PR and its generated snapshot. Review and independently verify the new records before merging that PR; the publisher re-fetches manifests before publishing and runs the canary against the published asset afterward.

A release-scoped metadata improvement may retain a dataset version only when it obeys the [release evolution rules](<https://github.com/jolars/datamonger/blob/main/spec/registry.md#release-evolution>). Incorrect component expectations or verification records require an approved erratum in a later registry release; earlier release bytes remain unchanged. 

<a id="curated-dataset-names"></a>

### Curated dataset names

For new datasets curated and distributed under the `datamonger` source namespace, use `<surname><year>[<paper-letter>][-<dataset-label>]`. Use the first author's surname normalized to lowercase ASCII and the paper's publication year. Preserve the provider's spelling in `provenance.upstream_name`. 

| Situation | Dataset name |
| --- | --- |
| One paper, one dataset | `smith2023` |
| Multiple distinct datasets from that paper | `smith2023-plasma`, `smith2023-tissue` |
| Another paper with the same first-author surname and publication year | `smith2023b` |
| Multiple distinct datasets from that second paper | `smith2023b-plasma`, `smith2023b-tissue` |

The first paper registered with a surname and year uses the unsuffixed base. For subsequent papers with the same base, assign the next available letter starting with `b`, then `c`, and so on. Reuse that paper's base and letter for all its datasets. These letters identify papers within the registry and are independent of bibliography labels. Check existing manifests, curation directories, and published indexes before allocating a name. 

For distinct datasets from one paper, prefer short suffixes describing their scientific content. When no useful descriptive label exists, use a stable source label such as `-table-s2`. Avoid bare numeric suffixes such as `-1`: dataset versions already have a separate field, written as `@1` in the canonical ID. Multiple tasks or training and test splits alone generally belong within one dataset. 

Keep existing dataset IDs unchanged when adding papers or datasets. If a second dataset is discovered after an unsuffixed name is established, retain that name and give the new dataset a descriptive suffix. This policy applies to new curated names; existing IDs and names in upstream source namespaces retain their established spelling. 

<a id="registry-and-specification-changes"></a>

## Registry and specification changes

Treat the following as separate questions during review: 

- Does the dataset identity change?
- Does any accepted input or decoded logical output change?
- Do canonical bytes or error precedence change?
- Is the edit release-scoped metadata that the evolution rules permit?
- Does the change require a new schema, decoder, canonical-form, behavioral contract, dataset, or registry release?

`dm-index` compares repeated dataset identities with every lower-sequence release and rejects forbidden mutations. Passing that check is necessary, but it does not replace semantic review. 

Normative prose, JSON Schemas, conformance descriptors, reference-client behavior, and package documentation must agree. A pull request that changes a contract should update every affected surface together and explain the version decision. 

<a id="pull-requests"></a>

## Pull requests

Keep changes focused and use a Conventional Commit subject. In the pull request description: 

- explain the user-visible or protocol-visible effect;
- link the relevant issue;
- state which contract and registry versions are affected;
- identify any dataset identity, licensing, distribution, or preservation consequence;
- list conformance and client tests added or changed;
- report `devenv test`; and
- report separately any live checks run or intentionally skipped.

Reviewers should be able to reproduce generated files and understand every trust claim without consulting an unrecorded discussion.
