Adaptiven A1-Kurs und statistisches Aussprachetraining integrieren
Direkte DeepSeek- und Mistral-Anbindung mit versionierten Aktionsprofilen, Budgetreservierung, Tokenabrechnung und administrativen Qualitätsprüfungen ersetzen die Flowise-Abhängigkeit im regulären Betrieb. 840 geprüfte A1-Aufgaben mit geschützter Testauswertung und konkreten offenen Arbeitsaufträgen ergänzen den Kurs. Inhalts- und Sprachbewertung bleiben von Azure-Aussprachewerten getrennt; historische Aufgaben und Antworten bleiben erhalten. Echte Wort- und Phonemmessungen werden mit Herkunft, Aktualität und Nachweisdichte gebündelt. Go bestimmt Trainingsziele und Wiederholungen, das Modell formuliert dazu passende Nachsprechübungen. Profilansicht und Auswahlgründe werden angezeigt. Validierung: Go-Race-Tests mit lokaler PostgreSQL-Integration, go vet, Web-Build, Audit aller 840 Aufgaben und drei Browser-Smokes mit lokalen Modell-/Speech-Fixtures bestanden. Keine Produktionsänderungen oder Live-Aufrufe.
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"speech-learning-api/internal/domain"
|
||||
)
|
||||
|
||||
func TestPronunciationGenerationUsesCurrentLanguageAndLatestEvidence(t *testing.T) {
|
||||
input := domain.GeneratedExerciseRequest{
|
||||
UserID: "private-user", TargetLanguage: "en-US", CEFRLevel: "A1", UILanguage: "de-DE",
|
||||
AvoidReferenceTexts: []string{"I drink water."}, AvoidReferenceText: "Water is cold.",
|
||||
Progress: domain.ProgressSummary{RecentAttempts: []domain.Attempt{
|
||||
{UserID: "private-user", TargetLanguage: "en-US", WordScores: []domain.WordScore{
|
||||
{Word: "water", Accuracy: 95, PhonemeScores: []domain.PhonemeScore{{Phoneme: "t", Accuracy: 90}}},
|
||||
{Word: "three", Accuracy: 60, PhonemeScores: []domain.PhonemeScore{{Phoneme: "θ", Accuracy: 40}}},
|
||||
{Word: "bread", Accuracy: 0, ErrorType: "Omission", PhonemeScores: []domain.PhonemeScore{{Phoneme: "b", Accuracy: 0}}},
|
||||
}},
|
||||
{TargetLanguage: "de-DE", WordScores: []domain.WordScore{{Word: "Brötchen", Accuracy: 30}}},
|
||||
{TargetLanguage: "en-US", WordScores: []domain.WordScore{{Word: "water", Accuracy: 40, PhonemeScores: []domain.PhonemeScore{{Phoneme: "t", Accuracy: 30}}}}},
|
||||
}},
|
||||
}
|
||||
request := pronunciationGenerationInput(input)
|
||||
words := request["recent_weak_words"].([]domain.WordScore)
|
||||
phonemes := request["recent_weak_phonemes"].([]domain.WeakPhoneme)
|
||||
if len(words) != 2 || words[0].Word != "three" || words[1].Word != "bread" {
|
||||
t.Fatalf("wrong active weaknesses: %+v", words)
|
||||
}
|
||||
if len(phonemes) != 1 || phonemes[0].Word != "three" || phonemes[0].Phoneme != "θ" || phonemes[0].Accuracy != 40 {
|
||||
t.Fatalf("wrong measured phonemes: %+v", phonemes)
|
||||
}
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(b), "private-user") || strings.Contains(string(b), "Brötchen") {
|
||||
t.Fatalf("unrelated evidence or identity leaked: %s", b)
|
||||
}
|
||||
if len(request["avoid_reference_texts"].([]string)) != 2 {
|
||||
t.Fatal("recent sentences lost")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPronunciationGenerationEmptyEvidenceDoesNotInventWeaknesses(t *testing.T) {
|
||||
request := pronunciationGenerationInput(domain.GeneratedExerciseRequest{TargetLanguage: "en-US"})
|
||||
if len(request["recent_weak_words"].([]domain.WordScore)) != 0 || len(request["recent_weak_phonemes"].([]domain.WeakPhoneme)) != 0 {
|
||||
t.Fatal("invented weaknesses")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPronunciationGenerationDoesNotExposeResolvedHistoricalErrors(t *testing.T) {
|
||||
input := domain.GeneratedExerciseRequest{TargetLanguage: "en-US", AvoidReferenceTexts: []string{"I drink tea.", " I DRINK tea. "}, Progress: domain.ProgressSummary{RecentAttempts: []domain.Attempt{
|
||||
{TargetLanguage: "en-US", RecognizedText: "New successful answer", WordScores: []domain.WordScore{{Word: "tea", Accuracy: 100, PhonemeScores: []domain.PhonemeScore{{Phoneme: "t", Accuracy: 100}}}}},
|
||||
{TargetLanguage: "en-US", RecognizedText: "Old incorrect answer", WordScores: []domain.WordScore{{Word: "tea", Accuracy: 24, PhonemeScores: []domain.PhonemeScore{{Phoneme: "t", Accuracy: 20}}}}},
|
||||
}}}
|
||||
request := pronunciationGenerationInput(input)
|
||||
if request["training_mode"] != "general" || request["evidence_window_attempts"] != 2 {
|
||||
t.Fatalf("bad evidence summary: %v", request)
|
||||
}
|
||||
b, _ := json.Marshal(request)
|
||||
for _, forbidden := range []string{"recent_evidence", "recognized_text", "accuracy", "null"} {
|
||||
if strings.Contains(string(b), forbidden) {
|
||||
t.Fatalf("obsolete evidence exposed: %s", b)
|
||||
}
|
||||
}
|
||||
if len(request["avoid_reference_texts"].([]string)) != 1 {
|
||||
t.Fatal("duplicate avoidance entries")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPronunciationTargetsMeasuredWordInsteadOfSubstitute(t *testing.T) {
|
||||
input := domain.GeneratedExerciseRequest{TargetLanguage: "en-US", Progress: domain.ProgressSummary{RecentAttempts: []domain.Attempt{{TargetLanguage: "en-US", WordScores: []domain.WordScore{
|
||||
{Word: "cat", Accuracy: 29, PhonemeScores: []domain.PhonemeScore{{Phoneme: "k", Accuracy: 19}}},
|
||||
{Word: "sits", Accuracy: 80, PhonemeScores: []domain.PhonemeScore{{Phoneme: "ɪ", Accuracy: 37}}},
|
||||
}}}}}
|
||||
request := pronunciationGenerationInput(input)
|
||||
if request["training_mode"] != "targeted" || strings.Join(request["required_practice_words"].([]string), ",") != "cat" {
|
||||
t.Fatalf("wrong focus: %v", request)
|
||||
}
|
||||
ex := pronunciationFixture()
|
||||
ex.ReferenceText = "The dog sits on the rug."
|
||||
ex.TTSText = ex.ReferenceText
|
||||
ex.FocusPoints = []string{"dog", "sits"}
|
||||
if err := pronunciationTrainingValidation(ex, request); !strings.Contains(err, `required practice word "cat"`) {
|
||||
t.Fatalf("substitution accepted: %s", err)
|
||||
}
|
||||
ex.ReferenceText = "My cat is very small."
|
||||
ex.TTSText = ex.ReferenceText
|
||||
ex.FocusPoints = []string{"cat /k/"}
|
||||
if err := pronunciationTrainingValidation(ex, request); err != "" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ex.TTSText = "My dog is very small."
|
||||
if err := pronunciationTrainingValidation(ex, request); err != "tts_text must match reference_text" {
|
||||
t.Fatal("different audio accepted", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPracticeWordMatching(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
text, word string
|
||||
want bool
|
||||
}{
|
||||
{"A CAT, please.", "cat", true}, {"Education is fun.", "cat", false}, {"Cats are small.", "cat", false},
|
||||
{"Meine Füße sind kalt.", "Füße", true}, {"Я вижу кота.", "кота", true}, {"这是我的猫。", "猫", true},
|
||||
{"I like my mother-in-law.", "mother-in-law", true}, {"", "", false},
|
||||
} {
|
||||
if got := containsPracticeWord(tc.text, tc.word); got != tc.want {
|
||||
t.Errorf("%q/%q: %v", tc.text, tc.word, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatisticalPronunciationInputUsesFrozenPlanInsteadOfRawHistory(t *testing.T) {
|
||||
plan := domain.PronunciationPlan{Algorithm: domain.PronunciationAlgorithm, Mode: "targeted", Category: "targeted", RequiredWords: []string{"cat"}, Reason: "Ein gespeichertes Trainingsziel"}
|
||||
request := pronunciationGenerationInput(domain.GeneratedExerciseRequest{TargetLanguage: "en-US", TrainingPlan: &plan, Progress: domain.ProgressSummary{RecentAttempts: []domain.Attempt{{RecognizedText: "private obsolete history", TargetLanguage: "en-US", WordScores: []domain.WordScore{{Word: "old", Accuracy: 1}}}}}})
|
||||
if request["training_plan"] != &plan || request["training_mode"] != "targeted" {
|
||||
t.Fatal("frozen plan not used", request)
|
||||
}
|
||||
raw, _ := json.Marshal(request)
|
||||
if strings.Contains(string(raw), "obsolete") || strings.Contains(string(raw), "recent_weak_words") {
|
||||
t.Fatal("historical weakness reintroduced", string(raw))
|
||||
}
|
||||
transfer := domain.PronunciationPlan{Mode: "transfer", KnownWords: []string{"cat"}, RequiredWords: []string{}}
|
||||
request["training_plan"] = &transfer
|
||||
request["required_practice_words"] = []string{}
|
||||
ex := pronunciationFixture()
|
||||
ex.CandidateWord = "cat"
|
||||
ex.ReferenceText = "My cat is small."
|
||||
ex.TTSText = ex.ReferenceText
|
||||
ex.FocusPoints = []string{"cat"}
|
||||
if reason := pronunciationTrainingValidation(ex, request); !strings.Contains(reason, "must be new") {
|
||||
t.Fatal("known transfer word accepted", reason)
|
||||
}
|
||||
ex.CandidateWord = "cup"
|
||||
ex.ReferenceText = "My cup is small."
|
||||
ex.TTSText = ex.ReferenceText
|
||||
ex.FocusPoints = []string{"cup"}
|
||||
if reason := pronunciationTrainingValidation(ex, request); reason != "" {
|
||||
t.Fatal("new candidate rejected", reason)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user