Conversation
| test("GET /search delegates to internal endpoints returned by OpenAI", async () => { | ||
| const { axios } = await getTestServer() | ||
|
|
||
| const response = await axios.get("/search?q=leds") | ||
|
|
||
| expect(response.status).toBe(200) | ||
| expect(response.data.search_result.endpoint_used).toBe("/leds/list") | ||
| expect(response.data.search_result.filter_params).toEqual({ json: "true" }) | ||
| expect(openAiRequests.length).toBe(1) | ||
|
|
||
| const [{ body }] = openAiRequests | ||
|
|
||
| expect(body.messages?.[1]?.content).toContain("GET /leds/list") | ||
| expect(body.messages?.[1]?.content).toContain("User query: leds") | ||
| }) | ||
|
|
||
| test("GET /search returns error when OPENAI_API_KEY is missing", async () => { | ||
| delete process.env.OPENAI_API_KEY | ||
|
|
||
| const { axios } = await getTestServer() | ||
|
|
||
| let response: { status: number; data: any } | undefined | ||
|
|
||
| try { | ||
| response = await axios.get("/search?q=test") | ||
| } catch (error) { | ||
| response = error as { status: number; data: any } | ||
| } | ||
|
|
||
| expect(response?.status).toBe(500) | ||
| expect(response?.data).toEqual({ | ||
| error: { | ||
| error_code: "missing_openai_api_key", | ||
| message: "OPENAI_API_KEY environment variable is not configured", | ||
| }, | ||
| }) | ||
|
|
||
| expect(openAiRequests.length).toBe(0) | ||
| }) |
There was a problem hiding this comment.
This test file contains 2 test() functions (lines 80-94 and 96-118), which violates the rule that a *.test.ts file may have AT MOST one test(...). After the first test, the user should split into multiple, numbered files. To fix this, split the tests into separate files like 'search1.test.ts' and 'search2.test.ts', with each file containing only one test() function.
Spotted by Diamond (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| try { | ||
| internalResponse = await fetch(url.toString(), { | ||
| headers: { | ||
| Accept: "application/json", | ||
| }, |
There was a problem hiding this comment.
Ensure delegated requests trigger JSON responses
The /search handler forwards requests to internal GET endpoints but only sets an Accept: application/json header before calling fetch. Routes built with withWinterSpec treat requests as HTML unless a json query param or Content-Type: application/json is present (withIsApiRequest middleware). When OpenAI selects an endpoint whose json parameter is optional and omits it—which is plausible given the prompt only marks required params—the delegated call returns HTML and internalResponse.json() throws, so users receive invalid_internal_response despite a valid endpoint selection. Force JSON mode (e.g. always add json=true or set Content-Type on the forwarded request) to avoid this systematic failure.
Useful? React with 👍 / 👎.
Summary
getOpenAiClienthelper and update the/searchroute to build prompts from all GET endpoints, reuse the helper, and fail fast when no API key is configuredTesting
https://chatgpt.com/codex/tasks/task_b_68e5aa749598832ea69db0fc554986f1