Skip to content

feat: add integration tests for ASR functionality using sample audio files#120

Open
twangodev wants to merge 1 commit intomainfrom
feat/asr-test
Open

feat: add integration tests for ASR functionality using sample audio files#120
twangodev wants to merge 1 commit intomainfrom
feat/asr-test

Conversation

@twangodev
Copy link
Collaborator

@twangodev twangodev commented Mar 6, 2026

Summary by CodeRabbit

  • Tests
    • Added comprehensive integration tests for audio file transcription functionality, covering both synchronous and asynchronous operations with various configuration options including timestamp support.

Copilot AI review requested due to automatic review settings March 6, 2026 03:35
@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

This pull request adds integration tests for ASR functionality that work with actual audio files. It introduces a new test suite with synchronous and asynchronous variants, including fixtures and test cases that validate transcription accuracy, timestamp handling, and text content verification.

Changes

Cohort / File(s) Summary
ASR File Integration Tests
tests/integration/test_asr_integration.py
Added SAMPLES_DIR constant and two test classes (TestASRFromFileIntegration and TestAsyncASRFromFileIntegration) with fixtures and test methods covering transcription with/without timestamps and async variants using a JFK audio sample.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop hop, the ASR tests now run,
With JFK's voice and files from disk,
Transcripts dance both sync and async fun,
Timestamps verified with careful brisk,
Integration growing, tests are spun! 🎙️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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 change: adding integration tests for ASR functionality using sample audio files, which directly matches the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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
  • Commit unit tests in branch feat/asr-test

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.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new ASR integration coverage that transcribes a known, committed sample audio file (samples/jfk.wav) to validate end-to-end ASR behavior (sync + async) against expected English content.

Changes:

  • Introduce SAMPLES_DIR and a jfk.wav-backed fixture for integration testing.
  • Add sync ASR integration tests validating transcription text and segment timing.
  • Add an async ASR integration test validating transcription text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def test_asr_from_file_with_timestamps(self, client, jfk_audio):
"""Test transcription with timestamps from a known audio file."""
result = client.asr.transcribe(audio=jfk_audio, language="en")
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

test_asr_from_file_with_timestamps relies on the default include_timestamps=True. Making this explicit in the call would prevent the test from silently changing meaning if the client default ever changes.

Suggested change
result = client.asr.transcribe(audio=jfk_audio, language="en")
result = client.asr.transcribe(audio=jfk_audio, language="en", include_timestamps=True)

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +85
def test_asr_from_file_without_timestamps(self, client, jfk_audio):
"""Test transcription without timestamps from a known audio file."""
result = client.asr.transcribe(audio=jfk_audio, include_timestamps=False)

assert isinstance(result, ASRResponse)
assert result.text
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

test_asr_from_file_without_timestamps doesn’t currently assert anything about timestamps/segments (it only checks result.text). To validate include_timestamps=False, assert that result.segments is empty (or that segment timing fields are absent, depending on the API contract).

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +58
@pytest.fixture
def jfk_audio(self):
"""Load the JFK sample audio file."""
return (SAMPLES_DIR / "jfk.wav").read_bytes()
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The jfk_audio fixture is duplicated in both sync and async test classes. Consider defining it once (e.g., at module level, optionally with a broader scope like module/session) to avoid repetition and repeated disk I/O.

Copilot uses AI. Check for mistakes.
Copy link

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/integration/test_asr_integration.py (1)

55-58: Extract jfk_audio into one module-level fixture.

The fixture is duplicated verbatim in both classes. Keeping the file read in one place avoids drift and makes future sample-path changes a single edit.

♻️ Proposed refactor
 SAMPLES_DIR = Path(__file__).resolve().parents[2] / "samples"
+
+
+@pytest.fixture
+def jfk_audio():
+    """Load the JFK sample audio file."""
+    return (SAMPLES_DIR / "jfk.wav").read_bytes()
 
 
 class TestASRFromFileIntegration:
     """Test ASR using a sample audio file with known content."""
-
-    `@pytest.fixture`
-    def jfk_audio(self):
-        """Load the JFK sample audio file."""
-        return (SAMPLES_DIR / "jfk.wav").read_bytes()
 
     def test_asr_from_file(self, client, jfk_audio):
         """Test transcription of a known audio file."""
         result = client.asr.transcribe(audio=jfk_audio, language="en")
@@
 class TestAsyncASRFromFileIntegration:
     """Test async ASR using a sample audio file."""
-
-    `@pytest.fixture`
-    def jfk_audio(self):
-        """Load the JFK sample audio file."""
-        return (SAMPLES_DIR / "jfk.wav").read_bytes()
 
     `@pytest.mark.asyncio`
     async def test_async_asr_from_file(self, async_client, jfk_audio):

