Files
OSGKeyboard/OSGKeyboardTests/FinalChunkRecoveryTests.swift
T
Cursor Agent c7ee891a90 fix(flow): improve tail capture and final chunk ASR recovery
- Add FlowUtteranceEndCoordinator with 350ms silence drain and 150ms post-roll
- Extend FinalChunkRecovery for short/empty final chunks in chunked pipeline
- Snapshot partial at mic stop and guard final transcript in FlowSessionManager
- Unify tail drain presets (iosFlow/macMLX) and expand diagnostics

Co-authored-by: Rocky <hkgood@users.noreply.github.com>
2026-07-26 10:13:40 +00:00

75 lines
2.1 KiB
Swift

// FinalChunkRecoveryTests.swift
// OSGKeyboardTests
import XCTest
@testable import OSGKeyboardShared
final class FinalChunkRecoveryTests: XCTestCase {
private let config = FlowUtteranceChunkConfig(
maxChunkDurationSeconds: 5.0,
overlapDurationSeconds: 0.5,
pauseExtensionMaxSeconds: 2,
pauseRMSThreshold: 0.015,
minFinalChunkDurationSeconds: 0.8,
sampleRate: 16_000
)
func testPreMergePlanForShortFinalChunk() {
let chunk = UtteranceAudioChunk(
index: 1,
samples: [Float](repeating: 0.1, count: 4_000),
isLast: true
)
let previous = [Float](repeating: 0.2, count: 80_000)
let plan = FinalChunkRecovery.preMergePlan(
chunk: chunk,
processedChunks: 2,
previousChunkSamples: previous,
config: config
)
XCTAssertNotNil(plan)
XCTAssertGreaterThan(plan?.samples.count ?? 0, chunk.samples.count)
XCTAssertEqual(plan?.stitchIndex, 0)
}
func testEmptyResultRetryPlanUsesOverlapWhenPriorChunkExists() {
let chunk = UtteranceAudioChunk(
index: 1,
samples: [Float](repeating: 0.1, count: 20_000),
isLast: true
)
let previous = [Float](repeating: 0.2, count: 80_000)
let plan = FinalChunkRecovery.emptyResultRetryPlan(
chunk: chunk,
previousChunkSamples: previous,
config: config,
asrText: " "
)
XCTAssertNotNil(plan)
XCTAssertGreaterThan(plan?.samples.count ?? 0, chunk.samples.count)
}
func testEmptyResultRetryPlanRetriesSingleChunkSamples() {
let chunk = UtteranceAudioChunk(
index: 0,
samples: [Float](repeating: 0.1, count: 20_000),
isLast: true
)
let plan = FinalChunkRecovery.emptyResultRetryPlan(
chunk: chunk,
previousChunkSamples: [],
config: config,
asrText: ""
)
XCTAssertEqual(plan?.samples.count, chunk.samples.count)
XCTAssertEqual(plan?.stitchIndex, 0)
}
}