Skip to content

Comments

Add comprehensive tests for AudioSegmentProcessor#69

Open
ysdede wants to merge 2 commits intostagingfrom
test-audio-segment-processor-4272967605191316370
Open

Add comprehensive tests for AudioSegmentProcessor#69
ysdede wants to merge 2 commits intostagingfrom
test-audio-segment-processor-4272967605191316370

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 7, 2026

Improved test coverage for AudioSegmentProcessor.ts by adding a comprehensive test suite in AudioSegmentProcessor.test.ts. Verified that tests pass with bun test and npm test.


PR created automatically by Jules for task 4272967605191316370 started by @ysdede

Summary by CodeRabbit

  • Tests
    • Enhanced test suite for audio segment processing with comprehensive coverage for initialization, noise floor adaptation, speech detection, segment splitting, statistical calculations, and state management.

This commit overwrites `src/lib/audio/AudioSegmentProcessor.test.ts` with a full test suite using `vitest`.
The new tests cover:
- Initialization and defaults
- Noise floor adaptation (silence processing)
- Speech onset detection
- Speech offset detection with silence thresholds
- Proactive segment splitting for long utterances
- Statistics calculation
- Configuration updates via setters

This ensures the core VAD logic is reliable and behaves as expected.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

The test suite for AudioSegmentProcessor is significantly expanded, replacing a basic initialization test with comprehensive test coverage. New tests exercise initialization defaults, noise floor adaptation, speech onset/offset detection, segment splitting based on duration limits, statistical calculations, configuration changes, and state reset behavior.

Changes

Cohort / File(s) Summary
Test Suite Expansion
src/lib/audio/AudioSegmentProcessor.test.ts
Comprehensive test suite added covering initialization, noise floor adaptation, speech onset/offset detection, long segment splitting, statistical calculations, configuration changes, and reset behavior. Introduces shared processor initialization via beforeEach and concrete test helpers (createSilenceChunk, createSpeechChunk) and constants for cleaner, more maintainable tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With tests so thorough, row by row,
We test the silence, test the flow,
Each segment splits just right on time,
Statistics counted, state sublime—
hop hop the audio processor shines! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'Add comprehensive tests for AudioSegmentProcessor' directly and clearly describes the main change—a comprehensive test suite expansion for AudioSegmentProcessor with 173 added lines.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test-audio-segment-processor-4272967605191316370

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.

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

