mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-28 20:49:11 +01:00
usage_report: delete the dead _compute_window shim
Documented as "kept for backwards import compatibility", it had zero production callers - only its own two tests. Removed the function, those two tests, and the pathlib.Path import that only its signature used. _SEC_PER_DAY stays: two live callers remain at _usage_report_run.py:135 and :181, so only the function was dead, not the constant. Verified: usage_report.py --help exits 0 (the unit tests stub subprocesses, so only a real run proves the import graph), 202 tests pass, and _usage_report_run.py holds 100% line+branch coverage after removing both the code and the tests that covered it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
This commit is contained in:
parent
0cf487b3f3
commit
57b9005a6b
@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"intent": "Delete the dead _compute_window shim from _usage_report_run.py so the module carries no code without callers, ahead of the remaining file-length split work.",
|
||||||
|
"scope": [
|
||||||
|
"linux_configuration/scripts/periodic_background/system-maintenance/bin/_usage_report_run.py",
|
||||||
|
"linux_configuration/tests/test_usage_report_segments.py",
|
||||||
|
"Non-goal: any behaviour change to _run_single_day or _run_since",
|
||||||
|
"Non-goal: splitting this file - it is already 86 statements, well under the 250-line cap"
|
||||||
|
],
|
||||||
|
"changes": [
|
||||||
|
"Removed _compute_window, a helper documented as 'kept for backwards import compatibility' whose only in-tree callers were its own two tests.",
|
||||||
|
"Removed the two tests that exercised only the shim, and dropped it from the test module docstring.",
|
||||||
|
"Removed the now-unused `from pathlib import Path` TYPE_CHECKING import; Path was referenced only by the deleted signature.",
|
||||||
|
"Kept _SEC_PER_DAY: grep shows two live callers remain at _usage_report_run.py:135 and :181, so only the function was dead, not the constant."
|
||||||
|
],
|
||||||
|
"verification": [
|
||||||
|
{
|
||||||
|
"command": "grep -rn '_compute_window' --include='*.py' --include='*.sh' --include='*.md' --include='*.json' . (excluding .venv/node_modules)",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "Before deletion: one definition, two tests, and prose mentions in NEXT_SESSION_PROMPT.md plus prior evidence/contract JSON. Zero production callers, and the name appears in no __all__."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "grep -c '_SEC_PER_DAY' _usage_report_run.py",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "4 hits: the definition, the deleted shim's use, and two live uses at lines 135 and 181. The constant is retained."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "python3 -c 'import _usage_report_run as r; print(hasattr(r, \"_compute_window\"), r._SEC_PER_DAY)'",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "imports OK / has _compute_window: False / _SEC_PER_DAY: 86400"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "python3 usage_report.py --help",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "Exit 0, full usage text printed. Unit tests stub subprocesses, so running the real entry point is what proves the post-deletion import graph resolves."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "systemd-run --user --scope -p MemoryMax=2G -p MemorySwapMax=0 python3 -m pytest linux_configuration/tests/ -q",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "202 passed in 4.21s. Count dropped from 204 by exactly the two deleted shim tests."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "pytest --cov=.../system-maintenance/bin --cov-branch --cov-report=term-missing",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "_usage_report_run.py: 86 statements, 0 missing, 22 branches, 0 partial, 100%. Coverage held at 100% line+branch after removing both the code and its tests."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "bash ~/utils/scripts/check_file_length.sh --all",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "36 files over cap, unchanged by this commit; neither touched file is among them. Checked before committing, per the known trap that a split can push a file over."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"risks": [
|
||||||
|
"An out-of-tree consumer could import _compute_window by name. Judged negligible: these bin/ modules are private (leading underscore), are not packaged or installed, and are imported only by usage_report.py and the tests beside them.",
|
||||||
|
"The deleted tests contributed to the module's covered branches; coverage was re-measured rather than assumed, and is still 100%."
|
||||||
|
],
|
||||||
|
"rollback": [
|
||||||
|
"git revert the commit; the shim and its two tests return together.",
|
||||||
|
"After rollback, re-run pytest linux_configuration/tests/ and expect 204 passed, and confirm _usage_report_run.py is back to 100% coverage."
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -36,19 +36,6 @@ _SEC_PER_DAY = 86_400
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
def _compute_window(atop_log: Path, progress: _Progress) -> _Window:
|
|
||||||
"""Deprecated helper kept for backwards import compatibility.
|
|
||||||
|
|
||||||
New code should call :func:`aggregate_atop`, which returns the window
|
|
||||||
alongside the per-process aggregates from a single atop subprocess.
|
|
||||||
"""
|
|
||||||
_, window = aggregate_atop(atop_log, progress)
|
|
||||||
if not window.seconds:
|
|
||||||
window.seconds = _SEC_PER_DAY
|
|
||||||
return window
|
|
||||||
|
|
||||||
|
|
||||||
_REPORT_STAGES = 2
|
_REPORT_STAGES = 2
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
"""Tests for usage_report's per-day segment aggregation, the log-description
|
"""Tests for usage_report's per-day segment aggregation and the
|
||||||
strings, and the deprecated _compute_window shim.
|
log-description strings.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import _usage_report_run as run
|
import _usage_report_run as run
|
||||||
from _usage_report_types import _Progress, _Window
|
from _usage_report_types import _Progress, _Window
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -19,35 +20,6 @@ def _progress() -> _Progress:
|
|||||||
return _Progress(enabled=False, total_stages=1)
|
return _Progress(enabled=False, total_stages=1)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
|
||||||
# _compute_window (deprecated shim; no callers remain in-tree)
|
|
||||||
# --------------------------------------------------------------------------- #
|
|
||||||
def test_compute_window_returns_the_aggregate_window(
|
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
|
||||||
) -> None:
|
|
||||||
"""The shim forwards to aggregate_atop and hands back its window."""
|
|
||||||
window = _Window(distinct_samples=3, interval_s=600, seconds=1200)
|
|
||||||
monkeypatch.setattr(run, "aggregate_atop", lambda *_a: ({}, window))
|
|
||||||
|
|
||||||
result = run._compute_window(Path("/nonexistent/atop"), _progress())
|
|
||||||
|
|
||||||
assert result is window
|
|
||||||
assert result.seconds == 1200
|
|
||||||
|
|
||||||
|
|
||||||
def test_compute_window_defaults_an_empty_window_to_a_day(
|
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
|
||||||
) -> None:
|
|
||||||
"""A window with no measured seconds is widened to a full day."""
|
|
||||||
window = _Window(distinct_samples=1)
|
|
||||||
monkeypatch.setattr(run, "aggregate_atop", lambda *_a: ({}, window))
|
|
||||||
|
|
||||||
assert (
|
|
||||||
run._compute_window(Path("/nonexistent/atop"), _progress()).seconds
|
|
||||||
== run._SEC_PER_DAY
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
# _aggregate_segments / _log_descriptions
|
# _aggregate_segments / _log_descriptions
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user