From 3584b7a60fd4efadd9c16363a9cdaa043294fe7c Mon Sep 17 00:00:00 2001 From: Ruslan Strazhnyk Date: Sun, 22 Nov 2026 11:11:04 +0100 Subject: [PATCH] Add opt-in pytest CI selection adapter --- README.md | 53 ++++++- adapter/pytest_ci.py | 222 +++++++++++++++++++++++++++++ adapter/requirements-dev.txt | 1 + adapter/test_pytest_ci.py | 204 ++++++++++++++++++++++++++ examples/ci_demo/campaign.json | 35 +++++ examples/ci_demo/failure_source.py | 9 ++ examples/ci_demo/landing.html | 2 + examples/ci_demo/scope.json | 7 + examples/ci_demo/test_landing.py | 21 +++ examples/ci_demo/test_worker.py | 19 +++ examples/ci_demo/worker.py | 15 ++ 11 files changed, 587 insertions(+), 1 deletion(-) create mode 100644 adapter/pytest_ci.py create mode 100644 adapter/test_pytest_ci.py create mode 100644 examples/ci_demo/campaign.json create mode 100644 examples/ci_demo/failure_source.py create mode 100644 examples/ci_demo/landing.html create mode 100644 examples/ci_demo/scope.json create mode 100644 examples/ci_demo/test_landing.py create mode 100644 examples/ci_demo/test_worker.py create mode 100644 examples/ci_demo/worker.py diff --git a/README.md b/README.md index 734bc6a..8102114 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ failing-test identities, and per-phase outcomes. Exit 0 requires agreement and a passing full run. A report that finds no missed failures with `complete: false` is inconclusive. Historical observations do not prove new paths, reflection, thread attribution, native code, or cross-test effects safe. Receipts are trusted -local JSON, not signed attestations. **There is no CI-skipping switch.** +local JSON, not signed attestations. Shadow runs always retain the full comparison. `report.json` records planning time, subprocess wall time and child CPU time. Selected total includes planning; source copying and build time are excluded. @@ -219,6 +219,57 @@ additional performance baseline. Child CPU excludes snapshot/planning CPU. Single samples are not a speedup claim. Shadow mode itself costs more because it runs both selections. Peak memory, provider cost and CI billing are not measured. +## Opt-in pytest CI selection + +`adapter/pytest_ci.py` applies a trusted Panthera plan in ordinary pytest and +pytest-xdist jobs. Enable it for a reviewed content file whose tests have been +qualified in the application repository. The application CI owns the baseline, +plan generation, path allowlist, and schedule for full comparisons. + +Run from the application's Git root with the same pytest configuration, +arguments, interpreter, and dependencies used by the green baseline. Use an +external artifact directory and the `--option=value` form to keep artifact paths +out of pytest's root directory inference: + +```sh +PYTHONPATH="/path/to/panthera/adapter${PYTHONPATH:+:$PYTHONPATH}" \ + python -m pytest -p pytest_ci \ + --panthera-plan=/ci-artifacts/panthera-plan.json \ + --panthera-select-path=static/landing.html \ + --panthera-receipt=/ci-artifacts/panthera-execution.json +``` + +CI wraps the engine's `selected` and `expand` fields in a JSON object with +`schema: 1`, `head_commit` and `baseline_commit` as full 40-character Git SHAs, +and `baseline_tests` as the exact node ID inventory of its verified green, +complete full run. Include `planning_seconds` if measured. Keep the plan in a +trusted CI artifact and verify the profiling context when generating it. + +The plugin preserves ordinary pytest collection and applies the subset only +when the checkout is clean, the tree diff from the ancestor baseline is a +single content edit to the allowed tracked file, and the collected inventory +matches the baseline. Missing, invalid, stale, expanded, and out-of-scope plans +fall back to the original pytest invocation. An empty or full-size selection +also falls back. Keep application-level full audit runs active. + +The execution receipt reports selected or full mode, the fallback reason, +counts of collected, scheduled, attempted, and failed tests, +pytest's exit code, validation time, pytest wall time, and supplied planning +time. Collection failures can produce an incomplete receipt. A job supplying +only `--panthera-receipt` records an ordinary full comparison. Use fresh jobs +with the same inputs and account for planning and baseline maintenance when +measuring CI savings. + +The [bundled CI demo](examples/ci_demo) exercises attribution of a landing HTML +read in a function-scoped fixture alongside a session-scoped autouse fixture. +Its campaign also seeds two faults that would allow an earlier transient error +to mask a later permanent error, one in the worker and one in its dependency: + +```sh +target/release/panthera qualify . examples/ci_demo/scope.json \ + examples/ci_demo/campaign.json artifacts/ci-demo --python .venv/bin/python +``` + ## Fault qualification campaigns `qualify` profiles a green baseline once, applies one declared mutation per trial, diff --git a/adapter/pytest_ci.py b/adapter/pytest_ci.py new file mode 100644 index 0000000..90f25e7 --- /dev/null +++ b/adapter/pytest_ci.py @@ -0,0 +1,222 @@ +"""Apply a CI-produced Panthera plan to one explicitly allowed content edit.""" + +import json +import math +import os +import re +import subprocess +import time +from pathlib import Path + +import pytest + +MAX_PLAN_BYTES = 16 * 1024 * 1024 +GIT_TIMEOUT = 10 + + +def pytest_addoption(parser): + group = parser.getgroup("panthera") + group.addoption("--panthera-plan", type=Path, help="Trusted Panthera CI plan JSON") + group.addoption("--panthera-select-path", help="Allow selection for a content edit to this Git-root-relative path") + group.addoption("--panthera-receipt", type=Path, help="Write a Panthera CI execution receipt") + + +def read_plan(path): + with path.open("rb") as stream: + data = stream.read(MAX_PLAN_BYTES + 1) + if len(data) > MAX_PLAN_BYTES: + raise ValueError("plan exceeds size limit") + plan = json.loads(data) + if ( + type(plan["schema"]) is not int + or plan["schema"] != 1 + or type(plan["expand"]) is not bool + or not all(re.fullmatch(r"[0-9a-f]{40}", plan[key]) for key in ("head_commit", "baseline_commit")) + ): + raise ValueError("unsupported plan") + planning_seconds = plan.get("planning_seconds") + if planning_seconds is not None and ( + type(planning_seconds) not in (float, int) or not math.isfinite(planning_seconds) or planning_seconds < 0 + ): + raise ValueError("invalid planning time") + if plan["expand"]: + return plan, "expanded_plan" + for key in ("baseline_tests", "selected"): + nodes = plan[key] + if ( + not isinstance(nodes, list) + or not all(isinstance(node, str) and node for node in nodes) + or len(set(nodes)) != len(nodes) + ): + raise ValueError("invalid test inventory") + if not plan["selected"] or not set(plan["selected"]) < set(plan["baseline_tests"]): + return plan, "selection_not_smaller" + return plan, None + + +def checkout_fallback(path, plan, cwd): + def git(*args): + return subprocess.check_output(["git", *args], cwd=cwd, stderr=subprocess.DEVNULL, timeout=GIT_TIMEOUT) + + if git("rev-parse", "HEAD").strip().decode("ascii") != plan["head_commit"]: + return "stale_plan" + if git("status", "--porcelain=v1", "-z", "--untracked-files=normal", "--ignore-submodules=none"): + return "dirty_checkout" + baseline = plan["baseline_commit"] + try: + git("merge-base", "--is-ancestor", baseline, plan["head_commit"]) + except subprocess.CalledProcessError: + return "baseline_not_ancestor" + changes = git( + "diff", "--raw", "-z", "--no-renames", "--no-ext-diff", "--no-relative", baseline, plan["head_commit"], "--" + ) + metadata, _, paths = changes.partition(b"\0") + fields = metadata.split() + if fields[:2] != [b":100644", b"100644"] or fields[-1:] != [b"M"] or paths != os.fsencode(path) + b"\0": + return "change_out_of_scope" + return None + + +def validate_plan(config): + path = config.getoption("panthera_select_path") + plan_path = config.getoption("panthera_plan") + if not path: + return None, "selection_disabled" + if config.option.collectonly: + return None, "collect_only" + if not plan_path: + return None, "missing_plan" + try: + plan, reason = read_plan(plan_path) + except FileNotFoundError: + return None, "missing_plan" + except (OSError, ValueError, TypeError, KeyError, OverflowError, RecursionError): + return None, "invalid_plan" + if reason is None: + try: + reason = checkout_fallback(path, plan, config.invocation_params.dir) + except (OSError, subprocess.SubprocessError): + reason = "git_unavailable" + return plan, reason + + +class Selection: + def __init__(self, plan, reason): + self.reason = reason + self.known = set(plan["baseline_tests"]) if reason is None else set() + self.selected = set(plan["selected"]) if reason is None else set() + self.collection = None + + @pytest.hookimpl(hookwrapper=True, tryfirst=True) + def pytest_collection_modifyitems(self, session, config, items): + outcome = yield + self.collection = {"count": len(items), "reason": self.reason} + if self.reason is None: + if outcome.excinfo or session.testsfailed: + self.collection["reason"] = "collection_failed" + elif len(items) != len(self.known) or {item.nodeid for item in items} != self.known: + self.collection["reason"] = "inventory_changed" + else: + deselected = [item for item in items if item.nodeid not in self.selected] + items[:] = [item for item in items if item.nodeid in self.selected] + config.hook.pytest_deselected(items=deselected) + self.collection["scheduled"] = len(items) + + +class ExecutionReceipt: + def __init__(self, selection, plan, reason, path, validation_seconds): + self.selection = selection + self.plan = plan + self.reason = reason + self.path = path + self.validation_seconds = validation_seconds + self.started = time.perf_counter() + self.executed = set() + self.failed = set() + self.workers = [] + self.worker_collection = None + self.inconsistent_workers = False + self.collection_failed = False + + @pytest.hookimpl(optionalhook=True) + def pytest_configure_node(self, node): + inventory = None + if self.reason is None: + inventory = {key: self.plan[key] for key in ("baseline_tests", "selected")} + node.workerinput["panthera"] = (inventory, self.reason) + + @pytest.hookimpl(optionalhook=True) + def pytest_xdist_node_collection_finished(self, node, ids): + if self.worker_collection is None: + self.worker_collection = ids + elif ids != self.worker_collection: + self.inconsistent_workers = True + + @pytest.hookimpl(optionalhook=True) + def pytest_testnodedown(self, node, error): + self.workers.append(getattr(node, "workeroutput", {}).get("panthera_collection")) + + def pytest_collectreport(self, report): + self.collection_failed |= report.failed + + def pytest_runtest_logreport(self, report): + self.executed.add(report.nodeid) + if report.failed: + self.failed.add(report.nodeid) + + def pytest_sessionfinish(self, session, exitstatus): + collection = self.selection.collection + reason = self.reason + mode = "full" + if self.workers: + collection = self.workers[0] + if self.inconsistent_workers or any(row != collection for row in self.workers): + collection, reason, mode = None, "inconsistent_workers", "incomplete" + if self.collection_failed: + reason, mode = "collection_failed", "incomplete" + elif collection is not None: + reason = collection["reason"] + mode = "selected" if reason is None else "full" + elif mode == "full" and (reason is None or self.workers): + reason, mode = "collection_incomplete", "incomplete" + receipt = { + "schema": 1, + "mode": mode, + "fallback_reason": reason, + "tests_collected": collection["count"] if collection is not None else None, + "tests_scheduled": collection["scheduled"] if collection is not None else None, + "tests_executed": len(self.executed), + "failed_tests": len(self.failed), + "pytest_exit_code": int(exitstatus), + "planning_seconds": self.plan.get("planning_seconds") if self.plan is not None else None, + "validation_seconds": self.validation_seconds, + "pytest_wall_seconds": time.perf_counter() - self.started, + } + try: + self.path.write_text(json.dumps(receipt, indent=2) + "\n") + except OSError: + reporter = session.config.pluginmanager.get_plugin("terminalreporter") + if reporter is not None: + reporter.write_line("Panthera could not write the CI receipt.") + + +class WorkerSelection(Selection): + def pytest_sessionfinish(self, session): + session.config.workeroutput["panthera_collection"] = self.collection + + +def pytest_configure(config): + if hasattr(config, "workerinput"): + if "panthera" in config.workerinput: + config.pluginmanager.register(WorkerSelection(*config.workerinput["panthera"])) + return + receipt = config.getoption("panthera_receipt") + if receipt is None: + if config.getoption("panthera_select_path") or config.getoption("panthera_plan"): + raise pytest.UsageError("Panthera selection requires --panthera-receipt") + return + start = time.perf_counter() + plan, reason = validate_plan(config) + selection = Selection(plan, reason) + config.pluginmanager.register(selection) + config.pluginmanager.register(ExecutionReceipt(selection, plan, reason, receipt, time.perf_counter() - start)) diff --git a/adapter/requirements-dev.txt b/adapter/requirements-dev.txt index 25af0a1..7779bd5 100644 --- a/adapter/requirements-dev.txt +++ b/adapter/requirements-dev.txt @@ -1,3 +1,4 @@ pytest==8.3.5 pytest-asyncio==0.24.0 +pytest-xdist==3.8.0 ruff==0.15.0 diff --git a/adapter/test_pytest_ci.py b/adapter/test_pytest_ci.py new file mode 100644 index 0000000..e3b14e7 --- /dev/null +++ b/adapter/test_pytest_ci.py @@ -0,0 +1,204 @@ +"""Apply real engine plans to a disposable checkout with ordinary pytest collection.""" + +import json +import os +import shutil +import subprocess +import sys +import time +import unittest +import xml.etree.ElementTree as ET +from pathlib import Path +from tempfile import TemporaryDirectory + +import qualify +import shadow + +ROOT = Path(__file__).resolve().parents[1] +ENGINE = ROOT / "target/debug/panthera" +EXAMPLE = ROOT / "examples/ci_demo" + + +class PytestCITests(unittest.TestCase): + def setUp(self): + self.temp = Path(self.enterContext(TemporaryDirectory())).resolve() + self.root = self.temp / "checkout" + shutil.copytree(EXAMPLE, self.root, ignore=shutil.ignore_patterns("__pycache__")) + self.plan_path = self.temp / "plan.json" + self.git("init", "-q") + self.git("add", ".") + self.baseline_commit = self.commit("baseline") + self.scope = { + "targets": ["failure_source.py", "worker.py"], + "suites": ["test_landing.py", "test_worker.py"], + "resources": ["landing.html"], + "input_tracking": "files", + "fixture_tracking": "consumers", + } + shadow.configure(self.scope) + + def git(self, *args): + return subprocess.check_output( + [ + "git", + "-c", + "user.name=Panthera", + "-c", + "user.email=test@example.test", + "-c", + "commit.gpgsign=false", + *args, + ], + cwd=self.root, + text=True, + ).strip() + + def commit(self, message): + self.git("commit", "-qm", message) + return self.git("rev-parse", "HEAD") + + def plan_landing_fault(self): + baseline = shadow.snapshot(self.root, ENGINE) + profile = shadow.run_tests(self.root, self.temp / "profile.json") + qualify.validate_run(profile) + self.assertEqual(profile["exit_code"], 0) + baseline["tests"] = { + node: {"passed": evidence["passed"], "dependencies": evidence["dependencies"]} + for node, evidence in profile["tests"].items() + } + landing = self.root / "landing.html" + landing.write_text(landing.read_text().replace("QA Wiki", "Wrong heading")) + self.git("add", "landing.html") + head = self.commit("seed landing fault") + start = time.perf_counter() + plan = shadow.plan_shadow(shadow.snapshot(self.root, ENGINE), baseline, self.temp, ENGINE) + self.assertEqual(plan["selected"], ["test_landing.py::test_heading", "test_landing.py::test_resources_link"]) + return { + "schema": 1, + "head_commit": head, + "baseline_commit": self.baseline_commit, + "baseline_tests": sorted(baseline["tests"]), + "selected": plan["selected"], + "expand": plan["expand"], + "planning_seconds": time.perf_counter() - start, + } + + def pytest(self, name, *args, enable=True): + receipt = self.temp / f"{name}.json" + results = self.temp / f"{name}.xml" + policy = [f"--panthera-plan={self.plan_path}", "--panthera-select-path=landing.html"] if enable else [] + command = [ + sys.executable, + "-m", + "pytest", + "-p", + "no:cacheprovider", + "-p", + "pytest_ci", + f"--panthera-receipt={receipt}", + f"--junitxml={results}", + "-q", + "--tb=no", + *policy, + *args, + ] + result = subprocess.run( + command, + cwd=self.root, + env={ + **shadow.child_environment(self.root), + "PYTHONPATH": os.pathsep.join([str(ROOT / "adapter"), str(self.root)]), + }, + capture_output=True, + text=True, + timeout=30, + ) + self.assertTrue(receipt.exists(), f"{result.stdout}\n{result.stderr}") + evidence = json.loads(receipt.read_text()) + self.assertEqual(evidence["pytest_exit_code"], result.returncode) + failures = {case.get("name") for case in ET.parse(results).iter("testcase") if case.find("failure") is not None} + return evidence, failures + + def test_landing_fixture_selects_readers_and_matches_full_failure(self): + self.plan_path.write_text(json.dumps(self.plan_landing_fault())) + full, full_failures = self.pytest("full", enable=False) + self.assertEqual(full["mode"], "full") + self.assertEqual(full["tests_executed"], 4) + self.assertEqual(full_failures, {"test_heading"}) + + for name, args in (("serial", ()), ("parallel", ("-p", "xdist.plugin", "-n", "2"))): + with self.subTest(mode=name): + selected, failures = self.pytest(f"selected-{name}", *args) + self.assertEqual(failures, full_failures) + self.assertEqual(selected["mode"], "selected") + self.assertIsNone(selected["fallback_reason"]) + self.assertEqual(selected["tests_collected"], 4) + self.assertEqual(selected["tests_scheduled"], 2) + self.assertEqual(selected["tests_executed"], 2) + self.assertEqual(selected["failed_tests"], 1) + for key in ("planning_seconds", "validation_seconds", "pytest_wall_seconds"): + self.assertGreater(selected[key], 0) + + def test_missing_or_invalid_plan_is_full(self): + missing, _ = self.pytest("missing") + self.assertEqual(missing["mode"], "full") + self.assertEqual(missing["fallback_reason"], "missing_plan") + self.assertEqual(missing["tests_executed"], 4) + + self.plan_path.write_text("{") + invalid, _ = self.pytest("invalid") + self.assertEqual(invalid["mode"], "full") + self.assertEqual(invalid["fallback_reason"], "invalid_plan") + self.assertEqual(invalid["tests_executed"], 4) + + def test_inventory_drift_is_full_even_when_ids_equal_the_plan(self): + self.plan_path.write_text(json.dumps(self.plan_landing_fault())) + for name, args in (("serial", ()), ("parallel", ("-p", "xdist.plugin", "-n", "2"))): + with self.subTest(mode=name): + changed, failures = self.pytest(f"drift-{name}", "-k", "heading or resources", *args) + self.assertEqual(changed["mode"], "full") + self.assertEqual(changed["fallback_reason"], "inventory_changed") + self.assertEqual(changed["tests_executed"], 2) + self.assertEqual(failures, {"test_heading"}) + + def test_stale_plan_and_other_tracked_changes_are_full(self): + plan = self.plan_landing_fault() + self.plan_path.write_text(json.dumps(plan)) + (self.root / "notes.txt").write_text("other CI input") + dirty, _ = self.pytest("dirty") + self.assertEqual(dirty["fallback_reason"], "dirty_checkout") + self.assertEqual(dirty["tests_executed"], 4) + + self.git("add", "notes.txt") + head = self.commit("add other CI input") + stale, _ = self.pytest("stale") + self.assertEqual(stale["fallback_reason"], "stale_plan") + self.assertEqual(stale["tests_executed"], 4) + + self.plan_path.write_text(json.dumps({**plan, "head_commit": head})) + outside, _ = self.pytest("outside") + self.assertEqual(outside["fallback_reason"], "change_out_of_scope") + self.assertEqual(outside["tests_executed"], 4) + + def test_campaign_catches_mixed_failure_from_worker_and_dependency(self): + campaign = json.loads((EXAMPLE / "campaign.json").read_text()) + for trial in campaign["trials"]: + trial["path"] = Path(trial["path"]).name + report = qualify.campaign(self.root, self.scope, campaign, ENGINE, self.temp / "qualification", 30) + self.assertTrue(report["qualified"], report["trials"]) + for result in report["trials"]: + node = ( + "test_landing.py::test_heading" + if result["id"] == "landing_heading" + else "test_worker.py::test_permanent_error_wins_after_transient_error" + ) + with self.subTest(trial=result["id"]): + self.assertEqual(result["selected_cases"], 2) + self.assertEqual(result["full_cases"], 4) + self.assertEqual(result["selected_failures"], [node]) + self.assertEqual(result["full_failures"], [node]) + self.assertEqual(result["missed_failures"], []) + + +if __name__ == "__main__": + unittest.main() diff --git a/examples/ci_demo/campaign.json b/examples/ci_demo/campaign.json new file mode 100644 index 0000000..3d931a1 --- /dev/null +++ b/examples/ci_demo/campaign.json @@ -0,0 +1,35 @@ +{ + "schema": 1, + "trials": [ + { + "id": "landing_heading", + "kind": "replace_text", + "stratum": "resource", + "path": "examples/ci_demo/landing.html", + "find": "

