Skip to content

test(quality): per-test AST duplicate gate, taxonomy placement and promise-link ratchets - #4146

Merged
Daniel Meppiel (danielmeppiel) merged 17 commits into
mainfrom
danielmeppiel-refactored-garbanzo
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 17 commits into
mainfrom
danielmeppiel-refactored-garbanzo

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR. The test-duplicate gate hashed whole files, so it found 0 of the corpus's same-body tests. It now hashes each test's normalized AST body (ast-body-v1) and also flags a Class::name reused across files. The taxonomy contract gains three no-growth ratchets: unclassified modules, misplaced modules, and new modules without a pytest.mark.promise link. All ratchets record today's debt, fail only on new debt with a [x] <file>: ... Fix: ... line, and report stale or moved entries as [i] without failing. No existing test is deleted, moved or rewritten.

Measured on main (1b96706):

Metric Value
Test modules / test functions 1,725 / 34,625
Old whole-file gate: duplicate groups 0
ast-body-v1 same-body groups 2,979 groups, 6,028 tests (3,049 extra copies)
Cross-file Class::name collisions 5,980 tests
Unclassified modules (no unit/component/e2e pytestmark) 1,288
unit modules under tests/integration 1
tests/unit modules that spawn processes 60

What changed

File Change
scripts/test_body_hash.py (new) Shared ast-body-v1 hashing. TestFunction keeps the function and class AST nodes, so the follow-up equal-copy report can add the stricter decorator, fixture and class-context checks.
scripts/check_exact_test_duplicates.py Schema 2. Baseline maps each file to its tests that are body duplicates or cross-file Class::name reuses. A test outside the baseline that becomes a duplicate fails. A lockstep edit of a baselined pair does not fail. A baselined test moved to another file under the same name is re-keyed. --update-baseline only prunes or re-keys.
tests/quality/exact_test_duplicates.json Regenerated. algorithm_doc documents the algorithm and its limitation: the hash ignores decorators, parametrize values, fixtures, class context and module bindings.
tests/quality/taxonomy_inventory_plugin.py The collection inventory also emits module-level promise ids and which modules call process-spawning APIs (subprocess, os.exec*/spawn*/system, asyncio subprocess, pexpect).
tests/quality/test_test_taxonomy.py Ratchets tm006 and catalog rules tm011, plus negative controls tm007-tm010 and tm012 (unknown prefix, undeclared family, missing P-LAW). They collect a seeded tmp tree with one violation per ratchet, a moved module, a removed entry and a compliant module.
tests/quality/test_taxonomy_baseline.json (new) Sorted lists: unclassified_modules, misplaced_modules, promise_exempt_modules (every module present today).
tests/quality/promise-catalog.json (new) The single promise catalog. Its families list declares the id families, and an id with an unknown prefix or an undeclared family fails. 307 ids: 148 spec req-* (as in CONFORMANCE.json), 139 P-OWN-<owner id>, P-INV-I1..I9, and 11 P-LAW-<id>. Drift test tm011 keeps P-LAW ids equal to the lifecycle ledger's property_catalog.
pyproject.toml Registers the promise marker.
tests/quality/test_quality_baselines.py, tests/unit/scripts/test_check_exact_test_duplicates.py Updated to the new contract. The symlink, containment, untracked, worktree and provisional cases are kept. Added: seeded duplicate, Class::name reuse, third copy, lockstep edit, move re-key, stale info/prune, malformed baselines.
Contributor docs (integration-testing.md, tests.instructions.md x2) New "Test corpus ratchets" section describing the three ratchets.

