Skip to content

test(templates): 80 tests for the template engine — schema, render, compose, registry - #11

Merged
nusendra merged 4 commits into
mainfrom
test/template-engine-coverage
Oct 29, 2026
Merged

nusendra merged 4 commits into
mainfrom
test/template-engine-coverage

Conversation

@nusendra

Copy link
Copy Markdown
Owner

What

80 new tests for the ployer-templates crate — the code path that turns a remote
registry entry into a running container. It had almost no coverage; a template
that renders wrong is an install that fails on the user's machine, not in CI.

Workspace goes from 143 → 223 passing Rust tests. No production code changes
beyond four #[cfg(test)] mod declarations.

File Tests Covers
schema_tests.rs 22 (+20) YAML/JSON parsing of Template, IndexEntry, inputs, generators, ports, volumes; the API serialisation contract the dashboard reads
render_tests.rs 29 (+25) placeholder substitution, {{ app.slug }}, generated secrets, missing/unknown inputs, container naming via the real Application::slug()
compose_tests.rs 24 (new) compose-body manipulation: volume rewriting, port exposure, labels, network wiring
registry_tests.rs 11 (new) sha256 verification, the disk cache, corrupt-index handling, cache-miss semantics

(+N is new on this branch; the rest already existed on main. 80 new tests,
ployer-templates goes 6 → 86.)

What it asserts, specifically

  • Forgiving where the contract says forgiving. Unknown top-level keys are
    ignored; absent optional sections default to empty rather than erroring.
    version parses as either a number or a string.
  • Strict where it must be. No compose body, no slug, an unknown input
    type, or a port above the u16 range are all rejected.
  • Failure modes, not just happy paths. A sha256 mismatch surfaces as a bare
    HashMismatch; a corrupt index on disk is an error, not a panic; a cache miss
    is an error so the caller refetches.
  • The serialisation contract. GET /api/v1/templates/:slug returns
    Template verbatim, so the JSON key names are published API. Round-trip and
    key-name tests pin them.

Deliberately not covered

  • No test touches the network or the Docker daemon. Registry tests drive the
    cache and hashing through a temp dir; render tests build fixtures in memory.
  • The actual docker compose up is not exercised here — that belongs in an
    integration test with a daemon, and I would rather have none than a flaky one.
  • The crate's production files are left rustfmt-dirty. The workspace as a whole
    is not rustfmt-clean (337 files differ on main), so the last commit formats
    only the four test modules this branch adds rather than burying the tests in
    unrelated reformatting.

Base and rebase notes

Rebased onto c652aea (current main, post-#7). Two tests on the original
branch —
an_index_entry_carrying_the_removed_icon_key_still_parses and
a_template_carrying_the_removed_icon_key_still_parses — landed upstream in #7
while this branch sat unpushed. The duplicates are dropped; #7's versions,
which carry the live-registry verification in their comments, are the ones kept.
A marker comment at the old location says where they went.

Pre-rebase state is preserved at backup/template-engine-coverage-prerebase.

Gates (run against c652aea, not the stale base)

SQLX_OFFLINE=true cargo test --workspace
  53 + 26 + 24 + 6 + 28 + 86 = 223 passed, 0 failed    exit 0

SQLX_OFFLINE=true cargo clippy --workspace --all-targets -- -D warnings
  exit 0

The 223 figure was re-measured after the rebase. The previous measurement was
against f314846, which main has since moved past.

test-writer and others added 4 commits October 29, 2026 13:02
ployer-templates had no tests. It is the crate that turns a registry YAML
into the container spec Ployer deploys, so a silent regression there
misconfigures every installed service.

Covers credential generation (length, uniqueness, URI-safety), volume
naming, input resolution and its empty-string fallback, placeholder
substitution, the six-key compose subset (including the keys it silently
drops), and host port publishing round-trips.

Catalog content is deliberately not asserted here; the registry lives in
ployer-website and is tested there.
The disk cache is re-hashed on every read, so a tampered or truncated
cache file must surface as HashMismatch rather than being parsed. The
cache filename carries the hash prefix, which is what stops an upgraded
template being masked by the copy already on disk.

Network paths are not exercised; these cover hashing, cache-key naming
and the on-disk index fallback.
…hanges

Rebasing onto main pulled in three breaking changes:

- `ac178ed` dropped `icon` from `Template` and `IndexEntry`, so the six
  assertions that referenced it no longer compile.
- `0c80422` added a seventh `app_slug` parameter to `substitute()`.
- `0c80422` also added its own `render_tests.rs`. Both files are kept: its
  four `{{ app.slug }}` tests are merged in alongside the engine tests, with
  a single `ctx` helper rather than two.

Also adds two tests for a cross-repo hazard the schema change opened up: the
published registry still ships `icon` on every template and index entry, and
the two repos deploy independently, so the parser must keep ignoring the key.
Without that tolerance every install would fail on a field nobody reads.
The workspace as a whole is not rustfmt-clean (337 files differ on main),
so this formats only the four test modules this branch owns rather than
touching unrelated production files.
@nusendra
nusendra merged commit 820c65a into main Oct 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant