Skip to content

Commit fb18f7d

Browse files
ShaneLogicclaude
andcommitted
ci(scheduled): run core coverage shards from the checkout source they are bound to
The first Linux run of the scheduled suite (40966847092) refused 81 core reference loaders. The coverage shards installed the package with --no-editable and removed PYTHONPATH. The core assembly-parity references check that they load the actual classes under the checkout's src/, so they correctly refused the installed copy. The core coverage shards now run against the checkout source, as the per-push core job does. Installation verification stays in the shards that need it. The tests/ci guards now cover the install mode and the order of shards. Performance classified all 181 failed or errored nodes of that run (CiCoverageV2.json af684253): - 83 environment/compatibility, including 2 legacy fixtures that eagerly use the removed numpy.trapz; - 3 platform-bound captures; - 44 pre-existing legacy failures; - 0 confirmed refactor regressions; - 51 unknown, still needing native GitHub evidence: 6 process-budget cases and 45 legacy numerical/identity cases. Constraint: Production source, ci.yml, fixtures, markers and thresholds are unchanged; no xfail added Confidence: high Scope-risk: narrow Not-tested: The 51 unknown cases (the next scheduled dispatch provides the native evidence) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aad6c73 commit fb18f7d

2 files changed

Lines changed: 143 additions & 4 deletions

File tree

‎scripts/ci/scheduled_suite.py‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
"OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS",
3838
"VECLIB_MAXIMUM_THREADS", "NUMEXPR_NUM_THREADS", "BLIS_NUM_THREADS",
3939
)
40+
# These tests observe real child-process deadlines. Instrument the pytest
41+
# parent, but leave the measured children in the same mode as push CI.
42+
PARENT_ONLY_COVERAGE = {
43+
"tests/numerical_contracts/test_g2_route_launcher.py":
44+
"Synthetic process-group startup/closeout is measured inside a fixed wall budget.",
45+
"tests/runtime/test_ionic_jv_job_service.py":
46+
"The HTTP worker has a fixed 30 s wall limit; child tracing changes the measured workload.",
47+
}
4048

4149

4250
def read(path):
@@ -64,6 +72,10 @@ def pinned_environment():
6472
env["PYTHONDONTWRITEBYTECODE"] = "1"
6573
env.pop("PYTHONPATH", None)
6674
env.pop("PYTHONHOME", None)
75+
# Each child receives this runner's explicit coverage policy, never an
76+
# outer caller's automatic subprocess tracing configuration.
77+
env.pop("COVERAGE_PROCESS_CONFIG", None)
78+
env.pop("COVERAGE_PROCESS_START", None)
6779
return env
6880

6981

@@ -222,8 +234,27 @@ def build_shards(collections):
222234
)
223235
shard["ignored"] = list(selection.ignored_files)
224236
shard["ci_job"] = selection.job
225-
if selected:
237+
isolated = {
238+
path: [item for item in selected if item["path"] == path]
239+
for path in PARENT_ONLY_COVERAGE
240+
if any(item["path"] == path for item in selected)
241+
}
242+
if isolated:
243+
shard["nodeids"] = [item["nodeid"] for item in selected
244+
if item["path"] not in isolated]
245+
shard["count"] = len(shard["nodeids"])
246+
shard["ignored"] += sorted(isolated)
247+
if shard["count"]:
226248
coverage.append(shard)
249+
for path, items in sorted(isolated.items()):
250+
separate = make_shard(
251+
"coverage", suite, [path], selection.markers, items,
252+
shard["id"] + "-" + Path(path).stem.removeprefix("test_"),
253+
)
254+
separate["ci_job"] = selection.job
255+
separate["subprocess_coverage"] = False
256+
separate["coverage_limitation"] = PARENT_ONLY_COVERAGE[path]
257+
coverage.append(separate)
227258
else:
228259
groups = defaultdict(list)
229260
for item in default_items:
@@ -288,14 +319,17 @@ def plan(args):
288319
print(kind, row["id"], row["count"], *row["paths"])
289320

290321

