Skip to content

test(fal): add speech/transcription usage coverage; drop e2e billing test#725

Merged
AlemTuzlak merged 1 commit into
mainfrom
fal-billing-coderabbit-followups
Jun 8, 2026
Merged

test(fal): add speech/transcription usage coverage; drop e2e billing test#725
AlemTuzlak merged 1 commit into
mainfrom
fal-billing-coderabbit-followups

Conversation

@tombeckenham

@tombeckenham tombeckenham commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #723 addressing CodeRabbit review feedback.

What

  • Add unit coverage for result.usage.unitsBilled on the fal speech and transcription adapters (billed + unbilled cases), mirroring the existing audio/image/video adapter tests.
  • Remove the e2e fal-billable-units spec, its /api/fal-billable-units route, and the hand-rolled /fal-queue aimock mount — plus the now-orphaned @tanstack/ai-fal e2e dependency (route tree regenerated).

Why

aimock has no seam to stamp the x-fal-billable-units response header the feature reads, so the e2e test only worked by manipulating fetch to redirect fal's hardcoded queue.fal.run URLs. The billed-units behavior is now covered by unit tests across all five fal adapters instead.

Testing

  • @tanstack/ai-fal unit tests: 103 pass
  • tsc + eslint (./src) clean; sherif clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Enhanced test coverage for usage and billing tracking in speech and transcription adapters.
  • Chores

    • Removed legacy e2e test infrastructure and routes for billing unit simulation, streamlining the test suite.

…test

Follow-up to #723 addressing CodeRabbit review feedback.

- Add unit coverage for `result.usage.unitsBilled` on the fal speech and
  transcription adapters (billed + unbilled cases), mirroring the existing
  audio/image/video adapter tests.
- Remove the e2e `fal-billable-units` spec, its `/api/fal-billable-units`
  route, and the hand-rolled `/fal-queue` aimock mount. aimock has no seam to
  stamp the `x-fal-billable-units` response header the feature reads, so any
  e2e test required manipulating `fetch` to redirect fal's hardcoded
  `queue.fal.run` URLs. The billed-units behavior is now covered by unit tests
  across all five fal adapters instead.
- Drop the now-orphaned `@tanstack/ai-fal` dependency from the e2e app and
  regenerate the route tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates Fal billing/usage test coverage from E2E to unit test scope. Unit tests are added to the speech and transcription adapters to validate result.usage.unitsBilled population when Fal returns billable-units headers. The corresponding E2E test infrastructure—global mock setup, dedicated route, dependency, and e2e tests—is removed.

Changes

Consolidate Fal Billing Tests to Unit Level

Layer / File(s) Summary
Speech adapter billing unit tests
packages/ai-fal/tests/speech-adapter.test.ts
Introduces seedBillableUnits helper that injects Fal's billable-units response headers, and adds two tests: one asserts result.usage.unitsBilled is populated when billable units are reported, the other asserts result.usage is undefined when absent.
Transcription adapter billing unit tests
packages/ai-fal/tests/transcription-adapter.test.ts
Introduces seedBillableUnits helper and two parallel tests for generateTranscription: one validates result.usage.unitsBilled matches seeded billable units, the other validates result.usage is undefined when billable units are not present.
E2E global fal-queue mock removal
testing/e2e/global-setup.ts
Removes the '/fal-queue' aimock mount and deletes the falQueueMount() handler that simulated Fal's queue protocol, along with associated billing constants FAL_E2E_REQUEST_ID and FAL_E2E_BILLABLE_UNITS.
E2E fal-billable-units route and dependency cleanup
testing/e2e/package.json, testing/e2e/src/routeTree.gen.ts
Removes @tanstack/ai-fal from e2e dependencies and cleans up all generated route tree type mappings and entries that registered the now-deleted /api/fal-billable-units route.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • TanStack/ai#723: Introduces the billing utility recordBillableUnitsFromResponse and result.usage.unitsBilled flow that is exercised in the new adapter unit tests.

Suggested reviewers

  • AlemTuzlak
  • crutchcorn

🐰 Billing tests now hop to unit scope,
E2E queues fade from sight,
Speech and transcription adapt with grace—
Usage surfaces clear and bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding unit tests for speech/transcription usage coverage and removing the e2e billing test, which aligns with the core changes and PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fal-billing-coderabbit-followups

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

3 package(s) bumped directly, 28 bumped as dependents.

🟥 Major bumps

Package Version Reason
@tanstack/ai-event-client 0.5.4 → 1.0.0 Changeset
@tanstack/ai-fal 0.7.23 → 1.0.0 Changeset
@tanstack/ai-anthropic 0.15.1 → 1.0.0 Dependent
@tanstack/ai-code-mode 0.2.5 → 1.0.0 Dependent
@tanstack/ai-code-mode-skills 0.2.5 → 1.0.0 Dependent
@tanstack/ai-elevenlabs 0.2.20 → 1.0.0 Dependent
@tanstack/ai-gemini 0.15.1 → 1.0.0 Dependent
@tanstack/ai-grok 0.11.2 → 1.0.0 Dependent
@tanstack/ai-groq 0.4.2 → 1.0.0 Dependent
@tanstack/ai-isolate-node 0.1.30 → 1.0.0 Dependent
@tanstack/ai-isolate-quickjs 0.1.30 → 1.0.0 Dependent
@tanstack/ai-ollama 0.8.1 → 1.0.0 Dependent
@tanstack/ai-openai 0.14.1 → 1.0.0 Dependent
@tanstack/ai-openrouter 0.13.1 → 1.0.0 Dependent
@tanstack/ai-preact 0.9.4 → 1.0.0 Dependent
@tanstack/ai-react 0.15.4 → 1.0.0 Dependent
@tanstack/ai-react-ui 0.8.6 → 1.0.0 Dependent
@tanstack/ai-solid 0.13.4 → 1.0.0 Dependent
@tanstack/ai-solid-ui 0.7.6 → 1.0.0 Dependent
@tanstack/ai-svelte 0.13.4 → 1.0.0 Dependent
@tanstack/ai-vue 0.13.4 → 1.0.0 Dependent
@tanstack/openai-base 0.8.1 → 1.0.0 Dependent

