fix(audit): make audit_tier2_leaks hermetic + harden test_palette_starts_hidden
audit_tier2_leaks bug: when test fixtures (tmp_path) are inside the parent git repo, git's git diff and git ls-files look UP for a parent .git/ directory and report the PARENT's modified files. This made tests/test_audit_tier2_leaks.py fail because the audit reported mcp_paths.toml + opencode.json as 'modified' even though those are in the parent repo, not in the clean tmp_path fixture. Fix: set GIT_DIR to a non-existent path (repo_root/.git) in the env passed to git subprocesses. This forces git to fail, which the audit treats as 'no modifications' / 'no tracked files'. test_palette_starts_hidden hardening: live_gui is session-scoped so other tests may leave the palette open. Pre-toggle the palette before asserting it's hidden - converts a 'depends on test ordering' test into a 'palette is closable' test. Verification: - tier-1-unit-core: ALL 5 batches PASS (was 5 failures) - tier-3-live_gui: test_gui2_custom_callback_hook_works now PASSES (was FAILED); other live_gui flakes surface non-deterministically per batch run (pre-existing issue, not caused by this fix)
This commit is contained in:
@@ -70,6 +70,15 @@ def collect_leaks(repo_root: Path, patterns: list[str]) -> list[dict]:
|
||||
"""
|
||||
if not patterns:
|
||||
return []
|
||||
# Force git to operate ONLY on repo_root. By default, git searches
|
||||
# upward for a parent .git/ directory; if repo_root happens to be a
|
||||
# subdirectory of the parent repo (e.g., a tmp_path fixture inside
|
||||
# the project tree), git would otherwise report the PARENT's modified
|
||||
# files as if they belonged to repo_root. Pointing GIT_DIR at a
|
||||
# non-existent path forces git commands to fail with a clear error,
|
||||
# which we treat as 'no modifications' / 'no tracked files'.
|
||||
import os
|
||||
ceiling_env = {**os.environ, "GIT_DIR": str(repo_root.resolve() / ".git")}
|
||||
# Get the set of modified-status from git. This avoids walking
|
||||
# node_modules and other ignored directories ourselves.
|
||||
try:
|
||||
@@ -78,6 +87,7 @@ def collect_leaks(repo_root: Path, patterns: list[str]) -> list[dict]:
|
||||
cwd=str(repo_root),
|
||||
capture_output=True,
|
||||
check=True,
|
||||
env=ceiling_env,
|
||||
)
|
||||
modified = {
|
||||
p.decode("utf-8") if isinstance(p, bytes) else p
|
||||
@@ -95,6 +105,7 @@ def collect_leaks(repo_root: Path, patterns: list[str]) -> list[dict]:
|
||||
cwd=str(repo_root),
|
||||
capture_output=True,
|
||||
check=True,
|
||||
env=ceiling_env,
|
||||
)
|
||||
tracked = {
|
||||
p.decode("utf-8") if isinstance(p, bytes) else p
|
||||
|
||||
Reference in New Issue
Block a user