Ariver
2026-07-02 8c9ba89a748d4c99810b31f3b455d1ed43d9b61f
privatevoice.src/app_live_caption_test.go
@@ -29,12 +29,120 @@
   }
}
func TestReleaseTailCaptureDelayDefaultsToZero(t *testing.T) {
func TestReleaseTailCaptureDelayCanBeDisabledByEngineCapability(t *testing.T) {
   a := &App{}
   a.replaceEngine(tailCaptureTestEngine{delay: 0})
   if got := a.releaseTailCaptureDelay(); got != 0 {
      t.Fatalf("releaseTailCaptureDelay() = %v, want 0", got)
   }
}
func TestReleaseTailCaptureDelayDefaultsToNoProtectionWindow(t *testing.T) {
   a := &App{}
   a.replaceEngine(plainTestEngine{})
   if got := a.releaseTailCaptureDelay(); got != 0 {
      t.Fatalf("releaseTailCaptureDelay() = %v, want 0", got)
   }
}
func TestReleaseTailCaptureDelayDisabledWithoutEngine(t *testing.T) {
   a := &App{}
   a.replaceEngine(nil)
   if got := a.releaseTailCaptureDelay(); got != 0 {
      t.Fatalf("releaseTailCaptureDelay() = %v, want 0 without engine", got)
   }
}
func TestSlowRecognitionReason(t *testing.T) {
   tests := []struct {
      name        string
      recognizeMS int64
      totalMS     int64
      want        string
   }{
      {name: "fast", recognizeMS: 2000, totalMS: 2500, want: ""},
      {name: "recognize", recognizeMS: 2001, totalMS: 2400, want: "recognize"},
      {name: "total", recognizeMS: 1000, totalMS: 2501, want: "total"},
      {name: "both", recognizeMS: 2001, totalMS: 2501, want: "recognize,total"},
   }
   for _, tt := range tests {
      t.Run(tt.name, func(t *testing.T) {
         if got := slowRecognitionReason(tt.recognizeMS, tt.totalMS); got != tt.want {
            t.Fatalf("slowRecognitionReason(%d, %d) = %q, want %q", tt.recognizeMS, tt.totalMS, got, tt.want)
         }
      })
   }
}
func TestHoldPreCaptureUsesEngineCapability(t *testing.T) {
   a := &App{}
   a.replaceEngine(holdPreCaptureTestEngine{enabled: true})
   if !a.holdPreCaptureEnabled.Load() {
      t.Fatal("hold pre-capture should be enabled by engine capability")
   }
}
func TestHoldPreCaptureCanBeDisabledByEngineCapability(t *testing.T) {
   a := &App{}
   a.replaceEngine(holdPreCaptureTestEngine{enabled: false})
   if a.holdPreCaptureEnabled.Load() {
      t.Fatal("hold pre-capture should respect engine capability false")
   }
}
func TestHoldPreCaptureDefaultsToTrueForReadyEngine(t *testing.T) {
   a := &App{}
   a.replaceEngine(plainTestEngine{})
   if !a.holdPreCaptureEnabled.Load() {
      t.Fatal("hold pre-capture should default to true for ready engines")
   }
}
func TestHoldPreCaptureDisabledWithoutEngine(t *testing.T) {
   a := &App{}
   a.replaceEngine(nil)
   if a.holdPreCaptureEnabled.Load() {
      t.Fatal("hold pre-capture should be disabled without an engine")
   }
}
func TestShouldStartHoldPreCaptureLocked(t *testing.T) {
   a := &App{}
   a.holdPreCaptureEnabled.Store(true)
   if !a.shouldStartHoldPreCaptureLocked() {
      t.Fatal("expected hold pre-capture to start when enabled and idle")
   }
   a.isRecording = true
   if a.shouldStartHoldPreCaptureLocked() {
      t.Fatal("should not pre-capture while already recording")
   }
   a.isRecording = false
   a.isStoppingRecording = true
   if a.shouldStartHoldPreCaptureLocked() {
      t.Fatal("should not pre-capture while stopping")
   }
   a.isStoppingRecording = false
   a.isFreetalking = true
   if a.shouldStartHoldPreCaptureLocked() {
      t.Fatal("should not pre-capture while tap recording is active")
   }
   a.isFreetalking = false
   a.lastStopTime = time.Now()
   if a.shouldStartHoldPreCaptureLocked() {
      t.Fatal("should not pre-capture during post-stop debounce")
   }
}
@@ -72,3 +180,12 @@
func (e tailCaptureTestEngine) ReleaseTailCaptureDelay() time.Duration {
   return e.delay
}
type holdPreCaptureTestEngine struct {
   plainTestEngine
   enabled bool
}
func (e holdPreCaptureTestEngine) HoldPreCaptureEnabled() bool {
   return e.enabled
}