MAINT-21: tests read and patch the Controller through tools/main_files.py

Prepares the split of app/main.py's Controller into files by job, with no app
change. tools/main_files.py gives a test the text and the AST of main.py plus
the files split from it, and `live`, which sets a global in every file whose
functions read it (and raises when none does). Tests that read main.py's
source, and tests and replay tools that patch a main global (datetime,
compute, resolve, _mono, WRITE_BUDGET_S, ...), go through it, so they pass on
this layout and on the split one. test_split_patches.py fails when a test or
tool patches an app.main attribute that main.py no longer reads, or that
another file also reads. tools/maint21_same_ast.py proves every function,
method and module-level assignment of main.py at the base is found unchanged
in its new file.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-11-09 00:27:07 +01:00
co-authored by Claude
parent 56fc41fffa
commit 0d49027daa
50 changed files with 707 additions and 179 deletions
+4 -5
View File
@@ -34,6 +34,8 @@ import sys
from datetime import datetime, timedelta, timezone
from math import inf
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent / "tools"))
import main_files # noqa: E402
from app import arbitrage, packshare
from named_absence import first, nth, present
@@ -1132,8 +1134,7 @@ check("...and misfiling it ON THE SITE is caught and REFUSED, not consumed. A "
# main.py's own AST, the way test_peakguard.py part 12i pins the arguments of
# `arbitrage.decide()`, and for the same reason: a call site that stopped
# passing it is invisible to every fixture.
_main_src = (Path(__file__).resolve().parent / "app" / "main.py").read_text(
encoding="utf-8")
_main_src = main_files.source()
_resolve_calls = [n for n in ast.walk(ast.parse(_main_src))
if isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
and n.func.id == "resolve"]
@@ -1158,9 +1159,7 @@ check("⚠️ MAIN.PY ACTUALLY PASSES `weights=`, AND IT PASSES THE METHOD RATHE
# cycle's value, and logs. What it does NOT grade is the sentence it logs or
# that a real cycle reaches it; that is stated here rather than implied.
_cycle_src = first(
f for cls in ast.walk(ast.parse(
(Path(__file__).resolve().parent / "app" / "main.py")
.read_text(encoding="utf-8")))
f for cls in ast.walk(main_files.tree())
if isinstance(cls, ast.ClassDef) and cls.name == "Controller"
for f in cls.body
if isinstance(f, (ast.FunctionDef, ast.AsyncFunctionDef)) and f.name == "cycle")