Template test cases¶
This page defines the files consumed by git tpl test.
For writing and maintaining a suite, follow the testing guide.
A case¶
Cases are files in tests/ at the template repository root, in TOML, JSON or YAML.
The file's stem is the case name.
# tests/minimal.toml
[answers]
project_name = "thing"
with_ci = false
[expect]
files = ["pyproject.toml", "src/thing/__init__.py"]
absent = [".github/workflows/ci.yml"]
[expect.contains]
"pyproject.toml" = ['name = "thing"']
[expect.lacks]
"pyproject.toml" = ["deploy"]
| Key | Meaning |
|---|---|
answers |
The answer set to render with. Same shape as an answers file. |
trust |
Whether this case's render may reach the template's declared remote data sources. true unless set to false. See Trust. |
expect.files |
Paths the rendering must contain. |
expect.absent |
Paths it must not. |
expect.contains |
Path to the text that must appear in it. A bare string or an array. |
expect.lacks |
Path to the text that must not appear in it. Same shape as contains. |
expect.error |
A diagnostic code the render must fail with. |
expect.context |
Presence, absence, typed equality and boolean assertions over the resolved context. |
commands |
Setup, checks and teardown run around the rendering. See Commands. |
git |
Whether the sandbox commands runs in is an isolated Git repository, seeded with one commit. false/absent unless set. See Git sandbox. |
snapshot |
Whether this case is written and compared against a recorded snapshot. false unless set. See Snapshots. |
migration |
Initialize an old project, update and merge it, then assert the result. See Migration cases. |
A path named in expect.contains or expect.lacks that the rendering never produces is a failure either way —
never a pass, vacuous or otherwise.
"This file does not mention deploy" is not proven by a file that never rendered.
Everything is optional.
A case with only [answers] asserts that the answer set renders at all, which is a real and frequently
sufficient test.
Unanswered questions take their defaults.
Nothing is ever prompted for — a prompt in a test runner is a hang — so a question with no default and no answer
fails the case with tpl::eval::unanswered, which is a true thing to know about the template.
An answer that names no question fails the case too, with tpl::answers::unknown_key — unconditionally, unlike
render's --strict-answers, which this command has no equivalent of and never will (see
command options). A case's [answers] is hand-authored,
not a recorded set that might outlive a dropped
question, so an unrecognised key here is always the case's own mistake. See
ADR-029.
Context assertions¶
Assert question applicability, defaults, explicit answers and computed values independently of rendered files:
[answers]
feature_enabled = true
[expect.context]
present = ["feature_label"]
absent = ["disabled_only"]
expressions = ["{{ optional_value is defined and optional_value is none }}"]
[expect.context.equals]
feature_enabled = true
feature_label = "Default label"
computed_options = { enabled = false, items = [1, 2] }
"data.settings.retries" = 3
present and absent check membership, never truthiness.
Null, false, zero, empty strings, empty arrays and empty objects are all present values.
equals requires presence and exact typed equality, recursively through arrays and objects.
An integer differs from a string or float; object member order does not matter and extra members fail equality.
Expected values are literal: a string containing {{ ... }} is still a string.
Paths use dotted table members, such as computed_options.enabled, data.settings.retries or template.name.
Quote dotted keys in TOML so they remain paths rather than nested expectation tables.
Empty segments and bare data/template namespace paths are rejected.
Use expressions for array indices, literal-dot keys and inspecting namespace objects.
Each expression must be a whole {{ ... }} expression returning boolean true; false and nonboolean results fail.
JSON and YAML cases can express native null equality, including null nested inside objects or arrays:
TOML has no null literal; use the defined-and-none expression above.
Missing names never equal null.
A false when leaves a question absent even if its answer was supplied.
With default_when_skipped = true, the question's default is visible and can be asserted,
but remains outside recorded answers.
Skipping because choices resolve to an empty list still leaves the question absent.
Assertions share the render's evaluation session, partials and trust decisions.
They demand only the computed values or data sources they access, including those unused by output files.
Even absent resolves a declared root before checking: unloaded does not mean absent.
Data/evaluation errors use the usual render-error reporting; value mismatches accumulate as assertion failures.
The parent context does not include composed child templates' private contexts.
Context assertions run with --skip-commands, without additional generated files or commands.
--write neither checks them nor evaluates their dependencies.
Migration cases assert the destination update's context with replayed answers and case overrides;
their file expectations still inspect the merged project.
Nonempty context assertions cannot be combined with expect.error.
Human failures show the path or expression and expected/actual values, with <absent> distinct from null and "".
JSON failure kinds are contextMissing, contextUnexpected, contextMismatch and contextExpression.
Path failures carry path and actualPresent; present values use typed actual and equality uses typed expected.
contextMissing omits actual; it includes expected only for equality, including a literal expected null.
Expression failures carry expression, expected: true and the typed actual result.
Failures are asserted by code, never by message¶
A suite that pinned error prose would make every improvement to a diagnostic a breaking change, which is how error messages stop improving. The codes are already the stable surface, so they are what a case names.
The code is matched anywhere in the failure's cause chain.
tpl::render::content says a file failed to render; only the tpl::eval::expression beneath it says why, and
that is usually the one worth naming.
Either passes.
A case with error cannot also have output, context or migration expectations — there is no successful result to
describe.
Split it into two cases.
Migration cases¶
A migration case exercises a real project upgrade, including committed project-local changes:
# tests/readme-move.toml
snapshot = true
[answers]
project_name = "widget"
[migration]
from = "v1"
# to = "v2" # optional; defaults to this suite's target
absent = ["obsolete.txt"]
[migration.answers]
project_name = "old-widget"
[migration.files]
"README.md" = "# My project\n\nA project-local customisation.\n"
"local-only.txt" = "Keep this file.\n"
[expect]
files = ["docs/README.md", "local-only.txt"]
absent = ["README.md", "obsolete.txt"]
migrations = ["migrations/010-readme.toml"]
[expect.contains]
"docs/README.md" = "project-local customisation"
[expect.messages]
"migrations/010-readme.toml" = ["README", "widget"]
from is a required branch, tag or commit in the template's local repository.
to, if supplied, also names a committed revision there.
Without to, the destination is the suite's resolved target: the current working tree by default,
or the revision selected by --ref.
The suite target supplies case files and snapshots even when a case selects a different destination.
Keep old revisions available in your checkout; a shallow clone may need more history or tags.
The runner initializes an isolated Git project from from, applies and commits the literal local edits,
runs the production update flow, then merges the updated template ref with the Git backend.
The expectations and snapshot inspect that merged project, including local-only files.
They exclude the harness's attachment file .config/git.tpl.toml and Git metadata.
Any merge conflict fails the case and identifies Git's conflicting paths.
migration.answers supplies old-state answers.
If omitted, it copies the top-level answers; an explicit empty table supplies no old answers.
Initialization records defaults as usual, then top-level answers overrides those recorded answers during update.
Both hand-authored answer sets are strict against their respective revisions.
Old recorded questions removed by the destination are tolerated, as with an ordinary update.
Each endpoint uses the case's trust setting for its own declared data sources.
Ancestor and composed-child repository access still follows the ordinary trust rules.
migration.files maps project-relative paths to literal UTF-8 contents; there is no interpolation.
It adds or replaces files, preserving an existing regular file's executable bit.
Replacing a symlink creates an ordinary text file without following its target.
migration.absent deletes named existing files; a missing deletion is a setup failure.
Unsafe paths, Git metadata, attachment configuration and overlapping edits are rejected.
expect.migrations requires the exact discovered paths in application order.
Omit it to make no discovery assertion; use [] to require no newly crossed migrations.
expect.messages maps migration paths to a string or nonempty array of substrings in their evaluated messages.
A missing migration or message fails the assertion.
These are template-authored messages; git-tpl diagnostic failures are still asserted only by stable code.
Migration-specific expectations require a [migration] section.
For negative cases, expect.error matches a destination update failure's diagnostic cause chain.
Failure to resolve or initialize the old state, invalid local edits and merge conflicts cannot satisfy it.
As in render cases, it cannot be combined with successful-output expectations, snapshots,
or commands.rendered/commands.after.
Intermediate migrations¶
Each case performs one direct endpoint update. New migration files are discovered by comparing the old and destination template trees, then applied in path order, with moves in declaration order. Moves operate on the running old rendered tree; messages use the destination answers. The runner does not render every historical intermediate revision.
Test v1 → current to cover a skipped-version jump and chained moves.
Add separate cases with from = "v1", to = "v2" and from = "v2" to cover individual upgrade boundaries.
A file introduced only in a skipped intermediate rendering cannot be moved from the starting tree.
That is a real update failure, and a direct-jump case exposes it.
Commands and recording¶
Migration cases always need isolated Git, including under --skip-commands and with git = false or omitted.
git = true or a Git identity table configures this same repository.
Its checkout defaults pin core.autocrlf = false and core.eol = lf
so ambient line-ending conversion cannot make the merged project appear dirty to commands.
commands.before runs before old-project initialization; declare committed customisations in migration.files
and migration.absent.
commands.rendered sees the completed merged project, after follows assertions,
and finally runs even after preparation, update or merge failures.
Command edits do not change the immutable tree used by expectations and snapshots.
--write runs the declarative upgrade to obtain a snapshot, but runs no commands or expectations.
Cases without snapshot = true are skipped.
Preparation, update and merge must succeed before anything is recorded.
Only snapshot files are written into the template checkout, unstaged.
See ADR-046 for the contract.
Commands¶
[commands]
before = ["mkdir -p src", "touch src/existing.py"]
rendered = ["python -m venv .venv"]
after = [".venv/bin/pip install -e ."]
finally = ["rm -rf .venv"]
Four lists, each run in a fresh, empty scratch directory created just for this case and thrown away afterward:
| List | Runs | Sees |
|---|---|---|
before |
Before anything is rendered. | Nothing but what it creates itself. |
rendered |
After the rendering is written into the sandbox, before expect is checked. |
before's files, merged with the render. |
after |
After expect and the snapshot are checked. |
The same merged sandbox. |
finally |
Always, last, regardless of anything above. | Whatever state the sandbox is in. |
The render is written on top of whatever before created, not into a directory cleared first.
This lets a case test its output alongside files that already exist in a project, which --dirty/render alone
cannot exercise. update itself builds a Git tree and never writes rendered files into the project worktree.
before sees "nothing but what it creates itself" only when the case has no git: a case that
sets it finds a .git directory and one commit already there before before runs its first entry.
Each entry is a plain string, split into a program and its arguments the way a shell would parse quoting and
escapes — but no shell actually runs. There is no pipe, no glob, no redirection and no $VAR expansion. A
pipeline needs a script file: write it with before, then name it in rendered.
--write never runs any of the four lists. It only records what a case renders; proving what running it does is
what a plain git tpl test is for. See Snapshots and
ADR-032.
Environment¶
Every command inherits the full environment git tpl test itself runs under. commands.env adds to it, for
every list in the case:
[commands]
env = { PDM_IGNORE_ACTIVE_VENV = "true" }
rendered = ["pdm install --plugins", "pdm install -dG:all", "pdm test"]
A single list can override commands.env for itself alone by writing it as a table with run and env instead
of a bare array:
[commands]
env = { PDM_IGNORE_ACTIVE_VENV = "true" }
[commands.after]
env = { PDM_IGNORE_ACTIVE_VENV = "false" }
run = ["pdm run something-that-needs-the-active-venv"]
commands.after.env wins over commands.env for a key both set; every other list still gets commands.env
alone. Neither adds $VAR expansion to a command's own text — a value only ever reaches a process as an
environment variable, never as text substituted into the command line before it runs.
Every command also sees TEMPLATE_ROOT, set to the local template repository's working tree,
both for the default working-tree input and with --ref selecting a committed revision.
It does not become a checkout of that revision, since test never resolves a remote (see
ADR-030).
It is distinct from both cwd (each list's own
throwaway sandbox) and from a template's declared render subdirectory: a case's script does not live in the
sandbox, so a command that needs more than a line or two writes it once, commits it in the template repository,
and names it directly — "{{ env.TEMPLATE_ROOT }}/tests/scripts/check.sh" — instead of synthesizing it inline via
before on every run. A case's own env/commands.env may still override it for a key it deliberately sets, the
same as any other default.
before, rendered and after each stop at their own first failure — they are sequential, and a later entry
usually assumes an earlier one worked. A failing before, or a render that fails without expect.error naming
it, skips straight to finally: there is nothing for rendered/after to run against. finally is the
opposite: every entry in it runs regardless of anything failing before or within it, because it is cleanup.
There is no timeout. A hanging command hangs the run.
Every command also gets CLICOLOR_FORCE=1 and FORCE_COLOR=1 added to its environment, whenever git tpl test's
own output is colourised under the effective colour policy.
Explicit --color always or force-colour variables can enable colour despite NO_COLOR or non-terminal stderr.
A command talking to a pipe rather than a terminal otherwise assumes nobody can see colour.
Capturing its output requires a pipe, but that output can still be shown on a real terminal.
commands.env (or a list's own env) still wins for either variable,
so a case that wants plain output from a tool that only checks these two can still ask for it.
A CI job wants colour for the same reason, but has to ask for it explicitly: a runner's shell is not a terminal,
so --color auto (the default) never colourises there on its own — the same reason a workflow already sets
CARGO_TERM_COLOR=always to get colour out of cargo itself. Set FORCE_COLOR=1 or CLICOLOR_FORCE=1 (or pass
--color always) in the job's own environment — either variable works, they are treated as aliases for the same
signal:
One variable does double duty: it colourises git tpl test's own progress output below, and is what causes
CLICOLOR_FORCE/FORCE_COLOR to be forwarded to [commands] children, as described above — so a case's own
cargo build no longer needs CARGO_TERM_COLOR set separately for that part either. See
the environment for the full colour precedence.
Templating¶
A command is rendered as a MiniJinja template — the same engine that renders every other string in the template — before it is word-split, against two names:
env.*— exactly what that command is about to be spawned with: the inherited environment,TEMPLATE_ROOT,CLICOLOR_FORCE/FORCE_COLORwhen set, and the list's ownenv/commands.env, all merged in the order described above.{{ env.TEMPLATE_ROOT }}always names the same path$TEMPLATE_ROOTwould inside the process.answers.*— the case's own[answers]table, exactly as written, with no defaults or computed values applied. Available tobeforeas well asrendered/after/finally, since it comes from the case file itself rather than from a render.
[answers]
name = "widget"
[commands]
rendered = ["'{{ env.TEMPLATE_ROOT }}/tests/scripts/check.sh' '{{ answers.name }}'"]
A command with no {{/{% in it is never templated, so every case written before this existed keeps behaving
identically. One that references a name that does not exist — {{ answers.projct_name }}, a typo — fails that
command alone, reported the same way a missing program already is, rather than silently spawning it with an empty
string in place of the mistake.
Each list entry is a complete command, including its arguments. The quotes above preserve spaces; values containing quote characters need appropriate word-splitting escapes.
This is not $VAR shell expansion: a literal $FOO in a command is still passed through unchanged. Only
{{ }}/{% %} mean anything, because MiniJinja renders the string — no shell runs, and nothing about the command
format above changes.
Progress¶
A case in progress shows on stderr: a spinner naming the current case and phase — rendering, or a running
command — on a real terminal, or the same events as plain scrolling lines when stderr is not one (a CI log, say).
Neither shows under --quiet or --json.
In the final report, failure explanations and successful snapshot-change details start under the case name, after its status marker. Supporting hints and patch lines nest further beneath the explanation they belong to.
-v/--verbose replaces the spinner with a full scrolling log: every phase, and every command's own stdout/stderr
forwarded live, exactly as it writes it — ANSI included. The final report no longer repeats a failed command's
captured output in that case, since it was already shown as it happened; --json is unaffected either way, and
always carries it.
Under --write, no [commands] run at all (see Snapshots), so there is nothing for -v to stream
live. In its place, -v shows the same coloured unified diff a normal run's snapshot-mismatch failure already
shows, once per case whose snapshot changed — and the final summary names which cases were written, updated or
left unchanged. See ADR-032.
Under GitHub Actions¶
When GITHUB_ACTIONS=true is set — every job on GitHub Actions sets it, so this needs no flag and has no
opt-out — git tpl test reports progress as workflow
commands instead of any
of the above: each case is wrapped in a ::group::/::endgroup:: pair, so a scan of the log shows one line per
case with everything else folded away, expandable on demand. While a case's group is open, its commands' own
stdout/stderr are forwarded live, exactly as -v would, whether or not -v was passed — a folded group has
nothing left to trade that away for. A failing case gets exactly one ::error:: annotation, naming the case's own
file, so it shows up on a pull request's "Files changed" view without opening the log at all. Everything that
would otherwise be internal phase chatter — "rendering", "checking snapshot" — goes to ::debug:: instead,
visible only once a job has step debug logging enabled.
--json is unaffected: it is checked first, and always wins. See
ADR-035.
Running git tpl test is the consent¶
A case's [commands] need no confirmation: running git tpl test on a template you have in front of you is
already the same act as cloning a repository and running make test in it. Commands run by default. To skip them
for one invocation, pass --skip-commands; to disable them for yourself by default, set tpl.testCommands to
false (git config --global tpl.testCommands false also applies outside repositories).
--skip-commands can only disable further, never re-enable what
configuration turned off. See ADR-027 for the full reasoning, including why
this does not reopen the rule that rendering and init cannot execute anything.
Explicit integration, including the separate phase after update --merge,
runs native Git under ADR-052.
Both also skip an ordinary render case's git, since no commands remain to use its sandbox.
Migration cases still initialize isolated Git and run their migration assertions;
only their external command lists are disabled.
A case's trust rests on the same act of consent, extended to a template's declared remote data sources
— see ADR-028.
Git sandbox¶
Some tooling needs Git for its own identity — pdm-backend's source = "scm", and every setuptools_scm-alike
version source, read git describe before installing a single dependency. git = true makes the sandbox
commands runs in an isolated Git repository rather than a plain scratch directory: one empty commit, already
there before before runs its first entry, so there is something for that tooling to find.
The identity is a built-in default unless overridden:
git.user.name/git.user.email are the only keys a case may set; everything else about the seed commit —
commit.gpgsign off, the branch it lands on — is fixed. git = false, or no git key at all, is today's plain
scratch directory, byte for byte: this is opt-in, the same choice snapshot already made for the same reason.
Isolation excludes ordinary global and system configuration files.
The seed commit is written through git-tpl's own Git backend, never a spawned git process.
The chosen identity is installed in the sandbox's local .git/config before signature creation,
so ordinary global and system identity settings do not replace it.
Every command in a case that set git is spawned with GIT_CONFIG_NOSYSTEM=1
and GIT_CONFIG_GLOBAL pointed at a path that is never created.
A literal git therefore skips the machine's ordinary global and system configuration files.
Commands still inherit the rest of the calling environment.
Git environment overrides such as GIT_CONFIG_COUNT/GIT_CONFIG_KEY_*/GIT_CONFIG_VALUE_*,
GIT_CONFIG_PARAMETERS and author/committer variables can affect their behavior.
This is file-level configuration isolation, not a fully scrubbed Git environment.
commands.env or a list's own env can explicitly override the isolation variables too.
See ADR-033 for the full reasoning, and issue #155 for where the gap this closes came from.
Trust¶
trust decides whether this case's render may reach the template's declared remote data sources — a [data.*]
source that is remote or git.
It defaults to true: a case renders for real unless it says otherwise, because the point of a suite is to prove
what the template's output actually looks like, and an untested remote source is a gap in the suite, not a safety
margin.
Set trust = false to assert the refused path instead — the render fails with
tpl::data::untrusted before anything reaches the network, deterministically and
with no host to reach.
This is not the --trust/[trust] mechanism render, init, update and backport use.
For case-level data loading, test never asks anybody and does not consult the persistent [trust] list:
a case's trust must mean the same thing on every machine, including CI.
See ADR-028 for the reasoning.
Before discovering cases, test resolves the template's [extends] ancestors using persistent trust from
~/.config/git-tpl/config.toml.
Remote ancestors must be authorized there on each machine, including CI;
case-level trust cannot authorize them, and test has no invocation-wide --trust option.
Missing authorization fails with tpl::extends::untrusted before cases run.
Snapshots¶
records each case's rendering under tests/__snapshots__/<case>/, and every later run compares against it.
A case is written and compared only when it says snapshot = true. This is explicit for a reason: without it,
--write would silently start recording (and every future run silently start comparing) a case that never asked
for one. A case that says snapshot = true but has never been recorded fails outright — "record one with
git tpl test --write" — rather than passing having asserted nothing.
tests/
├── minimal.toml
└── __snapshots__/
└── minimal/
├── manifest.toml
└── files/
├── pyproject.toml
└── src/thing/__init__.py
The rendered files are stored verbatim, at their rendered paths.
That is the whole point: a change to the template shows up as a git diff of the generated project, in the
generated project's own language.
Reviewing it needs no tooling and no Rust.
manifest.toml records the expected paths and Git modes, sorted by path:
Modes are 100644 for ordinary files, 100755 for executables and 120000 for symbolic links.
A Windows checkout loses the mode on disk, and a snapshot that silently stopped asserting on chmod +x would be
worse than none.
Symlink payloads are ordinary files containing the exact target bytes, never live links.
Comparison checks mode and bytes, including regular-file/link conversions.
Command sandboxes materialize real links on Unix and fail explicitly on unsupported platforms.
See ADR-044.
An empty [files] table records an empty expected output.
The manifest contains no checksums or sizes: changing expected contents does not change shared metadata.
Independent PRs changing different file contents can therefore merge without conflicting on the manifest.
The manifest and files/ must still list the same paths.
Expectation-first testing¶
Edit a file under files/ to describe the output you want, then run git tpl test.
The test reports an ordinary snapshot difference until you change the template to match the expectation.
No manifest edit is needed for content changes, including binary content.
When adding or deleting an expected file, also add or delete its [files] entry;
when changing its kind or executable bit, edit its mode.
Use plain git tpl test throughout this red/green loop.
--write replaces expectations with the template's current output, so it would overwrite the desired failing example.
Legacy snapshots¶
Existing MANIFEST snapshots remain readable, with their old checksums and sizes ignored.
Their path inventories and modes are still checked.
Plain comparison leaves them untouched; --write records manifest.toml and removes the legacy MANIFEST,
even when the rendered output has not changed.
This format-only update reports updated with no content or mode differences.
If both files exist, manifest.toml is authoritative and the next write removes MANIFEST.
To convert a deliberately failing expectation without replacing its contents, create manifest.toml as above,
copy each legacy path and mode into [files], and remove MANIFEST manually.
Leave the payload files unchanged.
Recording behavior¶
Things worth knowing:
- A case with
snapshotunset (orfalse) is not a failure on a plain run. Snapshots are opt-in per case, and are neither written nor compared for it. snapshot = truewith nothing recorded yet is a failure, not a pass. Run--writeonce to record it.--writeclears the case's snapshot directory rather than merging into it. A template that stops producing a file has to be seen to stop.--writedoes not stage or commit anything. You review the diff and commit it.--writeonly records; it does not run a case. A case's[commands]never run, andexpectis never checked, under--write— recording a broken rendering is not the same as passing it. Run a plaingit tpl testafterward (or let CI do it) to prove the recording still holds. See ADR-032.- A case with no
snapshot = trueis skipped under--write— not rendered or checked. It still has a selected outcome in JSON:snapshotis"skipped", andpassedis true because it has no failures. It contributes tosummary.totalandsummary.passed; these counters do not prove assertions ran.--write's only reason to render a case is to write its snapshot.
--write writes into the checked-out template's working tree — there is nowhere else for a snapshot to go.
Sharding¶
git tpl test --record-durations # once, to seed tests/__timings__/durations
git tpl test --shard 1/4 # then, in each of four CI matrix jobs
git tpl test --shard 2/4
git tpl test --shard 3/4
git tpl test --shard 4/4
--shard INDEX/TOTAL (both starting at 1) runs only the cases assigned to this shard, out of whatever this
invocation would otherwise run — applied after [CASE] filtering, not instead of it. Without a recorded durations
file, the split is a deterministic slice by count: this never fails just because nothing has been recorded yet, so
a template's first --shard run works exactly as well as its hundredth.
--record-durations runs the suite exactly as a plain invocation would — nothing about [commands], expect or
snapshots changes — while timing each case, then writes tests/__timings__/durations, merged over whatever was
already there. Commit that file to the template repository; a later --shard reads it back and bin-packs the
split so every shard finishes in about the same time, rather than merely getting the same number of cases. A case
missing from the file (new, or never measured) is weighted at the mean of the ones that are.
If no selected case has a positive recorded duration, the split falls back to count,
including when timings are all zero milliseconds or name only cases outside the selection.
--record-durations conflicts with --shard — recording from a partial run would corrupt the file with timings
for only some of the suite — and with --write, which does not run a case at all and so has nothing real to time.
A GitHub Actions matrix supplies both halves of --shard directly, with only the shard index varying between
jobs:
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- run: git tpl test --shard ${{ matrix.shard }}/${{ strategy.job-total }}
This is unrelated to the "no matrix language" rule below: that rule is about a case file expanding into many
cases combinatorially, which this project still refuses. Splitting the cases that already exist across several CI
jobs is a different question, and --shard/--record-durations is this project's answer to it. See
ADR-036.
Cases come from the revision, not from disk¶
| Given | Cases and snapshots come from |
|---|---|
no --ref |
The working tree, uncommitted changes included. |
--ref X |
Commit, branch or tag X, committed. |
git tpl test --ref v1.2.0 runs that tag's cases against that tag's template, and compares against that tag's
snapshots.
Without --ref, test reads the working tree instead: the point of testing is catching a broken conditional
before it is committed, not after.
Reading cases off the filesystem is not a special case, though it may look like one: the resolver builds a
synthetic tree of the working directory the same way it always has for a --dirty render on any other command, so
an edited-but-uncommitted case is picked up by the same code path, with the same .gitignore handling the
rendering got. See ADR-030.
A snapshot is not subject to the project's .gitignore either, deliberately: it is data --write recorded, not a
project file a render produced.
An ordinary rule matching manifest.toml or the legacy MANIFEST does not stop it from being read back.
In CI¶
Exit 0 if every case passed, 1 if any did not, and 1 with a diagnostic code
if the run could not start.
Under --json, note that ok is true whenever the command ran.
Whether the suite passed is summary.failed:
The two are separate because a caller has to be able to tell "two cases failed" from "the template could not be resolved", and both are non-zero exits.
--json also carries summary.durationsRecorded (whether this run wrote the durations file), a top-level shard
object (null unless --shard was given: {index, total, casesTotal, balanced}), and a durationMs on every
case — measured on every run, whether or not --shard/--record-durations was used. See
Sharding and ADR-036.
What a case cannot do¶
[commands] runs against a scratch sandbox the test harness creates and destroys for one case — never against a
render, init or update, none of which can execute anything, still, unconditionally. See
Commands and ADR-027 for exactly what a case's commands can and
cannot see.
For everything outside that sandbox — checking a real, project-shaped rendering with the tools that understand
it, actionlint, a full npm ci, a linter with its own config discovery — your own CI still does it better:
git tpl render . --dirty -o /tmp/out --answers-from tests/minimal.toml
cd /tmp/out && cargo build && actionlint .github/workflows/*.yaml
There is also no matrix language. Three files beat a combinatorial block whose expansion nobody can predict; if a template needs twelve cases, twelve files say so honestly.
A note on partials¶
A rendered file named something.jinja lands in the snapshot as
tests/__snapshots__/<case>/files/something.jinja, and the renderer collects every .jinja outside the render
root as an importable partial.
It is keyed by its full path, so it shadows nothing and changes no rendering.