Skip to content

test: add failing test for openrouter adapter issue#315

Open
tombeckenham wants to merge 1 commit intoTanStack:mainfrom
tombeckenham:openrouter-test-issue
Open

test: add failing test for openrouter adapter issue#315
tombeckenham wants to merge 1 commit intoTanStack:mainfrom
tombeckenham:openrouter-test-issue

Conversation

@tombeckenham
Copy link
Contributor

@tombeckenham tombeckenham commented Feb 25, 2026

🎯 Changes

This PR includes a failing test that demonstrates modelOptions not passing though to openrouter.

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for SDK serialization behavior, validating correct parameter transformation to wire format before API requests.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

The change adds comprehensive test coverage for OpenRouter adapter parameter serialization, verifying that outbound parameters are correctly converted from camelCase to snake_case format before transmission to the endpoint. The tests reference an existing outbound schema and validate serialization of core parameters and model options without modifying any runtime logic.

Changes

Cohort / File(s) Summary
OpenRouter Serialization Tests
packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts
Added test blocks validating outbound schema serialization behavior, confirming camelCase-to-snake_case conversion for parameters (model, temperature, top_p, max_tokens, stream, tool_choice) and modelOptions (frequency_penalty, presence_penalty, max_completion_tokens).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 From camel to serpent, the parameters dance,
Snake_case conversion—we test every chance!
Schemas aligned, serialization true,
The wire format shines, through and through. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description explains the purpose of the failing test but is incomplete against the template. The checklist items are not addressed and the release impact section is missing. Complete the checklist items (testing, Contributing guide), and clarify whether a changeset is needed or if this is dev-only since it's test-only.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: add failing test for openrouter adapter issue' accurately and specifically describes the main change: adding a test that demonstrates a problem with the openrouter adapter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 25, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 1606955

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 10s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-25 02:52:26 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@315

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@315

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@315

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@315

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@315

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@315

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@315

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@315

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@315

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@315

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@315

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@315

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@315

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@315

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@315

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@315

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@315

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@315

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@315

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@315

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@315

commit: 1606955

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts (2)

142-143: The "false positive" assertion muddies the test signal.

Line 143 checks raw pre-serialization params, where tool_choice is trivially present regardless of whether the underlying adapter bug exists. With the corrective assertion on Line 162 (serialized having tool_choice) now in place, keeping this assertion as a labeled "false positive" is misleading — it will continue to pass even after the bug is fixed, which obscures whether the test is correctly tracking the issue.

Consider removing this assertion and relying solely on the post-serialization check on Line 162 to keep the test's intent unambiguous.

♻️ Suggested cleanup
-    // This is the false postive - as it never gets passed to the openrouter endpoint
-    expect(params.tool_choice).toBe('auto')
-
     expect(params.messages).toBeDefined()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts` around
lines 142 - 143, Remove the misleading pre-serialization assertion that checks
params.tool_choice (the line with expect(params.tool_choice).toBe('auto'))
because it always passes and obscures the real check; instead, delete that
assertion and rely solely on the post-serialization assertion that inspects
serialized (the existing check around serialized.tool_choice) to verify the
adapter behavior.

873-874: Redundant rawParams alias — use the destructuring pattern used elsewhere.

rawParams is assigned and immediately aliased to params with no transformation. Lines 135 and 366 in the same file use the direct destructuring form.

♻️ Proposed simplification
-    const [rawParams] = mockSend.mock.calls[0]!
-    const params = rawParams
+    const [params] = mockSend.mock.calls[0]!
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts` around
lines 873 - 874, The test creates an unnecessary alias rawParams before
assigning it to params; replace that two-step assignment with the direct
destructuring pattern used elsewhere by extracting params directly from
mockSend.mock.calls[0] (i.e., destructure the first element into params instead
of creating rawParams then assigning it to params) so the test uses a single
const [params] = mockSend.mock.calls[0]! like the other examples.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts`:
- Around line 142-143: Remove the misleading pre-serialization assertion that
checks params.tool_choice (the line with
expect(params.tool_choice).toBe('auto')) because it always passes and obscures
the real check; instead, delete that assertion and rely solely on the
post-serialization assertion that inspects serialized (the existing check around
serialized.tool_choice) to verify the adapter behavior.
- Around line 873-874: The test creates an unnecessary alias rawParams before
assigning it to params; replace that two-step assignment with the direct
destructuring pattern used elsewhere by extracting params directly from
mockSend.mock.calls[0] (i.e., destructure the first element into params instead
of creating rawParams then assigning it to params) so the test uses a single
const [params] = mockSend.mock.calls[0]! like the other examples.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f800aa and 1606955.

📒 Files selected for processing (1)
  • packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts

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.

1 participant