Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/870.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed `ref doctor` producing a different report on each run.
Diagnostics that share a name were ordered by set iteration order, so two identical runs disagreed.
6 changes: 3 additions & 3 deletions packages/climate-ref-core/src/climate_ref_core/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def label(self) -> str:
return f"{self.name} ({self.provider_slug})"

@property
def sort_key(self) -> str:
"""Sort by provider then name."""
return f"{self.provider_slug}/{self.name}"
def sort_key(self) -> tuple[str, str, str]:
"""Sort by provider, then name, then slug. Several diagnostics can share a name."""
return (self.provider_slug, self.name, self.slug)


@frozen
Expand Down
11 changes: 11 additions & 0 deletions packages/climate-ref-core/tests/unit/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,17 @@ def test_diagnostics_tracked_per_variable(self, simple_provider):
assert ref.provider_slug == "test-provider"
assert ref.label == "Simple Diagnostic (test-provider)"

def test_sort_key_breaks_ties_on_slug(self):
"""Several diagnostics can share a name, so the slug has to settle the order."""
shared = [
DiagnosticReference(name="Ozone Diagnostics", slug=slug, provider_slug="esmvaltool")
for slug in ("ozone-sh-oct", "ozone-annual-cycle", "ozone-nh-mar")
]

ordered = sorted(shared, key=lambda r: r.sort_key)

assert [r.slug for r in ordered] == ["ozone-annual-cycle", "ozone-nh-mar", "ozone-sh-oct"]

def test_empty_providers(self):
result = collect_by_source_type([])
assert result == []
Expand Down
2 changes: 1 addition & 1 deletion packages/climate-ref/src/climate_ref/doctor/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def register_check(registered: RegisteredCheck) -> None:
------
ValueError
If another check already claims the same slug. Two checks sharing a slug would be
indistinguishable in the output and in ``--only``.
indistinguishable in the report.
"""
existing = _REGISTRY.get(registered.slug)
if existing is not None:
Expand Down
Loading