291-
def coverage_config(path):
322+
def coverage_config(path, *, subprocesses=True):
292323
"""Trace only this checkout and its installed packages, not old producer clones."""
293324
site = Path(sysconfig.get_paths()["purelib"])
294325
pairs = {
295326
"solarlab": [ROOT / "src/solarlab", site / "solarlab"],
296327
"perovskite_sim": [ROOT / "perovskite-sim/perovskite_sim", site / "perovskite_sim"],
297328
}
298-
text = "[run]\nparallel = true\npatch = subprocess\nsigterm = true\nsource =\n"
329+
text = "[run]\nparallel = true\n"
330+
if subprocesses:
331+
text += "patch = subprocess\n"
332+
text += "sigterm = true\nsource =\n"
299333
text += "".join(f" {p}\n" for paths in pairs.values() for p in paths)
300334
text += "\n[paths]\n"
301335
for name, paths in pairs.items():
@@ -320,6 +354,12 @@ def run_shard(args):
320354
env = pinned_environment()
321355
if shard.get("ci_job"):
322356
env["PYTEST_CI_JOB"] = shard["ci_job"]
357+
if args.kind == "coverage" and shard.get("ci_job") == "core":
358+
# Live reference loaders require classes from this exact checkout.
359+
# Audit the non-editable installation above before binding only the
360+
# pytest child to the same bytes, as the core push job already does.
361+
env["PYTHONPATH"] = str(ROOT / "src")
362+
result["execution_source"] = str(ROOT / "src")
323363
pytest_args = [
324364
*shard["paths"], "-m", shard["markers"], "-q", "-ra", "-p",
325365
"no:cacheprovider", "--durations=0", "--junitxml=" + str(out / "junit.xml"),
@@ -329,7 +369,8 @@ def run_shard(args):
329369
command = [sys.executable]
330370
if args.kind == "coverage":
331371
config = out / "coverage.ini"
332-
coverage_config(config)
372+
result["subprocess_coverage"] = shard.get("subprocess_coverage", True)
373+
coverage_config(config, subprocesses=result["subprocess_coverage"])
333374
env["COVERAGE_FILE"] = str(out / "coverage.data")
334375
command += ["-m", "coverage", "run", "--rcfile=" + str(config),
335376
"--parallel-mode", "--context=" + shard["id"]]

‎tests/ci/test_scheduled_suite.py‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ def test_new_unowned_root_directory_fails_the_default_suite_plan():
6363
scheduled.build_shards(data)
6464

6565

66+
def test_clock_bound_files_run_once_in_explicit_parent_only_coverage_shards():
67+
data = inventory()
68+
for path in scheduled.PARENT_ONLY_COVERAGE:
69+
data["root"]["items"].append(item(path))
70+
rows = {row["id"]: row for row in scheduled.build_shards(data)["coverage"]}
71+
for job, file in [("core", "test_g2_route_launcher.py"),
72+
("backend", "test_ionic_jv_job_service.py")]:
73+
isolated = next(row for row in rows.values() if row["paths"] == [next(
74+
path for path in scheduled.PARENT_ONLY_COVERAGE if path.endswith(file)
75+
)])
76+
assert isolated["ci_job"] == job and isolated["subprocess_coverage"] is False
77+
assert isolated["coverage_limitation"]
78+
assert isolated["paths"][0] in rows["coverage-root-" + job]["ignored"]
79+
assert sum(isolated["nodeids"][0] in row["nodeids"] for row in rows.values()) == 1
80+
assert rows["coverage-root-backend-scan_execution"].get("subprocess_coverage", True)
81+
82+
6683
def test_large_slow_file_is_partitioned_without_dropping_parameterized_nodes():
6784
data = {"legacy": {"items": [
6885
item("tests/integration/test_large.py", f"test_case[{i}]", ("slow",))
@@ -102,6 +119,87 @@ def test_coverage_filters_current_source_and_installed_copy_not_foreign_producer
102119
assert "fail_under" not in text and "fail-under" not in text
103120

104121

122+
def test_parent_only_coverage_keeps_parent_trace_and_leaves_children_uninstrumented(tmp_path):
123+
config = tmp_path / "coverage.ini"
124+
scheduled.coverage_config(config, subprocesses=False)
125+
assert "patch = subprocess" not in config.read_text()
126+
probe = tmp_path / "probe.py"
127+
probe.write_text(
128+
"import coverage, subprocess, sys\n"
129+
"assert coverage.Coverage.current() is not None\n"
130+
"subprocess.run([sys.executable, '-c', "
131+
"'import coverage; assert coverage.Coverage.current() is None'], check=True)\n"
132+
)
133+
env = scheduled.pinned_environment()
134+
env["COVERAGE_FILE"] = str(tmp_path / "coverage.data")
135+
result = subprocess.run([sys.executable, "-m", "coverage", "run", "--rcfile=" + str(config), str(probe)],
136+
env=env, cwd=tmp_path, text=True, capture_output=True, timeout=30)
137+
assert result.returncode == 0, result.stdout + result.stderr
138+
139+
140+
@pytest.mark.parametrize(("kind", "job", "source_bound"), [
141+
("coverage", "core", True),
142+
("coverage", "backend", False),
143+
("slow", None, False),
144+
])
145+
def test_core_source_binding_follows_installation_audit_only_in_its_child(
146+
tmp_path, monkeypatch, kind, job, source_bound,
147+
):
148+
monkeypatch.setattr(scheduled, "ROOT", tmp_path)
149+
monkeypatch.setattr(scheduled, "SUITES", {"root": tmp_path})
150+
monkeypatch.setattr(scheduled, "commit", lambda: "frozen")
151+
monkeypatch.setenv("PYTHONPATH", "/foreign/source")
152+
monkeypatch.delenv("PYTEST_CI_JOB", raising=False)
153+
(tmp_path / "uv.lock").write_text("locked")
154+
shard = {"id": "case", "suite": "root", "paths": ["tests"],
155+
"markers": "not slow", "nodeids": ["tests/test_one.py::test_one"],
156+
"ignored": [], "ci_job": job}
157+
plan = tmp_path / "plan.json"
158+
scheduled.write(plan, {"commit": "frozen", "lock_sha256": scheduled.sha256(tmp_path / "uv.lock"),
159+
"selected_shards": {kind: [shard]}})
160+
audited = []
161+
162+
def audit():
163+
# Source binding must not make the installation guard audit itself.
164+
assert scheduled.os.environ["PYTHONPATH"] == "/foreign/source"
165+
audited.append(True)
166+
return {"solarlab": {"files_verified": 1}}
167+
168+
def execute(command, **kwargs):
169+
assert audited == [True]
170+
assert kwargs["env"].get("PYTHONPATH") == (
171+
str(tmp_path / "src") if source_bound else None
172+
)
173+
assert kwargs["env"].get("PYTEST_CI_JOB") == job
174+
assert ("coverage" in command) is (kind == "coverage")
175+
return SimpleNamespace(returncode=0)
176+
177+
monkeypatch.setattr(scheduled, "verify_installation", audit)
178+
monkeypatch.setattr(scheduled.subprocess, "run", execute)
179+
out = tmp_path / "out"
180+
assert scheduled.run_shard(SimpleNamespace(plan=plan, kind=kind, shard="case", out=out)) == 0
181+
result = scheduled.read(out / "result.json")
182+
assert result["installed_source_verification"] == {"solarlab": {"files_verified": 1}}
183+
assert result.get("execution_source") == (str(tmp_path / "src") if source_bound else None)
184+
185+
186+
def test_source_bound_coverage_never_runs_after_installation_failure(tmp_path, monkeypatch):
187+
monkeypatch.setattr(scheduled, "ROOT", tmp_path)
188+
monkeypatch.setattr(scheduled, "commit", lambda: "frozen")
189+
(tmp_path / "uv.lock").write_text("locked")
190+
plan = tmp_path / "plan.json"
191+
scheduled.write(plan, {"commit": "frozen", "lock_sha256": scheduled.sha256(tmp_path / "uv.lock"),
192+
"selected_shards": {"coverage": [{"id": "case", "ci_job": "core", "nodeids": []}]}})
193+
194+
def stale():
195+
raise ValueError("installed package differs from checkout")
196+
197+
monkeypatch.setattr(scheduled, "verify_installation", stale)
198+
monkeypatch.setattr(scheduled.subprocess, "run", lambda *a, **k: pytest.fail("stale package executed"))
199+
with pytest.raises(ValueError, match="installed package differs"):
200+
scheduled.run_shard(SimpleNamespace(plan=plan, kind="coverage", shard="case", out=tmp_path / "out"))
201+
202+
105203
@pytest.mark.parametrize(("expected", "body", "code"), [
106204
(["test_probe.py::absent"], "assert True", 4),
107205
(["test_probe.py::test_probe"], "assert False, 'failure must remain visible'", 1),

0 commit comments

Comments
 (0)