Skip to content

fix(tests): update provider tests for abortSignal second argument#463

Closed
easonLiangWorldedtech wants to merge 2 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:main
Closed

fix(tests): update provider tests for abortSignal second argument#463
easonLiangWorldedtech wants to merge 2 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:main

Conversation

@easonLiangWorldedtech
Copy link
Copy Markdown

@easonLiangWorldedtech easonLiangWorldedtech commented Jun 3, 2026

Summary

Fixes 31 failing provider tests caused by abortSignal changes in PR #434.

Root Cause

Providers now pass { signal: metadata?.abortSignal } as a second argument to chat.completions.create(), but test expectations only checked for one argument.

Changes

  • Added { signal: undefined } as second argument to all provider test mocks
  • Fixed openai-compatible.ts: changed abortSignal: to signal: (AI SDK expects signal)
  • Removed incorrectly added signal args from OpenAI constructor tests and completePrompt tests

Test Results

31 failures → 0 failures (5956 passed, 35 skipped)

Summary by CodeRabbit

  • New Features

    • Added request cancellation support across all AI providers, allowing users to stop in-progress API calls.
  • Tests

    • Added comprehensive test coverage for request cancellation functionality across all supported providers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 81b92c15-28d0-4cd3-bc26-75c6a462f393

📥 Commits

Reviewing files that changed from the base of the PR and between 75d4eee and 6926916.

📒 Files selected for processing (29)
  • src/api/index.ts
  • src/api/providers/__tests__/base-openai-compatible-provider.spec.ts
  • src/api/providers/__tests__/fireworks.spec.ts
  • src/api/providers/__tests__/lmstudio-native-tools.spec.ts
  • src/api/providers/__tests__/mimo.spec.ts
  • src/api/providers/__tests__/openai-compatible-abort-signal.spec.ts
  • src/api/providers/__tests__/opencode-go.spec.ts
  • src/api/providers/__tests__/qwen-code-native-tools.spec.ts
  • src/api/providers/__tests__/requesty.spec.ts
  • src/api/providers/__tests__/sambanova.spec.ts
  • src/api/providers/__tests__/unbound.spec.ts
  • src/api/providers/__tests__/vercel-ai-gateway.spec.ts
  • src/api/providers/__tests__/zai.spec.ts
  • src/api/providers/base-openai-compatible-provider.ts
  • src/api/providers/deepseek.ts
  • src/api/providers/lite-llm.ts
  • src/api/providers/lm-studio.ts
  • src/api/providers/mimo.ts
  • src/api/providers/openai-compatible.ts
  • src/api/providers/openai.ts
  • src/api/providers/opencode-go.ts
  • src/api/providers/openrouter.ts
  • src/api/providers/qwen-code.ts
  • src/api/providers/requesty.ts
  • src/api/providers/unbound.ts
  • src/api/providers/vercel-ai-gateway.ts
  • src/api/providers/zai.ts
  • src/core/task/Task.ts
  • src/core/task/__tests__/task-abort-signal-passing.spec.ts

📝 Walkthrough

Walkthrough

This PR adds cancellation support for streaming API requests by threading an abortSignal from the task layer through all LLM provider implementations. The API metadata interface gains an optional signal field, which Task passes during API calls, and each of the 17+ LLM providers now wires that signal into their underlying streaming requests.

Changes

AbortSignal Propagation Through API Providers

Layer / File(s) Summary
API Contract and Task Integration
src/api/index.ts, src/core/task/Task.ts, src/core/task/__tests__/task-abort-signal-passing.spec.ts
ApiHandlerCreateMessageMetadata interface adds optional abortSignal?: AbortSignal. Task.attemptApiRequest() wires the current AbortController signal into metadata. Integration tests verify signal presence, state transitions, and metadata field integrity.
Base OpenAI-Compatible Provider Wiring
src/api/providers/base-openai-compatible-provider.ts, src/api/providers/__tests__/openai-compatible-abort-signal.spec.ts
BaseOpenAiCompatibleProvider.createStream merges metadata's abort signal into request options. New test suite verifies signal forwarding for provided/omitted/missing metadata cases and confirms signal capability during streaming.
OpenAI and OpenAI-Compatible Providers
src/api/providers/openai.ts, src/api/providers/openrouter.ts, src/api/providers/openai-compatible.ts, src/api/providers/opencode-go.ts, src/api/providers/vercel-ai-gateway.ts
All OpenAI-compatible implementations pass metadata?.abortSignal into streaming calls, preserving existing options (e.g., Azure path overrides). OpenAI handles both streaming and non-streaming paths and O3-family special handling.
Specialized LLM Providers
src/api/providers/deepseek.ts, src/api/providers/lite-llm.ts, src/api/providers/lm-studio.ts, src/api/providers/mimo.ts, src/api/providers/qwen-code.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts, src/api/providers/zai.ts
Each provider wires metadata?.abortSignal into its streaming request options using the same pattern. LiteLLM uses chained method syntax; others use options object spread.
Provider Test Updates
src/api/providers/__tests__/*.spec.ts (11 test files)
All provider tests updated to expect { signal: undefined } or expect.any(Object) in mocked streaming calls. Fireworks test reformatted model metadata assertions. Tests verify signal parameter threading across temperature, tool-calling, token limits, and usage-tracking scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Zoo-Code-Org/Zoo-Code#210: Both PRs modify MimoHandler.createMessage in src/api/providers/mimo.ts—one to forward metadata.abortSignal into the streaming request options, the other to sanitize streamed delta.tool_calls[].id values—so the changes are code-level related within the same function.

Suggested reviewers

  • taltas
  • navedmerchant
  • hannesrudolph
  • edelauna
  • JamesRobert20

🐰 Request cancellation hops through the rabbit warren—
Each provider now listens for the signal to abort,
From task to API, the chain unbroken flows,
Users can stop mid-stream with a single call.
No hanging threads, just graceful stops. 🛑

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/__tests__/base-openai-compatible-provider.spec.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/api/providers/__tests__/fireworks.spec.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 26 others

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.

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.

2 participants