Tag /api/gateway requests with direct-gateway feature header#547
Tag /api/gateway requests with direct-gateway feature header#547emilieschario wants to merge 1 commit intomainfrom
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Clean change that wraps the gateway route handler to inject the Files Reviewed (2 files)
|
pedroheyerdahl
left a comment
There was a problem hiding this comment.
The route change is exactly right — this is the route-based approach Pedro originally had in #307 before reverting it, and it's the correct solution to #329.
One concern: the test mocks the openrouter POST handler and asserts on the forwarded request object. Per our coding guidelines, we avoid mocks because they make tests brittle and tied to implementation details. The test doesn't verify any observable behavior — it would still pass even if the header injection had no effect downstream.
Could the test instead make a real request through the stack and verify the feature column in the DB ends up as direct-gateway? There are examples in the existing integration test helpers (src/tests/helpers/microdollar-usage.helper.ts) that show how to check usage records. That would give us real confidence the wiring works end-to-end, rather than just that we're calling openrouterPOST with certain headers.
pedroheyerdahl
left a comment
There was a problem hiding this comment.
nit: the test mocks openrouter and checks what headers we passed in, but that doesn't actually verify the feature ends up in the DB (coding-style.md suggest not using mocks). would be worth wiring this up as an integration test instead, similar to what's in src/tests/helpers/microdollar-usage.helper.ts. I can send a follow up.
|
|
||
| export function POST(request: NextRequest) { | ||
| const headers = new Headers(request.headers); | ||
| headers.set(FEATURE_HEADER, 'direct-gateway'); |
There was a problem hiding this comment.
we probably don't want to override it if it's already set
Summary
/api/gateway/now havex-kilocode-feature: direct-gatewayinjected before being forwarded to the openrouter handlerx-kilocode-featureheader is overwritten