Skip to content

[0.38] test(git-cache): resolve, clone and fetch against a real local remote (#4552 item 6, slice 4) - #4721

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-4552-weak-tests-slice4
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-4552-weak-tests-slice4

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

#4552 item 6, slice 4: the owner-group rewrite of tests/integration/test_git_cache_hermetic.py (owner apm_cli.cache.git_cache). It had 66 AQ004 entries, the largest AQ004 debt among the files no open PR or lane touches. Slice 3 (test_config_command.py) is #4718.

The ls-remote, bare-repo, has-sha and fetch-by-sha tests patched git_env's own get_git_executable, git_subprocess_env and _validated_git_url_rewrite_policy (49 sites). They now run the real git_cache and git_env code:

  • A _Remote fixture: a real repository served over file://, with main, tag v1.0.0 and a feature/topic branch.
    • Ref resolution (HEAD, heads, tags, tail fallback, unknown refs, unreachable remotes) runs a real git ls-remote.
    • A cold clone lands a real bare repo, and the test asserts that no staged .inc. directory is left behind.
    • A failed clone removes its staged directory.
    • Fetch by sha, and the explicit-refspec fallback, put the commit in the bare repo; the test checks its object store and refs.
  • A lost atomic_land race is simulated honestly: a competing process lands the winner first, then the real atomic_land loses. The test asserts whether the winner is fetched to the sha or reused.
  • A _GitChild stand-in at subprocess.run is used only where real git cannot produce the case: malformed output, timeouts, OSError, a server refusing a fetch by sha, and env pass-through. It records each child's argv and env, so the tests assert the sanitized env (an explicit GIT_DIR never reaches the child).
  • Out of scope: the 16 remaining sites, which cover the checkout and evict tests (robust_rmtree and the clone patches in TestCreateCheckout). They are left for a later slice.

Assertion-quality baseline (shrink only):

Rule File Before After
AQ004 tests/integration/test_git_cache_hermetic.py 66 16

Issue and approved scope

Issue: Refs #4552 (item 6, slice 4)

Human scope-approval comment: #4552 (comment) (item 6: "start the owner-group rewrites of mock-only, owner-patching and assertion-free tests, shrinking the AQ003, AQ004 and AQ006 entries").

Does this PR complete the issue, or what remains? No. Slices 1 (#4683), 2 (#4716) and 3 (#4718) cover other owner groups. Further groups and the other #4552 items remain.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass: CI pending.
  • Added tests for new functionality (if applicable)

Local results, run through the host guard:

  • pytest tests/integration/test_git_cache_hermetic.py: 60 passed (58 before; the parametrized cases add 2).
  • pytest -n 2 tests/quality/test_quality_baselines.py tests/quality/test_test_taxonomy.py: 43 passed.
  • scripts/check_test_assertions.py: the ratchet is clean. python -m tests.quality.taxonomy --changed: tm006 is clean. scripts/check_exact_test_duplicates.py: clean.
  • Coverage compares the old and new module with --cov=apm_cli.cache.git_cache --cov=apm_cli.cache.locking: git_cache.py goes from 317 to 319 executed lines and locking.py from 18 to 29. No line is lost.
  • The lint contract is clean: ruff 0.15.12 check and format, and auth signals.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor). The [FEATURE] 0.38 test-corpus hygiene residual from 0.37 #4552 record specifies no CHANGELOG line.

Spec conformance (OpenAPM v0.1)

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

…ocal remote

#4552 item 6, slice 4 (work in progress).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#4552 item 6, slice 4. The ls-remote, bare-repo, has-sha and fetch-by-sha
tests patched git_env's executable lookup and child env (49 sites). They
now run the real git_cache and git_env against a file:// remote, faking
only the git child process at subprocess.run for parser edge cases and
failures. AQ004 for tests/integration/test_git_cache_hermetic.py drops
from 66 to 16.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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 new Git integration tests inherit runner settings that can redirect fixture setup, require commit signing, or disable file transport, so they need an isolated environment throughout.

1 open issue
What changed in this PR

This test-only refactor advances #4552 item 6 by replacing owner-level mocks with real local Git operations, strengthening coverage of the Git cache without changing production behavior.

Changes:

  • Exercise ref resolution, cloning, commit lookup and fetching against a local file:// remote.
  • Check durable repository state, staged-directory cleanup and lost-landing behavior, using child-process stand-ins for exceptional cases.
  • Reduce the module's owner-patching baseline (AQ004) from 66 to 16, leaving checkout and eviction rewrites for a later slice.
File Description
tests/​quality/​assertion_quality_baseline.json Lowers the Git cache module's AQ004 allowance to 16.
tests/​integration/​test_git_cache_hermetic.py Adds a real remote fixture and replaces mocked outcomes with repository-state assertions.

Review effort: Balanced

Addresses review on #4721: fixtures, probes and cache calls inherit an
IsolatedApmEnvironment base, so runner GIT_DIR, global config and
credential state never reach the real git children.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🟢 Approval recommended

No active review issues are recorded for the Git cache test rewrite.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 956e063 into main Nov 22, 2026
71 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4552-weak-tests-slice4 branch November 22, 2026 16:29
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