Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ultrawiki): one backlog number, so the checklist stops contradicting the strip

Ruben Lütkee5ef631243ef
diff --git a/jarvis/ultrawiki/health.py b/jarvis/ultrawiki/health.py
index d45d62a3bd..f115241ec0 100644
--- a/jarvis/ultrawiki/health.py
+++ b/jarvis/ultrawiki/health.py
@@ -40,6 +40,8 @@ from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Literal
+from jarvis.ultrawiki.progress import build_progress
+
__all__ = [
"CheckState",
"HealthCheck",
@@ -55,6 +57,34 @@ CheckState = Literal["ok", "working", "attention", "blocked"]
_SEVERITY: dict[str, int] = {"ok": 0, "working": 1, "attention": 2, "blocked": 3}
+#: What a queue is waiting for, in words a reader recognises. Keyed by
+#: ``progress["next_step"]`` so the checklist and the overview name the same
+#: activity — "still being summarised" must not become "still embedding".
+_STEP_WORDING: dict[str, str] = {
+ "indexing": "being made searchable",
+ "embedding": "being indexed by meaning",
+ "summarising": "being summarised",
+}
+
+
+def _num(value: int) -> str:
+ """4712 → "4 712". Thin-space grouping, the format the checklist already used."""
+ return f"{int(value):,}".replace(",", " ")
+
+
+def _progress_of(status: dict[str, Any]) -> dict[str, Any]:
+ """The shared progress model — never a second derivation.
+
+ Prefers the block the status payload already carries and falls back to
+ deriving it from the same counts, so a caller that hand-builds a status
+ dict (every unit test does) gets identical arithmetic.
+ """
+ progress = status.get("progress")
+ if isinstance(progress, dict) and progress:
+ return progress
+ return build_progress(status.get("counts"))
+
+
def _names(rows: list[dict[str, Any]], limit: int = 3) -> tuple[str, bool]:
"""A readable "A, B and C" plus whether the verb needs a plural.
@@ -271,8 +301,8 @@ def _sources_check(
def _content_check(status: dict[str, Any]) -> HealthCheck:
- counts = dict(status.get("counts") or {})
- total = int(counts.get("total") or 0)
+ progress = _progress_of(status)
+ total = int(progress.get("total") or 0)
if total == 0:
return HealthCheck(
id="content",
@@ -285,15 +315,29 @@ def _content_check(status: dict[str, Any]) -> HealthCheck:
action={"kind": "sync_all"},
facts={"total": 0},
)
- searchable = int(counts.get("keyword_indexed") or 0) + int(
- counts.get("embedded") or 0
- ) + int(counts.get("distilled") or 0)
+ searchable = int(progress.get("searchable") or 0)
+ failed = int(progress.get("failed") or 0)
+ detail = f"{_num(searchable)} of them can be found by searching."
+ if failed:
+ # Named here rather than silently missing from the searchable count:
+ # an item can dead-letter at any stage, so whether it ever reached the
+ # index is genuinely unknown — and a number nobody can explain is how
+ # a settings screen loses its credibility.
+ detail += (
+ f" {_num(failed)} could not be finished and may not be complete."
+ )
return HealthCheck(
id="content",
- title=f"{total:,} item(s) stored".replace(",", " "),
+ title=f"{_num(total)} item(s) stored",
state="ok",
- detail=f"{searchable:,} of them are already searchable.".replace(",", " "),
- facts={"total": total, "searchable": searchable, **counts},
+ detail=detail,
+ facts={
+ "total": total,
+ "searchable": searchable,
+ "summarised": int(progress.get("summarised") or 0),
+ "failed": failed,
+ **dict(progress.get("buckets") or {}),
+ },
)
@@ -301,7 +345,7 @@ def _search_check(status: dict[str, Any]) -> HealthCheck:
legs = dict(status.get("search_legs") or {})
keyword = dict(legs.get("keyword") or {})
vector = dict(legs.get("vector") or {})
- counts = dict(status.get("counts") or {})
+ progress = _progress_of(status)
keyword_ready = bool(keyword.get("available"))
vector_ready = bool(vector.get("available"))
facts = {"keyword": keyword_ready, "vector": vector_ready}
@@ -317,9 +361,7 @@ def _search_check(status: dict[str, Any]) -> HealthCheck:
),
facts=facts,
)
- if int(counts.get("keyword_indexed") or 0) + int(counts.get("embedded") or 0) + int(
- counts.get("distilled") or 0
- ) == 0:
+ if int(progress.get("searchable") or 0) == 0:
return HealthCheck(
id="search",
title="Nothing to search yet",
@@ -353,32 +395,67 @@ def _search_check(status: dict[str, Any]) -> HealthCheck:
def _processing_check(status: dict[str, Any]) -> HealthCheck:
- counts = dict(status.get("counts") or {})
+ """The row that used to lie.
+
+ It read the backlog as ``counts["captured"]`` — items not yet keyword-
+ indexed — while the import strip two centimetres above read it as
+ ``captured + keyword_indexed + embedded``. On a corpus of 4 712 items with
+ 3 237 queued for distillation, the strip said "Processing (3237 pending)"
+ and this row said "Everything is processed. No backlog." Both from the
+ same payload, in the same second. It now takes the ONE backlog number
+ (:mod:`jarvis.ultrawiki.progress`), so "ok" is reachable only when there
+ is genuinely nothing left to do.
+ """
+ progress = _progress_of(status)
pipeline = dict(status.get("pipeline") or {})
- captured = int(counts.get("captured") or 0)
- failed = int(counts.get("failed") or 0)
+ waiting = int(progress.get("waiting") or 0)
+ failed = int(progress.get("failed") or 0)
+ searchable = int(progress.get("searchable") or 0)
state = str(pipeline.get("state") or "")
- facts = {"backlog": captured, "failed": failed, "pipeline_state": state}
+ step = _STEP_WORDING.get(str(progress.get("next_step") or ""), "being processed")
+ facts = {
+ "waiting": waiting,
+ "failed": failed,
+ "pipeline_state": state,
+ "next_step": progress.get("next_step"),
+ **dict(progress.get("waiting_by_bucket") or {}),
+ }
+ backlog_note = (
+ f" {_num(waiting)} item(s) are still {step}." if waiting else ""
+ )
if failed:
return HealthCheck(
id="processing",
- title=f"{failed} item(s) could not be processed",
+ title=f"{_num(failed)} item(s) could not be processed",
state="attention",
detail=(
- "They stay stored and keyword-searchable; only their "
- "summaries are missing. Retrying usually clears them."
+ "They gave up after repeated errors and are missing at least "
+ "their summary. Retrying usually clears them." + backlog_note
+ ),
+ facts=facts,
+ )
+ if waiting and state == "paused":
+ return HealthCheck(
+ id="processing",
+ title=f"{_num(waiting)} item(s) are waiting — processing is paused",
+ state="attention",
+ detail=str(
+ pipeline.get("reason")
+ or "The background pipeline is not running, so the queue is "
+ "standing still."
),
facts=facts,
)
- if captured:
+ if waiting:
return HealthCheck(
id="processing",
- title=f"{captured:,} item(s) still being processed".replace(",", " "),
+ title=f"{_num(waiting)} item(s) still {step}",
state="working",
detail=(
- "Summarising and indexing run in the background. Everything "
- "already processed is searchable now — you do not have to wait."
+ f"This runs in the background. The {_num(searchable)} item(s) "
+ "already processed can be searched right now — you do not "
+ "have to wait for the rest."
),
facts=facts,
)
@@ -498,5 +575,8 @@ def build_health(
return {
"overall": overall,
"usable": usable,
+ # The same numbers the overview draws its bar from. Shipped with the
+ # verdict so a client never has to add up buckets to caption it.
+ "progress": _progress_of(status),
"checks": [c.as_dict() for c in checks],
}
diff --git a/jarvis/ultrawiki/progress.py b/jarvis/ultrawiki/progress.py
new file mode 100644
index 0000000000..d357238bde
--- /dev/null
+++ b/jarvis/ultrawiki/progress.py
@@ -0,0 +1,161 @@
+"""The one honest answer to "how far along is the knowledge base?".
+
+Why this module exists (2026-07-26 forensic). A single screenshot of the Wiki
+section showed, two centimetres apart:
+
+* the import strip: ``Processing (3237 pending)``,
+* the checklist: ``Everything is processed. No backlog.``
+
+Both were computed correctly. They simply did not compute the same thing:
+:func:`jarvis.ultrawiki.service.UltraWikiService._pipeline_state` counted
+``captured + keyword_indexed + embedded`` as the backlog, while
+``health._processing_check`` counted ``captured`` alone. One concept, derived
+twice, no test that could see the disagreement — the exact multi-layer drift
+class the repo keeps re-learning (BUG-008).
+
+So "how far along" is now derived **once**, here, and every surface reads the
+result instead of adding up buckets of its own.
+
+The second half of the same defect was arithmetic, not wiring.
+``uw_items.state`` is a state machine and ``store.counts()`` is a
+``GROUP BY state``, so the five numbers are **mutually exclusive buckets** —
+an item sits in exactly one. Printing them under cumulative-sounding labels
+produced "Keyword-searchable 0" on a corpus where all 4 712 items were
+keyword-searchable (they had simply moved past that bucket), and made the
+numbers appear to run backwards as work progressed. Everything this module
+reports is therefore **cumulative**: how many items have *reached* a
+milestone, never how many are parked on it right now.
+
+Deliberately prose-free. It returns numbers and stable ids; the sentences are
+composed in the UI from translated strings, so the same model serves every
+locale.
+"""
+
+from __future__ import annotations
+
+from collections.abc import Mapping
+from typing import Any, Literal
+
+__all__ = [
+ "MILESTONES",
+ "NEXT_STEP_BY_BUCKET",
+ "ProgressState",
+ "STAGE_ORDER",
+ "build_progress",
+]
+
+#: The pipeline buckets in the order an item travels through them. ``failed``
+#: is not here: it is a dead end reachable from any of these, not a stage.
+STAGE_ORDER: tuple[str, ...] = ("captured", "keyword_indexed", "embedded", "distilled")
+
+#: What an item sitting in a bucket is *waiting for*. An ``embedded`` item is
+#: not "doing embedding" — it is done with that and queued for distillation.
+#: Getting this backwards is how a progress bar ends up one stage optimistic.
+NEXT_STEP_BY_BUCKET: dict[str, str] = {
+ "captured": "indexing",
+ "keyword_indexed": "embedding",
+ "embedded": "summarising",
+}
+
+#: The cumulative milestones the UI draws, outermost first. Each is a superset
+#: of the next, which is what makes a nested bar honest.
+MILESTONES: tuple[str, ...] = ("stored", "searchable", "summarised")
+
+#: ``empty`` — nothing stored yet. ``working`` — items still queued.
+#: ``done`` — every stored item reached the end of the pipeline.
+ProgressState = Literal["empty", "working", "done"]
+
+
+def _int(counts: Mapping[str, Any], key: str) -> int:
+ """A bucket count, tolerant of a missing or malformed status payload.
+
+ ``/api/ultrawiki/status`` answers with ``"counts": {}`` while the service
+ is still starting, and a progress model that raised there would take the
+ whole settings screen down with it.
+ """
+ try:
+ return max(0, int(counts.get(key) or 0))
+ except (TypeError, ValueError):
+ return 0
+
+
+def build_progress(counts: Mapping[str, Any] | None) -> dict[str, Any]:
+ """Turn the per-stage buckets into the cumulative view everything reads.
+
+ Args:
+ counts: the ``counts`` block of the UltraWiki status payload — the
+ five mutually exclusive bucket sizes.
+
+ Returns:
+ A dict with, in cumulative terms:
+
+ ``total``
+ every live item, whatever state it is in.
+ ``searchable``
+ items proven past the keyword-index stage. Findable by exact
+ words right now.
+ ``summarised``
+ items that reached the last stage and have a distillation.
+ ``waiting``
+ items still queued for some stage — the ONE backlog number.
+ ``failed``
+ dead-lettered items. Excluded from ``searchable`` on purpose: an
+ item can dead-letter at any stage, and the counts no longer say
+ which, so claiming it is searchable would be a guess.
+ ``next_step``
+ what the largest waiting bucket is queued for, or ``None``.
+ ``buckets`` / ``waiting_by_bucket``
+ the raw state-machine numbers, for surfaces that genuinely want
+ the state machine (the Contents filter does).
+ """
+ src: Mapping[str, Any] = counts or {}
+ buckets = {name: _int(src, name) for name in STAGE_ORDER}
+ failed = _int(src, "failed")
+ total = sum(buckets.values()) + failed
+
+ # Cumulative, so an item counts toward every milestone it has passed.
+ searchable = buckets["keyword_indexed"] + buckets["embedded"] + buckets["distilled"]
+ summarised = buckets["distilled"]
+
+ waiting_by_bucket = {
+ name: buckets[name] for name in NEXT_STEP_BY_BUCKET if buckets[name]
+ }
+ waiting = sum(waiting_by_bucket.values())
+
+ # Which step the queue is mostly stuck behind. Biggest bucket wins; a tie
+ # goes to the earliest stage, because that is the one holding the rest up.
+ next_step: str | None = None
+ if waiting_by_bucket:
+ busiest = max(
+ waiting_by_bucket,
+ key=lambda name: (waiting_by_bucket[name], -STAGE_ORDER.index(name)),
+ )
+ next_step = NEXT_STEP_BY_BUCKET[busiest]
+
+ state: ProgressState = "empty" if total == 0 else ("working" if waiting else "done")
+
+ return {
+ "state": state,
+ "total": total,
+ "searchable": searchable,
+ "summarised": summarised,
+ "waiting": waiting,
+ "failed": failed,
+ "next_step": next_step,
+ "waiting_by_bucket": waiting_by_bucket,
+ "buckets": {**buckets, "failed": failed},
+ # Ready to draw: each milestone with the count that reached it and its
+ # share of the corpus, so no client divides by zero on an empty store.
+ "milestones": [
+ {
+ "id": name,
+ "reached": reached,
+ "share": (reached / total) if total else 0.0,
+ }
+ for name, reached in (
+ ("stored", total),
+ ("searchable", searchable),
+ ("summarised", summarised),
+ )
+ ],
+ }
diff --git a/jarvis/ultrawiki/service.py b/jarvis/ultrawiki/service.py
index 61c66a70ce..876e59a1f3 100644
--- a/jarvis/ultrawiki/service.py
+++ b/jarvis/ultrawiki/service.py
@@ -39,6 +39,7 @@ from dataclasses import dataclass, field
from datetime import UTC, datetime
from typing import Any
+from jarvis.ultrawiki.progress import build_progress
from jarvis.ultrawiki.types import (
ConnectorContext,
ConsentState,
@@ -550,8 +551,13 @@ class UltraWikiService:
# Every slot probe walks credentials (keyring / .env) or an endpoint —
# all three go to a worker thread together, never on the event loop.
slots = await asyncio.to_thread(self._slot_statuses)
+ # ONE derivation of "how far along" for every surface that asks (the
+ # strip, the checklist, the overview). See jarvis/ultrawiki/progress.py
+ # for the screenshot that made a second derivation unacceptable.
+ counts_payload = _counts_dict(counts)
+ progress = build_progress(counts_payload)
state, reason = self._pipeline_state(
- counts, sources, slots, running=pipeline_running
+ progress, sources, slots, running=pipeline_running
)
return {
"enabled": self._uw_enabled(),
@@ -564,7 +570,8 @@ class UltraWikiService:
},
"slots": slots,
"vector": vector,
- "counts": _counts_dict(counts),
+ "counts": counts_payload,
+ "progress": progress,
"pipeline": {
"running": pipeline_running,
"state": state,
@@ -587,7 +594,7 @@ class UltraWikiService:
def _pipeline_state(
self,
- counts: PipelineCounts,
+ progress: dict[str, Any],
sources: list[dict[str, Any]],
slots: dict[str, Any],
*,
@@ -601,6 +608,11 @@ class UltraWikiService:
being done, so the strip states which of the four situations holds:
nothing approved yet, nothing left to do, actually processing, or
blocked on a slot. ``running`` is still reported separately.
+
+ Takes the shared progress model rather than raw counts: the backlog
+ this function reports and the backlog the checklist reports must be
+ the same number, and the only way to guarantee that is to have one
+ function produce it (:mod:`jarvis.ultrawiki.progress`).
"""
approved = [
source
@@ -608,11 +620,12 @@ class UltraWikiService:
if str(source.get("consent") or "") == ConsentState.APPROVED.value
and bool(source.get("enabled"))
]
- pending_keyword = int(counts.captured)
- pending_embed = int(counts.keyword_indexed)
- pending_distill = int(counts.embedded)
- backlog = pending_keyword + pending_embed + pending_distill
- failed = int(counts.failed)
+ waiting = dict(progress.get("waiting_by_bucket") or {})
+ pending_keyword = int(waiting.get("captured") or 0)
+ pending_embed = int(waiting.get("keyword_indexed") or 0)
+ pending_distill = int(waiting.get("embedded") or 0)
+ backlog = int(progress.get("waiting") or 0)
+ failed = int(progress.get("failed") or 0)
failed_note = (
f" {failed} item(s) gave up after repeated errors — use "
"'retry failed items' once the cause is fixed."
diff --git a/tests/unit/ultrawiki/test_health.py b/tests/unit/ultrawiki/test_health.py
index 140737a887..2eb51784b4 100644
--- a/tests/unit/ultrawiki/test_health.py
+++ b/tests/unit/ultrawiki/test_health.py
@@ -17,7 +17,14 @@ from jarvis.ultrawiki.health import build_health
def _status(**overrides: Any) -> dict[str, Any]:
- """A healthy, fully-imported install; tests override one thing at a time."""
+ """A healthy, fully-imported install; tests override one thing at a time.
+
+ The counts are per-stage buckets an item sits in EXACTLY ONE of, so
+ "fully processed" means every item has arrived in ``distilled``. This
+ fixture used to spread them over three stages and still assert that every
+ check was green — which is precisely the reading error that let the
+ checklist call an 80-item backlog "Everything is processed".
+ """
base: dict[str, Any] = {
"enabled": True,
"started": True,
@@ -25,9 +32,9 @@ def _status(**overrides: Any) -> dict[str, Any]:
"backend_in_use": "sqlite",
"counts": {
"captured": 0,
- "keyword_indexed": 40,
- "embedded": 40,
- "distilled": 20,
+ "keyword_indexed": 0,
+ "embedded": 0,
+ "distilled": 100,
"failed": 0,
"total": 100,
},
@@ -312,9 +319,9 @@ def test_failed_items_do_not_hide_that_the_rest_works():
_status(
counts={
"captured": 0,
- "keyword_indexed": 90,
- "embedded": 90,
- "distilled": 80,
+ "keyword_indexed": 0,
+ "embedded": 0,
+ "distilled": 90,
"failed": 10,
"total": 100,
}
@@ -323,8 +330,15 @@ def test_failed_items_do_not_hide_that_the_rest_works():
)
check = _check(health, "processing")
assert check["state"] == "attention"
- assert "keyword-searchable" in check["detail"]
+ assert "10" in check["title"]
+ # NOT "they stay keyword-searchable": an item can dead-letter at any
+ # stage, including before it was ever indexed, so the counts cannot prove
+ # that. The row promises only what it can show.
+ assert "keyword-searchable" not in check["detail"]
assert health["usable"] is True
+ # The 10 are named where the corpus is described, instead of quietly
+ # thinning the searchable number by ten with no explanation.
+ assert "10" in _check(health, "content")["detail"]
@pytest.mark.parametrize(
diff --git a/tests/unit/ultrawiki/test_progress.py b/tests/unit/ultrawiki/test_progress.py
new file mode 100644
index 0000000000..e2e806d43a
--- /dev/null
+++ b/tests/unit/ultrawiki/test_progress.py
@@ -0,0 +1,188 @@
+"""The cumulative progress model, and the contradiction it exists to prevent.
+
+The anchor case throughout this file is the 2026-07-26 screenshot: a live
+corpus of 4 712 items where the import strip said "Processing (3237 pending)"
+while the checklist directly below said "Everything is processed. No backlog."
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from jarvis.ultrawiki import health as health_mod
+from jarvis.ultrawiki.progress import build_progress
+
+#: The exact count vector from the screenshot that started this work.
+SCREENSHOT_COUNTS = {
+ "captured": 0,
+ "keyword_indexed": 0,
+ "embedded": 3237,
+ "distilled": 1475,
+ "failed": 0,
+ "total": 4712,
+}
+
+
+def test_buckets_add_up_to_the_corpus():
+ progress = build_progress(SCREENSHOT_COUNTS)
+ assert progress["total"] == 4712
+
+
+def test_searchable_is_cumulative_not_the_bucket():
+ """The "Keyword-searchable 0" defect: 0 items sit in that bucket, and all
+ 4 712 are past it."""
+ progress = build_progress(SCREENSHOT_COUNTS)
+ assert progress["searchable"] == 4712
+ assert progress["buckets"]["keyword_indexed"] == 0
+
+
+def test_waiting_counts_every_unfinished_stage():
+ progress = build_progress(SCREENSHOT_COUNTS)
+ assert progress["waiting"] == 3237
+ assert progress["state"] == "working"
+
+
+def test_next_step_names_what_the_queue_waits_for_not_what_it_finished():
+ """An ``embedded`` item is done embedding and queued for distillation."""
+ progress = build_progress(SCREENSHOT_COUNTS)
+ assert progress["next_step"] == "summarising"
+
+
+def test_next_step_prefers_the_earliest_stage_on_a_tie():
+ progress = build_progress(
+ {"captured": 5, "keyword_indexed": 5, "embedded": 5, "distilled": 0}
+ )
+ assert progress["next_step"] == "indexing"
+
+
+def test_milestones_are_nested_subsets():
+ progress = build_progress(
+ {"captured": 10, "keyword_indexed": 20, "embedded": 30, "distilled": 40}
+ )
+ reached = [m["reached"] for m in progress["milestones"]]
+ assert reached == [100, 90, 40]
+ assert reached == sorted(reached, reverse=True)
+
+
+def test_failed_items_are_never_claimed_as_searchable():
+ """An item can dead-letter at any stage, so the counts cannot prove it
+ ever reached the index. Claiming otherwise would be a guess."""
+ progress = build_progress({"captured": 0, "distilled": 10, "failed": 5})
+ assert progress["total"] == 15
+ assert progress["searchable"] == 10
+ assert progress["waiting"] == 0
+
+
+def test_empty_and_malformed_payloads_do_not_raise():
+ for payload in (None, {}, {"captured": "nonsense"}, {"embedded": -4}):
+ progress = build_progress(payload)
+ assert progress["total"] >= 0
+ assert progress["state"] in {"empty", "working", "done"}
+ assert build_progress({})["state"] == "empty"
+
+
+def test_a_fully_drained_store_is_done():
+ progress = build_progress({"distilled": 12})
+ assert progress["state"] == "done"
+ assert progress["waiting"] == 0
+ assert progress["next_step"] is None
+
+
+# ---------------------------------------------------------------------------
+# Cross-surface parity — the actual bug
+# ---------------------------------------------------------------------------
+
+
+def _status(counts: dict[str, int], pipeline_state: str = "processing") -> dict:
+ progress = build_progress(counts)
+ return {
+ "enabled": True,
+ "started": True,
+ "counts": counts,
+ "progress": progress,
+ "pipeline": {"running": True, "state": pipeline_state, "reason": ""},
+ "sources": [
+ {
+ "id": "s1",
+ "label": "A source",
+ "consent": "approved",
+ "enabled": True,
+ "last_sync_at": "2026-07-26T09:00:00Z",
+ }
+ ],
+ "search_legs": {
+ "keyword": {"available": True},
+ "vector": {"available": True},
+ },
+ "slots": {},
+ "degradations": [],
+ }
+
+
+def test_the_checklist_no_longer_claims_everything_is_processed():
+ """The regression. Same payload, same second — the two lines agreed on
+ "3237 pending" and "no backlog" before this test existed."""
+ health = health_mod.build_health(_status(SCREENSHOT_COUNTS), [])
+ row = next(c for c in health["checks"] if c["id"] == "processing")
+
+ assert row["state"] == "working"
+ assert "3 237" in row["title"]
+ assert "summarised" in row["title"]
+ assert "Everything is processed" not in row["title"]
+
+
+def test_the_checklist_and_the_strip_report_the_same_backlog():
+ status = _status(SCREENSHOT_COUNTS)
+ health = health_mod.build_health(status, [])
+ row = next(c for c in health["checks"] if c["id"] == "processing")
+ assert row["facts"]["waiting"] == status["progress"]["waiting"]
+
+
+ "counts",
+ [
+ {"captured": 100},
+ {"keyword_indexed": 7},
+ {"embedded": 3237, "distilled": 1475},
+ {"captured": 1, "keyword_indexed": 1, "embedded": 1, "distilled": 1},
+ ],
+)
+def test_processing_is_never_ok_while_anything_is_queued(counts):
+ """The invariant that kills this bug class: a non-empty queue can never
+ produce a green processing row, whatever the mix of stages."""
+ health = health_mod.build_health(_status(counts), [])
+ row = next(c for c in health["checks"] if c["id"] == "processing")
+ assert row["state"] != "ok"
+
+
+def test_processing_is_ok_only_when_the_queue_is_genuinely_empty():
+ health = health_mod.build_health(_status({"distilled": 9}, "idle"), [])
+ row = next(c for c in health["checks"] if c["id"] == "processing")
+ assert row["state"] == "ok"
+
+
+def test_a_paused_pipeline_with_a_backlog_asks_for_attention():
+ health = health_mod.build_health(_status({"embedded": 40}, "paused"), [])
+ row = next(c for c in health["checks"] if c["id"] == "processing")
+ assert row["state"] == "attention"
+ assert "40" in row["title"]
+
+
+def test_the_content_row_reports_the_cumulative_searchable_count():
+ health = health_mod.build_health(_status(SCREENSHOT_COUNTS), [])
+ row = next(c for c in health["checks"] if c["id"] == "content")
+ assert "4 712 item(s) stored" == row["title"]
+ assert "4 712" in row["detail"]
+
+
+def test_failed_items_are_named_in_the_content_row_instead_of_vanishing():
+ health = health_mod.build_health(_status({"distilled": 10, "failed": 3}, "idle"), [])
+ row = next(c for c in health["checks"] if c["id"] == "content")
+ assert row["facts"]["searchable"] == 10
+ assert "3" in row["detail"]
+
+
+def test_health_ships_the_progress_block_for_the_overview():
+ health = health_mod.build_health(_status(SCREENSHOT_COUNTS), [])
+ assert health["progress"]["waiting"] == 3237
+ assert health["progress"]["searchable"] == 4712