This skill guides lifecycle testing from identifying a user promise and selecting a test instrument through running failing-before and passing-after checks, applying invariants, and recording evidence. It emphasizes hermetic tests of the real CLI, snapshot-based assertions, and coverage for security, state changes, and user-visible outcomes. It also sets constraints for test quality and provides reusable evidence formats for maintaining lifecycle tests.
97%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Low
Low-risk findings worth noting
A lifecycle test proves a USER PROMISE on the installed CLI. It drives
apm through real command sequences in a hermetic world, snapshots
durable state before and after, and asserts observable facts: files
present or absent, bytes unchanged, lockfile rows, MCP config entries,
egress. It is the only tier that can prove a negative ("nothing else
was written", "the user's file survived", "the denied hook is gone").
In agentic coding, where no human walks the CLI by hand, this harness
is the walkthrough.
Unit tests on each side of a boundary do not replace it. A lifecycle test whose only assertion is a string compare is NOT lifecycle proof.
Surfaces that need it: install / uninstall / update / compile / audit
paths; the deployment ledger, lockfile write path or deployed_files;
target resolution, widening or narrowing; any write into a target root
(.github/, .claude/, .cursor/, .agents/, ...) or user scope
(~/.apm/); --dry-run on any command; cleanup, prune, drift or
orphan handling.
pytest, grep or ls output in this
session, never from memory or prose.Run ls tests/lifecycle/conftest.py.
tests/lifecycle/replay/rows/*.yaml run by
tests/lifecycle/rows.py). Read the TARGET section of
references/family.md and verify each name there with ls/grep.ApmLifecycleRunner,
IsolatedApmEnvironment, LifecycleStateSnapshot,
LocalPackageFactory, the tests/integration/_*_kit.py worlds, and
the reference module
tests/integration/test_required_lifecycle_state_machine.py. Read
the TODAY section of references/family.md. This branch is
authoritative until tests/lifecycle/ exists.property_catalog/ in
tests/fixtures/lifecycle_bug_ledger/); OpenAPM req-* ids
(CONFORMANCE.json); owner decisions
(.apm/architecture/owners/*.json); CHANGELOG.md guarantees; docs
claims with must / never / fails / exits wording. When
tests/lifecycle/ is present, rows use P-INV-I1..P-INV-I9 and
P-LAW-<ledger property id>; owner ids (P-OWN-*) resolve only
once a promise catalog exists. Write:
PROMISE: <id> -- <sentence> (source: <path>).OP=update SRC=git PRIM=lsp SCOPE=project GATE=revoked-after-deploy.owner field in
.apm/architecture/owners/*.json). A fix belongs in the owner.If you cannot name a promise, stop and ask. A test with no promise is unexplained, not automatically deletable.
file:line from grep -n).deps update and lock share one pipeline. Each
SIDE DOOR (a mutating path that skips the pipeline: local bundle,
--mcp, the --dry-run planner, unpack) is its own family; defects
cluster there.grep -rn "<symbol|flag|error text|issue>" tests/.
Look in tests/lifecycle/ (if present), then
tests/integration/*lifecycle*.py. Prefer EXTENDING an existing
test (parametrize case, assertion, replay row, machine rule) over a
new module; lifecycle tests are expensive in CI time.| Situation | Today (no tests/lifecycle/) | Target family |
|---|---|---|
| one cell, fixed steps | ApmLifecycleRunner test or parametrize case in the matching tests/integration/*lifecycle*.py | replay row in tests/lifecycle/replay/rows/*.yaml |
| transition that must hold from many states | case in test_required_lifecycle_state_machine.py or rule in tests/lifecycle/machines/test_m_spine.py | state-machine rule, where the family provides machines (verify with ls) |
| history, ownership of unmanaged assets, platform, failure phase, cache, graph or version, concurrency | scenario on a _*_kit.py world | planned scenario suite; today's harness until present |
| trust, policy outcomes, integrity, egress, origin, credentials | table-driven E2E with egress log or snapshot-absence oracle | planned security table; today's harness until present |
| docs golden path or user-visible transcript | real-CLI journey with every printed hint executed | planned journey step + golden; today's harness until present |
| flag combination the command must refuse | ONE refusal test (exit code + unchanged snapshot) | same |
| owner decision | table-driven test at the owner symbol (owner not patched) + one E2E | same |
A refusal test never discharges a success obligation. Derive
per-target parameters from KNOWN_TARGETS
(src/apm_cli/integration/targets.py); never hardcode target names.
Start from assets/templates.md. Mandatory properties:
apm_binary_path). The
engine command (apm_engine_command, python -m apm_cli.cli) only
for exploration or engine contracts. Never CliRunner for a lifecycle
promise.tests/lifecycle/ is present): run every command
through driver.run(world, argv, scope=...); never choose the entry
point yourself. APM_LIFECYCLE_DRIVER selects engine (PR default)
or binary (nightly).LifecycleStateSnapshot before and after each mutating
command; assert the exact changed set and that nothing else changed.--no-policy from older helpers
(_INSTALL_ARGS in the state-machine module carries it). Use it only
when --no-policy is the behavior under test.references/oracles.md
when writing the assertions..apm/instructions/tests.instructions.md.APM_BINARY_PATH="$(uv run which apm)" \
uv run --extra dev pytest <node> -n 0 -p no:cacheprovider -qAdd APM_E2E_TESTS=1 when the module carries requires_e2e_mode. Use
a built binary instead of the in-tree one when one exists. Keep the
failing assertion line. A test that is green before the fix is not a
regression trap; tighten the oracle.
_EXPECTED_RULE_ID_TEXT
(tests/unit/scripts/test_architecture_runner.py) and add one
MutationCase to MUTATIONS in
tests/integration/test_architecture_owner_rule_mutations.py, kept
sorted by guard_id, that disables ONLY that guard.Rerun the same node green. Then run the module and every test that
shares the touched owner (grep -rln <owner symbol> tests/). Run the
lint contract before pushing.
tests/fixtures/lifecycle_bug_ledger/bugs/<issue>.json (template in
assets/templates.md). Validate with
uv run --extra dev pytest tests/quality/test_lifecycle_bug_ledger.py -q.
Every Fixed line in CHANGELOG.md maps to a ledger row.Every hint the CLI prints ("Run apm ...") is a test case: run it and assert that it reaches the stated outcome. Assert on every output line: non-ASCII, duplicates, stale command names, errors on stdout.
| Id | Invariant |
|---|---|
| I1 | The lockfile matches the deployed files. |
| I2 | Repeating a converged command changes no bytes. |
| I3 | install --frozen and audit --ci agree, with the same remediation. |
| I4 | Gates are monotone: a deny, revoked approval or stricter policy never increases what is deployed or runs; the next mutating command removes what is no longer allowed. |
| I5 | Each command writes only its declared write set and never crosses scopes. |
| I6 | Output is ASCII. |
| I7 | Nothing is skipped silently; a failed command preserves state. |
| I8 | The command's documented exit contract holds. |
| I9 | No duplicate or noisy lines. |
Defaults that hide defects (use only when they are the subject):
--no-policy in E2E; mock-only assertions; patching the owner under
test; a sample package that is not a twin of the real one;
anti-oracles (assertions that pin current wrong behavior). Credit
comes only from oracle evidence; deleting an oracle call must uncover
its obligation (negative control).
Read references/migrate-and-merge.md before you move a test, fold an
old *_lifecycle.py into the family, or delete a test. A test goes
only if it maps to no promise, or a stronger test of the same cell
strictly subsumes it. An exact or equal copy may be removed when its
twin is kept (same body, fixtures, markers, conftest scope, CI lane).
Name files by promise or owner, never by phase, wave or gap.
promise: <id> -- <sentence> (source: <path>)
cell: <factor tuple> owner: <owner id or path>
instrument: <today|target> <row|rule|scenario|security|journey|test> -> <node id> (extends|new: <why>)
oracles: [I1, I4, I7, snapshot-absence, ...] decisive: <assertion>
failing-before: <cmd> -> <result line>
passing-after: <cmd> -> <result line>
guard+mutation: <rule id> | n/a ledger: <issue> | n/a
diagnostic-mutation: <file:line edit at the emit site> -> <red assertion line> | n/a
hints executed: <cmd -> outcome> | none printedreferences/family.md -- Step 0 and Step 3: world, fixtures, file
location.references/oracles.md -- Step 4: assertions for I1-I9, strength
floor, anti-oracles, receipts.references/migrate-and-merge.md -- ONLY when moving, merging or
retiring tests.assets/templates.md -- Step 4 and Step 8: pytest skeleton (today),
replay row (target), bug-ledger row.microsoft/apm
641743f
greplspythonpytestuvuv runuv run pytestuv run whichapmwhichAlso appears in
since Nov 25, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.