feat(flags): serve /api/flags, and keep the public proxy off it
The endpoint and its exposure control ship together on purpose. The moment /api/flags exists, app/api/[...path] forwards it — and the response names every unreleased feature the codebase knows about, along with whether it is on. Publishing that is the opposite of shipping dark. Denied on an exact first-segment match, not a prefix, so /api/flagship does not go down with /api/flags. Next reads the endpoint server-side over the Docker network, which never transits the public proxy. jest.setup.js now guards its browser globals. It runs for every suite, including the one that declares @jest-environment node to exercise the route handler — NextRequest needs Fetch API globals jsdom lacks, and there is no window there to define matchMedia on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015mWQnpye9F299NVRCCSRvj
This commit is contained in:
1 parent
7424cef7c6
commit
c30ad1db07
5 files changed
+93
No files matched your search
@@ -72,3 +72,24 @@ def test_a_flag_older_than_the_limit_fails_this_test():
|
||||
"Remove the flag and the code branches it guards, or move its `added` "
|
||||
"date deliberately."
|
||||
)
|
||||
|
||||
|
||||
def _client():
|
||||
from fastapi.testclient import TestClient
|
||||
from backend import app as app_module
|
||||
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||
|
||||
|
||||
def test_the_flags_endpoint_lists_every_declared_flag(monkeypatch):
|
||||
monkeypatch.setattr(flags, "_client", None)
|
||||
body = _client().get("/api/flags").json()
|
||||
assert set(body) == set(flags.REGISTRY)
|
||||
|
||||
|
||||
def test_the_flags_endpoint_answers_false_when_unleash_is_unreachable(monkeypatch):
|
||||
# The endpoint must still answer. A frontend that cannot read flags renders
|
||||
# everything dark, which is right; one that gets a 500 renders nothing.
|
||||
monkeypatch.setattr(flags, "_client", None)
|
||||
res = _client().get("/api/flags")
|
||||
assert res.status_code == 200
|
||||
assert all(v is False for v in res.json().values())
|
||||
Reference in new issue
Block a user