Skip to content

test: add coverage for Cloudflare AI timeout fallback behavior #70

@whoabuddy

Description

@whoabuddy

Context

During review of PR #69 (#69), Copilot noted that the new timeout-fallback behavior and fallback_model response field are not covered by tests.

What needs testing

Add tests that cover the Cloudflare AI timeout fallback path:

  1. Simulate timeout error: Mock c.env.AI.run to throw an error with code 3046 (timeout) on the primary model
  2. Verify fallback retry: Confirm the handler retries the request with the fallback model after the primary model times out
  3. Verify metadata in non-streaming responses: Assert that the fallback_model field is present and correct in the JSON response body when fallback is triggered
  4. Verify metadata in streaming responses: Assert that the X-Fallback-Model header is set correctly when the fallback model is used in streaming mode
  5. Verify normal path: Ensure that when the primary model succeeds, no fallback metadata is present

Acceptance criteria

  • Test exists that triggers code 3046 timeout on primary model
  • Test verifies fallback model is called after timeout
  • Test checks fallback_model field in non-streaming JSON response
  • Test checks X-Fallback-Model header in streaming response
  • Test confirms no fallback metadata when primary model succeeds

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions