Skip to content

Commit 6ffb5f3

Browse files
committed
refactor(tests): address Copilot review on the CI-compat fix
- conftest: set JWT_SECRET when missing OR empty (setdefault would keep an explicit JWT_SECRET="", still tripping pyjwt 2.13's empty-key guard). - smoke: store route methods as an immutable frozenset in _ResolvedRoute (a set inside a NamedTuple is mutable and makes the tuple non-hashable).
1 parent 30f69af commit 6ffb5f3

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
# .env) does not set JWT_SECRET, leaving it "" — and pyjwt >= 2.13 rejects empty
2323
# HMAC keys ("HMAC key must not be empty."). Provide a non-prod test secret here,
2424
# before any test module constructs AppSettings(), so signing/verification match.
25-
os.environ.setdefault("JWT_SECRET", "test-jwt-secret-not-for-production")
25+
# Set when missing *or* empty (setdefault would keep an explicit JWT_SECRET="").
26+
if not os.environ.get("JWT_SECRET"):
27+
os.environ["JWT_SECRET"] = "test-jwt-secret-not-for-production"
2628

2729
from config import AppSettings
2830
from middleware.error_handler import register_error_handlers

tests/smoke/test_routes_registered.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class _ResolvedRoute(NamedTuple):
1515
"""A flattened API route with its fully-qualified path and HTTP methods."""
1616

1717
path: str
18-
methods: set[str]
18+
methods: frozenset[str]
1919

2020

2121
def _get_api_routes(app: FastAPI) -> list[_ResolvedRoute]:
@@ -34,7 +34,9 @@ def _collect(routes, prefix: str = "") -> list[_ResolvedRoute]:
3434
found: list[_ResolvedRoute] = []
3535
for route in routes:
3636
if isinstance(route, APIRoute):
37-
found.append(_ResolvedRoute(prefix + route.path, set(route.methods)))
37+
found.append(
38+
_ResolvedRoute(prefix + route.path, frozenset(route.methods))
39+
)
3840
elif hasattr(route, "original_router"):
3941
child_prefix = (
4042
getattr(getattr(route, "include_context", None), "prefix", "") or ""

0 commit comments

Comments
 (0)