Also applies to: 91-94

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/test_asr_integration.py` around lines 55 - 58, Move the
duplicated pytest fixture jfk_audio out of the test classes and define it once
at module scope (a single top-level fixture that reads SAMPLES_DIR / "jfk.wav").
Remove the class-level jfk_audio methods in both test classes so tests simply
depend on the module-level jfk_audio fixture; keep the fixture name unchanged so
no test signatures need updating.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/test_asr_integration.py`:
- Around line 80-85: Update the test_asr_from_file_without_timestamps test to
also assert that the ASRResponse contains no segments when
include_timestamps=False and to pass language="en" to transcribe; specifically,
call client.asr.transcribe(audio=jfk_audio, include_timestamps=False,
language="en") and then assert isinstance(result, ASRResponse), assert
result.text, and assert that result.segments is empty (e.g.,
len(result.segments) == 0 or result.segments == []), referencing the ASRResponse
and client.asr.transcribe usage.
- Around line 70-72: The test function test_asr_from_file_with_timestamps should
explicitly pass include_timestamps=True to the SDK call so it exercises the
timestamped-transcription path regardless of SDK defaults; update the call to
client.asr.transcribe(audio=jfk_audio, language="en", include_timestamps=True)
to ensure the test asserts timestamp behavior deterministically.

---

Nitpick comments:
In `@tests/integration/test_asr_integration.py`:
- Around line 55-58: Move the duplicated pytest fixture jfk_audio out of the
test classes and define it once at module scope (a single top-level fixture that
reads SAMPLES_DIR / "jfk.wav"). Remove the class-level jfk_audio methods in both
test classes so tests simply depend on the module-level jfk_audio fixture; keep
the fixture name unchanged so no test signatures need updating.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 45c8bbea-b008-4ed7-b91b-9ac8f0d76f00

📥 Commits

Reviewing files that changed from the base of the PR and between dd251bf and 2d3075f.

⛔ Files ignored due to path filters (1)
  • samples/jfk.wav is excluded by !**/*.wav
📒 Files selected for processing (1)
  • tests/integration/test_asr_integration.py

Comment on lines +70 to +72
def test_asr_from_file_with_timestamps(self, client, jfk_audio):
"""Test transcription with timestamps from a known audio file."""
result = client.asr.transcribe(audio=jfk_audio, language="en")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Pass include_timestamps=True explicitly.

Line 72 currently depends on the SDK default. If that default changes, this test stops exercising the timestamped path and becomes a false positive.

🛠️ Suggested fix
-        result = client.asr.transcribe(audio=jfk_audio, language="en")
+        result = client.asr.transcribe(
+            audio=jfk_audio,
+            language="en",
+            include_timestamps=True,
+        )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/test_asr_integration.py` around lines 70 - 72, The test
function test_asr_from_file_with_timestamps should explicitly pass
include_timestamps=True to the SDK call so it exercises the
timestamped-transcription path regardless of SDK defaults; update the call to
client.asr.transcribe(audio=jfk_audio, language="en", include_timestamps=True)
to ensure the test asserts timestamp behavior deterministically.

Comment on lines +80 to +85
def test_asr_from_file_without_timestamps(self, client, jfk_audio):
"""Test transcription without timestamps from a known audio file."""
result = client.asr.transcribe(audio=jfk_audio, include_timestamps=False)

assert isinstance(result, ASRResponse)
assert result.text
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Assert that timestamps are actually omitted.

This test still passes if include_timestamps=False is ignored and segments are returned, so it doesn't verify the behavior its name promises. src/fishaudio/types/asr.py:20-31 documents segments as empty when timestamps are disabled. While touching this, pass language="en" here too so the test only varies the timestamp flag.

🛠️ Suggested fix
-        result = client.asr.transcribe(audio=jfk_audio, include_timestamps=False)
+        result = client.asr.transcribe(
+            audio=jfk_audio,
+            language="en",
+            include_timestamps=False,
+        )
 
         assert isinstance(result, ASRResponse)
         assert result.text
+        assert not result.segments
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/test_asr_integration.py` around lines 80 - 85, Update the
test_asr_from_file_without_timestamps test to also assert that the ASRResponse
contains no segments when include_timestamps=False and to pass language="en" to
transcribe; specifically, call client.asr.transcribe(audio=jfk_audio,
include_timestamps=False, language="en") and then assert isinstance(result,
ASRResponse), assert result.text, and assert that result.segments is empty
(e.g., len(result.segments) == 0 or result.segments == []), referencing the
ASRResponse and client.asr.transcribe usage.

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