Touched architecture owner: behavioral-test-taxonomy-classification (.apm/architecture/owners/core-runtime.json). The getattr(module, "pytestmark" mutation anchor in the plugin is still unique.

Trade-offs

  • Membership, not digest, is the ratchet key. Editing both copies of a baselined pair in lockstep is not new debt. A test that newly joins any group is.
  • Stale and moved entries never fail. Parallel consolidation PRs shrink the corpus without conflicting on the baselines, which are sorted with one entry per line. The cost is that pruning is optional (--update-baseline for duplicates; by hand for taxonomy).
  • Spawn detection is static. It finds direct calls only. Helpers that spawn indirectly are not seen. This is acceptable for a no-growth gate on new modules.
  • Promise links are required only on new modules. Existing modules are exempt via promise_exempt_modules.

In-flight allowances (prune after these land)

These modules or tests are added or changed by open 0.37 PRs. They are pre-seeded so those PRs need no change. Before their PRs land, the entries are reported as stale, never as failures.

Allowances by PR
PR List Entry
#4023 promise_exempt tests/integration/test_file_primitive_receipt_lifecycle.py
#4023 promise_exempt tests/spec_conformance/test_cowork_deployed_hash_reqs.py
#4023 unclassified tests/integration/test_file_primitive_receipt_lifecycle.py
#4023 unclassified tests/spec_conformance/test_cowork_deployed_hash_reqs.py
#4025 promise_exempt tests/spec_conformance/test_exec_decision_reqs.py
#4025 promise_exempt tests/unit/install/test_exec_decision_equivalence.py
#4025 unclassified tests/spec_conformance/test_exec_decision_reqs.py
#4025 unclassified tests/unit/install/test_exec_decision_equivalence.py
#4049 promise_exempt tests/integration/test_cleanup_deployment_evidence_lifecycle.py
#4049 promise_exempt tests/spec_conformance/test_deletion_evidence_reqs.py
#4049 unclassified tests/integration/test_cleanup_deployment_evidence_lifecycle.py
#4049 unclassified tests/spec_conformance/test_deletion_evidence_reqs.py
#4055 duplicate_bodies (also #4025) tests/integration/test_architecture_owner_rule_mutations.py::test_deploy_path_allow_map_comes_from_the_trust_owner
#4055 duplicate_bodies (also #4025) tests/integration/test_architecture_owner_rule_mutations.py::test_trust_owner_reads_the_scope_manifest_closed_world
#4055 promise_exempt tests/integration/test_pinned_hook_policy_deny_lifecycle.py
#4055 unclassified tests/integration/test_pinned_hook_policy_deny_lifecycle.py
#4057 promise_exempt tests/integration/test_uninstall_lsp_without_mcp_lifecycle.py
#4063 misplaced tests/unit/install/test_partial_subtree_reconciliation.py
#4064 promise_exempt tests/integration/test_bin_canvas_deny_diagnostics_lifecycle.py
#4064 unclassified tests/integration/test_bin_canvas_deny_diagnostics_lifecycle.py
#4065 promise_exempt tests/integration/test_frozen_stale_exec_status_lifecycle.py
#4065 unclassified tests/integration/test_frozen_stale_exec_status_lifecycle.py
#4068 promise_exempt tests/integration/test_uninstall_lsp_recorded_targets_lifecycle.py
#4128 promise_exempt tests/integration/test_remediation_advice_lifecycle.py
#4129 promise_exempt tests/integration/test_policy_install_enforcement_lifecycle.py
#4137 promise_exempt tests/unit/core/test_token_manager_purpose_env_var.py
#4137 unclassified tests/unit/core/test_token_manager_purpose_env_var.py
#4138 promise_exempt tests/integration/test_install_commit_order_lifecycle.py
#4138 unclassified tests/integration/test_install_commit_order_lifecycle.py
#4143 promise_exempt tests/integration/test_command_output_owner_e2e.py
#4142 promise_exempt tests/lifecycle/test_core_example.py
#4142 promise_exempt tests/quality/test_promise_obligations.py
#4142 unclassified tests/lifecycle/test_core_example.py
#4142 unclassified tests/quality/test_promise_obligations.py

Issue and approved scope

Issue: Refs #4028 (Part of #4028; follow-up C-1b adds the equal-copy report, AQ003/AQ004 and the e2e-drive ratchet).

Human scope-approval comment: #4028 (comment) (plus the amendment recorded on the issue).

Remaining after this PR: the C-1b items above.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
Validation evidence (merged with current main)
$ uv run --frozen python scripts/check_exact_test_duplicates.py
[+] test duplicate ratchet clean: 1728 files, 34659 tests, 2979 duplicate body group(s), 5980 duplicate Class::name test(s)

$ uv run --frozen --extra dev pytest -p no:cacheprovider -q -n 4 tests/quality tests/unit/scripts/test_check_exact_test_duplicates.py
240 passed in 89.59s

$ ruff check / ruff format --check (src/ tests/ + CI script set), pylint R0801, lint-auth-signals.sh, lint-architecture-boundaries.sh
all exit 0

tests/unit/scripts/test_architecture_registry_conflicts.py fails locally only because commit signing is enforced in this environment. It is unrelated, and it also fails on main here.

How to test

  1. uv run --frozen python scripts/check_exact_test_duplicates.py should be clean.
  2. Copy any test function body into a new test in another file: the gate prints [x] <file>: test <name> duplicates the body ... Fix: ....
  3. Add tests/unit/test_tmp.py without a pytestmark, then run uv run --extra dev pytest -q tests/quality/test_test_taxonomy.py -k tm006. It fails, naming the file as unclassified and promise-less.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (internal, per the approved scope).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

Temporary in-flight allowances (approved; shrink after #4142 lands)

These modules and one duplicate pair landed on main after the baselines were seeded. They are recorded as existing debt and are removed as their owners add markers or differentiate the tests.

  • tests/integration/test_config_credential_rendering_lifecycle.py -- new test module carries no pytest.mark.promise
  • tests/integration/test_policy_outcome_routing_lifecycle.py -- new test module carries no pytest.mark.promise
  • tests/integration/test_registry_archive_limits_lifecycle.py -- new test module carries no pytest.mark.promise
  • tests/integration/test_registry_archive_limits_lifecycle.py -- unclassified test module
  • tests/quality/test_journey_index.py -- new test module carries no pytest.mark.promise
  • tests/quality/test_journey_index.py -- unclassified test module
  • tests/spec_conformance/test_ext_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_ext_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_lockfile_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_lockfile_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_lockfile_cli_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_manifest_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_manifest_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_manifest_cli_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_policy_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_policy_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_resolve_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_resolve_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_security_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_security_behavior_reqs.py -- unclassified test module
  • tests/spec_conformance/test_targets_behavior_reqs.py -- new test module carries no pytest.mark.promise
  • tests/spec_conformance/test_targets_behavior_reqs.py -- unclassified test module
  • tests/unit/utils/test_credential_rendering.py -- new test module carries no pytest.mark.promise
  • tests/unit/utils/test_credential_rendering.py -- unclassified test module
  • tests/integration/test_git_lock_content_hash_lifecycle.py -- new test module carries no pytest.mark.promise
  • tests/unit/utils/test_credential_rendering.py -- same-body pair: test_query_credentials_in_config_values_are_masked / test_userinfo_inside_equals_form_args_is_removed

…omise-link ratchets

Part of #4028.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:39
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The duplicate and taxonomy gates still permit allowance growth and miss process-spawning imports, leaving enforcement gaps that need fixes and regression coverage.

4 open issues
What changed in this PR

This PR strengthens APM's test-quality gates as part of #4028, detecting per-test duplication and preventing new classification, placement, and promise-link debt without rewriting existing tests.

Changes:

  • Replaces whole-file duplicate detection with normalized AST body hashes and cross-file Class::name checks.
  • Adds taxonomy and promise-link checks, with informational handling of stale or moved allowances.
  • Updates regression coverage, contributor guidance, and marker registration.
File Description
tests/​unit/​scripts/​test_check_exact_test_duplicates.py Tests duplicate detection and baseline lifecycle behavior.
tests/​quality/​test_test_taxonomy.py Adds taxonomy and promise-link checks with seeded controls.
tests/​quality/​test_quality_baselines.py Adapts baseline contracts to the new duplicate format.
tests/​quality/​taxonomy_inventory_plugin.py Collects promise IDs and detects process-spawning calls.
tests/​quality/​promise-catalog.json Seeds recognized specification and architecture-owner promises.
scripts/​test_body_hash.py Provides shared per-test AST hashing.
scripts/​check_exact_test_duplicates.py Implements per-test duplicate checks and baseline rekeying.
pyproject.toml Registers the promise marker.
docs/​src/​content/​docs/​contributing/​integration-testing.md Explains the new test-corpus checks.
CHANGELOG.md Records the internal test-quality changes.
.github/​instructions/​tests.instructions.md Updates contributor instructions for the checks.
.apm/​instructions/​tests.instructions.md Mirrors the test-corpus guidance in APM instructions.

Review effort: Balanced

Comment thread scripts/check_exact_test_duplicates.py Resolved
Comment thread tests/quality/test_test_taxonomy.py Resolved
Adds P-INV-I1..I9 and P-LAW-<id> for every lifecycle law, renames
owner:<id> to P-OWN-<id>, rejects unknown prefixes and undeclared
families, and fails when a lifecycle law has no P-LAW id. Pre-seeds
an in-flight allowance for #4143.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
- duplicate gate: only absent baselined tests can be a move source
- spawn detection: aliases resolve per lexical scope; asyncio.subprocess
  create_subprocess_exec/_shell count as spawning
- taxonomy allowances: shrink-only against the PR base revision
  (scripts/check_taxonomy_allowances.py, wired into the Lint job), with
  validated move re-keys as the only accepted additions
- baseline modules that landed on main

Part of #4028

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…d on main

The module reached main after the promise-link allowances were seeded, so
tm006 flags it as a new promise-less module. Record it as an existing
module.

Co-authored-by: Copilot App <[email protected]>
Resolve the self-deployed tests instruction hash in apm.lock.yaml to the
merged file content.

Co-authored-by: Copilot App <[email protected]>
Modules and one same-body pair landed on main after the ratchet baselines
were seeded. Record them as existing debt so the ratchets fail only on new
growth; their owners add promise and taxonomy markers in follow-ups.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d96c2bd into main Nov 20, 2026
38 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-refactored-garbanzo branch November 20, 2026 13:09
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…4142 resolves

- Taxonomy baseline: drop the temporary allowances for the modules #4142 marks
  (spec behavior modules, journey index, registry archive, git lock content hash,
  policy outcome routing, credential rendering) and the deleted integration machines;
  test_m_gate.py now carries e2e and promise marks.
- Exact-duplicate baseline: drop the credential_rendering pair (now one parametrized test).
- #4270 landed (#4276): the Claude plugin bin/ user-scope world cells are required again.
- #4178 cell keys on the same approve warning printed twice, not on any warning.

Co-authored-by: Copilot App <[email protected]>
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.

2 participants