fix: report total counts in wf status
This commit is contained in:
@@ -42,7 +42,7 @@ async def _fetch_status_data(context: CliContext) -> dict[str, Any]:
|
|||||||
if isinstance(item, dict) and isinstance(item.get("name"), str)
|
if isinstance(item, dict) and isinstance(item.get("name"), str)
|
||||||
]
|
]
|
||||||
workflow = {
|
workflow = {
|
||||||
"capability_count": len(items),
|
"capability_count": _payload_count(capabilities, "capabilities"),
|
||||||
"sample_capabilities": names[:5],
|
"sample_capabilities": names[:5],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ async def _fetch_sources(context: CliContext) -> dict[str, Any]:
|
|||||||
]
|
]
|
||||||
return {
|
return {
|
||||||
"available": True,
|
"available": True,
|
||||||
"source_count": len(sources),
|
"source_count": _payload_count(payload, "sources"),
|
||||||
"sample_sources": source_ids[:5],
|
"sample_sources": source_ids[:5],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,10 +112,19 @@ async def _fetch_registry(context: CliContext) -> dict[str, Any]:
|
|||||||
return _unavailable(exc)
|
return _unavailable(exc)
|
||||||
return {
|
return {
|
||||||
"available": True,
|
"available": True,
|
||||||
"entry_count": len(payload.get("entries", [])),
|
"entry_count": _payload_count(payload, "entries"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _payload_count(payload: dict[str, Any], items_key: str) -> int:
|
||||||
|
"""Prefer a paged API's total count, falling back to the current page size."""
|
||||||
|
total = payload.get("total")
|
||||||
|
if isinstance(total, int):
|
||||||
|
return total
|
||||||
|
items = payload.get(items_key, [])
|
||||||
|
return len(items) if isinstance(items, list) else 0
|
||||||
|
|
||||||
|
|
||||||
def _unavailable(exc: Exception) -> dict[str, Any]:
|
def _unavailable(exc: Exception) -> dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
"available": False,
|
"available": False,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import json
|
|||||||
from typer.testing import CliRunner
|
from typer.testing import CliRunner
|
||||||
|
|
||||||
from wf_cli.app import app
|
from wf_cli.app import app
|
||||||
|
from wf_cli.commands.status import _payload_count
|
||||||
|
|
||||||
|
|
||||||
def test_wf_status_local_static_target(tmp_path) -> None:
|
def test_wf_status_local_static_target(tmp_path) -> None:
|
||||||
@@ -46,3 +47,15 @@ def test_wf_status_local_static_target(tmp_path) -> None:
|
|||||||
assert payload["sources"]["source_count"] >= 1
|
assert payload["sources"]["source_count"] >= 1
|
||||||
assert payload["admin"]["available"] is True
|
assert payload["admin"]["available"] is True
|
||||||
assert payload["registry"]["available"] is False
|
assert payload["registry"]["available"] is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_status_count_prefers_paged_total() -> None:
|
||||||
|
payload = {"total": 91, "capabilities": [{"name": "first"}]}
|
||||||
|
|
||||||
|
assert _payload_count(payload, "capabilities") == 91
|
||||||
|
|
||||||
|
|
||||||
|
def test_status_count_falls_back_to_page_length_without_total() -> None:
|
||||||
|
payload = {"capabilities": [{"name": "first"}, {"name": "second"}]}
|
||||||
|
|
||||||
|
assert _payload_count(payload, "capabilities") == 2
|
||||||
|
|||||||
Reference in New Issue
Block a user