Testing Guide
HPM uses several layers of tests: traditional unit tests, integration tests, property-based tests with proptest, and a Houdini conformance test that checks generated package files against a real Houdini. This guide covers how to run them, how to write new ones, and how to debug failures.
Table of contents
Test layers
| Layer | Tools | Purpose |
|---|---|---|
| Unit | built-in #[test] | Exercise a specific function or edge case. |
| Integration | #[tokio::test] + tempfile | End-to-end workflows: CLI command invocation, filesystem layout, manifest roundtrips. |
| Property | proptest | Generate inputs at random and assert invariants. Catches edge cases a human wouldn’t think of. |
| Doc | rustdoc examples | Keep public API snippets compiling. |
| Houdini conformance | hconfig from a real Houdini install | Assert the values Houdini actually resolves from generated package files — the only layer that can catch wrong assumptions about Houdini’s semantics. |
Houdini conformance test
hpm-core/src/houdini_conformance_tests.rs writes package files through
the real emission path, runs HOUDINI_PACKAGE_VERBOSE=1 $HFS/bin/hconfig
(license-free), and asserts the merged env values from the verbose
package log. It exists because the emission layer was once validated only
against its own JSON output while Houdini silently ignored method on
flat-string custom variables. Two scenarios are covered:
-
houdini_resolves_generated_packages_per_method— packages sharing a variable plus project overrides in every method (set/prepend/append) and conditional (version/OS-gated) values. -
houdini_set_overwrites_path_registered_ocio_seed— the OCIO crash on H22.0.367: a projectseton a path-registered variable must OVERWRITE Houdini’s own$HFS/packages/ocio.jsonseed, not append onto it. It reads the real seed via a baselinehconfigrun (skipping with a note on builds that don’t seed OCIO), then assertssetreplaces it wholesale rather than resolving to the two-pathbuiltin;projectvalue that crashesOCIO.Config.CreateFromFile. The path-registered-append behavior is invisible to the executable model below (it starts from an empty variable set), so only this real-Houdini layer can catch it. -
The Houdini install is auto-discovered:
$HFSfirst, then the platform-standard locations (/opt/hfs*,/Applications/Houdini/...,C:\Houdini *). -
Without an install the test skips (passing, with a
SKIPPEDnote). SetHPM_REQUIRE_HOUDINI=1to turn the skip into a failure — the CI check pipeline does, since the workers all have Houdini.
The semantics the emission layer targets are also captured as an
executable model (hpm-core/src/houdini_env_model.rs); a property test
(houdini_emission_model_tests.rs) runs randomized packages and project
overrides through the real emission code and the model, asserting that
package values survive overrides, overrides apply exactly once, and
nothing emitted uses a method or value shape Houdini rejects. When a new
question about Houdini’s package semantics comes up, extend the
conformance test to settle it empirically, then encode the answer in the
model.
Known-answer tests for wire formats
A round-trip test cannot catch a changed format. sign → verify in the same
build passes whatever the bytes are, so it holds even if a dependency upgrade
silently re-encodes the output — and for a signature that would invalidate
every artifact already published, with the failure surfacing on a user’s
machine at install time rather than in CI.
Anything whose bytes leave the process and are read back by someone else — a
signature, a checksum, an index line — gets a known-answer test instead:
fixed input, expected output written out literally.
signing_matches_the_published_wire_format pins the base64 signature and
key_id for a fixed key and message; it is what makes an ed25519-dalek,
sha2 or base64 bump a mechanical change rather than a leap of faith.
This only works where the computation is deterministic. Ed25519 is (RFC 8032), so there is no nonce to make the vectors flaky: a changed value means the format changed. Where output legitimately varies, pin the invariant part rather than reaching for a round-trip.
Property test distribution
Property tests sit wherever a rule can be stated over generated inputs.
Exact counts shift over time — grep -rc "proptest!" crates/*/src crates/*/tests lists the files that hold them (one proptest! block may
hold several properties, and not every property is named prop_*).
| Crate | Focus |
|---|---|
hpm-cli | Every global flag parses on either side of every subcommand, and refused argument values (tests/cli_flags.rs); name@version parsing in add; text from a package or registry reaches the terminal without control or bidirectional characters (console.rs). |
hpm-core | Store layout and staging, the cleanup plan (dry run equals real run), what hpm clean keeps equal to what the roots reach, and cycle reporting (graph.rs), store coordinates that never leave their root (storage/layout.rs) and store identity (storage_tests.rs), dev copies living exactly as long as a project or process uses them, including under concurrent syncs and late background reclaims, tombstones an earlier reclaim left behind, claims made while a reclaim runs (before the move a copy is never moved, after it the copy goes back), and hpaths that spell the copy’s path differently (project_tests.rs, storage/dev_users.rs), ProjectManager::project_root() returning the root as it was passed (project_tests.rs), lockfile round-trips, lock_is_current and a tampered lock never passing (lock.rs), the lockfile tree digest (tree_hash.rs), the one version-requirement grammar and what it selects (registry/requirement.rs), the solver against brute force, including answers that do not depend on the order deps, versions or available packages are listed in (registry/solve.rs), the required-package loop choosing exactly what offering every package up front would, and keeping a lock’s versions exactly while they fit, falling back to a fresh choice unless frozen (registry/closure_tests.rs), hpm clean keeping exactly the versions a project’s lock and requirements reach (graph.rs), a sync against a git index installing a complete, minimal set that leaves excluded packages out, with a Houdini package file and lock entry exactly for what it installed (project_tests.rs), excluding a package being the same as offering everything but it (registry/closure_tests.rs), tokens sent only to their own registry’s origin (registry/mod.rs), git remotes that cannot become git options, and local paths that never pin to a URL (registry/git.rs), Windows hpm run argument quoting (script_run.rs), [dependencies] edits loading back exactly as written (project/manifest_edit.rs), pack descriptors and archive names, and every staged file getting its own archive path inside the image (packer/), the size check against the pack image (check.rs), project discovery and ignore patterns (discovery.rs), the Houdini env emission model (houdini_emission_model_tests.rs), the executable-bit repair (exec_mode.rs, the one place hpm changes permissions on a user’s installed files), install records, archive extraction, and the python submodule’s versions and content hashes. |
hpm-package | Manifest validation and TOML round-trips (tests/properties.rs), Houdini range matching against an independent model (tests/houdini_range_matches.rs), dependency specs, name@version splitting, the one path-confinement rule for archive entries and place targets (path_util.rs, manifest/stage.rs), and [python_dependencies] versions that cannot smuggle installer options (python.rs). |
hpm-config | Config overlays round-trip through TOML and write only the fields that are set (tests/overlay_properties.rs). |
hpm-assets | Asset index serialization. |
Documentation checks
crates/hpm-cli/tests/docs.rs tests docs/ against the code:
SUMMARY.mdandmanifest.tomleach list exactly the pages indocs/.- Every relative link, and every
#anchor, points at a page and heading that exist. - Every
tomlblock parses, and every block made ofhpm.tomlsections loads as a manifest. - The long flags
cli.mdmentions are the long flags clap defines, in both directions. - Identifiers named in
architecture.md,api-overview.mdand this page exist somewhere incrates/.
A failure names the page and line. Where a page legitimately names something that is not a Rust item, or a flag of another program, add it to the allow-list beside the test.
Running tests
# everything: cli (single-threaded), rest of workspace, then doctests
just test
# doctests only — public-API examples in //! and /// blocks
just test-doc
# slow / external-dependency tests gated behind `#[ignore]`
# (currently: real-uv venv smoke tests in hpm-core::python)
just test-ignored
# raw cargo equivalents
cargo test --workspace
cargo test --workspace --doc
# one crate
cargo test -p hpm-core
# one test by name
cargo test prop_a_requirement_reads_back_as_written
# property tests only
cargo test prop_
# sequential execution (required when tests touch shared filesystem paths;
# `just test` already does this for hpm-cli via the CwdGuard)
cargo test --workspace -- --test-threads=1
# more proptest cases (default 256)
PROPTEST_CASES=1000 cargo test prop_ --workspace
Configuration
Proptest environment variables
| Variable | Default | Purpose |
|---|---|---|
PROPTEST_CASES | 256 | Number of cases per property test. |
PROPTEST_MAX_SHRINK_ITERS | 1024 | Shrinking budget on failure. |
PROPTEST_TIMEOUT | — | Per-case timeout (ms). |
PROPTEST_VERBOSE | 0 | Dump generated inputs as they run. |
A proptest! block that sets its own count
(#![proptest_config(ProptestConfig::with_cases(n))]) runs n cases and
ignores PROPTEST_CASES; many of the solver’s and path-confinement blocks
do.
CI
There is no proptest-specific CI matrix — CI runs the suite at proptest’s
default case count and never sets PROPTEST_CASES.
The only test pipeline is .woodpecker/check.yml, which is tag-gated
(event: tag, ref: refs/tags/v*) and so does not run on push or pull
request. It runs:
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
with HPM_REQUIRE_HOUDINI=1, since the build workers have Houdini installed
and the hconfig conformance test must run rather than silently skip.
Raising the case count is therefore a local operation:
PROPTEST_CASES=2000 cargo test --workspace
Writing property tests
A property test defines a strategy for generating inputs and an invariant that must hold for every generated input.
Custom strategies
Constrain generators to the valid input space. Unconstrained any::<String>()
mostly generates nonsense and rejects it, which wastes cycles and produces
misleading shrinks.
#![allow(unused)]
fn main() {
use proptest::prelude::*;
// Good — produces valid package slugs by construction
fn slug_strategy() -> impl Strategy<Value = String> {
"[a-z][a-z0-9-]{1,20}"
.prop_map(|s| s.trim_end_matches('-').to_string())
.prop_filter("non-empty", |s| !s.is_empty())
}
fn version_strategy() -> impl Strategy<Value = String> {
(0u32..100, 0u32..100, 0u32..100)
.prop_map(|(maj, min, pat)| format!("{maj}.{min}.{pat}"))
}
}
Invariants worth testing
Roundtrip — serialize and deserialize and compare:
#![allow(unused)]
fn main() {
proptest! {
#[test]
fn prop_manifest_toml_roundtrip(manifest in manifest_strategy()) {
let toml_str = toml::to_string(&manifest).unwrap();
let parsed: PackageManifest = toml::from_str(&toml_str).unwrap();
prop_assert_eq!(manifest.package.path, parsed.package.path);
prop_assert_eq!(manifest.package.version, parsed.package.version);
}
}
}
Validation always holds — every value the strategy produces should pass validation:
#![allow(unused)]
fn main() {
proptest! {
#[test]
fn prop_valid_manifests_validate(manifest in valid_manifest_strategy()) {
prop_assert!(manifest.validate().is_ok());
}
}
}
Determinism — running the same operation twice should produce the same result:
#![allow(unused)]
fn main() {
proptest! {
#[test]
fn prop_content_hash_is_deterministic(set in resolved_set_strategy()) {
prop_assert_eq!(set.hash(), set.hash());
}
}
}
Additive change — an operation that repairs or upgrades a value should
only ever add, never remove. exec_mode’s executable-bit repair is the
example: for every mode and every file content, the repaired mode is a
superset of the original, nothing outside the execute bits moves, and a file
that is not a program is returned untouched. When the code under test widens
a permission on a user’s files, this is the shape to reach for — a handful of
examples cannot express “and nothing else changed”.
When exhaustive beats sampled
If the input space is small enough to enumerate, enumerate it: a loop over
every value is complete, where proptest only samples. A Unix mode is 4096
values, so mirror_read_bits’s invariants are checked with a plain #[test]
over 0..=0o7777 rather than a strategy, and the desktop’s spawn-time repair
crosses all 512 permission modes with each error kind it can see. Reserve
proptest for the dimension that genuinely can’t be enumerated — in the same
module, that’s file content, which decides whether a file is a program.
Mixing the two in one module is normal and worth doing deliberately: state in the test’s doc comment which dimension is exhaustive and which is sampled, so the next reader doesn’t “upgrade” a complete check into a weaker one.
Filesystem properties
A property test that writes real files hits cases examples never generate,
including ones that break the test: a generated mode of 0o000 makes the
file unreadable and unwritable by its own owner, so a test that rewrites a
fixture per iteration, or reads content back before asserting on modes, will
fail on its own harness rather than on the code. Create the fixture once and
chmod per case, and do content assertions last, after granting yourself
access back.
Real bug caught by property tests
A whitespace-only version requirement (" ") was once accepted as valid.
A property test that fed r"\s*" into the parser surfaced it; the fix was
to trim before the empty check. Every such bug gets a regression file
that fails until the fix stays in place.
Regression files
Proptest persists failing cases to crates/<crate>/proptest-regressions/.
These are source-of-truth regression tests — commit them alongside the fix.
crates/hpm-core/proptest-regressions/
├── check.txt # Each line is a minimized failing input.
├── discovery.txt
├── packer/package.txt
├── project_tests.txt
├── storage_tests.txt
└── tree_hash.txt
hpm-config and hpm-package keep theirs beside the test file
(tests/*.proptest-regressions). A seed recorded while checking that a
property catches a deliberately planted bug is worth committing too: it is
the smallest input that exposes that bug, and proptest replays it first.
Never delete these by hand unless you’re certain the bug class is gone and the input is no longer meaningful.
Debugging failures
Get a minimal failing input
Proptest automatically shrinks to the smallest input that still fails. To see the shrink trace:
PROPTEST_VERBOSE=1 cargo test failing_prop_test -- --nocapture
Reduce the case count while iterating
PROPTEST_CASES=10 cargo test failing_prop_test -- --nocapture
Inspect the regression file
cat crates/hpm-core/proptest-regressions/project.txt
Each line is a serialized form of the seed that reproduced the bug. Proptest replays these on every subsequent run, so the same minimal case is checked deterministically until you fix it.
Move/borrow issues in assertions
prop_assert_eq! moves its operands. If you want to assert on a field and
then on a predicate, clone:
#![allow(unused)]
fn main() {
prop_assert_eq!(value.field.clone(), expected);
prop_assert!(value.is_valid());
}
Running coverage
cargo install cargo-tarpaulin
PROPTEST_CASES=500 cargo tarpaulin --workspace --out html