Skip to content

test: stop the agentrc probe from poisoning the git executable cache - #4123

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-test-pollution-git-cache
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-test-pollution-git-cache

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Release validation of main (run 44695495012) failed 84 macOS-arm64 unit tests. The cause is test pollution; there is no product impact. This PR fixes it in tests only, plus a hardening of the architecture linter's inventory walk.

  1. Git executable cache poisoned by the agentrc probe.
    • TestInitAgentrcSuggestion patched apm_cli.commands.init.shutil.which, which is the global shutil.which.
    • apm init resolves git during the run, so git_env._git_executable cached /usr/bin/agentrc for the whole process.
    • Every later test on that xdist worker then failed: GitUrlRewriteProbeError, FileNotFoundError '/usr/bin/agentrc', and 'agentrc' == 'git'.
    • Fix: the patch now answers only for agentrc and delegates everything else (_agentrc_on_path).
    • Defense: an autouse fixture in tests/conftest.py resets the git/gh executable caches (reset_git_cache) after each test.
    • Regression test: test_agentrc_probe_never_poisons_the_git_executable_cache fails with the old blanket patch and passes now.
  2. test_real_tree_is_clean crashed on a vanished apm_modules.
    • The architecture inventory now excludes the gitignored root apm_modules.
    • It also skips a directory that disappears mid-walk (FileNotFoundError only). Every other walk error still fails closed, and tracked source is still walked.
    • Tests cover both behaviors.

I did not pinpoint which test creates and removes apm_modules at the repo root. A local run leaves none behind, and the inventory change removes the failure mode either way.

Issue and approved scope

Issue: Refs #3983. This is a release-validation repair requested by the 0.37 delivery manager and coordinator.

Human scope-approval comment: coordinator-directed release mechanics (test-only).

Does this PR complete the issue, or what remains? It restores release validation. #3983 remains the umbrella issue.

Type of change

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

Testing

  • Tested locally

  • All existing tests pass (CI)

  • Added tests for new functionality (if applicable)

  • pytest -n 0 -p no:randomly tests/unit/test_init_command.py tests/unit/test_version.py tests/unit/test_list_remote_refs.py (polluting order): 163 passed.

  • pytest -n 2 over those files plus tests/unit/scripts/test_architecture_inventory.py and tests/unit/scripts/test_architecture_skill_layout_guard.py: 191 passed.

  • Leak probe: with the old patch, the git cache ends up as /usr/bin/agentrc; with the new patch it does not.

  • uvx [email protected] check and format --check are clean, and scripts/lint-architecture-boundaries.sh exits 0.

Changelog

  • One line in one section under ## [Unreleased]
  • N/A -- internal-only change (tests and linter inventory).

Spec conformance (OpenAPM v0.1)

No behaviour change.

… inventory skips root apm_modules

TestInitAgentrcSuggestion patched the global shutil.which, so apm init's
git resolution cached /usr/bin/agentrc process-wide and broke every later
test on the xdist worker (84 macOS-arm64 release-validation failures).
The patch now answers only for agentrc. An autouse fixture resets the
git/gh executable caches after each test, and a regression test pins the
leak (it fails with the old blanket patch).

The architecture inventory excludes the gitignored root apm_modules and
skips a directory that vanishes mid-walk (FileNotFoundError only), so a
concurrent test's scratch output cannot crash the real-tree guard.

Co-authored-by: Copilot App <[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 inventory traversal silently omits disappearing source subtrees, allowing architecture checks on incomplete data, while the cache-pollution regression can miss the bug on Windows.

2 open issues
What changed in this PR

This PR addresses release-validation test pollution by isolating executable lookup mocks and clearing cached paths between tests. It also adjusts the architecture linter’s handling of generated output and disappearing directories.

Changes:

  • Limit agentrc mocks to agentrc lookups and add a cache-pollution regression test.
  • Reset git and gh executable caches after each test.
  • Exclude root apm_modules from architecture scans and add coverage for traversal-error handling.
File Description
tests/​unit/​test_init_command.py Narrows agentrc mocks and adds a cache-pollution regression.
tests/​unit/​scripts/​test_architecture_inventory.py Tests generated-root exclusion and traversal-error handling.
tests/​conftest.py Clears executable caches after each test.
scripts/​architecture_linter/​inventory.py Excludes root install output and skips missing-directory errors.

Review effort: Balanced

Comment thread tests/unit/test_init_command.py Resolved
… clearing them

Clearing left a cold cache that tests relying on a warm, already-resolved
git path observe differently on Windows (test_auth_scoping). Restoring the
pre-test value still undoes any leak a test causes.

Co-authored-by: Copilot App <[email protected]>
Tests that clear PATH (test_auth_scoping on Windows) relied on an earlier
test having warmed the git cache. The fixture now resolves the real git
before each test when the cache is cold, so every test sees the same
warm cache, and still restores it afterwards so no test leaks a value.

Co-authored-by: Copilot App <[email protected]>
…olved path

Fold Copilot review: a vanished source subtree must fail the inventory
(root apm_modules exclusion already covers the install-output race), and
the agentrc regression now requires a populated git cache and compares
resolved paths so it detects pollution on Windows too.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
tests/unit/core/test_output_mode.py invokes `cli ... --format=json`, which
calls set_console_stderr(True). That routing is process-global, and only
tests/integration/conftest.py reset it, so a later unit test on the same
xdist worker read empty stdout through capsys. Example:
test_targets_phase.py::test_config_default_target_provenance_names_config_source
on Windows units (1/3), run 44705583099.

Promote _reset_console_state to the root tests/conftest.py so every suite
starts and ends each test with default console routing. The integration
cwd repair keeps running after each test, now in
_integration_process_cwd_guard.

Co-authored-by: Copilot App <[email protected]>
…tion"

This reverts commit 9bfdc2d. It duplicated other work: the console-routing
pollution is owned by a separate PR (Part of #4115). #4123 stays scoped to
the git executable cache.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit c5a5115 into main Nov 20, 2026
27 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-test-pollution-git-cache branch November 20, 2026 09:58
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