QA Wiki

", + "replace": "

Wrong heading

", + "expect": "detected", + "expect_expand": false + }, + { + "id": "worker_masks_permanent_error", + "kind": "replace_text", + "stratum": "function", + "path": "examples/ci_demo/worker.py", + "find": " except UnsupportedModel:\n raise\n", + "replace": "", + "expect": "detected", + "expect_expand": false + }, + { + "id": "dependency_raises_retryable_error", + "kind": "replace_text", + "stratum": "function", + "path": "examples/ci_demo/failure_source.py", + "find": "raise UnsupportedModel(\"embedding model is unavailable\")", + "replace": "raise ConnectionError(\"embedding model is unavailable\")", + "expect": "detected", + "expect_expand": false + } + ] +} diff --git a/examples/ci_demo/failure_source.py b/examples/ci_demo/failure_source.py new file mode 100644 index 0000000..c97708d --- /dev/null +++ b/examples/ci_demo/failure_source.py @@ -0,0 +1,9 @@ +class UnsupportedModel(RuntimeError): + pass + + +def index_repository(repository): + if repository == "first": + raise ConnectionError("database connection lost") + if repository == "second": + raise UnsupportedModel("embedding model is unavailable") diff --git a/examples/ci_demo/landing.html b/examples/ci_demo/landing.html new file mode 100644 index 0000000..4b97386 --- /dev/null +++ b/examples/ci_demo/landing.html @@ -0,0 +1,2 @@ +

