test: call the configured API when available - #430
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the TypeScript model integration test suite so it can optionally perform a real OpenAI request when OPENAI_API_KEY and OPENAI_MODEL are set, while keeping the existing deterministic mocked tests as the default behavior.
Changes:
- Adds a conditional integration test that calls
createLanguageModel(process.env)and runscomplete()against the configured OpenAI model when credentials are present. - Keeps the existing mocked routing tests for Chat Completions vs Responses API behavior unchanged.
Show a summary per file
| File | Description |
|---|---|
typescript/tests/model.test.mjs |
Adds a conditional test intended to hit the real configured OpenAI API when credentials are available. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| test("calls the configured API when credentials are available", { skip: !process.env.OPENAI_API_KEY || !process.env.OPENAI_MODEL }, async () => { | ||
| const model = createLanguageModel(process.env); | ||
| const result = await model.complete("Reply with the single word: pong"); | ||
| assert.equal(result.success, true, result.message); | ||
| assert.equal(typeof result.data, "string"); | ||
| assert.notEqual(result.data.trim(), ""); | ||
| }); |
|
Thanks for picking up #328! Can you please address copilot's comment, it seems valid to me. Your test results show 113 passed / 1 skipped, which means this path hasn't been exercised yet — could you re-run with credentials set and paste the output? Second, gating purely on OPENAI_API_KEY being present will make npm test silently issue billable calls for anyone who's run the examples. Please add a separate explicit opt-in (e.g. TYPECHAT_LIVE_TESTS=1), bound the timeout and retry count, and move the test into its own describe so it never interacts with the fetch mocking." |
|
Addressed the review feedback in commit f6b4a6d.
Validation:
The live request was verified against the local LM Studio OpenAI-compatible endpoint rather than the hosted OpenAI API; no OpenAI credential was available in this environment. |
Summary
Closes #328.
The model integration test suite now performs a real language-model request when
OPENAI_API_KEYandOPENAI_MODELare configured. In environments without those variables, the existing deterministic mocked tests remain the default, so local and CI runs do not require credentials.Tests
npm run buildnpx tsc -p testnode --test out/validate.test.js out/zod.test.js out/program.test.js tests/model.test.mjs