diffcone 0.4.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {diffcone-0.4.0 → diffcone-0.5.0}/PKG-INFO +1 -1
  2. {diffcone-0.4.0 → diffcone-0.5.0}/pyproject.toml +2 -1
  3. {diffcone-0.4.0 → diffcone-0.5.0}/pyproject.toml.orig +2 -1
  4. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/cache.py +84 -7
  5. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/check.py +32 -2
  6. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/child.py +7 -0
  7. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/ci_report.py +100 -12
  8. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/cli.py +135 -15
  9. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/collect.py +124 -8
  10. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/declarations.py +6 -16
  11. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/discovery/asv_static.py +17 -2
  12. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/discovery/common.py +41 -0
  13. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/discovery/pytest_static.py +1410 -90
  14. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/evidence.py +99 -8
  15. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/evidence_plan.py +440 -86
  16. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/execution.py +325 -36
  17. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/__init__.py +51 -8
  18. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/aliases.py +127 -1
  19. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/core.py +740 -29
  20. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/facts.py +268 -13
  21. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/lazy.py +199 -3
  22. diffcone-0.5.0/src/diffcone/indexer/literals.py +1200 -0
  23. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/process.py +10 -1
  24. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/references.py +2086 -24
  25. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/resolver.py +170 -6
  26. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/scopes.py +37 -0
  27. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/scripts.py +144 -24
  28. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/state.py +17 -1
  29. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/symbols.py +37 -0
  30. diffcone-0.5.0/src/diffcone/indexer/writes.py +1969 -0
  31. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/model.py +57 -23
  32. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/planner.py +172 -25
  33. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/report.py +8 -2
  34. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/selection.py +5 -3
  35. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/snapshot.py +130 -5
  36. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/testing.py +30 -17
  37. diffcone-0.4.0/src/diffcone/indexer/literals.py +0 -559
  38. diffcone-0.4.0/src/diffcone/indexer/writes.py +0 -1061
  39. {diffcone-0.4.0 → diffcone-0.5.0}/LICENSE +0 -0
  40. {diffcone-0.4.0 → diffcone-0.5.0}/README.md +0 -0
  41. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/__init__.py +0 -0
  42. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/classify.py +0 -0
  43. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/cython.py +0 -0
  44. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/discovery/__init__.py +0 -0
  45. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/discovery/session_state.py +0 -0
  46. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/definitions.py +0 -0
  47. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/dynamics.py +0 -0
  48. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/patches.py +0 -0
  49. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/syntax.py +0 -0
  50. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/indexer/uses.py +0 -0
  51. {diffcone-0.4.0 → diffcone-0.5.0}/src/diffcone/manifest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffcone
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why
5
5
  Keywords: test selection,test impact analysis,change impact,pytest,asv,ci
