Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
"""The progress totals announced by ``_GenerationRun._announce_total``.
Regression for issue #922: the up-front total omitted the level-8 onboarding
pages (the non-promoted slots), so the bar could report more pages completed
than its total (e.g. "43 of 41"). The estimate must include one slot per
registered onboarding spec that has not already been generated, gated by
``config.enable_onboarding``.
The total is now announced as two, one per cost tier — free template renders
on the main bar, model-backed pages on ``generation.llm`` — because a single
bar spanning both runs the cheap levels first and then sits at ~97% for the
rest of the run. #922's requirement is unchanged and asserted here against
their sum: onboarding slots must still be counted, they are simply counted on
the paid bar now.
"""
from __future__ import annotations
from types import SimpleNamespace
from repowise.core.generation import onboarding as _onboarding
from repowise.core.generation.models import compute_page_id
from repowise.core.generation.page_generator.orchestrate import _GenerationRun
def _selection() -> SimpleNamespace:
"""A selection with a single file page and nothing else, so the onboarding
contribution is the only moving part of the total."""
return SimpleNamespace(
counts=lambda: {
"api_contract": 0,
"symbol_spotlight": 0,
"file_page": 1,
"scc_page": 0,
"module_page": 0,
"infra_page": 0,
},
emit_repo_overview=False,
emit_arch_diagram=False,
deterministic_tail_paths=[],
)
def _fake_run(*, enable_onboarding: bool, completed_ids: set[str]) -> SimpleNamespace:
announced: list[int] = []
paid: list[tuple[str, int]] = []
return SimpleNamespace(
selection=_selection(),
kg_ctx=SimpleNamespace(available=False),
config=SimpleNamespace(enable_onboarding=enable_onboarding),
completed_ids=completed_ids,
# None: the selection-derived total path (a scoped run short-circuits
# to len(only_page_ids), tested in test_deterministic_generation).
only_page_ids=None,
on_total_known=announced.append,
on_subphase=lambda name, total: paid.append((name, total)),
job_system=None,
job_id=None,
_announced=announced,
_paid=paid,
)
def _paid_total(run: SimpleNamespace) -> int:
"""The count announced for the model-backed bar, or 0 when it never starts."""
return sum(total for name, total in run._paid if name == "generation.llm")
def test_total_includes_onboarding_pages() -> None:
specs = _onboarding.iter_specs()
assert specs, "expected onboarding subkinds to be registered on import"
run = _fake_run(enable_onboarding=True, completed_ids=set())
_GenerationRun._announce_total(run)
(free_total,) = run._announced
# 1 file page + one page per registered onboarding slot, across both bars.
assert free_total + _paid_total(run) == 1 + len(specs)
def test_the_tiers_are_split_by_cost_not_by_level() -> None:
"""The free bar must carry only pages that cost nothing.
A slot landing on the free bar would leave it unable to reach the
denominator, which is the arithmetic this split exists to fix.
"""
specs = _onboarding.iter_specs()
run = _fake_run(enable_onboarding=True, completed_ids=set())
_GenerationRun._announce_total(run)
(free_total,) = run._announced
assert free_total == 1, "only the file page is free"
assert _paid_total(run) == len(specs)
def test_onboarding_disabled_excludes_those_pages() -> None:
run = _fake_run(enable_onboarding=False, completed_ids=set())
_GenerationRun._announce_total(run)
(free_total,) = run._announced
assert free_total == 1
# Nothing model-backed remains, so that bar is never started rather than
# sitting at 0 for the whole run.
assert run._paid == []
def test_already_generated_onboarding_pages_are_not_recounted() -> None:
specs = _onboarding.iter_specs()
done = {compute_page_id("onboarding", _onboarding.target_path(specs[0].slot))}
run = _fake_run(enable_onboarding=True, completed_ids=done)
_GenerationRun._announce_total(run)
(free_total,) = run._announced
# The one already-completed slot drops out of the remaining total, and it
# drops out of the paid tier specifically — the free bar is untouched by a
# resumed onboarding page.
assert free_total == 1
assert _paid_total(run) == len(specs) - 1