diff --git a/backend/app/api.py b/backend/app/api.py index 332a8bb..3c5df1c 100644 --- a/backend/app/api.py +++ b/backend/app/api.py @@ -827,10 +827,16 @@ def make_router( if idea_clash: raise HTTPException(409, f"Slug `{slug}` is already reserved by an open proposal") + # §22.4b: the target project's landing state. Through Plan A every + # entry lands in the default project; M3-frontend routing carries a + # non-default target later. + target_project = auth.DEFAULT_PROJECT_ID + landing_state = "active" if projects_mod.project_initial_state(target_project) == "active" else "super-draft" + entry = entry_mod.Entry( slug=slug, title=payload.title.strip(), - state="super-draft", + state=landing_state, id=None, repo=None, proposed_by=user.email or user.gitea_login, @@ -845,6 +851,7 @@ def make_router( arbiters=[], tags=[t.strip() for t in payload.tags if t.strip()], body=payload.pitch.strip() + "\n", + unreviewed=(landing_state == "active"), ) contents = entry_mod.serialize(entry) pr_title = f"Propose: {entry.title}" diff --git a/backend/tests/test_initial_state_landing.py b/backend/tests/test_initial_state_landing.py new file mode 100644 index 0000000..dd0931c --- /dev/null +++ b/backend/tests/test_initial_state_landing.py @@ -0,0 +1,43 @@ +"""§22.4b — a project with initial_state='active' lands new entries active + +unreviewed; the default 'super-draft' project is unchanged.""" +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 _propose(client): + return client.post("/api/rfcs/propose", json={ + "title": "Active Lander", "slug": "active-lander", + "pitch": "Lands active.", "tags": [], + }) + + +def test_super_draft_default_unchanged(app_with_fake_gitea): + from app import entry as entry_mod + app, fake = app_with_fake_gitea + with TestClient(app) as client: + provision_user_row(user_id=1, login="ben", role="owner") + sign_in_as(client, user_id=1, gitea_login="ben", display_name="Ben", role="owner") + assert _propose(client).status_code == 200 + f = fake.files[("wiggleverse", "meta", "propose/active-lander", "rfcs/active-lander.md")] + e = entry_mod.parse(f["content"]) + assert e.state == "super-draft" + assert e.unreviewed is False + + +def test_active_initial_state_lands_active_unreviewed(app_with_fake_gitea): + from app import db, entry as entry_mod + app, fake = app_with_fake_gitea + with TestClient(app) as client: + db.conn().execute("UPDATE projects SET initial_state='active' WHERE id='default'") + provision_user_row(user_id=1, login="ben", role="owner") + sign_in_as(client, user_id=1, gitea_login="ben", display_name="Ben", role="owner") + assert _propose(client).status_code == 200 + f = fake.files[("wiggleverse", "meta", "propose/active-lander", "rfcs/active-lander.md")] + e = entry_mod.parse(f["content"]) + assert e.state == "active" + assert e.unreviewed is True