Skip to content

test: call the configured API when available - #430

Closed
mikemikimike wants to merge 2 commits into
microsoft:mainfrom
mikemikimike:codex/issue-328-api-tests
Closed

test: call the configured API when available#430
mikemikimike wants to merge 2 commits into
microsoft:mainfrom
mikemikimike:codex/issue-328-api-tests

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

Closes #328.

The model integration test suite now performs a real language-model request when OPENAI_API_KEY and OPENAI_MODEL are 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 build
  • npx tsc -p test
  • node --test out/validate.test.js out/zod.test.js out/program.test.js tests/model.test.mjs
  • Result: 113 passed, 1 skipped (no API credentials configured)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 runs complete() 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

Comment thread typescript/tests/model.test.mjs Outdated
Comment on lines +349 to +355
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(), "");
});
@robgruen

Copy link
Copy Markdown
Contributor

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."

@mikemikimike

Copy link
Copy Markdown
Author

Addressed the review feedback in commit f6b4a6d.

  • Preserved the native global fetch at module initialization and restore it in teardown instead of deleting it, so later live tests can use the runtime implementation.
  • Moved the network test into its own createLanguageModel live API integration suite.
  • Added an explicit TYPECHAT_LIVE_TESTS=1 opt-in, so normal test runs never make billable calls accidentally.
  • Bounded the live test with a 30-second timeout and zero retries.

Validation:

  • npm test with TYPECHAT_LIVE_TESTS=1, OPENAI_MODEL=qwen3.5-4b, and OPENAI_ENDPOINT=http://127.0.0.1:1234/v1/chat/completions
  • LM Studio served the local qwen3.5-4b model through its OpenAI-compatible API.
  • Result: 114 passed, 0 skipped, 0 failed.

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.

@mikemikimike
mikemikimike deleted the codex/issue-328-api-tests branch August 31, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update tests to call actual API if available, mock otherwise

3 participants