🤖 Fix all issues with AI agents
In `@src/lib/audio/AudioSegmentProcessor.test.ts`:
- Around line 64-65: The test captures the return value from
processor.processAudioData into the segments variable but never asserts on it;
add an assertion such as expect(segments).toHaveLength(0) (or appropriate
expected length) after calling processAudioData to confirm processAudioData (in
AudioSegmentProcessor.processAudioData) does not emit a segment prematurely.
- Around line 6-8: The test hardcodes windowSize (1280) which duplicates
DEFAULT_WINDOW_DURATION; update the test to import DEFAULT_WINDOW_DURATION (or
an exported computed WINDOW_SIZE) from the audio module and compute windowSize =
Math.round(DEFAULT_WINDOW_DURATION * sampleRate) so the test follows the
implementation; locate references to windowSize in AudioSegmentProcessor.test.ts
and replace the literal with the derived value using the imported
DEFAULT_WINDOW_DURATION (or use the module's exported computed value) so changes
to DEFAULT_WINDOW_DURATION automatically keep tests correct.
📜 Review details

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4adbc64 and 281d2a9.

📒 Files selected for processing (1)
  • src/lib/audio/AudioSegmentProcessor.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/lib/audio/AudioSegmentProcessor.test.ts (2)
src/lib/audio/AudioSegmentProcessor.ts (1)
  • AudioSegmentProcessor (102-609)
src/lib/audio/audioParams.ts (1)
  • sampleRate (144-144)
🔇 Additional comments (7)
src/lib/audio/AudioSegmentProcessor.test.ts (7)

23-31: LGTM!

Initialization test correctly verifies default state: stats defined, positive noise floor, no active speech.


33-49: LGTM!

Good coverage of noise floor adaptation during sustained silence.


76-114: LGTM — well-documented silence threshold logic.

The test clearly explains the chunk-by-chunk silence counter reasoning. Consider adding a few silence chunks before speech (as done in the onset test) to stabilize the noise floor, but the high energy delta (0.5 vs default 0.005) makes this unlikely to cause flakiness.


116-148: LGTM!

Good test for proactive splitting. Verifies split occurs, segment duration meets minimum, and speech state persists after the split.


191-202: LGTM!

Reset test properly verifies state is cleared and noise floor returns to the known default.


150-156: No action needed—maxSilenceWithinSpeech is a valid and fully implemented constructor option.

The property is defined in the config interface, has a default value of 0.160 (160ms), and is actively used in the speech detection logic (line 250: if (silenceDuration < this.options.maxSilenceWithinSpeech)). The test's use of maxSilenceWithinSpeech: 0 correctly configures the processor to end speech immediately upon detecting any silence.

Likely an incorrect or invalid review comment.


172-189: No issues found. The reset() method only resets internal state (inSpeech, recentChunks, stats, etc.) and does not modify configuration stored in this.options. The setThreshold() call on line 173 persists through the reset() call on line 181, so the test correctly expects inSpeech to be false when energy (0.5) is below the threshold (0.9).

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +6 to +8
const sampleRate = 16000;
// Default window duration is 0.08s (80ms), so 1280 samples at 16k
const windowSize = 1280;
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Hardcoded windowSize is fragile — derive from source constants.

windowSize is computed from an assumed DEFAULT_WINDOW_DURATION of 0.08s. If that constant changes in the implementation, these tests will silently pass wrong-sized chunks without failing, leading to subtle test inaccuracies. Consider importing DEFAULT_WINDOW_DURATION (or the computed windowSize) from the source module to keep the test in sync.

-    const sampleRate = 16000;
-    // Default window duration is 0.08s (80ms), so 1280 samples at 16k
-    const windowSize = 1280;
+    const sampleRate = 16000;
+    // Import DEFAULT_WINDOW_DURATION from the source if exported,
+    // or keep this in sync with AudioSegmentProcessor's default.
+    const DEFAULT_WINDOW_DURATION = 0.08;
+    const windowSize = Math.round(DEFAULT_WINDOW_DURATION * sampleRate);

Alternatively, if DEFAULT_WINDOW_DURATION is exported, import it directly.

#!/bin/bash
# Check if DEFAULT_WINDOW_DURATION is exported from the source
rg -n 'DEFAULT_WINDOW_DURATION' --type=ts -C2
🤖 Prompt for AI Agents
In `@src/lib/audio/AudioSegmentProcessor.test.ts` around lines 6 - 8, The test
hardcodes windowSize (1280) which duplicates DEFAULT_WINDOW_DURATION; update the
test to import DEFAULT_WINDOW_DURATION (or an exported computed WINDOW_SIZE)
from the audio module and compute windowSize =
Math.round(DEFAULT_WINDOW_DURATION * sampleRate) so the test follows the
implementation; locate references to windowSize in AudioSegmentProcessor.test.ts
and replace the literal with the derived value using the imported
DEFAULT_WINDOW_DURATION (or use the module's exported computed value) so changes
to DEFAULT_WINDOW_DURATION automatically keep tests correct.

Comment on lines +64 to +65
const startTime = 10 * 0.08;
const segments = processor.processAudioData(chunk, startTime, 0.5);
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Unused segments — consider asserting on it.

segments is captured but never checked. Adding expect(segments).toHaveLength(0) would strengthen the test by confirming that speech onset does not prematurely emit a segment.

🤖 Prompt for AI Agents
In `@src/lib/audio/AudioSegmentProcessor.test.ts` around lines 64 - 65, The test
captures the return value from processor.processAudioData into the segments
variable but never asserts on it; add an assertion such as
expect(segments).toHaveLength(0) (or appropriate expected length) after calling
processAudioData to confirm processAudioData (in
AudioSegmentProcessor.processAudioData) does not emit a segment prematurely.

@ysdede ysdede changed the base branch from release/r1 to staging February 10, 2026 20:59
@ysdede
Copy link
Owner Author

ysdede commented Feb 10, 2026

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Comprehensive test overhaul for AudioSegmentProcessor. Replaces the existing minimal tests with proper structured tests covering:

  • Speech detection with energy thresholds
  • Silence-to-speech transitions and segment emission
  • Proactive long segment splitting
  • Statistics tracking
  • Configuration setters (threshold changes)
  • State reset

Assessment: Solid improvement. Uses proper �eforeEach setup and helper functions (createSpeechChunk, createSilenceChunk). The tests are deterministic and well-structured.

Note: Overlaps with PR #66 (both add long-segment splitting tests). If merging both, merge #66 first, then #69 will need minor conflict resolution in the test file.

Recommendation:Merge — Significant test quality improvement

@google-labs-jules
Copy link
Contributor

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Comprehensive test overhaul for AudioSegmentProcessor. Replaces the existing minimal tests with proper structured tests covering:

  • Speech detection with energy thresholds
  • Silence-to-speech transitions and segment emission
  • Proactive long segment splitting
  • Statistics tracking
  • Configuration setters (threshold changes)
  • State reset

Assessment: Solid improvement. Uses proper �eforeEach setup and helper functions (createSpeechChunk, createSilenceChunk). The tests are deterministic and well-structured.

Note: Overlaps with PR #66 (both add long-segment splitting tests). If merging both, merge #66 first, then #69 will need minor conflict resolution in the test file.

Recommendation:Merge — Significant test quality improvement

Acknowledged. Thank you for the detailed review and the note regarding PR #66.

This commit overwrites `src/lib/audio/AudioSegmentProcessor.test.ts` with a full test suite using `vitest`.
The new tests cover:
- Initialization and defaults
- Noise floor adaptation (silence processing)
- Speech onset detection
- Speech offset detection with silence thresholds
- Proactive segment splitting for long utterances
- Statistics calculation
- Configuration updates via setters

This ensures the core VAD logic is reliable and behaves as expected.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@ysdede ysdede changed the title 🧪 Add comprehensive tests for AudioSegmentProcessor Add comprehensive tests for AudioSegmentProcessor Feb 12, 2026
Repository owner deleted a comment from google-labs-jules bot Feb 17, 2026
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