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
fix(generate): seed --unwritten from model-written pages only (#3811)
Yunus Ozend1b367cfcd37
diff --git a/packages/core/src/repowise/core/generation/page_selection.py b/packages/core/src/repowise/core/generation/page_selection.pyindex 232b7aaaa..cdbdb3410 100644--- a/packages/core/src/repowise/core/generation/page_selection.py+++ b/packages/core/src/repowise/core/generation/page_selection.py@@ -17,6 +17,8 @@ from __future__ import annotationsimport fnmatchfrom dataclasses import dataclass, field+from repowise.core.generation.models import MODEL_WRITTEN_PAGE_TYPES+# Page freshness values that count as "needs refresh" for ``--stale``.## Public because it is the product's one definition of the word. The MCP@@ -109,8 +111,11 @@ def resolve_page_selection(The result is the union of every selector the intent sets:* ``all_pages`` — every existing page.- * ``unwritten`` — every template (deterministic) page, i.e. the pages a- model has not written yet.+ * ``unwritten`` — every model-written page type (``MODEL_WRITTEN_PAGE_TYPES``)+ still stamped template, i.e. the pages a model has not written yet.+ Structural pages are always templates and never written by a model, so+ they are not "unwritten"; seeding them would also make the ``dependents``+ cascade pull in the module pages above them even when those are written.* ``stale`` — every page whose freshness is stale or expired.* ``path_globs`` — every page whose ``target_path`` matches a glob/prefix.* ``page_ids`` — the named ids, when they exist. Names that match no record@@ -122,7 +127,9 @@ def resolve_page_selection(if intent.all_pages:selected.update(by_id)if intent.unwritten:- selected.update(r.page_id for r in records if r.is_template)+ selected.update(+ r.page_id for r in records if r.is_template and r.page_type in MODEL_WRITTEN_PAGE_TYPES+ )if intent.stale:selected.update(r.page_id for r in records if r.is_stale)if intent.path_globs:diff --git a/tests/unit/cli/test_generate_scope.py b/tests/unit/cli/test_generate_scope.pyindex b914d0421..7eefa1c0d 100644--- a/tests/unit/cli/test_generate_scope.py+++ b/tests/unit/cli/test_generate_scope.py@@ -87,17 +87,15 @@ def test_resolve_scope_unwritten_with_cascade_none() -> None:cascade_mode="none",deps=deps,)- # Seeds are the template pages: a.py, module_page:src, repo_overview:demo.+ # Seeds are the model-written template pages: module_page:src and+ # repo_overview:demo. a.py is a structural page, so it is never "unwritten".assert plan.generate_ids == {- "file_page:src/a.py","module_page:src","repo_overview:demo",}- # cascade=none marks the file's containers stale, minus anything regenerated.- # module_page:src is a container of a.py but is itself regenerated, so it is- # not stale. No repo-wide left (overview is regenerated).+ # No file page is seeded, so nothing is marked stale.assert plan.stale_ids == set()- assert plan.seed_count == 3+ assert plan.seed_count == 2class _FakeGroup:@@ -173,9 +171,7 @@ def test_resolve_scope_uses_ranked_seed_verbatim() -> None:PageRecord("file_page:a.py", "file_page", "a.py", is_template=True),PageRecord("file_page:b.py", "file_page", "b.py", is_template=True),]- deps = build_page_dependencies(- module_groups=[], scc_groups=[], repo_wide_ids=()- )+ deps = build_page_dependencies(module_groups=[], scc_groups=[], repo_wide_ids=())# An all-selecting intent would pick both; the ranked seed overrides it.plan = resolve_scope(records=records,diff --git a/tests/unit/generation/test_page_selection.py b/tests/unit/generation/test_page_selection.pyindex db29025d6..9c357cd00 100644--- a/tests/unit/generation/test_page_selection.py+++ b/tests/unit/generation/test_page_selection.py@@ -2,11 +2,23 @@from __future__ import annotations+from dataclasses import dataclass++from repowise.core.generation.cascade import build_page_dependenciesfrom repowise.core.generation.page_selection import (PageRecord,PageSelectionIntent,resolve_page_selection,)+from repowise.core.generation.scope import resolve_scope+++@dataclass(frozen=True)+class _MG:+ """Duck-typed stand-in for selection.ModuleGroup."""++ key: str+ file_paths: tuple[str, ...]def _records() -> list[PageRecord]:@@ -25,16 +37,37 @@ def _records() -> list[PageRecord]:]-def test_unwritten_selects_template_pages_only() -> None:+def test_unwritten_selects_model_written_template_pages_only() -> None:+ # File pages are structural: always templates, never written by a model.result = resolve_page_selection(_records(), PageSelectionIntent(unwritten=True))- assert result.page_ids == {- "file_page:src/a.py",- "file_page:tests/t.py",- "module_page:src",- }+ assert result.page_ids == {"module_page:src"}assert result.unknown_page_ids == ()+def test_unwritten_does_not_pull_written_module_pages_through_the_cascade() -> None:+ # #3205: template file pages used to seed `--unwritten`, and the default+ # `dependents` cascade then regenerated the written module page above them.+ records = [+ PageRecord("file_page:src/a.py", "file_page", "src/a.py", is_template=True),+ PageRecord("file_page:lib/b.py", "file_page", "lib/b.py", is_template=True),+ PageRecord("module_page:src", "module_page", "src", is_template=False),+ PageRecord("module_page:lib", "module_page", "lib", is_template=True),+ PageRecord("repo_overview:demo", "repo_overview", "demo", is_template=False),+ ]+ deps = build_page_dependencies(+ module_groups=[_MG("src", ("src/a.py",)), _MG("lib", ("lib/b.py",))],+ scc_groups=[],+ repo_wide_ids=("repo_overview:demo",),+ )+ plan = resolve_scope(+ records=records,+ intent=PageSelectionIntent(unwritten=True),+ cascade_mode="dependents",+ deps=deps,+ )+ assert plan.generate_ids == {"module_page:lib"}++def test_all_pages_selects_everything() -> None:result = resolve_page_selection(_records(), PageSelectionIntent(all_pages=True))assert len(result) == 5