From fdb7b6f9122193a71fe44c4938f9097f5ef1ab8a Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:54:02 +0100 Subject: [PATCH] refactor: host lock and measurement records go low --- .github/workflows/deploy-site.yml | 2 +- scripts/autorun.py | 90 +++---------------- scripts/campaign.py | 23 ++--- scripts/core/childenv.py | 31 +++++++ scripts/core/hostguard.py | 51 +++++++++++ scripts/core/statefile.py | 19 ++++ scripts/core_probe.py | 10 +-- .../measurements.py} | 0 scripts/pack_probe.py | 4 +- scripts/region_check.py | 2 +- scripts/sitegen/measurements.py | 2 +- scripts/standalone_probe.py | 4 +- scripts/validate_schemas.py | 2 +- tests/test_autorun.py | 23 ++--- tests/test_campaign.py | 2 +- tests/test_core_probe.py | 2 +- tests/test_layers.py | 3 +- tests/test_measurements.py | 2 +- tests/test_pack_probe.py | 2 +- tests/test_region_check.py | 2 +- tests/test_site_reference.py | 2 +- 21 files changed, 160 insertions(+), 118 deletions(-) create mode 100644 scripts/core/childenv.py create mode 100644 scripts/core/hostguard.py create mode 100644 scripts/core/statefile.py rename scripts/{measurement_records.py => model/measurements.py} (100%) diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 318595fc9..4e02819eb 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -31,7 +31,6 @@ on: - "scripts/generate_readme.py" - "scripts/generate_site.py" - "scripts/indexnow.py" - - "scripts/measurement_records.py" - "scripts/model/__init__.py" - "scripts/model/alternatives.py" - "scripts/model/cliargs.py" @@ -42,6 +41,7 @@ on: - "scripts/model/dumpcatalog.py" - "scripts/model/guides.py" - "scripts/model/largefiles.py" + - "scripts/model/measurements.py" - "scripts/model/nodedup.py" - "scripts/model/platforms.py" - "scripts/model/profiles.py" diff --git a/scripts/autorun.py b/scripts/autorun.py index 573f62b20..f7e2aa7fa 100644 --- a/scripts/autorun.py +++ b/scripts/autorun.py @@ -44,16 +44,25 @@ import shutil import subprocess import sys import time -from collections.abc import Callable, Iterator, Sequence +from collections.abc import Callable, Sequence from dataclasses import dataclass, field from pathlib import Path +from core.childenv import is_secret, safe_env +from core.hostguard import ( + DEFAULT_LOCK, + LOCK_ENV, + LOCK_HELD_ENV, + LockBusy, + free_gb, + global_lock, + lock_busy, +) +from core.statefile import now_iso, save_state + REPO_ROOT = Path(__file__).resolve().parents[1] JOBS_FILE = REPO_ROOT / "automation" / "jobs.yml" AUTORUN_DIR = Path(".cache") / "autorun" -DEFAULT_LOCK = Path.home() / ".local" / "state" / "retrobios" / "auto.lock" -LOCK_ENV = "RETROBIOS_AUTO_LOCK" -LOCK_HELD_ENV = "RETROBIOS_AUTO_LOCK_HELD" BRANCH = "autorun" REMOTE = "origin" @@ -91,10 +100,6 @@ class AutorunError(RuntimeError): self.detail = detail -class LockBusy(RuntimeError): - """Another job holds the host-wide lock.""" - - @dataclass(frozen=True) class Step: argv: tuple[str, ...] @@ -312,35 +317,6 @@ def load_jobs(path: Path = JOBS_FILE) -> dict[str, Job]: # Host guards -@contextlib.contextmanager -def global_lock(path: Path) -> Iterator[None]: - """Hold the host-wide automation lock, or raise LockBusy at once.""" - import fcntl - - path.parent.mkdir(parents=True, exist_ok=True) - with path.open("a+", encoding="utf-8") as handle: - try: - fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB) - except OSError as exc: - raise LockBusy(f"{path} is held by another job") from exc - handle.seek(0) - handle.truncate() - handle.write(f"{os.getpid()}\n") - handle.flush() - try: - yield - finally: - fcntl.flock(handle, fcntl.LOCK_UN) - - -def lock_busy(path: Path) -> bool: - try: - with global_lock(path): - return False - except LockBusy: - return True - - def wait_for_load(host: Host, max_wait: float) -> bool: """True once the 1-minute load is at most a quarter of the CPUs.""" deadline = host.clock() + max_wait @@ -353,10 +329,6 @@ def wait_for_load(host: Host, max_wait: float) -> bool: host.sleep(min(host.poll, left)) -def free_gb(path: Path) -> float: - return shutil.disk_usage(path).free / 1024 ** 3 - - def host_misread(returncode: int, text: str) -> bool: """A failure this host's CPU produces under load, worth one idle retry.""" if returncode in SEGFAULT_CODES: @@ -707,10 +679,6 @@ def may_push(state: dict) -> str: # State and logs -def now_iso() -> str: - return dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat() - - def load_state(path: Path) -> dict: try: return json.loads(path.read_text(encoding="utf-8")) @@ -720,13 +688,6 @@ def load_state(path: Path) -> dict: raise AutorunError(FAILED, f"{path} is unreadable: {exc}") from exc -def save_state(path: Path, state: dict) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - scratch = path.with_suffix(".tmp") - scratch.write_text(json.dumps(state, indent=2, sort_keys=True) + "\n", encoding="utf-8") - os.replace(scratch, path) - - def prune_logs(logs: Path, days: int = LOG_DAYS, now: float | None = None) -> int: limit = (now if now is not None else time.time()) - days * 86400 removed = 0 @@ -748,31 +709,6 @@ def set_alert(state: dict, name: str, active: bool, detail: str, now: str) -> No # Running a job -# What a job step inherits. A step can run third-party code (a buildbot -# core, a scraped page, a downloaded tool), so it gets the variables a -# program needs to run and nothing it could leak: no token, no password. -SAFE_ENV = frozenset({"PATH", "HOME", "LANG", "TZ", "TMPDIR"}) -SECRET_NAMES = frozenset({"GITHUB_TOKEN", "GH_TOKEN", "ROMSTATION_USER", "ROMSTATION_PASS"}) -SECRET_MARKERS = ("TOKEN", "SECRET", "PASS") - - -def is_secret(name: str) -> bool: - upper = name.upper() - return name in SECRET_NAMES or any(marker in upper for marker in SECRET_MARKERS) - - -def safe_env(names: Sequence[str] = (), add: dict[str, str] | None = None, - source: dict[str, str] | None = None) -> dict[str, str]: - """The allowlisted environment, plus the variables a step names - explicitly. A secret is dropped even when named.""" - source = dict(os.environ) if source is None else source - wanted = set(names) - env = {key: value for key, value in source.items() - if (key in SAFE_ENV or key.startswith("LC_") or key in wanted) and not is_secret(key)} - env.update({key: value for key, value in (add or {}).items() if not is_secret(key)}) - return env - - def token_env() -> dict[str, str]: """The environment of the phases that need GitHub: the push and gh.""" sys.path.insert(0, str(REPO_ROOT / "scripts")) diff --git a/scripts/campaign.py b/scripts/campaign.py index 15b8f3db9..b259f073a 100644 --- a/scripts/campaign.py +++ b/scripts/campaign.py @@ -97,17 +97,20 @@ import core_probe import yaml import autorun +from core import childenv +from core import hostguard +from core import statefile import campaign_profiles import campaign_rules as rules -import measurement_records as mr -from autorun import now_iso +from model import measurements as mr +from core.statefile import now_iso from core.paths import REPO_ROOT T = TypeVar("T") CONTENT_FILE = REPO_ROOT / "tests" / "campaign" / "content.yml" BUILDBOT = "https://buildbot.libretro.com/nightly/linux/x86_64/latest/" -LOCK_HELD_ENV = autorun.LOCK_HELD_ENV +LOCK_HELD_ENV = hostguard.LOCK_HELD_ENV ROMFETCH_ENV = "RETROBIOS_ROMFETCH" STATE_VERSION = 1 @@ -256,7 +259,7 @@ class Host: sleep: Callable[[float], None] = time.sleep clock: Callable[[], float] = time.monotonic cpu_count: int = os.cpu_count() or 1 - free_gb: Callable[[Path], float] = autorun.free_gb + free_gb: Callable[[Path], float] = hostguard.free_gb poll: float = 60.0 run: Callable[..., subprocess.CompletedProcess] = run_group urlopen: Callable[..., http.client.HTTPResponse] = urllib.request.urlopen @@ -329,7 +332,7 @@ def child_env(romfetch: bool = False) -> dict[str, str]: names: list[str] = [core_probe.PROBE_LOCK_ENV, core_probe.PROBE_LOCK_HELD_ENV] if romfetch: names += [k for k in os.environ if k.startswith("ROMFETCH_")] + list(ROMFETCH_PASSED) - return autorun.safe_env(names) + return childenv.safe_env(names) # Host-side git on a third-party project. It only ever touches bare mirrors @@ -501,7 +504,7 @@ def host_lock(lock_path: Path) -> Iterator[None]: if os.environ.get(LOCK_HELD_ENV): yield return - with autorun.global_lock(lock_path): + with hostguard.global_lock(lock_path): yield @@ -521,7 +524,7 @@ def load_state(path: Path) -> dict: def save_state(path: Path, state: dict) -> None: - autorun.save_state(path, state) + statefile.save_state(path, state) def should_run(previous: dict | None, core_sha: str, digest: str, oracle_sha: str = "") -> bool: @@ -949,7 +952,7 @@ class Campaign: self.settings = settings or Settings() self.host = host or Host() self.probe_script = probe_script or REPO_ROOT / "scripts" / "core_probe.py" - self.lock_path = lock_path or Path(os.environ.get(autorun.LOCK_ENV) or autorun.DEFAULT_LOCK) + self.lock_path = lock_path or Path(os.environ.get(hostguard.LOCK_ENV) or hostguard.DEFAULT_LOCK) self.state = load_state(paths.state) self.cores = Cores(self) self.store = ContentStore(self) @@ -2048,7 +2051,7 @@ def _references(campaign: Campaign, args: argparse.Namespace, only: set[str]) -> try: with host_lock(campaign.lock_path): listed = campaign.references(only, args.system, Path(args.png_dir)) - except autorun.LockBusy as exc: + except hostguard.LockBusy as exc: print(f"campaign: deferred, {exc}", file=sys.stderr) return 75 print(json.dumps(listed, indent=2)) @@ -2094,7 +2097,7 @@ def _run_pass(campaign: Campaign, args: argparse.Namespace, only: set[str], path with host_lock(campaign.lock_path): current = campaign.run(only, args.system, commit_every=args.commit_every, commit=args.commit) - except autorun.LockBusy as exc: + except hostguard.LockBusy as exc: print(f"campaign: deferred, {exc}", file=sys.stderr) return 75 counts, _, _ = campaign.counts() diff --git a/scripts/core/childenv.py b/scripts/core/childenv.py new file mode 100644 index 000000000..595a146fb --- /dev/null +++ b/scripts/core/childenv.py @@ -0,0 +1,31 @@ +"""The environment a child process inherits: an allowlist, never a token or a password.""" + +from __future__ import annotations + +import os +from collections.abc import Sequence + + +# What a job step inherits. A step can run third-party code (a buildbot +# core, a scraped page, a downloaded tool), so it gets the variables a +# program needs to run and nothing it could leak: no token, no password. +SAFE_ENV = frozenset({"PATH", "HOME", "LANG", "TZ", "TMPDIR"}) +SECRET_NAMES = frozenset({"GITHUB_TOKEN", "GH_TOKEN", "ROMSTATION_USER", "ROMSTATION_PASS"}) +SECRET_MARKERS = ("TOKEN", "SECRET", "PASS") + + +def is_secret(name: str) -> bool: + upper = name.upper() + return name in SECRET_NAMES or any(marker in upper for marker in SECRET_MARKERS) + + +def safe_env(names: Sequence[str] = (), add: dict[str, str] | None = None, + source: dict[str, str] | None = None) -> dict[str, str]: + """The allowlisted environment, plus the variables a step names + explicitly. A secret is dropped even when named.""" + source = dict(os.environ) if source is None else source + wanted = set(names) + env = {key: value for key, value in source.items() + if (key in SAFE_ENV or key.startswith("LC_") or key in wanted) and not is_secret(key)} + env.update({key: value for key, value in (add or {}).items() if not is_secret(key)}) + return env diff --git a/scripts/core/hostguard.py b/scripts/core/hostguard.py new file mode 100644 index 000000000..8612f9e93 --- /dev/null +++ b/scripts/core/hostguard.py @@ -0,0 +1,51 @@ +"""Host-wide guards every heavy job shares: the automation lock and free disk space.""" + +from __future__ import annotations + +import contextlib +import os +import shutil +from collections.abc import Iterator +from pathlib import Path + + +DEFAULT_LOCK = Path.home() / ".local" / "state" / "retrobios" / "auto.lock" +LOCK_ENV = "RETROBIOS_AUTO_LOCK" +LOCK_HELD_ENV = "RETROBIOS_AUTO_LOCK_HELD" + + +class LockBusy(RuntimeError): + """Another job holds the host-wide lock.""" + + +@contextlib.contextmanager +def global_lock(path: Path) -> Iterator[None]: + """Hold the host-wide automation lock, or raise LockBusy at once.""" + import fcntl + + path.parent.mkdir(parents=True, exist_ok=True) + with path.open("a+", encoding="utf-8") as handle: + try: + fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB) + except OSError as exc: + raise LockBusy(f"{path} is held by another job") from exc + handle.seek(0) + handle.truncate() + handle.write(f"{os.getpid()}\n") + handle.flush() + try: + yield + finally: + fcntl.flock(handle, fcntl.LOCK_UN) + + +def lock_busy(path: Path) -> bool: + try: + with global_lock(path): + return False + except LockBusy: + return True + + +def free_gb(path: Path) -> float: + return shutil.disk_usage(path).free / 1024 ** 3 diff --git a/scripts/core/statefile.py b/scripts/core/statefile.py new file mode 100644 index 000000000..055b1d690 --- /dev/null +++ b/scripts/core/statefile.py @@ -0,0 +1,19 @@ +"""State files of unattended jobs: UTC timestamps and atomic JSON writes.""" + +from __future__ import annotations + +import datetime as dt +import json +import os +from pathlib import Path + + +def now_iso() -> str: + return dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat() + + +def save_state(path: Path, state: dict) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + scratch = path.with_suffix(".tmp") + scratch.write_text(json.dumps(state, indent=2, sort_keys=True) + "\n", encoding="utf-8") + os.replace(scratch, path) diff --git a/scripts/core_probe.py b/scripts/core_probe.py index c2764164c..1e826529d 100644 --- a/scripts/core_probe.py +++ b/scripts/core_probe.py @@ -1538,7 +1538,7 @@ def default_emulator(core_file: Path, library_name: str | None) -> str: def default_subject(record: dict) -> str: """A slug shared by the reruns of one test: a check by its claim and method, a run or bench by its inputs.""" - from measurement_records import canonical, sha256_hex, slugify + from model.measurements import canonical, sha256_hex, slugify check = record.get("check") if check: @@ -1554,7 +1554,7 @@ def default_subject(record: dict) -> str: def write_record(directory: Path, full: dict) -> tuple[Path, dict]: """Append the record, with its id, to its emulator's .jsonl. Returns the file and the record as written.""" - from measurement_records import line_text, parse_lines, records_path, seal + from model.measurements import line_text, parse_lines, records_path, seal sealed = seal(full) lines = directory / records_path(sealed["emulator"]) @@ -1599,7 +1599,7 @@ def _probe(args: argparse.Namespace) -> int: shutil.rmtree(work, ignore_errors=True) load_after = load_average() first = variants[0]["repetitions"][0] - from measurement_records import RECORD_VERSION + from model.measurements import RECORD_VERSION record: dict = { "record_version": RECORD_VERSION, @@ -1710,7 +1710,7 @@ def rejudged(record: dict, data: dict, identity: dict | None, now: str) -> dict def RECORD_VERSION_NOW() -> int: - from measurement_records import RECORD_VERSION + from model.measurements import RECORD_VERSION return RECORD_VERSION @@ -1718,7 +1718,7 @@ def RECORD_VERSION_NOW() -> int: def rejudge_records(args: argparse.Namespace) -> int: """Append, for each live record whose judgement the oracle now gives otherwise, the record judged again, superseding it.""" - from measurement_records import line_text, live, read_records, records_path, seal + from model.measurements import line_text, live, read_records, records_path, seal root = Path(args.record) data, identity = load_oracle(Path(args.oracle) if args.oracle else DEFAULT_ORACLE) diff --git a/scripts/measurement_records.py b/scripts/model/measurements.py similarity index 100% rename from scripts/measurement_records.py rename to scripts/model/measurements.py diff --git a/scripts/pack_probe.py b/scripts/pack_probe.py index 5837bb2d7..a5ce0b4bb 100644 --- a/scripts/pack_probe.py +++ b/scripts/pack_probe.py @@ -60,8 +60,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parent)) import autorun import campaign -import measurement_records as mr -from autorun import now_iso +from model import measurements as mr +from core.statefile import now_iso from model.systems import _norm_system_id from model.profiles import load_emulator_profiles from model.platforms import load_platform_config diff --git a/scripts/region_check.py b/scripts/region_check.py index 2ec018034..6d6e6b601 100644 --- a/scripts/region_check.py +++ b/scripts/region_check.py @@ -374,7 +374,7 @@ def collect(root: Path = REPO_ROOT, stored_records: list | None = None) -> list[ listed under several systems (sega-megacd and mega-cd) is judged under the one whose profile ran it.""" from model.profiles import load_emulator_profiles - from measurement_records import live, read_records + from model.measurements import live, read_records content: dict[str, list[tuple[str, dict]]] = {} for system, items in load_content(root / "tests" / "campaign" / "content.yml").items(): diff --git a/scripts/sitegen/measurements.py b/scripts/sitegen/measurements.py index 25dfb8a2d..ef76d7aee 100644 --- a/scripts/sitegen/measurements.py +++ b/scripts/sitegen/measurements.py @@ -31,7 +31,7 @@ import sys from dataclasses import dataclass from pathlib import Path -import measurement_records as mr +from model import measurements as mr from sitegen import markup from core.artifacts import json_text, write_if_changed from sitegen.render import _escape_tags diff --git a/scripts/standalone_probe.py b/scripts/standalone_probe.py index 782986164..6d6a643fe 100644 --- a/scripts/standalone_probe.py +++ b/scripts/standalone_probe.py @@ -48,7 +48,7 @@ from typing import IO sys.path.insert(0, str(Path(__file__).resolve().parent)) import core_probe as cp -from autorun import now_iso +from core.statefile import now_iso ROOT = Path(__file__).resolve().parent.parent CACHE = ROOT / ".cache" / "standalone" @@ -592,7 +592,7 @@ def _probe(args: argparse.Namespace, emu: Emulator) -> int: if args.mode == "check": record["check"] = {"claim": args.claim, "method": args.method, "observable": args.observable, "variable": args.vary[0][0], "result": check_result(variants, args.observable)} - from measurement_records import canonical, sha256_hex, slugify + from model.measurements import canonical, sha256_hex, slugify if args.subject: record["subject"] = args.subject diff --git a/scripts/validate_schemas.py b/scripts/validate_schemas.py index 1e194f339..3df92163a 100644 --- a/scripts/validate_schemas.py +++ b/scripts/validate_schemas.py @@ -844,7 +844,7 @@ def _format_errors() -> list[str]: def _measurement_errors(root: Path | None = None) -> list[str]: """Every record line under measurements/, against its schema and the rules measurement_records.read_records applies.""" - import measurement_records as mr + from model import measurements as mr root = root or ROOT validator = _validator("core-probe-record.schema.json") diff --git a/tests/test_autorun.py b/tests/test_autorun.py index 0bcedf8c5..9cd467bfe 100644 --- a/tests/test_autorun.py +++ b/tests/test_autorun.py @@ -24,6 +24,9 @@ from pathlib import Path from types import MappingProxyType import autorun as ar +from core import childenv +from core import hostguard +from core import statefile import bios_integrity as bib import cleanup_disk as cd import sync_release_assets as sra @@ -136,16 +139,16 @@ class Registry(Scratch): class Lock(Scratch): def test_a_second_holder_is_refused(self): path = self.tmp / "auto.lock" - with ar.global_lock(path): - self.assertTrue(ar.lock_busy(path)) - with self.assertRaises(ar.LockBusy), ar.global_lock(path): + with hostguard.global_lock(path): + self.assertTrue(hostguard.lock_busy(path)) + with self.assertRaises(hostguard.LockBusy), hostguard.global_lock(path): pass - self.assertFalse(ar.lock_busy(path)) + self.assertFalse(hostguard.lock_busy(path)) def test_a_job_waiting_on_the_lock_is_deferred_and_recorded(self): ctx = self.context({"x": {"worktree": False, "min_free_gb": 0, "steps": [[PY, "-c", "open('ran', 'w')"]]}}) - with ar.global_lock(ctx.lock_path): + with hostguard.global_lock(ctx.lock_path): result, detail = ar.run_job(ctx, "x") self.assertEqual(result, ar.DEFERRED) self.assertIn("held", detail) @@ -155,7 +158,7 @@ class Lock(Scratch): def test_a_job_that_takes_no_lock_runs_beside_a_holder(self): ctx = self.context({"x": {"worktree": False, "lock": False, "min_free_gb": 0, "steps": [[PY, "-c", "open('ran', 'w')"]]}}) - with ar.global_lock(ctx.lock_path): + with hostguard.global_lock(ctx.lock_path): self.assertEqual(ar.run_job(ctx, "x")[0], ar.OK) self.assertTrue((ctx.repo / "ran").exists()) @@ -208,7 +211,7 @@ class StepEnvironment(Scratch): "DB_PASSWORD": "p2", "ROMFETCH_CONTENT_DIR": "/c", "EDITOR": "vi"}) def test_the_allowlist(self): - env = ar.safe_env(["ROMFETCH_CONTENT_DIR", "GITHUB_TOKEN"], {"RETROBIOS_AUTO": "1"}, + env = childenv.safe_env(["ROMFETCH_CONTENT_DIR", "GITHUB_TOKEN"], {"RETROBIOS_AUTO": "1"}, source=dict(self.HOST)) self.assertEqual(env, {"PATH": "/usr/bin", "HOME": "/home/u", "LANG": "C.UTF-8", "LC_ALL": "C", "TZ": "UTC", "TMPDIR": "/t", @@ -232,7 +235,7 @@ class StepEnvironment(Scratch): seen = json.loads((ctx.repo / "env.json").read_text()) self.assertFalse({"GITHUB_TOKEN", "GH_TOKEN", "ROMSTATION_PASS", "EDITOR"} & set(seen)) self.assertEqual((seen["ROMFETCH_CONTENT_DIR"], seen["RETROBIOS_AUTO"]), ("/c", "1")) - self.assertEqual(seen[ar.LOCK_HELD_ENV], "1") + self.assertEqual(seen[hostguard.LOCK_HELD_ENV], "1") # The push and gh are the phases that get it. self.assertEqual(given["GITHUB_TOKEN"], "t1") @@ -393,7 +396,7 @@ class DoubleComputation(Scratch): "gate": [[PY, "gen.py", "db.json"]], "twice": [{"artifact": "db.json", "run": [PY, "gen.py", "{out}"]}], }}) - ar.save_state(ctx.state_path, {"alerts": {"host-integrity": {"since": "x"}}}) + statefile.save_state(ctx.state_path, {"alerts": {"host-integrity": {"since": "x"}}}) self.assertEqual(ar.run_job(ctx, "x")[0], ar.OK) self.assertNotIn("host-integrity", self.state(ctx).get("alerts", {})) @@ -453,7 +456,7 @@ class CircuitBreaker(Scratch): gh, _ = self._gh({"a" * 40: [ci_run("a" * 40, "failure", "t")]}, []) ctx = self.context({"x": {"min_free_gb": 0, "commits": [ {"subject": "chore: add a", "paths": ["a"]}]}}, gh=gh) - ar.save_state(ctx.state_path, {"push": {"sha": "a" * 40, "ci": "pending"}}) + statefile.save_state(ctx.state_path, {"push": {"sha": "a" * 40, "ci": "pending"}}) result, _ = ar.run_job(ctx, "x") self.assertEqual(result, ar.BLOCKED) self.assertFalse(ctx.worktree.exists()) diff --git a/tests/test_campaign.py b/tests/test_campaign.py index e7a0e6ebb..76f5de4b9 100644 --- a/tests/test_campaign.py +++ b/tests/test_campaign.py @@ -31,7 +31,7 @@ import yaml import campaign import campaign_profiles import campaign_rules as rules -import measurement_records as mr +from model import measurements as mr REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_core_probe.py b/tests/test_core_probe.py index 6ba91014f..1de56e6bc 100644 --- a/tests/test_core_probe.py +++ b/tests/test_core_probe.py @@ -26,7 +26,7 @@ from pathlib import Path from typing import ClassVar import core_probe -import measurement_records +from model import measurements as measurement_records REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_layers.py b/tests/test_layers.py index 52294577e..332b0a08f 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -42,7 +42,7 @@ SIBLING_IMPORTS: dict[str, frozenset[str]] = { NOT_YET_PACKAGED = frozenset({ "autorun", "build_port", "campaign", "campaign_profiles", "campaign_rules", "check_buildbot_system", "check_release_assets", "commit_rules", "core_probe", - "generate_event_schema", "measurement_records", "pin_installer", "pr_checks", + "generate_event_schema", "pin_installer", "pr_checks", "release_record", "romfolders", }) @@ -56,7 +56,6 @@ PENDING_TOP_LEVEL_IMPORTS = frozenset({ ("sitegen.getpages", "release_record"), ("sitegen.guidepage", "release_record"), ("sitegen.handheld", "build_port"), - ("sitegen.measurements", "measurement_records"), ("sitegen.platformindex", "release_record"), ("sitegen.publish", "release_record"), ("sitegen.readme", "pr_checks"), diff --git a/tests/test_measurements.py b/tests/test_measurements.py index 26ae73bdb..8b5bd4c1d 100644 --- a/tests/test_measurements.py +++ b/tests/test_measurements.py @@ -23,7 +23,7 @@ import tempfile import unittest from pathlib import Path -import measurement_records as mr +from model import measurements as mr from sitegen import measurements as sm REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_pack_probe.py b/tests/test_pack_probe.py index d59fa5fa5..e24e9eb74 100644 --- a/tests/test_pack_probe.py +++ b/tests/test_pack_probe.py @@ -23,7 +23,7 @@ import zipfile from pathlib import Path -import measurement_records as mr +from model import measurements as mr import pack_probe as pp REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_region_check.py b/tests/test_region_check.py index a26fa6340..43e0dea93 100644 --- a/tests/test_region_check.py +++ b/tests/test_region_check.py @@ -242,7 +242,7 @@ class SitePages(unittest.TestCase): def test_a_region_run_reaches_a_page_only_as_the_proof_of_a_field(self) -> None: """No page shows region outcomes. The Beetle PSX page names the runs its required: false rests on, each with the BIOS the core ran.""" - import measurement_records as mr + from model import measurements as mr from sitegen import measurements as sm stored = mr.read_records(ROOT) diff --git a/tests/test_site_reference.py b/tests/test_site_reference.py index 2b9412c02..b742c3935 100644 --- a/tests/test_site_reference.py +++ b/tests/test_site_reference.py @@ -1164,7 +1164,7 @@ class SourceLinksOnlyWhereTheFileIs(unittest.TestCase): def test_every_rendered_link_is_recorded(self): record = json.loads(sources.SOURCE_PATHS.read_text(encoding="utf-8")) pages = sorted(_built(DOCS / "emulators").rglob("*.md*")) + sorted(DOCS.glob("gaps*.md*")) - import measurement_records + from model import measurements as measurement_records # A Tested block links a record line and its data file in this # repository. The records are append-only, so a file a permalink