refactor: move pipeline steps into orchestrate

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 14:58:02 +01:00
1 parent 5be72484d8
commit 985d07b97e
38 files changed
+1838 -1661

No files matched your search

+6
View File
@@ -116,6 +116,12 @@ COMMANDS = {
"freshness/catalogs.py", "freshness/ci.py", "freshness/pinbuilds.py",
"freshness/profiles.py", "freshness/report.py",
),
"pipeline.py": (
"orchestrate/labels.py", "orchestrate/results.py", "orchestrate/runner.py",
"orchestrate/guards.py", "orchestrate/locks.py", "orchestrate/prepare.py",
"orchestrate/build.py", "orchestrate/checks.py", "orchestrate/docs.py",
"orchestrate/reports.py", "orchestrate/compare.py", "orchestrate/consistency.py",
"orchestrate/emulatorpacks.py", "orchestrate/narrowed.py", "orchestrate/splitcheck.py",
}
+3 -2
View File
@@ -26,6 +26,7 @@ from core.artifacts import (
publish_hold,
)
from tests.scratchtree import scratch_checkout
from tests.sources import script_source
from core import artifacts
from unittest import mock
@@ -359,7 +360,7 @@ class HeldLockTest(unittest.TestCase):
self.assertEqual(self._child_locks(dict(os.environ)).returncode, 0)
def test_the_pipeline_holds_its_output_for_the_run(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn("hold_artifact_lock(args.output_dir)", source)
@@ -369,7 +370,7 @@ class PipelineHoldsTheDataTrees(unittest.TestCase):
and the manifests, which then described two revisions of it."""
def test_the_trees_are_held_after_the_refresh_and_before_verify(self):
source = (Path(__file__).resolve().parents[1] / "scripts" / "pipeline.py").read_text()
source = script_source("pipeline.py")
refresh = source.index('"scripts/refresh_data_dirs.py"')
hold = source.index("hold_data_dirs(held,")
verify = source.index('"scripts/verify.py", "--all"')
+51 -54
View File
@@ -32,6 +32,7 @@ except ImportError:
import install
from packs import verdicts
from scripts import pipeline
from orchestrate import checks, consistency, reports, results, runner
from scripts.resolve import regionaudit, regions
from scripts.resolve.localfile import resolve_local_file
from scripts.core.ziptools import safe_extract_zip
@@ -1188,7 +1189,7 @@ class PipelineRegressions(unittest.TestCase):
def command(**flags) -> list[str]:
base = {"output_dir": "dist", "target": None, "all_variants": False}
return pipeline.integrity_command(argparse.Namespace(**{**base, **flags}))
return checks.integrity_command(argparse.Namespace(**{**base, **flags}))
self.assertIn("--all-variants", command(all_variants=True))
self.assertNotIn("--all-variants", command())
@@ -1201,12 +1202,12 @@ class PipelineRegressions(unittest.TestCase):
" 3 files packed (2 baseline + 1 from cores), 2/2 files OK",
]
)
self.assertEqual(pipeline.parse_pack_counts(output), {"RetroArch": (2, 2)})
self.assertEqual(reports.parse_pack_counts(output), {"RetroArch": (2, 2)})
def test_missing_pack_is_a_consistency_failure(self):
verify = "RetroArch: 2/2 OK"
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, ""))
self.assertFalse(consistency.check_consistency(verify, ""))
def test_display_name_matches_compact_registry_id(self):
verify = "MiSTer FPGA: 65/65 OK [md5]"
@@ -1218,7 +1219,7 @@ class PipelineRegressions(unittest.TestCase):
]
)
with contextlib.redirect_stdout(io.StringIO()):
self.assertTrue(pipeline.check_consistency(verify, pack))
self.assertTrue(consistency.check_consistency(verify, pack))
def test_the_cores_share_is_compared_too(self):
"""RomM passed this step while verify counted 412 core files and game
@@ -1234,9 +1235,9 @@ class PipelineRegressions(unittest.TestCase):
"383/383 files OK [md5]",
])
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, pack))
self.assertFalse(consistency.check_consistency(verify, pack))
agreed = verify.replace("61 in pack", "60 in pack").replace("351 in pack", "0 in pack")
self.assertTrue(pipeline.check_consistency(agreed, pack))
self.assertTrue(consistency.check_consistency(agreed, pack))
def test_an_exclusion_never_covers_a_file_verify_counts_ok(self):
"""An existence platform packs a file whose hash disagrees and a hash
@@ -1251,8 +1252,8 @@ class PipelineRegressions(unittest.TestCase):
]
)
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, pack))
self.assertEqual(pipeline.parse_pack_exclusions(pack), {"RetroArch": 1})
self.assertFalse(consistency.check_consistency(verify, pack))
self.assertEqual(reports.parse_pack_exclusions(pack), {"RetroArch": 1})
def test_unaccounted_pack_omission_is_a_consistency_failure(self):
verify = "RetroArch: 3/3 present [existence]"
@@ -1264,7 +1265,7 @@ class PipelineRegressions(unittest.TestCase):
]
)
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, pack))
self.assertFalse(consistency.check_consistency(verify, pack))
def test_a_pack_more_optimistic_than_verify_is_a_failure(self):
"""The invariant held one way only: a pack counting more OK files
@@ -1278,13 +1279,13 @@ class PipelineRegressions(unittest.TestCase):
]
)
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, pack))
self.assertFalse(consistency.check_consistency(verify, pack))
def test_nothing_parsed_is_not_consistent(self):
"""A changed output format must not pass with no platform compared."""
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency("RetroArch = 2/2 OK", ""))
self.assertFalse(pipeline.check_consistency("", ""))
self.assertFalse(consistency.check_consistency("RetroArch = 2/2 OK", ""))
self.assertFalse(consistency.check_consistency("", ""))
def test_pack_without_verify_result_is_a_failure(self):
verify = "RetroArch: 2/2 OK"
@@ -1297,7 +1298,7 @@ class PipelineRegressions(unittest.TestCase):
]
)
with contextlib.redirect_stdout(io.StringIO()):
self.assertFalse(pipeline.check_consistency(verify, pack))
self.assertFalse(consistency.check_consistency(verify, pack))
def test_only_the_full_variant_feeds_the_comparison(self):
"""--all-variants printed six packs under one label, and the last won."""
@@ -1307,7 +1308,7 @@ class PipelineRegressions(unittest.TestCase):
"Generating pack for RetroArch [source=platform, required]...",
" b.zip: 5 files packed (5 baseline + 0 from cores), 530/530 files OK",
])
self.assertEqual(pipeline.parse_pack_counts(output), {"RetroArch": (535, 535)})
self.assertEqual(reports.parse_pack_counts(output), {"RetroArch": (535, 535)})
def test_exclusions_read_only_the_full_variant(self):
"""--all-variants printed six packs under one label, and the last won."""
@@ -1317,10 +1318,10 @@ class PipelineRegressions(unittest.TestCase):
"Generating pack for Batocera [source=truth, required]...",
" b.zip: 2 files packed (0 baseline + 2 from cores), 2/2 files OK",
])
self.assertEqual(pipeline.parse_pack_exclusions(output), {"Batocera": 3})
self.assertEqual(reports.parse_pack_exclusions(output), {"Batocera": 3})
def test_slot_step_reaches_the_summary(self):
source = Path(pipeline.__file__).read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn('results["slots"] = ok', source)
def test_every_refresh_failure_reaches_pipeline_exit_status(self):
@@ -1336,7 +1337,7 @@ class PipelineRegressions(unittest.TestCase):
argv = ["pipeline.py", "--skip-packs", "--skip-docs"]
with (
mock.patch.object(sys, "argv", argv),
mock.patch.object(pipeline, "run", side_effect=fake_run),
mock.patch.object(runner, "run", side_effect=fake_run),
contextlib.redirect_stdout(io.StringIO()),
self.assertRaises(SystemExit) as raised,
):
@@ -1357,8 +1358,8 @@ class PipelineRegressions(unittest.TestCase):
# The originals the offline export patches are not cached in a
# checkout: the run would be refused before any step.
with mock.patch.object(sys, "argv", argv), mock.patch.object(
pipeline, "run", side_effect=fake_run
), mock.patch.object(pipeline, "_refuse_offline_export_without_originals"), \
runner, "run", side_effect=fake_run
), mock.patch.object(pipeline, "refuse_offline_export_without_originals"), \
contextlib.redirect_stdout(io.StringIO()), contextlib.suppress(SystemExit):
pipeline.main()
truth_runs = [c for c in commands if "scripts/generate_truth.py" in c]
@@ -2845,7 +2846,7 @@ class ReleaseAssetsMatchTheCollection(unittest.TestCase):
return True, ""
argv = ["pipeline.py", "--skip-packs", "--skip-docs", *flags]
with mock.patch.object(pipeline, "run", record), \
with mock.patch.object(runner, "run", record), \
mock.patch.object(sys, "argv", argv), \
contextlib.redirect_stdout(io.StringIO()) as out, \
self.assertRaises(SystemExit) as done:
@@ -2882,7 +2883,7 @@ class OneRefreshPerOnlineRun(unittest.TestCase):
# A scratch output directory: step 4 purges the ZIPs of the one it
# is given, and this run must never touch dist/.
with tempfile.TemporaryDirectory() as out, \
mock.patch.object(pipeline, "run", record), \
mock.patch.object(runner, "run", record), \
mock.patch.object(
sys, "argv", ["pipeline.py", "--skip-docs", "--output-dir", out]
), \
@@ -3086,14 +3087,12 @@ class PipelineReportsWhatItDid(unittest.TestCase):
"""
def test_a_skipped_step_is_not_reported_as_done(self):
import pipeline
self.assertTrue(bool(pipeline.SKIPPED), "a skip must not fail the run")
self.assertEqual(repr(pipeline.SKIPPED), "SKIPPED")
self.assertIsNot(pipeline.SKIPPED, True)
self.assertTrue(bool(results.SKIPPED), "a skip must not fail the run")
self.assertEqual(repr(results.SKIPPED), "SKIPPED")
self.assertIsNot(results.SKIPPED, True)
def test_every_skip_branch_uses_the_sentinel(self):
source = (ROOT / "scripts" / "pipeline.py").read_text()
source = script_source("pipeline.py")
stale = re.findall(r'results\["(\w+)"\] = True', source)
self.assertEqual(stale, [], f"steps still claiming OK when skipped: {stale}")
@@ -4047,7 +4046,7 @@ class PipelineStepsSpeakAsTheyGo(unittest.TestCase):
"print('two', file=sys.stderr, flush=True); print('three')")
echoed = io.StringIO()
with contextlib.redirect_stdout(echoed):
ok, output = pipeline.run([sys.executable, "-c", script], "probe")
ok, output = runner.run([sys.executable, "-c", script], "probe")
self.assertTrue(ok)
self.assertEqual(output, "one\ntwo\nthree\n")
text = echoed.getvalue()
@@ -4841,7 +4840,7 @@ class ThePipelineTableNamesEveryStep(unittest.TestCase):
def test_every_labelled_step_is_documented(self):
labels = set(re.findall(
r'"(\d[a-z]?\d?)(?:/8)? [a-z]', (ROOT / "scripts" / "pipeline.py").read_text()
r'"(\d[a-z]?\d?)(?:/8)? [a-z]', script_source("pipeline.py")
))
doc = (ROOT / "wiki" / "tools.md").read_text()
documented = set(re.findall(r"^\| (\d[a-z]?\d?)(?:/8)? \|", doc, re.MULTILINE))
@@ -5379,9 +5378,9 @@ class PipelineDocstringNamesThePrintedSteps(unittest.TestCase):
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
doc = ast.get_docstring(ast.parse(source))
listed = set(re.findall(r"^ (\d[a-z0-9]*)\s{2,}", doc, re.M))
import pipeline
from orchestrate.labels import STEP_LABELS, step_number
printed = {pipeline.step_number(key) for key in pipeline.STEP_LABELS}
printed = {step_number(key) for key in STEP_LABELS}
self.assertEqual(listed, printed)
@@ -6377,14 +6376,14 @@ class ThePipelineSummaryTimesEachStep(unittest.TestCase):
from unittest import mock
clock = iter([10.0, 12.5, 12.5, 20.0])
with mock.patch.object(pipeline.time, "monotonic", lambda: next(clock)):
results = pipeline.StepResults(pipeline.time.monotonic())
results["generate_db"] = True
results["refresh_data"] = pipeline.SKIPPED
results["verify"] = True
self.assertEqual(results.seconds, {"generate_db": 2.5, "refresh_data": 0.0, "verify": 7.5})
self.assertEqual(dict(results), {"generate_db": True, "refresh_data": pipeline.SKIPPED,
"verify": True})
with mock.patch.object(results.time, "monotonic", lambda: next(clock)):
outcomes = results.StepResults(results.time.monotonic())
outcomes["generate_db"] = True
outcomes["refresh_data"] = results.SKIPPED
outcomes["verify"] = True
self.assertEqual(outcomes.seconds, {"generate_db": 2.5, "refresh_data": 0.0, "verify": 7.5})
self.assertEqual(dict(outcomes), {"generate_db": True, "refresh_data": results.SKIPPED,
"verify": True})
class StrictFailsOnMissingOnly(unittest.TestCase):
@@ -7044,9 +7043,7 @@ class AStepThatCannotFailTheRunIsNotShownFailed(unittest.TestCase):
column by fourteen characters."""
def test_every_step_outside_all_ok_is_declared_non_blocking(self):
import pipeline
lines = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8").splitlines()
lines = script_source("pipeline.py").splitlines()
loose = set()
for number, line in enumerate(lines):
found = re.search(r'results\["(\w+)"\] = ok$', line.strip())
@@ -7055,14 +7052,14 @@ class AStepThatCannotFailTheRunIsNotShownFailed(unittest.TestCase):
after = " ".join(lines[number + 1:number + 4])
if "all_ok" not in after and "sys.exit" not in after:
loose.add(found.group(1))
self.assertEqual(loose, set(pipeline.NON_BLOCKING))
self.assertEqual(loose, set(results.NON_BLOCKING))
def test_the_total_sits_under_the_durations(self):
step = f" {'x':.<40} {'OK':<7}{1.0:>8.1f}s"
total = f" {'total':.<40} {'':<7}{12.5:>8.1f}s"
self.assertEqual(len(step), len(total))
self.assertIn("{'':<7}{total_elapsed:>8.1f}s",
(ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8"))
script_source("pipeline.py"))
class AHashConflictIsReportedOnce(unittest.TestCase):
@@ -7093,7 +7090,7 @@ class ThePipelineRunsTheSchemaCheckCIRuns(unittest.TestCase):
workflow = (ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
command = re.search(r"python (scripts/validate_schemas\.py[^\n]*)", workflow).group(1)
script, *flags = command.split()
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn(f'"{script}"', source)
for flag in flags:
self.assertIn(f'"{flag}"', source)
@@ -7102,7 +7099,7 @@ class ThePipelineRunsTheSchemaCheckCIRuns(unittest.TestCase):
"""The pipeline generated pages without rendering them: 20 pages with
duplicate ids passed it and failed the deploy."""
workflow = (ROOT / ".github" / "workflows" / "deploy-site.yml").read_text(encoding="utf-8")
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn("npm run build --prefix website", workflow)
self.assertIn('["npm", "run", "build", "--prefix", "website"]', source)
self.assertIn("scripts/validate_site.py", workflow)
@@ -7455,14 +7452,14 @@ class PipelineOutputDirIsTheOneItWrites(unittest.TestCase):
previous = os.getcwd()
self.addCleanup(os.chdir, previous)
os.chdir(ROOT / "scripts")
self.assertEqual(pipeline._output_dir(None), str(ROOT / "dist"))
self.assertEqual(pipeline._output_dir("out"), str(ROOT / "scripts" / "out"))
self.assertEqual(runner.pack_output_dir(None), str(ROOT / "dist"))
self.assertEqual(runner.pack_output_dir("out"), str(ROOT / "scripts" / "out"))
def test_main_resolves_it_before_the_lock(self):
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
body = source[source.index("def main("):]
self.assertLess(
body.index("args.output_dir = _output_dir(args.output_dir)"),
body.index("args.output_dir = pack_output_dir(args.output_dir)"),
body.index("hold_artifact_lock(args.output_dir)"),
)
@@ -7515,11 +7512,11 @@ class SkipPacksHelpSaysWhatRuns(unittest.TestCase):
self.assertNotIn("docs/", text)
def test_every_step_it_names_is_one_it_skips(self):
import pipeline
from orchestrate.labels import step_number
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
keys = re.findall(r'skip_notice\("(\w+)", "--skip-packs"\)', source)
skipped = {pipeline.step_number(key) for key in keys}
skipped = {step_number(key) for key in keys}
self.assertEqual(skipped, {"4", "4b", "4c", "6"})
@@ -7767,7 +7764,7 @@ class PipelineChildrenSkipNodeCompileCache(unittest.TestCase):
every child the pipeline starts carries NODE_DISABLE_COMPILE_CACHE."""
def test_the_run_helper_sets_it(self):
source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn('"NODE_DISABLE_COMPILE_CACHE": "1"', source)
+4 -4
View File
@@ -303,7 +303,7 @@ class ReleaseCommitCarriesTheManifests(unittest.TestCase):
release pipeline regenerates: v2026.10.10 added three by hand."""
def test_the_commit_step_adds_what_the_pipeline_rewrites(self):
pipeline = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
pipeline = script_source("pipeline.py")
self.assertIn('"--manifest"', pipeline)
block = _section(_page("release-process.md"), "Cutting a release")
add = next(line for line in block.splitlines() if line.startswith("git add "))
@@ -1174,7 +1174,7 @@ class ListsFollowTheCode(unittest.TestCase):
self.assertEqual({row[0].strip("`") for row in _table_rows(section)}, used)
def test_pipeline_steps(self):
from pipeline import STEP_LABELS
from orchestrate.labels import STEP_LABELS
section = _section(_page("adding-a-platform.md"), "Step 8: Validate the full pipeline")
listed = re.findall(r"^- (\d\w*) ", section, re.M)
@@ -1380,9 +1380,9 @@ class PipelineStepsMatchTheRun(unittest.TestCase):
@staticmethod
def labels() -> list[str]:
import pipeline
from orchestrate.labels import STEP_LABELS, step_number
return [pipeline.step_number(key) for key in pipeline.STEP_LABELS]
return [step_number(key) for key in STEP_LABELS]
@staticmethod
def cited(text: str) -> list[str]:
+4 -4
View File
@@ -1418,10 +1418,10 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase):
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
raise unittest.SkipTest("database.json is not built")
import pipeline
from orchestrate import compare
from model.profiles import load_emulator_profiles
cls.pipeline = pipeline
cls.compare = compare
cls.db = json.loads(db_path.read_text(encoding="utf-8"))
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
@@ -1460,11 +1460,11 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase):
)
self.assertEqual(report["systems"], [system_id])
credited = set(report["pack_destinations"])
trees = self.pipeline._tree_members(platform, str(REPO_ROOT / "platforms"))
trees = self.compare.tree_members(platform, str(REPO_ROOT / "platforms"))
members = self._packed(platform, chosen)
written = {
name for name, size in members.items()
if not self.pipeline._PACK_NOTES.search(name)
if not self.compare.PACK_NOTES.search(name)
and not (trees.get(name) == size and name not in credited)
}
self.assertTrue(written)
+3
View File
@@ -51,6 +51,9 @@ SIBLING_IMPORTS: dict[str, frozenset[str]] = {
# native export, the data directory refresh, the installer pins, the
# site's source trees and profile_sync's report.
"freshness": frozenset({"scraper", "exporter", "packs", "installer_build", "sitegen", "profiling"}),
# Step 5 builds the packs in memory, and the offline export refusal asks
# the exporters which ones patch a cached original.
"orchestrate": frozenset({"packs", "exporter"}),
}
# Top-level files that stay whole at their path although packages import them:
+27 -25
View File
@@ -24,6 +24,8 @@ from pathlib import Path
import yaml
from tests.sources import script_source
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -173,12 +175,12 @@ class EveryNarrowingIsCompared(unittest.TestCase):
def test_each_dimension_of_the_name_builder_is_accounted_for(self):
import inspect
import pipeline
from orchestrate import narrowed
from packs.naming import pack_narrowings
dimensions = set(inspect.signature(pack_narrowings).parameters)
compared = set(pipeline.NARROWINGS_COMPARED)
exempt = set(pipeline.NARROWINGS_NOT_COMPARED)
compared = set(narrowed.NARROWINGS_COMPARED)
exempt = set(narrowed.NARROWINGS_NOT_COMPARED)
self.assertFalse(compared & exempt)
self.assertEqual(dimensions, compared | exempt,
"compare the new narrowing in check_narrowed_packs, "
@@ -190,25 +192,25 @@ class EveryNarrowingIsCompared(unittest.TestCase):
it describes the platform packs only."""
import inspect
import pipeline
from orchestrate import emulatorpacks
from packs.naming import pack_narrowings
from packs.emulatorpack import generate_emulator_pack
taken = (set(inspect.signature(pack_narrowings).parameters)
& set(inspect.signature(generate_emulator_pack).parameters))
self.assertEqual(taken, set(pipeline.EMULATOR_NARROWINGS_COMPARED))
self.assertEqual(taken, set(emulatorpacks.EMULATOR_NARROWINGS_COMPARED))
profile = {"files": [{"name": "a.bin", "region": "japan"},
{"name": "b.bin", "region": ["north-america", "europe"]}]}
used = {key for _label, narrowing in pipeline.emulator_variants([profile], False)
used = {key for _label, narrowing in emulatorpacks.emulator_variants([profile], False)
for key in narrowing}
# standalone is the loop around the variants, both builds of each profile.
self.assertEqual(used, pipeline.EMULATOR_NARROWINGS_COMPARED - {"standalone"})
regions = [n["regions"] for _l, n in pipeline.emulator_variants([profile], True)
self.assertEqual(used, emulatorpacks.EMULATOR_NARROWINGS_COMPARED - {"standalone"})
regions = [n["regions"] for _l, n in emulatorpacks.emulator_variants([profile], True)
if "regions" in n]
self.assertEqual(len(regions), 3)
def test_the_variants_reach_every_compared_dimension(self):
import pipeline
from orchestrate import narrowed
from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
@@ -217,23 +219,23 @@ class EveryNarrowingIsCompared(unittest.TestCase):
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
for full in (False, True):
with self.subTest(full=full):
variants = pipeline.narrowed_variants(
variants = narrowed.narrowed_variants(
"retroarch", config, profiles, platforms, full,
)
used = {key for _label, narrowing in variants for key in narrowing}
self.assertEqual(used, pipeline.NARROWINGS_COMPARED | {"system_filter"})
self.assertEqual(used, narrowed.NARROWINGS_COMPARED | {"system_filter"})
systems = [n for _l, n in variants if "system_filter" in n]
self.assertEqual(len(systems), len(config["systems"]))
def test_the_sample_takes_both_ends_and_the_middle(self):
import pipeline
from orchestrate.narrowed import matrix_coverage
self.assertEqual(list(pipeline._matrix_coverage(False, 2)), [0, 1])
self.assertEqual(pipeline._matrix_coverage(False, 11), [0, 5, 10])
self.assertEqual(list(pipeline._matrix_coverage(True, 11)), list(range(11)))
self.assertEqual(list(matrix_coverage(False, 2)), [0, 1])
self.assertEqual(matrix_coverage(False, 11), [0, 5, 10])
self.assertEqual(list(matrix_coverage(True, 11)), list(range(11)))
def test_the_run_compares_them(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn("ok = check_narrowed_packs(", source)
@@ -241,7 +243,7 @@ class ThePipelineComparesPaths(unittest.TestCase):
"""Equal counts, other paths: the comparison fails and names both sides."""
def test_a_swap_at_equal_counts_fails(self):
import pipeline
from orchestrate.consistency import check_pack_destinations
root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, root, True)
@@ -260,7 +262,7 @@ class ThePipelineComparesPaths(unittest.TestCase):
os.chdir(REPO_ROOT)
try:
with mock_tree_members(), contextlib.redirect_stdout(io.StringIO()) as out:
ok = pipeline.check_pack_destinations(str(destinations), output)
ok = check_pack_destinations(str(destinations), output)
finally:
os.chdir(previous)
self.assertIs(ok, expected, out.getvalue())
@@ -269,7 +271,7 @@ class ThePipelineComparesPaths(unittest.TestCase):
self.assertIn("pack only 1: b.bin", out.getvalue())
def test_the_run_compares_every_emulator_pack(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn("ok = check_pack_destinations(destinations_file, pack_output) and ok", source)
self.assertIn("ok = check_emulator_packs(full=args.full_narrowings) and ok", source)
self.assertIn('"--destinations", destinations_file', source)
@@ -277,14 +279,14 @@ class ThePipelineComparesPaths(unittest.TestCase):
@contextlib.contextmanager
def mock_tree_members():
import pipeline
from orchestrate import compare
original = pipeline._tree_members
pipeline._tree_members = lambda *_args: {}
original = compare.tree_members
compare.tree_members = lambda *_args: {}
try:
yield
finally:
pipeline._tree_members = original
compare.tree_members = original
class EveryEmulatorPackMatchesItsReport(unittest.TestCase):
@@ -293,13 +295,13 @@ class EveryEmulatorPackMatchesItsReport(unittest.TestCase):
def test_the_paths_agree(self):
if not (REPO_ROOT / "database.json").is_file():
self.skipTest("database.json is not built")
import pipeline
from orchestrate.emulatorpacks import check_emulator_packs
previous = os.getcwd()
os.chdir(REPO_ROOT)
try:
with contextlib.redirect_stdout(io.StringIO()) as out:
ok = pipeline.check_emulator_packs()
ok = check_emulator_packs()
finally:
os.chdir(previous)
self.assertTrue(ok, out.getvalue())
+9 -7
View File
@@ -180,27 +180,29 @@ class APlatformWithoutAPackFailsNoCheck(unittest.TestCase):
)
def test_the_consistency_step_skips_a_setup_served_by_the_installer(self):
import pipeline
from orchestrate.consistency import check_consistency
from orchestrate.reports import release_pack_keys
with contextlib.redirect_stdout(io.StringIO()) as out:
self.assertTrue(pipeline.check_consistency(
self.VERIFY, self.PACK, pipeline.release_pack_keys(PLATFORMS)))
self.assertTrue(check_consistency(
self.VERIFY, self.PACK, release_pack_keys(PLATFORMS)))
self.assertIn("KNULLI: 5/5 (no release pack, served by the installer)", out.getvalue())
def test_a_released_platform_without_its_pack_still_fails(self):
import pipeline
from orchestrate.consistency import check_consistency
from orchestrate.reports import release_pack_keys
verify = self.VERIFY + "Batocera: 3/3 OK [md5]\n"
with contextlib.redirect_stdout(io.StringIO()) as out:
self.assertFalse(pipeline.check_consistency(
verify, self.PACK, pipeline.release_pack_keys(PLATFORMS)))
self.assertFalse(check_consistency(
verify, self.PACK, release_pack_keys(PLATFORMS)))
# The failing line says it fails: "(no separate pack)" read like
# the installer-only note above it.
self.assertIn("Batocera: MISSING pack: verify judged 3/3 but the build wrote no pack for it",
out.getvalue())
def test_the_pipeline_passes_the_release_platforms(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertIn("release_pack_keys()", source)
def test_verify_packs_sweeps_the_release_packs_only(self):
+1 -1
View File
@@ -124,7 +124,7 @@ class DiagramsMatchTheData(unittest.TestCase):
self.assertTrue(diagrams.minui_files().get(tag))
def test_the_pipeline_drawing_is_the_step_list(self):
from pipeline import STEP_LABELS
from orchestrate.labels import STEP_LABELS
numbers = [box.number for box in diagrams._pipeline_boxes()]
self.assertEqual(numbers, [label.split(" ", 1)[0] for label in STEP_LABELS.values()])
+2 -1
View File
@@ -17,6 +17,7 @@ from packs import slots as packs_slots
from resolve import collisions as resolve_collisions
from packs.slots import Claim, Conflict, arbitrate
from slots import format_decision
from tests.sources import script_source
def _db(entries: dict[str, dict]) -> dict:
@@ -942,7 +943,7 @@ class SlotsJudgeWhatVerifyJudged(unittest.TestCase):
the target does not ship."""
def test_the_pipeline_passes_the_target(self):
source = (Path(__file__).resolve().parents[1] / "scripts" / "pipeline.py").read_text()
source = script_source("pipeline.py")
step = source[source.index('slots_cmd = [sys.executable, "scripts/slots.py"]'):]
step = step[:step.index("3b slot arbitration")]
self.assertIn('slots_cmd.extend(["--target", args.target])', step)
+6 -5
View File
@@ -23,6 +23,7 @@ from model.profiles import load_emulator_profiles
from packs.archive import PackRecord
from packs.platformpack import generate_pack
from packs.platformpack import generate_split_packs
from tests.sources import script_source
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -206,9 +207,9 @@ class PipelineComparesTheSplitParts(unittest.TestCase):
RetroBat's 21 openmsx/openMSX twins passed every check."""
def setUp(self):
import pipeline
from orchestrate import splitcheck
self.pipeline = pipeline
self.splitcheck = splitcheck
def _record(self, sources: dict[str, str]) -> PackRecord:
record = PackRecord()
@@ -219,7 +220,7 @@ class PipelineComparesTheSplitParts(unittest.TestCase):
def test_equal_parts_report_nothing(self):
full = self._record({"a.bin": "x", "b.bin": "y"})
parts = {"A": self._record({"a.bin": "x"}), "B": self._record({"b.bin": "y"})}
self.assertEqual(self.pipeline.split_differences(full, parts, str.__eq__), [])
self.assertEqual(self.splitcheck.split_differences(full, parts, str.__eq__), [])
def test_each_difference_is_named(self):
full = self._record({"SGB1.sfc": "x", "kept.bin": "k", "lost.bin": "l"})
@@ -228,7 +229,7 @@ class PipelineComparesTheSplitParts(unittest.TestCase):
"Other": self._record({"SGB1.sfc/program.rom": "p"}),
}
self.assertEqual(
self.pipeline.split_differences(full, parts, str.__eq__),
self.splitcheck.split_differences(full, parts, str.__eq__),
[
"in a part, not in the full pack: SGB1.sfc/program.rom",
"in the full pack, in no part: lost.bin",
@@ -237,7 +238,7 @@ class PipelineComparesTheSplitParts(unittest.TestCase):
)
def test_step_five_runs_the_comparison(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text()
source = script_source("pipeline.py")
step = source[source.index("# Step 5: Consistency check"):source.index("# Step 6:")]
self.assertIn("check_split_packs(", step)
+2 -2
View File
@@ -29,7 +29,7 @@ from packs import archive
from packs import emulatorpack
from packs import md5pack
from tests.scratchtree import scratch_checkout, snapshot
from tests.sources import declared_options
from tests.sources import declared_options, script_source
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -539,7 +539,7 @@ class StrictVerifyFailsOnACriticalMiss(unittest.TestCase):
self.assertIn("1 required file(s) missing", strict.stderr)
def test_the_pipeline_asks_for_it(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text()
source = script_source("pipeline.py")
self.assertIn('"scripts/verify.py", "--all", "--strict"', source)
+2 -2
View File
@@ -161,7 +161,7 @@ class OneTruthModelPerTarget(unittest.TestCase):
with self.subTest(module=module):
self.assertIn("truth_target_dir(", source)
self.assertNotIn('re.sub(\n r"[^a-z0-9]+"', source)
pipeline = (REPO_ROOT / "scripts" / "pipeline.py").read_text()
pipeline = script_source("pipeline.py")
self.assertIn('diff_cmd.extend(["--target", args.target])', pipeline)
@@ -224,7 +224,7 @@ class PublishedListsAreNotNarrowed(unittest.TestCase):
file list with the Switch one and check_release asked for it as an asset."""
def test_pipeline_writes_install_unfiltered(self):
pipeline = (REPO_ROOT / "scripts" / "pipeline.py").read_text()
pipeline = script_source("pipeline.py")
self.assertNotIn('manifest_cmd.extend(["--target"', pipeline)
def test_every_install_list_is_a_whole_platform(self):
+23 -21
View File
@@ -22,11 +22,13 @@ from model.registry import list_registered_platforms
from model.targets import load_target_config, build_target_cores_cache
import diff_truth
import pipeline
from orchestrate import guards, labels, prepare, runner
from resolve import truth
import verify
from packs import coverage
from packs import report as packs_report
from packs import verdicts
from tests.sources import script_source
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -377,15 +379,15 @@ class AnOfflineRunWithNoCacheStopsFirst(unittest.TestCase):
f"data_directories:\n a:\n local_cache: {cache}\n"
)
parser = mock.Mock()
pipeline._refuse_offline_without_caches(parser, self._args(), tmp)
guards.refuse_offline_without_caches(parser, self._args(), tmp)
self.assertIn("refresh_data_dirs.py", parser.error.call_args.args[0])
for args in (self._args(offline=False), self._args(skip_packs=True)):
parser = mock.Mock()
pipeline._refuse_offline_without_caches(parser, args, tmp)
guards.refuse_offline_without_caches(parser, args, tmp)
parser.error.assert_not_called()
cache.mkdir()
parser = mock.Mock()
pipeline._refuse_offline_without_caches(parser, self._args(), tmp)
guards.refuse_offline_without_caches(parser, self._args(), tmp)
parser.error.assert_not_called()
@@ -407,19 +409,19 @@ class AnOfflineExportWithNoOriginalsStopsFirst(unittest.TestCase):
self.assertIn("batocera", patched)
with tempfile.TemporaryDirectory() as tmp:
parser = mock.Mock()
pipeline._refuse_offline_export_without_originals(parser, self._args(), tmp)
guards.refuse_offline_export_without_originals(parser, self._args(), tmp)
message = parser.error.call_args.args[0]
self.assertIn("export_native.py --all --refresh-cache", message)
self.assertIn("batocera", message)
for args in (self._args(offline=False), self._args(with_export=False)):
parser = mock.Mock()
pipeline._refuse_offline_export_without_originals(parser, args, tmp)
guards.refuse_offline_export_without_originals(parser, args, tmp)
parser.error.assert_not_called()
for name in patched:
(Path(tmp) / name).mkdir()
(Path(tmp) / name / "original").write_text("x")
parser = mock.Mock()
pipeline._refuse_offline_export_without_originals(parser, self._args(), tmp)
guards.refuse_offline_export_without_originals(parser, self._args(), tmp)
parser.error.assert_not_called()
def test_the_tools_page_says_so(self):
@@ -443,7 +445,7 @@ class ThePipelineFlagTableSaysEveryRefusal(unittest.TestCase):
for flag, value in flags.items():
setattr(args, flag.lstrip("-").replace("-", "_"), value)
parser = mock.Mock()
pipeline._refuse_unapplied_flags(parser, args)
guards.refuse_unapplied_flags(parser, args)
return parser.error.called
def test_each_refused_pair_is_in_the_row_of_a_flag(self):
@@ -696,7 +698,7 @@ class ThePipelineRefreshesTheCommittedExport(unittest.TestCase):
def test_the_export_step_writes_the_default_directory(self):
import ast
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
for node in ast.walk(ast.parse(source)):
if (isinstance(node, ast.Assign)
and any(getattr(t, "id", "") == "export_cmd" for t in node.targets)):
@@ -714,16 +716,16 @@ class ThePipelineCountsItsRealSteps(unittest.TestCase):
def test_every_recorded_step_has_a_label(self):
import re
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
keys = set(re.findall(r'results\["(\w+)"\] =', source))
self.assertEqual(keys - set(pipeline.STEP_LABELS), set())
self.assertEqual(keys - set(labels.STEP_LABELS), set())
def test_a_label_written_out_is_one_of_the_list(self):
import re
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
written = re.findall(r'run\([^()]*?, "([^"]+)"\)', source)
numbers = {label.split(" ", 1)[0] for label in pipeline.STEP_LABELS.values()}
numbers = {label.split(" ", 1)[0] for label in labels.STEP_LABELS.values()}
for label in written:
with self.subTest(label=label):
# A step's own label, or a second command of a listed step.
@@ -734,25 +736,25 @@ class ThePipelineCountsItsRealSteps(unittest.TestCase):
computed "5 consistency check [20/24]"."""
import re
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8")
source = script_source("pipeline.py")
self.assertEqual(re.findall(r'"[^"\n]*---[^"\n]*\b\d+[a-z]?/\d+\b[^"\n]*"', source), [])
def test_progress_comes_from_the_list(self):
total = len(pipeline.STEP_LABELS)
title = pipeline.step_title(pipeline.STEP_LABELS["render_site"])
total = len(labels.STEP_LABELS)
title = labels.step_title(labels.STEP_LABELS["render_site"])
self.assertEqual(title, f"8b render site [{total}/{total}]")
self.assertNotIn("/8", pipeline.step_title(pipeline.STEP_LABELS["verify"]))
self.assertNotIn("/8", labels.step_title(labels.STEP_LABELS["verify"]))
def test_a_skipped_schema_check_says_how_to_run_it(self):
"""Step 0 said only "jsonschema not installed", then the run read
COMPLETE and the schema failed in PR validation."""
argv = ["pipeline.py", "--offline", "--skip-packs", "--skip-docs"]
out = io.StringIO()
real_find_spec = pipeline.importlib.util.find_spec
real_find_spec = prepare.importlib.util.find_spec
with mock.patch.object(sys, "argv", argv), mock.patch.object(
pipeline, "run", return_value=(True, "")
runner, "run", return_value=(True, "")
), mock.patch.object(
pipeline.importlib.util, "find_spec",
prepare.importlib.util, "find_spec",
side_effect=lambda name, *a: None if name == "jsonschema"
else real_find_spec(name, *a),
), contextlib.redirect_stdout(out), contextlib.suppress(SystemExit):
@@ -769,7 +771,7 @@ class ThePipelineCountsItsRealSteps(unittest.TestCase):
"--skip-docs"]
out = io.StringIO()
with mock.patch.object(sys, "argv", argv), mock.patch.object(
pipeline, "run", return_value=(True, "RetroArch: 1/1 OK\n")
runner, "run", return_value=(True, "RetroArch: 1/1 OK\n")
), contextlib.redirect_stdout(out), contextlib.suppress(SystemExit):
pipeline.main()
summary = out.getvalue().split("=" * 60)[1]
@@ -777,7 +779,7 @@ class ThePipelineCountsItsRealSteps(unittest.TestCase):
# The number the run printed for the step leads its summary row.
self.assertIn("4d bundled_only", summary)
self.assertTrue(
pipeline.step_title(pipeline.STEP_LABELS["bundled_only"]).startswith("4d ")
labels.step_title(labels.STEP_LABELS["bundled_only"]).startswith("4d ")
)
+3 -2
View File
@@ -24,6 +24,7 @@ from unittest import mock
import yaml
from model.platforms import _platform_config_cache
from tests.sources import script_source
from model.profiles import emulator_profiles_cache
import generate_db
from packs import archive
@@ -245,8 +246,8 @@ class OfflinePipelineVerifiesOffline(unittest.TestCase):
step has to count them the same way, or step 5 compares two answers."""
def test_verify_step_gets_offline(self):
source = (REPO_ROOT / "scripts" / "pipeline.py").read_text()
block = source[source.index("verify_cmd = ["):source.index("ok, verify_output = run(")]
source = script_source("pipeline.py")
block = source[source.index("verify_cmd = ["):source.index("ok, verify_output = runner.run(")]
self.assertIn('verify_cmd.append("--offline")', block)