"""Put each v2.2.17 behaviour back, one at a time, in a copy of the package and check that the test class for that finding FAILS (a test that still passes with the bug back proves nothing). python tools/mutants_2218.py (from the scraper folder; offline, works on a temporary copy)""" import shutil import subprocess import sys import tempfile from pathlib import Path SRC = Path(__file__).resolve().parents[1] MUTANTS = [ ("F1 limited run treated as full", "marianos_scraper/site_runner.py", " limited = self.limited_reasons()\n catalog, prev_run", " limited = []\n catalog, prev_run", "TestF1PartialRunNeverReplacesFull and not api_runner"), ("F1 api subset treated as full", "marianos_scraper/runner.py", " limited = self.limited_reasons()\n previous = None if limited", " limited = []\n previous = None if limited", "test_api_runner_category_subset_is_a_sample_too"), ("F2 missing total read as page length", "marianos_scraper/site_runner.py", " if total is None:\n total_missing = True", " if total is None:\n total = len(items)", "test_a_listing_without_the_site_total_is_not_complete"), ("F2 category counts summed with overlap", "marianos_scraper/site_runner.py", " found = len(cat_ids.get(cat, ()))", " found = cat_listed.get(cat, 0)", "test_overlapping_units_are_counted_once"), ("F2 coupon totals not checked", "marianos_scraper/site_runner.py", " if site_total is None or have < site_total:", " if False:", "coupons_short or coupons_without"), ("F2 coupon lookup coverage not checked", "marianos_scraper/site_runner.py", " not_looked_up = sorted(", " not_looked_up = [] and sorted(", "test_every_product_must_have_been_asked_for_its_coupons"), ("F3 binding not checked on resume", "marianos_scraper/runner.py", " if state.get(\"binding\") != self.binding():", " if False:", "TestF3CheckpointBinding and not foreign"), ("F3 unit checkpoint binding not checked", "marianos_scraper/runner.py", " if result.get(\"binding_digest\") != state.get(\"binding_digest\"):", " if False:", "test_a_foreign_checkpoint_file_is_not_used"), ("F4 pointer written before the files", "marianos_scraper/delivery.py", " hashes = self._write_verified(prefix, files)\n", " hashes = {n: sha256_text(t) for n, t in files.items()}\n", "test_a_failed_write_leaves_the_previous_delivery_whole"), ("F4 pointer write not conditional", "marianos_scraper/storage.py", " if current != etag:\n raise PreconditionFailed(f\"{key} changed since it was read\")\n self.write_text(key, text)", " self.write_text(key, text)", "test_a_second_writer_cannot_overwrite_the_pointer"), ("F5 no reservation before dispatch", "marianos_scraper/site_source.py", " self.reserve(path) # durable", " pass # self.reserve(path) # durable", "test_the_real_transport_reserves_before_it_counts_and_sends"), ("F5 runner does not reserve", "marianos_scraper/site_runner.py", " self.site.reserve = self._reserve_request\n", "\n", "test_every_request_is_reserved or killed_process"), ("F5 crash not counted at the reservation", "marianos_scraper/site_runner.py", " used = reserved\n", "\n", "killed_process"), ("F5 oxylabs run without a ledger", "marianos_scraper/__main__.py", " if transport == \"oxylabs\" and source != \"api\" and not args.ledger:", " if False:", "without_the_allowance_ledger"), ("F6 no default deadline", "marianos_scraper/site_runner.py", " self.site.max_seconds = self.deadline", " pass", "test_normal_collection_gets_the_deadline_without_any_option"), ("F6 request without timeout", "marianos_scraper/site_source.py", " limit = self._request_limit(self.request_timeout)", " limit = self._request_limit(None)", "test_every_request_has_a_timeout_even_without_a_runtime_cap"), ("F6 no deadline between units", "marianos_scraper/runner.py", " if self.time_left() <= 0:", " if False:", "stops_at_the_deadline"), ("F6 retry wait ignores the deadline", "marianos_scraper/runner.py", " if seconds >= self.time_left():\n raise Interrupted(\"cap\")", " pass", "test_the_retry_wait_stops_at_the_deadline"), ] bad = 0 for name, rel, old, new, select in MUTANTS: dst = Path(tempfile.mkdtemp(prefix="mut2218-")) / "scraper" shutil.copytree(SRC, dst, ignore=shutil.ignore_patterns("__pycache__", ".pytest_cache", "data", "logs")) p = dst / rel raw = p.read_bytes().decode("utf-8") crlf = "\r\n" in raw s = raw.replace("\r\n", "\n") if s.count(old) != 1: print(f"!! {name}: pattern found {s.count(old)} times"); bad += 1; continue s = s.replace(old, new) p.write_bytes((s.replace("\n", "\r\n") if crlf else s).encode("utf-8")) r = subprocess.run([sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider", "tests/test_v2218.py", "-k", select], cwd=dst, capture_output=True, text=True) tail = [l for l in r.stdout.splitlines() if " passed" in l or " failed" in l or "error" in l.lower()][-1:] caught = r.returncode == 1 and "failed" in (tail[0] if tail else "") bad += not caught print(f"{'CAUGHT ' if caught else 'MISSED!'} {name}: {tail[0] if tail else r.stdout[-300:]}") shutil.rmtree(dst.parent, ignore_errors=True) print("ALL MUTANTS CAUGHT" if not bad else f"{bad} NOT CAUGHT") sys.exit(1 if bad else 0)