QA Wiki

+Resources diff --git a/examples/ci_demo/scope.json b/examples/ci_demo/scope.json new file mode 100644 index 0000000..f99ad08 --- /dev/null +++ b/examples/ci_demo/scope.json @@ -0,0 +1,7 @@ +{ + "targets": ["examples/ci_demo/failure_source.py", "examples/ci_demo/worker.py"], + "suites": ["examples/ci_demo/test_landing.py", "examples/ci_demo/test_worker.py"], + "resources": ["examples/ci_demo/landing.html"], + "input_tracking": "files", + "fixture_tracking": "consumers" +} diff --git a/examples/ci_demo/test_landing.py b/examples/ci_demo/test_landing.py new file mode 100644 index 0000000..f33ad0e --- /dev/null +++ b/examples/ci_demo/test_landing.py @@ -0,0 +1,21 @@ +from pathlib import Path + +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def session_context(): + yield + + +@pytest.fixture +def landing_html(): + return Path(__file__).with_name("landing.html").read_text() + + +def test_heading(landing_html): + assert "

QA Wiki

" in landing_html + + +def test_resources_link(landing_html): + assert 'href="/resources"' in landing_html diff --git a/examples/ci_demo/test_worker.py b/examples/ci_demo/test_worker.py new file mode 100644 index 0000000..77bfdc1 --- /dev/null +++ b/examples/ci_demo/test_worker.py @@ -0,0 +1,19 @@ +from unittest.mock import Mock + +import pytest +from failure_source import UnsupportedModel +from worker import index_registered + + +def test_permanent_error_wins_after_transient_error(): + retry = Mock() + with pytest.raises(UnsupportedModel): + index_registered(["first", "second"], retry) + retry.assert_not_called() + + +def test_transient_error_is_retried(): + retry = Mock() + index_registered(["first", "healthy"], retry) + retry.assert_called_once() + assert isinstance(retry.call_args.args[0], ConnectionError) diff --git a/examples/ci_demo/worker.py b/examples/ci_demo/worker.py new file mode 100644 index 0000000..fef0a29 --- /dev/null +++ b/examples/ci_demo/worker.py @@ -0,0 +1,15 @@ +from failure_source import UnsupportedModel, index_repository + + +def index_registered(repositories, retry): + first_failure = None + for repository in repositories: + try: + index_repository(repository) + except UnsupportedModel: + raise + except Exception as error: + if first_failure is None: + first_failure = error + if first_failure is not None: + retry(first_failure)