🟨 Minor bumps

Package Version Reason
@tanstack/ai 0.28.0 → 0.29.0 Changeset

🟩 Patch bumps

Package Version Reason
@tanstack/ai-client 0.16.3 → 0.16.4 Dependent
@tanstack/ai-devtools-core 0.4.8 → 0.4.9 Dependent
@tanstack/ai-isolate-cloudflare 0.2.21 → 0.2.22 Dependent
@tanstack/ai-mcp 0.1.0 → 0.1.1 Dependent
@tanstack/ai-vue-ui 0.2.16 → 0.2.17 Dependent
@tanstack/preact-ai-devtools 0.1.51 → 0.1.52 Dependent
@tanstack/react-ai-devtools 0.2.51 → 0.2.52 Dependent
@tanstack/solid-ai-devtools 0.2.51 → 0.2.52 Dependent

@nx-cloud

nx-cloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 9e23e54

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-08 09:54:28 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

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

@tanstack/ai-anthropic

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

@tanstack/ai-client

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

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@725

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@725

@tanstack/ai-devtools-core

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

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@725

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@725

@tanstack/ai-fal

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

@tanstack/ai-gemini

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

@tanstack/ai-grok

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

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@725

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@725

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@725

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@725

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@725

@tanstack/ai-ollama

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

@tanstack/ai-openai

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

@tanstack/ai-openrouter

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

@tanstack/ai-preact

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

@tanstack/ai-react

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

@tanstack/ai-react-ui

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

@tanstack/ai-solid

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

@tanstack/ai-solid-ui

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

@tanstack/ai-svelte

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

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@725

@tanstack/ai-vue

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

@tanstack/ai-vue-ui

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

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@725

@tanstack/preact-ai-devtools

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

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

commit: 9e23e54

@tombeckenham tombeckenham requested a review from AlemTuzlak June 8, 2026 09:55

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
packages/ai-fal/tests/transcription-adapter.test.ts (1)

7-16: ⚡ Quick win

Extract duplicated seedBillableUnits helper to shared test utility.

The seedBillableUnits helper is identical in both speech-adapter.test.ts and transcription-adapter.test.ts. Consider extracting it to a shared test utility file (e.g., packages/ai-fal/tests/test-utils.ts or packages/ai-fal/tests/helpers/billing.ts) to avoid duplication and ensure consistency.

♻️ Suggested refactor

Create packages/ai-fal/tests/test-utils.ts:

import { recordBillableUnitsFromResponse } from '../src/utils/billing'

export function seedBillableUnits(requestId: string, units: string) {
  recordBillableUnitsFromResponse(
    new Response(null, {
      headers: {
        'x-fal-request-id': requestId,
        'x-fal-billable-units': units,
      },
    }),
  )
}

Then import in both test files:

-import { recordBillableUnitsFromResponse } from '../src/utils/billing'
-
-function seedBillableUnits(requestId: string, units: string) {
-  recordBillableUnitsFromResponse(
-    new Response(null, {
-      headers: {
-        'x-fal-request-id': requestId,
-        'x-fal-billable-units': units,
-      },
-    }),
-  )
-}
+import { seedBillableUnits } from './test-utils'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ai-fal/tests/transcription-adapter.test.ts` around lines 7 - 16, The
seedBillableUnits helper is duplicated; extract it into a shared test utility
(e.g., test-utils or helpers file) that exports seedBillableUnits which calls
recordBillableUnitsFromResponse with a Response containing the
'x-fal-request-id' and 'x-fal-billable-units' headers; then replace the local
seedBillableUnits definitions in both transcription-adapter.test.ts and
speech-adapter.test.ts with a single import of the shared seedBillableUnits
utility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/ai-fal/tests/transcription-adapter.test.ts`:
- Around line 7-16: The seedBillableUnits helper is duplicated; extract it into
a shared test utility (e.g., test-utils or helpers file) that exports
seedBillableUnits which calls recordBillableUnitsFromResponse with a Response
containing the 'x-fal-request-id' and 'x-fal-billable-units' headers; then
replace the local seedBillableUnits definitions in both
transcription-adapter.test.ts and speech-adapter.test.ts with a single import of
the shared seedBillableUnits utility.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d516acd-adc2-4bc3-856a-9a6846e1d153

📥 Commits

Reviewing files that changed from the base of the PR and between 22c9b42 and 9e23e54.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • packages/ai-fal/tests/speech-adapter.test.ts
  • packages/ai-fal/tests/transcription-adapter.test.ts
  • testing/e2e/global-setup.ts
  • testing/e2e/package.json
  • testing/e2e/src/routeTree.gen.ts
  • testing/e2e/src/routes/api.fal-billable-units.ts
  • testing/e2e/tests/fal-billable-units.spec.ts
💤 Files with no reviewable changes (5)
  • testing/e2e/package.json
  • testing/e2e/global-setup.ts
  • testing/e2e/src/routes/api.fal-billable-units.ts
  • testing/e2e/tests/fal-billable-units.spec.ts
  • testing/e2e/src/routeTree.gen.ts

@AlemTuzlak AlemTuzlak merged commit 95fa51a into main Jun 8, 2026
10 checks passed
@AlemTuzlak AlemTuzlak deleted the fal-billing-coderabbit-followups branch June 8, 2026 21:55
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