§22 S2: collection-scoped list/get/propose endpoints

Refactor the project-scoped serve/propose internals into collection-grained
helpers (_list_rfcs_for_collection, _get_rfc_for_collection,
_propose_into_collection); add routes under
/api/projects/<id>/collections/<cid>/rfcs[/<slug>|/propose]. Propose writes
the entry under the target collection's <subfolder>/rfcs via a new rfcs_dir
param on bot.open_idea_pr. Default-collection routes preserved as wrappers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-05 13:05:58 -07:00
parent 91b0fb358c
commit f57d4080dc
3 changed files with 149 additions and 22 deletions
@@ -75,3 +75,67 @@ def test_mirror_keys_entries_by_collection():
got = {(r["collection_id"], r["slug"]) for r in
db.conn().execute("SELECT collection_id, slug FROM cached_rfcs")}
assert got == {("default", "a"), ("features", "b")}
# --- collection-scoped serve + propose (full app) -----------------------------
from fastapi.testclient import TestClient # noqa: E402
from test_propose_vertical import ( # noqa: E402,F401
app_with_fake_gitea, tmp_env, provision_user_row, sign_in_as,
)
def _add_features_collection(content_repo="meta"):
"""Add a named 'features' collection (subfolder 'features') under the seeded
default project, plus a single entry under features/rfcs/ in the db cache."""
db.conn().execute(
"INSERT OR REPLACE INTO collections (id, project_id, type, subfolder, "
"initial_state, visibility, name, created_at, updated_at) VALUES "
"('features','default','document','features','super-draft','public','Features', "
"datetime('now'), datetime('now'))")
def test_scoped_list_returns_only_that_collection(app_with_fake_gitea):
app, fake = app_with_fake_gitea
with TestClient(app) as client:
_add_features_collection()
# Seed one entry under each collection's rfcs dir + mirror them in.
fake.files[("wiggleverse", "meta", "main", "rfcs/a.md")] = {
"content": _entry_md("a", "Default A"), "sha": "sa"}
fake.files[("wiggleverse", "meta", "main", "features/rfcs/b.md")] = {
"content": _entry_md("b", "Feature B"), "sha": "sb"}
from app import cache as cache_mod, gitea as gitea_mod
from app.config import load_config
cfg = load_config()
asyncio.run(cache_mod.refresh_meta_repo(cfg, gitea_mod.Gitea(cfg)))
r = client.get("/api/projects/default/collections/features/rfcs")
assert r.status_code == 200, r.text
assert [i["slug"] for i in r.json()["items"]] == ["b"]
# The default collection still serves only its own entry.
r2 = client.get("/api/projects/default/collections/default/rfcs")
assert [i["slug"] for i in r2.json()["items"]] == ["a"]
def test_scoped_propose_writes_into_collection_subfolder(app_with_fake_gitea):
app, fake = app_with_fake_gitea
with TestClient(app) as client:
_add_features_collection()
provision_user_row(user_id=3, login="alice", role="contributor")
sign_in_as(client, user_id=3, gitea_login="alice", display_name="Alice",
role="contributor", email="alice@test")
r = client.post(
"/api/projects/default/collections/features/rfcs/propose",
json={"title": "New B", "slug": "newb", "pitch": "x", "tags": []})
assert r.status_code == 200, r.text
# The bot wrote the entry under features/rfcs/, not rfcs/.
keys = {(k[1], k[3]) for k in fake.files
if k[1] == "meta" and k[3].endswith("newb.md")}
assert ("meta", "features/rfcs/newb.md") in keys
def test_scoped_routes_404_for_collection_outside_project(app_with_fake_gitea):
app, _ = app_with_fake_gitea
with TestClient(app) as client:
r = client.get("/api/projects/default/collections/nope/rfcs")
assert r.status_code == 404