refactor: move campaign budget, report to probes

parse_budget goes to probes.host beside Settings, and the line a pass prints, with the alert key autorun reads, to probes.reports.pass_report. campaign.py keeps its parser, main and the exit codes.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 14:59:02 +01:00
1 parent ccb78ef5d9
commit 22a81c384d
5 files changed
+32 -21

No files matched your search

+3 -17
View File
@@ -62,7 +62,6 @@ from __future__ import annotations
import argparse
import json
import re
import signal
import sys
from collections.abc import Sequence
@@ -86,20 +85,13 @@ from core.paths import REPO_ROOT
from probes.campaign import Campaign
from probes.content import ROMFETCH_ENV
from probes.gate import changed_profiles, gate
from probes.host import CONTENT_FILE, Paths, Settings, host_lock
from probes.reports import REVIEWED, open_findings, render_status, review_finding, status_report
from probes.host import CONTENT_FILE, Paths, Settings, host_lock, parse_budget
from probes.reports import REVIEWED, open_findings, pass_report, render_status, review_finding, status_report
EXIT_REFUSED = 3
def parse_budget(text: str) -> float:
match = re.fullmatch(r"\s*(\d+(?:\.\d+)?)\s*([smh]?)\s*", text or "")
if not match:
raise argparse.ArgumentTypeError(f"--budget {text!r}: a number with s, m or h")
return float(match[1]) * {"": 1, "s": 1, "m": 60, "h": 3600}[match[2]]
# --------------------------------------------------------------------------
# Command line
# --------------------------------------------------------------------------
@@ -248,13 +240,7 @@ def _run_pass(campaign: Campaign, args: argparse.Namespace, only: set[str], path
except hostguard.LockBusy as exc:
print(f"campaign: deferred, {exc}", file=sys.stderr)
return 75
counts, _, _ = campaign.counts()
report = {"result": current.result, "detail": current.detail, "counts": counts,
"records": len(current.records), "findings": current.findings}
if current.result == "refused":
# autorun raises an alert from this key of a job's report.
report["alert"] = current.detail
print(json.dumps(report))
print(json.dumps(pass_report(campaign, current)))
if current.result == "refused":
return EXIT_REFUSED
return 75 if current.result == "paused" else 0
+9
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import argparse
import contextlib
import http.client
import os
@@ -127,6 +128,14 @@ class Host:
return self.cpu_count / 4
def parse_budget(text: str) -> float:
"""Seconds of a --budget value: a number with s, m or h."""
match = re.fullmatch(r"\s*(\d+(?:\.\d+)?)\s*([smh]?)\s*", text or "")
if not match:
raise argparse.ArgumentTypeError(f"--budget {text!r}: a number with s, m or h")
return float(match[1]) * {"": 1, "s": 1, "m": 60, "h": 3600}[match[2]]
@dataclass
class Settings:
budget: float = 6 * 3600
+12 -1
View File
@@ -14,7 +14,7 @@ from probes.profileedit import write_fields
from probes.state import DONE, FAILED, PENDING
if TYPE_CHECKING:
from probes.campaign import Campaign
from probes.campaign import Campaign, Pass
# --------------------------------------------------------------------------
@@ -32,6 +32,17 @@ def status_report(campaign: Campaign) -> dict:
"failed": failed, "emulators": per}
def pass_report(campaign: Campaign, current: Pass) -> dict:
"""The line a pass prints: its result, the check counts, its records and findings."""
counts, _, _ = campaign.counts()
report = {"result": current.result, "detail": current.detail, "counts": counts,
"records": len(current.records), "findings": current.findings}
if current.result == "refused":
# autorun raises an alert from this key of a job's report.
report["alert"] = current.detail
return report
def render_status(report: dict) -> str:
lines = []
last = report["last_run"]