fix(claude_code/conftest): allow xdist controller to merge worker shards

The previous early-return guard in pytest_sessionfinish exited before
the merge step for the xdist controller process: the controller never
runs tests itself (so _COLLECTOR.items is empty) and is not detected
as a worker (it has no workerinput), so the guard always tripped.

Worker shards were written but no process ever produced the canonical
compat-results.json. Also check for shards on disk so the controller
still proceeds to merge them under pytest -n auto.

Co-authored-by: Yassin Kortam <yassin@berri.ai>
This commit is contained in:
Cursor Agent 2026-05-15 23:42:21 +00:00
parent a1c4f0fc12
commit e886f3fec8
No known key found for this signature in database

View file

@ -419,11 +419,18 @@ def pytest_sessionfinish(session, exitstatus):
unit-test trees (e.g. `_driver_unit_tests/`). Writing an empty
artifact would silently overwrite a real artifact from a prior
compat-test run on the same checkout.
The xdist controller hits this hook with `_COLLECTOR.items` empty
(it never executes tests itself) and `_is_xdist_worker` False, so
we additionally allow the merge step to run when worker shards
are already on disk — otherwise the canonical artifact would
never be produced under `pytest -n auto`.
"""
if not _COLLECTOR.items and not _is_xdist_worker(session):
return
artifact_path = Path(os.environ.get(RESULTS_ARTIFACT_ENV) or DEFAULT_ARTIFACT_PATH)
shard_dir = _shard_dir(artifact_path)
has_worker_shards = shard_dir.is_dir() and any(shard_dir.glob("*.json"))
if not _COLLECTOR.items and not _is_xdist_worker(session) and not has_worker_shards:
return
shard_dir.mkdir(parents=True, exist_ok=True)
worker_id = _xdist_worker_id(session) or "main"