fix(§22/G-15): make the branch/edit/body subsystem three-tier aware (v0.53.0)

§22 migrated the READ/catalog path to the three-tier (project/collection)
model but the WRITE/branch/body subsystem still hardcoded the default
project's default collection — resolving every meta-resident entry to the
default content repo at rfcs/<slug>.md, ignoring the entry's project (its own
content repo) and collection (a <subfolder>/rfcs/ prefix). An entry outside
the default collection rendered a blank canonical body and every edit/PR/
body-write path hit the wrong file.

- New single resolver: projects.content_repo_for_collection() +
  projects.entry_location(config, cid, slug) -> (org, repo, md_path)
  (collection -> project -> content_repo + subfolder; falls back to the
  default repo for a legacy/unknown collection).
- Every entry write/read path resolves via it: api_branches (body GET + all
  branch write paths), api_prs (pr-draft/open/merge/withdraw/review/
  resolution-branch), api_graduation (graduate/claim/retire/unretire +
  orchestrator + state-flip), api.py mark-reviewed + idea-PR merge/decline/
  withdraw + proposal preview, api_metadata. bot.open_metadata_pr and
  bot.mark_entry_reviewed gained a file_path param. refresh_meta_branches,
  the webhook corpus-refresh dispatch, and the hygiene branch-delete now
  span every project's content repo, not just the default.
- New additive collection-scoped body-read routes:
  GET /api/projects/{pid}/collections/{cid}/rfcs/{slug}/main and
  .../branches/{branch} disambiguate a slug across collections (G-5) and read
  the entry's own repo. Slug-only routes kept (now collection-aware via the
  cached row). Frontend getRFCMain/getBranch take optional pid+cid; RFCView
  threads them (mirrors the v0.52.1 entry-detail fix).

No migration, no config change. Existing default-collection entries
unaffected. Tests: backend resolver + collection-scoped branch/body + graduate-
in-subfolder write path; frontend api unit. backend 677 / frontend 60 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-08 22:39:46 -07:00
parent afa8d26378
commit 4e7410f90b
18 changed files with 720 additions and 152 deletions
+108
View File
@@ -0,0 +1,108 @@
"""G-15 — the §22 three-tier write-path resolver.
`projects.content_repo_for_collection` and `projects.entry_location` resolve an
entry's git location (org, content_repo, md_path) from its *collection*
(collection → project → content_repo, plus the collection subfolder) instead of
the deployment default. This is the keystone the branch/edit/body/graduation
write paths share so an entry outside the default project's default collection
reads/writes the correct file.
"""
from __future__ import annotations
import tempfile
from pathlib import Path
from app import collections as collections_mod, db, projects as projects_mod
from app.config import Config
def _db() -> Config:
cfg = Config(
gitea_url="x", gitea_bot_user="x", gitea_bot_token="x", gitea_org="wiggleverse",
registry_repo="registry", oauth_client_id="x",
oauth_client_secret="x", app_url="x", secret_key="x",
database_path=Path(tempfile.mkdtemp(prefix="g15loc-")) / "t.db",
owner_gitea_login="x", webhook_secret="x",
)
db.run_migrations(cfg)
if db._CONN is not None:
db._CONN.close()
db._CONN = None
db.init(cfg)
return cfg
def _seed():
# Default project (its content_repo is the deployment default) + a second
# project with a DISTINCT content_repo, each with a default + a named
# (subfolder) collection.
db.conn().execute(
"INSERT OR REPLACE INTO projects (id, name, content_repo, visibility, updated_at) "
"VALUES ('default','Default','meta','public', datetime('now'))")
db.conn().execute(
"INSERT OR REPLACE INTO projects (id, name, content_repo, visibility, updated_at) "
"VALUES ('rfc-app','RFC App','rfc-app-content','public', datetime('now'))")
rows = [
("default", "default", ""),
("features", "default", "features"),
("rfc-app", "rfc-app", ""),
("specs", "rfc-app", "specs"),
]
for cid, pid, sub in rows:
db.conn().execute(
"INSERT OR REPLACE INTO collections (id, project_id, type, subfolder, "
"initial_state, visibility, created_at, updated_at) VALUES "
"(?,?, 'document', ?, 'super-draft','public', datetime('now'), datetime('now'))",
(cid, pid, sub))
def test_content_repo_for_collection_resolves_per_project():
_db()
_seed()
# Default project's collections → the default content repo.
assert projects_mod.content_repo_for_collection("default") == "meta"
assert projects_mod.content_repo_for_collection("features") == "meta"
# The second project's collections → its own content repo.
assert projects_mod.content_repo_for_collection("rfc-app") == "rfc-app-content"
assert projects_mod.content_repo_for_collection("specs") == "rfc-app-content"
def test_content_repo_for_collection_unknown_is_none():
_db()
_seed()
assert projects_mod.content_repo_for_collection("nope") is None
def test_entry_location_default_collection_repo_root():
cfg = _db()
_seed()
org, repo, path = projects_mod.entry_location(cfg, "default", "alpha")
assert (org, repo, path) == ("wiggleverse", "meta", "rfcs/alpha.md")
def test_entry_location_named_collection_uses_subfolder():
cfg = _db()
_seed()
org, repo, path = projects_mod.entry_location(cfg, "features", "beta")
assert (org, repo, path) == ("wiggleverse", "meta", "features/rfcs/beta.md")
def test_entry_location_other_project_distinct_repo():
cfg = _db()
_seed()
# Named collection in a non-default project: distinct repo AND subfolder.
org, repo, path = projects_mod.entry_location(cfg, "specs", "gamma")
assert (org, repo, path) == ("wiggleverse", "rfc-app-content", "specs/rfcs/gamma.md")
# Default collection of the non-default project: distinct repo, repo root.
org, repo, path = projects_mod.entry_location(cfg, "rfc-app", "delta")
assert (org, repo, path) == ("wiggleverse", "rfc-app-content", "rfcs/delta.md")
def test_entry_location_unknown_collection_falls_back_to_default_repo():
cfg = _db()
_seed()
# An entry whose collection_id is missing/unknown must still resolve to a
# usable location (the deployment default repo, repo root) rather than an
# empty repo — the legacy single-corpus behaviour.
org, repo, path = projects_mod.entry_location(cfg, "nope", "epsilon")
assert (org, repo, path) == ("wiggleverse", "meta", "rfcs/epsilon.md")