Ariver
2026-06-30 5b5cba7030b7f4dd519868fe310bb4fce893bf91
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
 
import (
    "strings"
    "testing"
    "time"
)
 
func TestLiveCaptionDisplayTextFitsOverlayBuffer(t *testing.T) {
    input := strings.Repeat("这是一句实时字幕", 12)
    got := liveCaptionDisplayText(input)
    if got == "" {
        t.Fatal("caption should not be empty")
    }
    if len([]byte(got)) > liveCaptionMaxBytes {
        t.Fatalf("caption bytes = %d, want <= %d", len([]byte(got)), liveCaptionMaxBytes)
    }
    if !strings.HasPrefix(got, "...") {
        t.Fatalf("caption = %q, want leading truncation marker", got)
    }
}
 
func TestReleaseTailCaptureDelayUsesEngineCapability(t *testing.T) {
    a := &App{}
    a.replaceEngine(tailCaptureTestEngine{delay: 300 * time.Millisecond})
 
    if got := a.releaseTailCaptureDelay(); got != 300*time.Millisecond {
        t.Fatalf("releaseTailCaptureDelay() = %v, want 300ms", got)
    }
}
 
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 TestReleaseTailCaptureDelayDefaultsToProtectionWindow(t *testing.T) {
    a := &App{}
    a.replaceEngine(plainTestEngine{})
 
    if got := a.releaseTailCaptureDelay(); got != defaultReleaseTailDelay {
        t.Fatalf("releaseTailCaptureDelay() = %v, want %v", got, defaultReleaseTailDelay)
    }
}
 
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 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")
    }
}
 
func TestStartRecordingIgnoredWhileStoppingRecording(t *testing.T) {
    a := &App{isStoppingRecording: true}
 
    a.startRecordingLocked()
 
    if a.isRecording {
        t.Fatal("startRecordingLocked should not start while stop tail capture is pending")
    }
}
 
func TestStartTapRecordingIgnoredWhileStoppingRecording(t *testing.T) {
    a := &App{isStoppingRecording: true}
 
    a.startTapRecordingLocked()
 
    if a.isRecording || a.isFreetalking {
        t.Fatal("startTapRecordingLocked should not start while stop tail capture is pending")
    }
}
 
type plainTestEngine struct{}
 
func (plainTestEngine) Recognize([]float32) (string, error) { return "", nil }
func (plainTestEngine) HardwareInfo() string                { return "test" }
func (plainTestEngine) Close()                              {}
 
type tailCaptureTestEngine struct {
    plainTestEngine
    delay time.Duration
}
 
func (e tailCaptureTestEngine) ReleaseTailCaptureDelay() time.Duration {
    return e.delay
}
 
type holdPreCaptureTestEngine struct {
    plainTestEngine
    enabled bool
}
 
func (e holdPreCaptureTestEngine) HoldPreCaptureEnabled() bool {
    return e.enabled
}