Skip to content

[0.38] test(git-env): exercise the real git_env owner in its seams (#4552 item 6, slice 1) - #4683

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

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
wip/4552-weak-tests-slice1

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

#4552 item 6, slice 1: the owner-group rewrite of owner-patching tests for apm_cli.utils.git_env. It was the largest AQ004 group that no open PR touched.

The two seams used to patch the owner's own functions (_read_effective_git_config, _git_config_run, _resolve_trusted_executable). They now run the real git_env code and replace only the I/O boundary:

  • tests/unit/utils/test_real_git_tls_config.py:
    • A fake git config child at subprocess.Popen answers with the exact bytes git config --null --show-scope --list prints.
    • The one test that reads real config files through a real git (a global file plus a command-scope override) moved to tests/integration/test_git_tls_config_probe.py. It is marked component and windows_compat, and checks that the probe writes nothing. The unit module now touches no filesystem and spawns no process.
    • The caching, thread-safety and precedence assertions are kept.
  • tests/unit/cache/test_git_env.py:
    • Config probes, including the retry and timeout paths, meet the same kind of fake child.
    • Executable lookup resolves stand-in files on a real PATH.
    • Snapshot reuse counts real git config probes. The snapshot still carries an indexed http.extraheader, and no config header survives into the child.

Assertion-quality baseline, which only shrinks:

Rule File Before After
AQ004 tests/unit/utils/test_real_git_tls_config.py 19 0
AQ004 tests/unit/cache/test_git_env.py 19 5

The five remaining AQ004 sites in test_git_env.py are clone-path tests that patch several git_env stages at once. They are left for a later slice so this one stays reviewable (4 files, +345/-318). AQ003 and AQ006 are unchanged.

Issue and approved scope

Issue: Refs #4552 (item 6)

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. This is the first slice of item 6; more owner groups follow, and the other #4552 items are tracked there.

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 with -n 2. The branch has origin/main merged in (merge commit 9e4605a).

  • pytest tests/quality/test_quality_baselines.py tests/quality/test_test_taxonomy.py tests/unit/cache/test_git_env.py tests/unit/utils/test_real_git_tls_config.py: 167 passed. After the review fixes, the two rewritten files plus tests/integration/test_git_tls_config_probe.py: 124 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.
  • No source line loses coverage. Comparing the old and new versions of both files, git_env.py coverage goes from 662 to 668 executed lines, with none lost.
  • The lint contract is clean: ruff 0.15.12 check and format, pylint R0801, auth signals and the complexity ratchet.

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.

…ild (#4552)

The TLS config seam patched the owner's own config reader. It now runs
the real chain down to the git config child process: a fake Popen
answers with the bytes git config --null --show-scope --list prints,
and one test reads real config files through a real git.

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

The git_env seam patched the owner's own config runner, executable
resolver and config reader. Config probes now meet a fake git config
child at subprocess.Popen, executable lookup resolves stand-in files on
a real PATH, and snapshot reuse counts real git config probes. No
git_env.py line loses coverage (662 -> 668 lines executed).

AQ004 for the git_env owner group shrinks from 38 to 5:
test_real_git_tls_config.py 19 -> 0, test_git_env.py 19 -> 5.

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 tests need corrected classification and placement for real Git execution, plus restored snapshot-reuse coverage that verifies config authorization headers are removed.

2 open issues
What changed in this PR

This PR begins #4552 item 6 by rewriting git_env tests to exercise the real owner logic instead of mocking its internal functions. Production behavior is unchanged.

Changes:

  • Replace internal probe mocks with fake child processes while preserving TLS precedence, caching, and concurrency checks.
  • Exercise executable discovery through stand-in files and configuration parsing through real Git.
  • Reduce owner-patching baseline counts from 19 to 0 for TLS tests and from 19 to 5 for cache tests.
File Description
tests/​unit/​utils/​test_real_git_tls_config.py Tests TLS configuration through process-boundary fakes and a real Git configuration probe.
tests/​unit/​cache/​test_git_env.py Reworks executable lookup, retry, timeout, and snapshot-reuse tests around real owner logic.
tests/​quality/​assertion_quality_baseline.json Lowers the owner-patching allowances for both test modules.

Review effort: Balanced

Comment thread tests/unit/cache/test_git_env.py Resolved
…ove the real-git TLS probe to a component module

Addresses review on #4683: the snapshot reuse test again carries an indexed
http.extraheader and asserts no config header survives; the real git
config test moves out of the unit module into tests/integration, marked
component and windows_compat, with a read-only durable-state oracle.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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