6
6
  Author: Bearing Research
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "diffcone"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -53,6 +53,7 @@ dev = [
53
53
  "cython>=3.1",
54
54
  "pytest>=8",
55
55
  "pytest-cov>=5",
56
+ "pytest-xdist>=3.6",
56
57
  "ruff>=0.5",
57
58
  "setuptools",
58
59
  "ty==0.0.84",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "diffcone"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -44,6 +44,7 @@ dev = [
44
44
  "cython>=3.1", # tests that build a profiled extension (evidence over Cython)
45
45
  "pytest>=8",
46
46
  "pytest-cov>=5",
47
+ "pytest-xdist>=3.6",
47
48
  "ruff>=0.5",
48
49
  "setuptools", # builds those extensions
49
50
  "ty==0.0.84", # pre-1.0: pinned, since new releases add checks
@@ -53,6 +53,39 @@ from diffcone.model import (
53
53
  )
54
54
 
55
55
  # Bump whenever the indexer's output for the same input can change.
56
+ # 62: a class reached by another name is written through it, one record of
57
+ # what each class is given (writes.ClassRecord), shared objects bound in
58
+ # methods, nested classes' state, library methods on a class and
59
+ # ``type()`` of three arguments (audit round 7, U2, U3, U11, U12);
60
+ # 63: SourceIndex.decorator_symbols goes through the whole-index cache
61
+ # (audit round 7, U27); the state rules of round 7's state batch;
62
+ # 64: typed_calls and shared_instances; receiver attribute stores keep
63
+ # their name (``@self.x``), re-initialisation is ``@init``; memoisers
64
+ # applied by a call (audit round 7, U4, U5, U14, U15, U16, U17, U18);
65
+ # 59: a class attribute bound once to a value that cannot change in place
66
+ # is no root of its class (audit round 6, T24); an instance holds the
67
+ # arguments its constructor was handed, and only a write that may reach
68
+ # them writes them (T23);
69
+ # 58: an instance an in-scope class makes (``Store()``, ``cls.__new__(cls)``)
70
+ # is no root of the class; a write in place into it writes the class
71
+ # when the class holds state, and ``__new__``/``__init_subclass__`` take
72
+ # the class (audit round 6, T22);
73
+ # 57: a write in place into a module variable holding an instance of an
74
+ # in-scope class with class-level state writes the class and its
75
+ # in-scope bases too (audit round 6, T21);
76
+ # 56: SourceIndex.stores without what the value derives from, through
77
+ # ``__dict__``/``vars()`` and explicit re-initialisation (audit T19);
78
+ # 55: no mutated_by edge from a module variable whose one binding is an
79
+ # immutable value nothing binds anew (audit round 6, T20);
80
+ # 54: writes to state held on a class, and through another name for a module
81
+ # variable (a local alias, a getter's result, globals()), give mutated_by
82
+ # edges (audit round 6, T6 and T7);
83
+ # 53: imports and runs of files [index] exclude keeps out are unknown
84
+ # dependencies; pytest.importorskip, find_spec, pkgutil imports (T2, T9);
85
+ # 52: SourceIndex.write_values, call_values removed again (audit T1);
86
+ # 51: SourceIndex.write_values, call_values (what in-place writes store and calls
87
+ # hand on; E32, E35, E36);
88
+ # 50: SnapshotInfo.excluded (diffcone.toml [index] exclude; E29);
56
89
  # 49: SourceIndex.lazy_constants (indexer/lazy.py; roadmap item 19, rule 2);
57
90
  # 48: Symbol.annotation_names (what a function's annotations can read; E7);
58
91
  # 47: a name bound to modules reads off them (indexer/aliases.py), and a
@@ -87,7 +120,7 @@ from diffcone.model import (
87
120
  # and modules (indexer.uses); 28: __subclasses__ reads; 27: type
88
121
  # parameters, unnameable build scripts as other files; 26: escaped values;
89
122
  # 25: external sites; 24: docstring decorators; 23: open classes
90
- INDEX_FORMAT = 49
123
+ INDEX_FORMAT = 64
91
124
 
92
125
 
93
126
  def _indexer_fingerprint() -> str:
@@ -183,6 +216,7 @@ def index_to_dict(index: SourceIndex) -> dict:
183
216
  "class_bases": {c: list(b) for c, b in sorted(index.class_bases.items())},
184
217
  "open_classes": sorted(index.open_classes),
185
218
  "doc_decorated": sorted(index.doc_decorated),
219
+ "decorator_symbols": sorted(index.decorator_symbols),
186
220
  "scripts": dict(sorted(index.scripts.items())),
187
221
  "script_refs": sorted(list(r) for r in index.script_refs),
188
222
  "process_writes": sorted(list(w) for w in index.process_writes),
@@ -191,6 +225,8 @@ def index_to_dict(index: SourceIndex) -> dict:
191
225
  "handed": sorted(list(h) for h in index.handed),
192
226
  "memoized": sorted(index.memoized),
193
227
  "decorations": sorted(list(d) for d in index.decorations),
228
+ "typed_calls": sorted(list(t) for t in index.typed_calls),
229
+ "shared_instances": sorted(index.shared_instances),
194
230
  "lazy_constants": dict(sorted(index.lazy_constants.items())),
195
231
  "cython": {
196
232
  path: {
@@ -211,7 +247,11 @@ def index_from_dict(data: dict) -> SourceIndex:
211
247
  symbols = {s.id: s for s in map(symbol_from_dict, data["symbols"])}
212
248
  return SourceIndex(
213
249
  snapshot=SnapshotInfo(
214
- **data["snapshot"] | {"kind": SnapshotKind(data["snapshot"]["kind"])}
250
+ **data["snapshot"]
251
+ | {
252
+ "kind": SnapshotKind(data["snapshot"]["kind"]),
253
+ "excluded": tuple(data["snapshot"]["excluded"]),
254
+ }
215
255
  ),
216
256
  modules=set(data["modules"]),
217
257
  symbols=symbols,
@@ -240,14 +280,17 @@ def index_from_dict(data: dict) -> SourceIndex:
240
280
  class_bases={c: tuple(b) for c, b in data["class_bases"].items()},
241
281
  open_classes=set(data["open_classes"]),
242
282
  doc_decorated=set(data["doc_decorated"]),
283
+ decorator_symbols=set(data["decorator_symbols"]),
243
284
  scripts=dict(data["scripts"]),
244
285
  script_refs={(s, p) for s, p in data["script_refs"]},
245
286
  process_writes={(s, w) for s, w in data["process_writes"]},
246
287
  main_guarded={(a, b, c) for a, b, c in data["main_guarded"]},
247
- stores={(a, b, c) for a, b, c in data["stores"]},
288
+ stores={(a, b) for a, b in data["stores"]},
248
289
  handed={(a, b, c) for a, b, c in data["handed"]},
249
290
  memoized=set(data["memoized"]),
250
291
  decorations={(a, b) for a, b in data["decorations"]},
292
+ typed_calls={(a, b) for a, b in data["typed_calls"]},
293
+ shared_instances=set(data["shared_instances"]),
251
294
  lazy_constants=dict(data["lazy_constants"]),
252
295
  cython={
253
296
  path: CythonModule(
@@ -298,7 +341,10 @@ class ModuleCache:
298
341
  the file read-only and work on a directory that cannot be written."""
299
342
 
300
343
  def __init__(self, directory: Path) -> None:
301
- self.path = directory / "modules.sqlite"
344
+ # Absolute, so that the read-only URI below can be formed: a relative
345
+ # directory (the default ``--repo .``) once made every read a miss
346
+ # (audit round 7, U24).
347
+ self.path = (directory / "modules.sqlite").absolute()
302
348
  # Hit and miss counters: test instrumentation, nothing reads them else.
303
349
  self.facts_hits = 0
304
350
  self.facts_misses = 0
@@ -405,7 +451,8 @@ class ModuleCache:
405
451
  conn.close()
406
452
 
407
453
 
408
- DISCOVERY_FORMAT = 1
454
+ # 2: lifecycle dependencies every target lists are written once (audit E37)
455
+ DISCOVERY_FORMAT = 2
409
456
 
410
457
 
411
458
  def _discovery_fingerprint() -> str:
@@ -422,6 +469,27 @@ def _discovery_fingerprint() -> str:
422
469
  DISCOVERY_FINGERPRINT = _discovery_fingerprint()
423
470
 
424
471
 
472
+ def _sorted_unique(deps: tuple[str, ...]) -> bool:
473
+ return all(a < b for a, b in zip(deps, deps[1:], strict=False))
474
+
475
+
476
+ def _shared_lifecycle(targets: list[Target]) -> frozenset[str]:
477
+ """The lifecycle dependencies every target lists, where each lists them
478
+ sorted and once (as discovery does), so a target's own rest rebuilds it."""
479
+ sets = [frozenset(t.lifecycle_dependencies) for t in targets]
480
+ if not sets or not all(_sorted_unique(t.lifecycle_dependencies) for t in targets):
481
+ return frozenset()
482
+ return frozenset.intersection(*sets)
483
+
484
+
485
+ def _target_entry(target: Target, shared: frozenset[str]) -> dict[str, Any]:
486
+ entry = asdict(target)
487
+ if shared:
488
+ del entry["lifecycle_dependencies"]
489
+ entry["own"] = [d for d in target.lifecycle_dependencies if d not in shared]
490
+ return entry
491
+
492
+
425
493
  class DiscoveryCache:
426
494
  """Static discovery results per committed snapshot. Discovery reads only
427
495
  the snapshot and its index, so a commit, source roots, runner and
@@ -449,6 +517,8 @@ class DiscoveryCache:
449
517
  data = json.loads(self._path(commit, roots, runner, options).read_text("utf-8"))
450
518
  if data.get("format") != DISCOVERY_FORMAT or data.get("commit") != commit:
451
519
  return None
520
+ shared = data["shared"]
521
+ pool: dict[str, str] = {d: d for d in shared}
452
522
  return DiscoveryResult(
453
523
  runner=data["runner"],
454
524
  targets=[
@@ -456,7 +526,9 @@ class DiscoveryCache:
456
526
  t["runner"],
457
527
  t["runner_id"],
458
528
  t["entry_symbol"],
459
- tuple(t["lifecycle_dependencies"]),
529
+ tuple(sorted([*shared, *(pool.setdefault(d, d) for d in t["own"])]))
530
+ if "own" in t
531
+ else tuple(t["lifecycle_dependencies"]),
460
532
  )
461
533
  for t in data["targets"]
462
534
  ],
@@ -476,12 +548,17 @@ class DiscoveryCache:
476
548
  if any(TOO_DEEP in n.detail for n in result.notes):
477
549
  return # depends on the caller's stack depth, not only on the commit
478
550
  path = self._path(commit, roots, result.runner, options)
551
+ shared = _shared_lifecycle(result.targets)
479
552
  data = {
480
553
  "format": DISCOVERY_FORMAT,
481
554
  "commit": commit,
482
555
  "fingerprint": DISCOVERY_FINGERPRINT,
483
556
  "runner": result.runner,
484
- "targets": [asdict(t) for t in result.targets],
557
+ # What every target depends on, written once (audit E37: pandas'
558
+ # 25 620 targets each carry the same 654, a 680 MB file that took
559
+ # 1.4 GB to load); a target lists the rest (``own``).
560
+ "shared": sorted(shared),
561
+ "targets": [_target_entry(t, shared) for t in result.targets],
485
562
  "notes": [asdict(n) for n in result.notes],
486
563
  "config": result.config,
487
564
  }
@@ -255,6 +255,24 @@ class CheckReport:
255
255
  def ok(self) -> bool:
256
256
  return not self.misses and not self.not_run
257
257
 
258
+ @property
259
+ def own_run_checked(self) -> bool:
260
+ """Whether diffcone's own run was given (``--run diffcone=...``):
261
+ without it the check says the plan selected every new failure, not
262
+ that the selected tests ran."""
263
+ return any(r.name == OWN_RUN for r in self.runs)
264
+
265
+ @property
266
+ def verdict(self) -> str:
267
+ if not self.ok:
268
+ return "MISS"
269
+ if self.own_run_checked:
270
+ return "OK: every new failure was selected and run"
271
+ return (
272
+ "OK: every new failure was selected; whether diffcone's run ran them was not "
273
+ f"checked (no --run {OWN_RUN}=JUNIT)"
274
+ )
275
+
258
276
 
259
277
  def _broken(cases: list[Case], targets: _Targets) -> dict[str, tuple[str, str, set[str]]]:
260
278
  """Test -> (outcome, kind, broken case keys) for every broken case, by
@@ -391,6 +409,7 @@ def to_dict(report: CheckReport) -> dict:
391
409
  return {
392
410
  "ok": report.ok,
393
411
  "not_run": report.not_run,
412
+ "own_run_checked": report.own_run_checked,
394
413
  "plan": {
395
414
  "status": report.plan_status,
396
415
  "discovery_incomplete": report.discovery_incomplete,
@@ -469,14 +488,19 @@ def to_text(report: CheckReport) -> str:
469
488
  lines.append(
470
489
  f"diffcone's run did not run {len(report.not_run)} new failure(s) (see NOT RUN above)"
471
490
  )
472
- lines.append("OK: every new failure was selected and run" if report.ok else "MISS")
491
+ lines.append(report.verdict)
473
492
  return "\n".join(lines) + "\n"
474
493
 
475
494
 
476
495
  def to_markdown(report: CheckReport) -> str:
477
496
  new = [f for f in report.failures if not f.already]
478
497
  missed = len({f.test for f in report.misses} | set(report.not_run))
479
- verdict = "no miss" if report.ok else f"**{missed} missed**"
498
+ if not report.ok:
499
+ verdict = f"**{missed} missed**"
500
+ elif report.own_run_checked:
501
+ verdict = "no miss"
502
+ else:
503
+ verdict = "no miss in the plan (diffcone's run not checked)"
480
504
  lines = [
481
505
  f"### diffcone check: {verdict}",
482
506
  "",
@@ -504,6 +528,12 @@ def to_markdown(report: CheckReport) -> str:
504
528
  )
505
529
  if report.mapping_doubtful:
506
530
  lines += ["", report.mapping_note + "."]
531
+ if not report.own_run_checked:
532
+ lines += [
533
+ "",
534
+ "Only the plan was checked: without the JUnit XML of diffcone's own run "
535
+ f"(`--run {OWN_RUN}=...`), whether the selected tests ran is not known.",
536
+ ]
507
537
  if report.misses:
508
538
  lines += ["", "Missed by the plan:", ""]
509
539
  lines += [f"- `{f.test}` ({f.outcome}, {f.kind})" for f in report.misses]
@@ -525,6 +525,13 @@ LISTING_EVENTS = frozenset({"os.listdir", "os.scandir"})
525
525
  # edit to any direct entry may have been read. The fold and the planner
526
526
  # read the suffix (evidence_plan._file).
527
527
  SCANNED = "/*"
528
+ # A file whose lines ``linecache`` read inside a test (a traceback or a
529
+ # warning formatted, ``inspect.getsource``) is recorded with this suffix
530
+ # instead: the test touched it, but what it read are lines to show, which
531
+ # planning does not follow into project state (evidence_plan's
532
+ # ``_file_readers`` seeds nothing from it; audit round 7, U6). A file has
533
+ # no entries, so the suffix names no real path.
534
+ SHOWN = "/:lines"
528
535
  # Events after which a path may resolve through other links: the memo of
529
536
  # real paths is dropped.
530
537
  LINK_EVENTS = frozenset({"os.symlink", "os.rename", "os.remove", "os.rmdir", "os.link"})
@@ -74,6 +74,9 @@ class CellReport:
74
74
  refused: int = 0
75
75
  plan_failed: int = 0
76
76
  not_collected: int = 0 # runs where pytest did not collect selected tests
77
+ # Runs whose ``diffcone run`` failed after a good plan (exit 2 or more,
78
+ # other than 3: it refused, or pytest was interrupted or could not start).
79
+ run_failed: int = 0
77
80
  pushes: int = 0
78
81
  checked: int = 0
79
82
  not_checked: Counter[str] = field(default_factory=Counter)
@@ -100,17 +103,29 @@ class Report:
100
103
  check_errors: int = 0
101
104
  not_collected: int = 0
102
105
  malformed: int = 0
106
+ run_failed: int = 0
107
+ # Pull-request runs that ran no selection: the plan failed (``plan``
108
+ # exited 2), or ``run`` refused an incomplete discovery (exit 3).
109
+ plan_failed: int = 0
110
+ refused: int = 0
111
+
112
+ @property
113
+ def missed(self) -> bool:
114
+ return bool(self.misses or self.earlier_misses or self.unlisted_misses)
103
115
 
104
116
  @property
105
117
  def ok(self) -> bool:
106
118
  """No confirmed miss, no check that failed to reach a verdict, no
107
- selected test left uncollected and no artifact that cannot be read."""
119
+ pull-request run that ran no selection (its plan failed, ``run``
120
+ refused it, or the run failed after a good plan), no selected test
121
+ left uncollected and no artifact that cannot be read."""
108
122
  return not (
109
- self.misses
110
- or self.earlier_misses
111
- or self.unlisted_misses
123
+ self.missed
112
124
  or self.check_errors
113
125
  or self.not_collected
126
+ or self.run_failed
127
+ or self.plan_failed
128
+ or self.refused
114
129
  or self.malformed
115
130
  )
116
131
 
@@ -123,6 +138,36 @@ def _read(path: Path) -> dict[str, Any] | None:
123
138
  return data if isinstance(data, dict) else None
124
139
 
125
140
 
141
+ def _plan_read(plan: dict[str, Any] | None) -> dict[str, Any] | None:
142
+ """The parts of a plan the report reads: its counts, whether it was
143
+ planned from a recording and why not, and each unselected target's
144
+ reason. A plan from a recording explains every target, so a large suite
145
+ writes tens of megabytes of it; held whole for every artifact of a day of
146
+ runs it outgrew the runner's memory. Anything not shaped as ``run``
147
+ writes it is kept as it is, for ``build`` to count as malformed."""
148
+ if plan is None:
149
+ return None
150
+ out: dict[str, Any] = {}
151
+ analysis = plan.get("analysis")
152
+ if isinstance(analysis, dict):
153
+ out["analysis"] = {"counts": analysis.get("counts"), "evidence": analysis.get("evidence")}
154
+ elif "analysis" in plan:
155
+ out["analysis"] = analysis
156
+ if "evidence_not_used" in plan:
157
+ out["evidence_not_used"] = plan["evidence_not_used"]
158
+ unselected = plan.get("unselected_targets")
159
+ if isinstance(unselected, list):
160
+ out["unselected_targets"] = [
161
+ {"runner_id": t.get("runner_id"), "reason": t.get("reason")}
162
+ if isinstance(t, dict)
163
+ else t
164
+ for t in unselected
165
+ ]
166
+ elif "unselected_targets" in plan:
167
+ out["unselected_targets"] = unselected
168
+ return out
169
+
170
+
126
171
  def load(directory: str | Path) -> list[Artifact]:
127
172
  root = Path(directory)
128
173
  if not root.is_dir():
@@ -145,7 +190,7 @@ def load(directory: str | Path) -> list[Artifact]:
145
190
  name=art.name,
146
191
  run=run,
147
192
  context=_read(art / "context.json"),
148
- plan=_read(art / "ran.json") or _read(art / "plan.json"),
193
+ plan=_plan_read(_read(art / "ran.json") or _read(art / "plan.json")),
149
194
  verdict=_read(art / "verdict.json"),
150
195
  rerun=_read(art / "rerun-verdict.json"),
151
196
  )
@@ -212,6 +257,9 @@ class _Totals:
212
257
  unlisted: int = 0
213
258
  check_errors: int = 0
214
259
  not_collected: int = 0
260
+ run_failed: int = 0
261
+ plan_failed: int = 0
262
+ refused: int = 0
215
263
 
216
264
 
217
265
  def _add(art: Artifact, context: dict[str, Any], cell: CellReport, totals: _Totals) -> None:
@@ -246,14 +294,24 @@ def _add(art: Artifact, context: dict[str, Any], cell: CellReport, totals: _Tota
246
294
  and context.get("run_exit") == 3
247
295
  )
248
296
  if plan_exit not in (0, 1, 3):
297
+ # No plan, so no test ran: as much a problem as a failed run.
249
298
  cell.plan_failed += 1
299
+ totals.plan_failed += 1
250
300
  elif refused:
251
301
  cell.refused += 1
302
+ totals.refused += 1
252
303
  elif context.get("run_exit") == 3:
253
- # ``run`` exits 3 when pytest did not collect selected targets:
254
- # they did not run.
304
+ # ``run`` exits 3 when pytest did not collect selected targets,
305
+ # or no process loaded the selection plugin: they did not run.
255
306
  cell.not_collected += 1
256
307
  totals.not_collected += 1
308
+ elif context.get("run_exit") not in (0, 1):
309
+ # After a good plan, anything else is a run that did not run the
310
+ # selection: ``run`` refused (exit 2: the working tree differs
311
+ # from the plan's), pytest was interrupted (2) or could not start
312
+ # (4), diffcone crashed. Not a pass.
313
+ cell.run_failed += 1
314
+ totals.run_failed += 1
257
315
  elif context.get("action") == "record":
258
316
  cell.pushes += 1
259
317
  if context.get("checked"):
@@ -338,6 +396,9 @@ def build(artifacts: list[Artifact]) -> Report:
338
396
  check_errors=totals.check_errors,
339
397
  not_collected=totals.not_collected,
340
398
  malformed=malformed,
399
+ run_failed=totals.run_failed,
400
+ plan_failed=totals.plan_failed,
401
+ refused=totals.refused,
341
402
  )
342
403
 
343
404
 
@@ -363,6 +424,7 @@ def to_dict(report: Report) -> dict[str, Any]:
363
424
  "refused": c.refused,
364
425
  "plan_failed": c.plan_failed,
365
426
  "not_collected": c.not_collected,
427
+ "run_failed": c.run_failed,
366
428
  },
367
429
  "pushes": {
368
430
  "runs": c.pushes,
@@ -394,6 +456,9 @@ def to_dict(report: Report) -> dict[str, Any]:
394
456
  "unlisted_misses": report.unlisted_misses,
395
457
  "check_errors": report.check_errors,
396
458
  "not_collected": report.not_collected,
459
+ "run_failed": report.run_failed,
460
+ "plan_failed": report.plan_failed,
461
+ "refused": report.refused,
397
462
  "malformed": report.malformed,
398
463
  }
399
464
 
@@ -421,7 +486,8 @@ def _share(value: float | None) -> str:
421
486
 
422
487
  def to_markdown(report: Report) -> str:
423
488
  lines = [
424
- f"### diffcone report: {'no miss' if report.ok else 'MISSES'}",
489
+ "### diffcone report: "
490
+ + ("no miss" if report.ok else "MISSES" if report.missed else "PROBLEMS"),
425
491
  "",
426
492
  f"{report.runs} workflow run(s) ({report.pull_request_runs} pull request, "
427
493
  f"{report.push_runs} push"
@@ -464,7 +530,28 @@ def to_markdown(report: Report) -> str:
464
530
  if report.not_collected:
465
531
  lines += [
466
532
  f"**{report.not_collected} pull-request run(s) did not run selected tests**: "
467
- "pytest did not collect them (discovery and collection disagree); see the jobs' logs.",
533
+ "pytest did not collect them (discovery and collection disagree), or the command "
534
+ "did not load diffcone's selection plugin; see the jobs' logs.",
535
+ "",
536
+ ]
537
+ if report.plan_failed:
538
+ lines += [
539
+ f"**{report.plan_failed} pull-request run(s) produced no plan**, so they ran no "
540
+ "test; see the jobs' logs.",
541
+ "",
542
+ ]
543
+ if report.refused:
544
+ lines += [
545
+ f"**{report.refused} pull-request run(s) were refused**: discovery may be short of "
546
+ "what pytest collects, and the run was not allowed to go ahead "
547
+ "(allow-incomplete-discovery), so they ran no test; see the jobs' logs.",
548
+ "",
549
+ ]
550
+ if report.run_failed:
551
+ lines += [
552
+ f"**{report.run_failed} pull-request run(s) failed to run the selection** after "
553
+ "a good plan (diffcone run refused, or pytest was interrupted or could not "
554
+ "start); see the jobs' logs.",
468
555
  "",
469
556
  ]
470
557
  if report.malformed:
@@ -480,8 +567,8 @@ def to_markdown(report: Report) -> str:
480
567
  "**Pull requests**",
481
568
  "",
482
569
  "| job | runs | selected (median) | selected (max) | planned from the code "
483
- "| refused | plan failed | selected, not collected |",
484
- "|---|---|---|---|---|---|---|---|",
570
+ "| refused | plan failed | run failed | selected, not collected |",
571
+ "|---|---|---|---|---|---|---|---|---|",
485
572
  ]
486
573
  for c in prs:
487
574
  median = statistics.median(c.selected_shares) if c.selected_shares else None
@@ -491,7 +578,8 @@ def to_markdown(report: Report) -> str:
491
578
  )
492
579
  lines.append(
493
580
  f"| {c.name} | {c.pull_requests} | {_share(median)} | {_share(peak)} | "
494
- f"{from_code} | {c.refused} | {c.plan_failed} | {c.not_collected} |"
581
+ f"{from_code} | {c.refused} | {c.plan_failed} | {c.run_failed} | "
582
+ f"{c.not_collected} |"
495
583
  )
496
584
  lines.append("")
497
585
  pushes = [c for c in report.cells if c.pushes]