9f548a340d
A second project's corpus now renders under /p/<id>/, isolated by its own
slug namespace. Completes step (1) "RFC app supports multiple projects" for
the read path.
- api.py: GET /api/projects/{pid}/rfcs (scoped catalog) + /{slug} (entry by
(project_id,slug)), behind the §22.5 read gate. Unscoped /api/rfcs stay as
default-project compat.
- cache.py: refresh_meta_repo iterates every projects row, mirroring each
content_repo into cached_rfcs stamped with its project_id (_upsert_cached_rfc
gains a project_id arg).
- frontend: api.listRFCs(projectId)/getRFC(projectId,slug); Catalog + RFCView
pass useProjectId(); ProjectLayout's NotServedPlaceholder guard removed (every
project serves), 404/not-readable branch kept; NotServedPlaceholder deleted.
- tests: test_project_scoped_serving.py (catalog scoping, entry isolation,
gated 404); ProjectLayout.test updated (non-default renders). 445 backend +
11 Vitest green; clean build.
Known limitation (next slice): write path + default-id re-stamp not yet scoped
(non-default project read-only); no live impact (no 2nd project in prod yet).
Per docs/superpowers/specs/2026-06-04-m3-backend-planb-design.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
"""§22.4 (Plan B) — per-project RFC serving. A second project's corpus renders
|
|
under its own slug namespace via /api/projects/{pid}/rfcs[/{slug}], isolated
|
|
from the default project and gated by §22.5 visibility."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from test_propose_vertical import ( # noqa: F401
|
|
app_with_fake_gitea, tmp_env, provision_user_row, sign_in_as,
|
|
)
|
|
|
|
|
|
def _add_project(pid, name, vis="public"):
|
|
from app import db
|
|
db.conn().execute(
|
|
"INSERT OR IGNORE INTO projects (id, name, type, content_repo, visibility, initial_state) "
|
|
"VALUES (?, ?, 'document', ?, ?, 'super-draft')",
|
|
(pid, name, pid + "-content", vis),
|
|
)
|
|
|
|
|
|
def _add_rfc(slug, title, pid, state="active"):
|
|
from app import db
|
|
db.conn().execute(
|
|
"INSERT INTO cached_rfcs (slug, title, state, project_id) VALUES (?, ?, ?, ?)",
|
|
(slug, title, state, pid),
|
|
)
|
|
|
|
|
|
def test_catalog_scoped_to_one_project(app_with_fake_gitea):
|
|
app, _ = app_with_fake_gitea
|
|
with TestClient(app) as client:
|
|
_add_project("ecomm", "Ecomm")
|
|
_add_rfc("intro", "Default Intro", "default")
|
|
_add_rfc("intro", "Ecomm Intro", "ecomm")
|
|
_add_rfc("only-ecomm", "Ecomm Only", "ecomm")
|
|
|
|
d = client.get("/api/projects/default/rfcs").json()["items"]
|
|
e = client.get("/api/projects/ecomm/rfcs").json()["items"]
|
|
d_slugs = {i["slug"] for i in d}
|
|
e_slugs = {i["slug"] for i in e}
|
|
assert "intro" in d_slugs and "only-ecomm" not in d_slugs
|
|
assert {"intro", "only-ecomm"} <= e_slugs
|
|
|
|
|
|
def test_entry_is_isolated_by_project(app_with_fake_gitea):
|
|
app, _ = app_with_fake_gitea
|
|
with TestClient(app) as client:
|
|
_add_project("ecomm", "Ecomm")
|
|
_add_rfc("intro", "Default Intro", "default")
|
|
_add_rfc("intro", "Ecomm Intro", "ecomm")
|
|
_add_rfc("only-ecomm", "Ecomm Only", "ecomm")
|
|
|
|
assert client.get("/api/projects/default/rfcs/intro").json()["title"] == "Default Intro"
|
|
assert client.get("/api/projects/ecomm/rfcs/intro").json()["title"] == "Ecomm Intro"
|
|
# a slug that exists only in ecomm 404s under default
|
|
assert client.get("/api/projects/ecomm/rfcs/only-ecomm").status_code == 200
|
|
assert client.get("/api/projects/default/rfcs/only-ecomm").status_code == 404
|
|
|
|
|
|
def test_gated_project_catalog_404s_for_anon(app_with_fake_gitea):
|
|
app, _ = app_with_fake_gitea
|
|
with TestClient(app) as client:
|
|
_add_project("secret", "Secret", vis="gated")
|
|
_add_rfc("hush", "Hush", "secret")
|
|
assert client.get("/api/projects/secret/rfcs").status_code == 404
|
|
assert client.get("/api/projects/secret/rfcs/hush").status_code == 404
|