Ariver
2026-07-12 8d5843394f6ac48c7f23c9fbf73d0bed3d99b069
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
package services
 
import (
    "testing"
 
    "voicesnap/internal/config"
    "voicesnap/internal/model"
)
 
func TestEngineServiceDownloadStatusTracksCancelAndFinish(t *testing.T) {
    service := NewEngineService(nil)
    status := service.GetModelDownloadStatus()
    if status["active"].(bool) {
        t.Fatal("new service should not report an active model download")
    }
 
    _, finish, err := service.beginModelDownload("zipformer-ko")
    if err != nil {
        t.Fatal(err)
    }
    status = service.GetModelDownloadStatus()
    if !status["active"].(bool) {
        t.Fatal("active download was not reported")
    }
    if got := status["modelID"]; got != "zipformer-ko" {
        t.Fatalf("modelID = %v, want zipformer-ko", got)
    }
    if status["cancelling"].(bool) {
        t.Fatal("new download should not start in cancelling state")
    }
 
    service.updateModelDownloadProgress("zipformer-ko", 42.5, 425, 1000)
    status = service.GetModelDownloadStatus()
    if got := status["percent"]; got != 42.5 {
        t.Fatalf("percent = %v, want 42.5", got)
    }
    if got := status["downloaded"]; got != int64(425) {
        t.Fatalf("downloaded = %v, want 425", got)
    }
    if got := status["total"]; got != int64(1000) {
        t.Fatalf("total = %v, want 1000", got)
    }
 
    if !service.CancelModelDownload("zipformer-ko") {
        t.Fatal("expected active download to be cancelled")
    }
    status = service.GetModelDownloadStatus()
    if !status["cancelling"].(bool) {
        t.Fatal("cancelled download should report cancelling state until finish")
    }
 
    finish()
    status = service.GetModelDownloadStatus()
    if status["active"].(bool) {
        t.Fatal("finished download should clear active state")
    }
    if got := status["modelID"]; got != "" {
        t.Fatalf("modelID after finish = %v, want empty", got)
    }
}
 
func TestListModelOptionsForCantoneseOnlyOffersSenseVoiceYue(t *testing.T) {
    cfg := config.Default()
    cfg.LanguageMode = config.LanguageModeManual
    cfg.LanguageID = model.CantoneseLanguageID
    cfg.ModelSelectionMode = config.ModelSelectionModeAuto
 
    service := NewEngineService(cfg)
    options := service.ListModelOptions()
    if len(options) != 1 {
        t.Fatalf("options len = %d, want 1: %#v", len(options), options)
    }
    if got := options[0]["modelID"]; got != model.SenseVoiceYueModelID {
        t.Fatalf("modelID = %v, want %s", got, model.SenseVoiceYueModelID)
    }
    if got := options[0]["isDefault"]; got != true {
        t.Fatalf("isDefault = %v, want true", got)
    }
}
 
func TestListModelOptionsForLanguagePreviewsCantoneseWithoutPersisting(t *testing.T) {
    cfg := config.Default()
    cfg.LanguageMode = config.LanguageModeManual
    cfg.LanguageID = model.DefaultLanguageID
    service := NewEngineService(cfg)
 
    options := service.ListModelOptionsForLanguage(model.CantoneseLanguageID)
    if len(options) != 1 {
        t.Fatalf("options len = %d, want 1: %#v", len(options), options)
    }
    if got := options[0]["modelID"]; got != model.SenseVoiceYueModelID {
        t.Fatalf("modelID = %v, want %s", got, model.SenseVoiceYueModelID)
    }
    if got := options[0]["languageID"]; got != model.CantoneseLanguageID {
        t.Fatalf("languageID = %v, want %s", got, model.CantoneseLanguageID)
    }
    if cfg.LanguageID != model.DefaultLanguageID {
        t.Fatalf("cfg.LanguageID = %q, want unchanged %q", cfg.LanguageID, model.DefaultLanguageID)
    }
}
 
func TestListModelOptionsForLanguageDoesNotMarkSharedCurrentModelForPendingLanguage(t *testing.T) {
    cfg := config.Default()
    cfg.LanguageMode = config.LanguageModeManual
    cfg.LanguageID = model.DefaultLanguageID
    cfg.ModelSelectionMode = config.ModelSelectionModeManual
    cfg.SelectedModelID = model.XASRZhEn960ModelID
    service := NewEngineService(cfg)
 
    options := service.ListModelOptionsForLanguage(model.EnglishLanguageID)
    var found bool
    for _, option := range options {
        if option["modelID"] != model.XASRZhEn960ModelID {
            continue
        }
        found = true
        if got := option["isCurrent"]; got != false {
            t.Fatalf("isCurrent = %v, want false for pending language shared model", got)
        }
    }
    if !found {
        t.Fatalf("expected %s in English options: %#v", model.XASRZhEn960ModelID, options)
    }
}
 
func TestAllowedModelProfileForLanguageAcceptsCantoneseWithoutPersisting(t *testing.T) {
    cfg := config.Default()
    cfg.LanguageMode = config.LanguageModeManual
    cfg.LanguageID = model.DefaultLanguageID
    service := NewEngineService(cfg)
 
    profile, languageProfile, err := service.allowedModelProfileForLanguage(model.CantoneseLanguageID, model.SenseVoiceYueModelID)
    if err != nil {
        t.Fatalf("allowedModelProfileForLanguage returned error: %v", err)
    }
    if profile.ID != model.SenseVoiceYueModelID {
        t.Fatalf("profile id = %q, want %q", profile.ID, model.SenseVoiceYueModelID)
    }
    if languageProfile.ID != model.CantoneseLanguageID {
        t.Fatalf("language profile id = %q, want %q", languageProfile.ID, model.CantoneseLanguageID)
    }
    if _, err := service.allowedModelProfile(model.SenseVoiceYueModelID); err == nil {
        t.Fatal("expected current Chinese language to reject SenseVoice Yue")
    }
}
 
func TestAllowedModelProfileForLanguageAcceptsTargetLanguageUpgradeWithoutPersisting(t *testing.T) {
    cfg := config.Default()
    cfg.LanguageMode = config.LanguageModeManual
    cfg.LanguageID = model.DefaultLanguageID
    service := NewEngineService(cfg)
 
    profile, languageProfile, err := service.allowedModelProfileForLanguage(model.EnglishLanguageID, model.ParakeetModelID)
    if err != nil {
        t.Fatalf("allowedModelProfileForLanguage returned error: %v", err)
    }
    if profile.ID != model.ParakeetModelID {
        t.Fatalf("profile id = %q, want %q", profile.ID, model.ParakeetModelID)
    }
    if languageProfile.ID != model.EnglishLanguageID {
        t.Fatalf("language profile id = %q, want %q", languageProfile.ID, model.EnglishLanguageID)
    }
    if _, err := service.allowedModelProfile(model.ParakeetModelID); err == nil {
        t.Fatal("expected current Chinese language to reject Parakeet")
    }
}