fix(codegen): make apply reach its fixed point by deriving search pat…
…hs once
codegen apply could never finish. It writes, re-plans to verify, and the re-plan always reported the same file as still changed:
codegen apply did not reach a fixed point: <root>/pyproject.toml
Two owners derived the analyzer search path from different inputs, so the render and the post-write sync could not agree:
rendered mypy_path = ["src", ".", "scripts"] <- every configured shared path
on disk mypy_path = ["src", "."] <- only the ones that exist
resolve_tooling_context seeded declared_roots with (source_dir, *project_shared_search_paths) unconditionally, while pyrefly_search_paths — which the ExtraPaths sync runs after the write — keeps a shared path only when (project_dir / path).is_dir(). A project without a scripts/ directory therefore drifted on every single run, forever.
The comment above that code already stated the intent — "prefer derivation so the template matches post-write ExtraPaths sync" — it just never applied the sync's own rule. It does now: a shared path belongs to the project when the scaffold declares it or the tree already has it. The project root is included by definition rather than by is_dir(), because on the first render the directory does not exist yet and dropping it produced the mirror-image drift (["src"] written against ["src", "."] rendered).
One more template was missing from the same batch-apply loss as the previous commit, and it took ten tests with it:
template source is missing or escapes its root: base/gitmodules.j2
tests/unit/codegen/test_codegen_setup_submodules.py 15 errors -> 16 passed
make gen WHAT=check -> exit 0
make check -> exit 0
suite -> 74 failed -> 28 failed
The 28 that remain are a different defect, reported separately: the detector builds WorkspaceSpec without project, so _project_render_context refuses every detected (as opposed to scaffolded) workspace with "workspace has no project metadata".
Claude-Session: https://claude.ai/code/session_015KsQxff1Aa5SZ18cSron71
Summary by cubic
Fixes codegen apply so it reaches a fixed point instead of re-reporting the same pyproject.toml as changed on every run. Render and post-write sync now derive analyzer search paths with the same rule, so a project without a scripts/ directory no longer drifts. Also restores the missing base/gitmodules.j2 template.
Bug Fixes
- A shared search path is kept only when the scaffold declares it or the directory already exists; the project root is always included.
- The restored template emits only mutable first-party governed members; external and fork paths remain read-only facts.
- Submodule tests and
make checkpass again.
Known issue
- Detected workspaces still fail because
WorkspaceSpecis built withoutproject; that is being handled separately.