"""§22.4c — _upsert_cached_rfc mirrors the review fields into cached_rfcs."""
from __future__ import annotations

from fastapi.testclient import TestClient

from test_propose_vertical import app_with_fake_gitea, tmp_env  # noqa: F401


def test_upsert_writes_review_fields(app_with_fake_gitea):
    from app import cache, db, entry as entry_mod

    app, _ = app_with_fake_gitea
    with TestClient(app):
        e = entry_mod.Entry(
            slug="rev", title="Rev", state="active",
            unreviewed=True, reviewed_at="2026-06-03", reviewed_by="ben",
        )
        cache._upsert_cached_rfc(e, body_sha="sha-rev")
        row = db.conn().execute(
            "SELECT unreviewed, reviewed_at, reviewed_by FROM cached_rfcs WHERE slug = 'rev'"
        ).fetchone()
        assert row["unreviewed"] == 1
        assert row["reviewed_at"] == "2026-06-03"
        assert row["reviewed_by"] == "ben"
