refactor(gc): split the risk plan to clear quality and review findings
CI / security-codeql (push) Blocked by required conditions
CI / test-unit (push) Blocked by required conditions
CI / test-integration (push) Blocked by required conditions
CI / test-env-virtual (push) Blocked by required conditions
CI / test-env-nix (push) Blocked by required conditions
CI / test-e2e (push) Blocked by required conditions
CI / test-virgin-user (push) Blocked by required conditions
CI / test-virgin-root (push) Blocked by required conditions
CI / lint-shell (push) Blocked by required conditions
CI / lint-python (push) Blocked by required conditions
CI / lint-docker (push) Blocked by required conditions
CI / quality (push) Blocked by required conditions
CI / security-codeql (push) Blocked by required conditions
CI / test-unit (push) Blocked by required conditions
CI / test-integration (push) Blocked by required conditions
CI / test-env-virtual (push) Blocked by required conditions
CI / test-env-nix (push) Blocked by required conditions
CI / test-e2e (push) Blocked by required conditions
CI / test-virgin-user (push) Blocked by required conditions
CI / test-virgin-root (push) Blocked by required conditions
CI / lint-shell (push) Blocked by required conditions
CI / lint-python (push) Blocked by required conditions
CI / lint-docker (push) Blocked by required conditions
CI / quality (push) Blocked by required conditions
quality, 24 findings: risk_cleanup(repo_roots, request) takes a frozen RiskRequest and splits into _refusal, _git_options, _host_items, _apply and _report; the hardcoded /tmp root is gone, the CLI passes tempfile.gettempdir() (so TMPDIR is honoured); classify, the tmp verdict and the HTTP client split into helpers in the same check order; gc_cmd options split into two adders; default-value fallbacks removed where every path sets the value. Tests: git(), AUTHOR and isolated_root move to tests/support/git_sandbox.py, the plan tests move to tests/unit/pkgmgr/actions/branch/test_gc_plan.py, test_risk_plan.py splits into risk_fixture.py, test_risk_plan.py and test_risk_apply.py. CodeRabbit: with --branch, --apply only plans and deletes the selected git items, docker and scratch items stay out with a warning; a truncated HTTP error body keeps its status and the partial body. | 🌿 Branch | 📊 Diff stat | 🎯 Fix | 💥 Break | 💸 Tokens | ⏱️ Velocity | 🛡️ Security | 🏆 Score | Gate | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | feature/gc-risk-levels | 17 files +946/-788 | 91 % | 4 % | – | – | 100 % | 87 | ✅ 90/5, tokens and velocity <= 100, security 100 % | Evidence: tests/unit + tests/integration with PYTHONPATH=src 904 passed; 2 known gpg-in-sandbox failures in test_publish_integration. quality check --staged 0 findings, ruff clean, MEDUSA 100 %, critical 0, 3 accepted (scheme-guarded urlopen moved into _send, fixed-argv git in the test helper). Hub review 913e2f2465eda2d9. Refs https://github.com/kevinveenbirkenbach/package-manager/pull/21 Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8248a0253
commit
cee58bcef1
17 files changed
+946
-788
No files matched your search
@@ -0,0 +1,59 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
AUTHOR = {
|
||||
"GIT_AUTHOR_NAME": "t",
|
||||
"GIT_AUTHOR_EMAIL": "t@example.org",
|
||||
"GIT_COMMITTER_NAME": "t",
|
||||
"GIT_COMMITTER_EMAIL": "t@example.org",
|
||||
}
|
||||
|
||||
|
||||
def git(cwd: str, *args: str) -> str:
|
||||
"""
|
||||
Args:
|
||||
cwd: the repository to run in.
|
||||
args: the git arguments; signing stays off and AUTHOR applies.
|
||||
|
||||
Returns:
|
||||
The stripped standard output.
|
||||
"""
|
||||
return subprocess.run(
|
||||
["git", "-c", "commit.gpgsign=false", *args],
|
||||
cwd=cwd,
|
||||
env={**os.environ, **AUTHOR},
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
|
||||
|
||||
def isolated_root(case: unittest.TestCase, env: dict[str, str]) -> str:
|
||||
"""
|
||||
Args:
|
||||
case: the test whose cleanups remove the directory and restore the
|
||||
working directory and environment.
|
||||
env: variables set over the environment, from which every GIT_*
|
||||
variable is dropped.
|
||||
|
||||
Returns:
|
||||
The realpath of a fresh temporary directory, now the working
|
||||
directory, whose empty `home` child is HOME.
|
||||
"""
|
||||
scratch = tempfile.TemporaryDirectory()
|
||||
case.addCleanup(scratch.cleanup)
|
||||
root = os.path.realpath(scratch.name)
|
||||
case.addCleanup(os.chdir, os.getcwd())
|
||||
os.chdir(root)
|
||||
home = os.path.join(root, "home")
|
||||
os.makedirs(home)
|
||||
kept = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
||||
environ = patch.dict(os.environ, {**kept, **env, "HOME": home}, clear=True)
|
||||
environ.start()
|
||||
case.addCleanup(environ.stop)
|
||||
return root
|
||||
Reference in new issue
Block a user