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,147 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
_ "embed"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"speech-learning-api/internal/config"
|
||||
"speech-learning-api/internal/domain"
|
||||
"speech-learning-api/internal/store"
|
||||
)
|
||||
|
||||
//go:embed testdata/bank-v1-jack.json
|
||||
var oldJackBankEntry []byte
|
||||
|
||||
func TestOpenBankInstructionsAndRubricsAreConcrete(t *testing.T) {
|
||||
entries, err := store.BundledBank()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
changed := 0
|
||||
for _, e := range entries {
|
||||
task := e.Task
|
||||
if task.Kind != "free_speech" && task.Kind != "free_text" {
|
||||
if !strings.HasPrefix(e.ID, "a1bank_en_v1_") {
|
||||
t.Fatal("unrelated task revised", e.ID)
|
||||
}
|
||||
continue
|
||||
}
|
||||
changed++
|
||||
if !strings.HasPrefix(e.ID, "a1bank_en_v2_") || strings.Contains(task.Prompt, "Situation") || !strings.Contains(task.Prompt, "eigene oder erfundene Angaben") || !strings.Contains(task.Prompt, "zwei oder drei") {
|
||||
t.Fatalf("unclear open task %s: %s", e.ID, task.Prompt)
|
||||
}
|
||||
if !strings.Contains(strings.Join(task.AnswerKey.Rubric, " "), "Werte aus der Beispielantwort sind nicht verbindlich") {
|
||||
t.Fatal("hidden example requirements", e.ID)
|
||||
}
|
||||
if e.ID == "a1bank_en_v2_introductions_speaking_17" {
|
||||
if strings.Contains(task.Prompt, "Jack") || !strings.Contains(task.Prompt, "Nenne einen Namen") || !strings.Contains(task.Prompt, "Hobby") {
|
||||
t.Fatal("reported introduction still ambiguous", task.Prompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed != 140 {
|
||||
t.Fatal("unexpected revision scope", changed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFreeSpeechEvaluationKeepsSpeechAndTranscriptDistinct(t *testing.T) {
|
||||
entries, err := store.BundledBank()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var task domain.AdaptiveTask
|
||||
for _, e := range entries {
|
||||
if e.ID == "a1bank_en_v2_introductions_speaking_17" {
|
||||
task = e.Task
|
||||
}
|
||||
}
|
||||
speech := &domain.PronunciationResult{Provider: "azure", OverallScore: 94, RecognizedText: "My name is Chuck Hill. I like sport."}
|
||||
attempt := domain.AdaptiveAttempt{Answer: speech.RecognizedText, Speech: speech}
|
||||
in := courseEvaluationInput(task, attempt, "en-US", "de-DE")
|
||||
if in["evaluation_scope"] != "content_and_language" || in["answer_source"] != "speech_transcript" || in["pronunciation_displayed_separately"] != true || in["speech"] != speech || in["answer"] != attempt.Answer {
|
||||
t.Fatal("speech contract lost", in)
|
||||
}
|
||||
if in["task"].(domain.AdaptiveTask).Prompt != task.Prompt {
|
||||
t.Fatal("visible task replaced")
|
||||
}
|
||||
prompt := NewAIService(nil, config.Config{}).Prompts["evaluate_course_attempt"]
|
||||
for _, rule := range []string{"keine solche", "Eigennamen", "kommentiere in diesem", "Chuck Hill"} {
|
||||
if !strings.Contains(prompt, rule) {
|
||||
t.Fatal("missing reported-case guidance", rule)
|
||||
}
|
||||
}
|
||||
task.Kind = "free_text"
|
||||
if _, ok := courseEvaluationInput(task, attempt, "en-US", "de-DE")["evaluation_scope"]; ok {
|
||||
t.Fatal("speech scope applied to writing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenBankPostgresRevisionPreservesAssignedTaskAndGrade(t *testing.T) {
|
||||
db, profiles := adaptiveTestDB(t)
|
||||
ctx := context.Background()
|
||||
user, err := profiles.CreateUser(ctx, "open-revision@example.test", "hash", "de-DE")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var old domain.BankEntry
|
||||
if err = json.Unmarshal(oldJackBankEntry, &old); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Reproduce an installed v1 entry and an already assigned, graded copy.
|
||||
raw, _ := json.Marshal(old)
|
||||
sum := sha256.Sum256(raw)
|
||||
_, err = db.Exec(`INSERT INTO course_v2_bank(id,language,version,revision,module_id,skill,goal,difficulty,data,checksum,active) VALUES($1,'en-US',$2,$3,$4,'speaking',$5,$6,$7,$8,true)`, old.ID, domain.CourseVersion, old.Revision, old.Task.ModuleID, old.Goal, old.Difficulty, raw, hex.EncodeToString(sum[:]))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assigned := old.Task
|
||||
assigned.ID = "old_assigned_jack"
|
||||
assigned.Source = "curated"
|
||||
data, _ := json.Marshal(assigned)
|
||||
_, err = db.Exec(`INSERT INTO course_v2_tasks(id,module_id,language,version,owner_id,source,skill,kind,data,fingerprint,bank_entry_id,presentation_count) VALUES($1,$2,'en-US',$3,$4,'curated','speaking','free_speech',$5,$6,$7,1)`, assigned.ID, assigned.ModuleID, domain.CourseVersion, user.ID, data, "bank:"+old.ID, old.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repo := store.NewAdaptiveStore(db)
|
||||
speech := &domain.PronunciationResult{Provider: "azure", OverallScore: 94}
|
||||
attempt, err := repo.Submit(ctx, user.ID, "old-open-attempt", assigned, "My name is Chuck Hill. I like sport.", speech)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
oldGrade := domain.CourseEvaluation{Score: 70, Verdict: "partial", Feedback: "Historische Bewertung", Issues: []string{"Historischer Kritikpunkt"}}
|
||||
if err = repo.Grade(ctx, user.ID, "en-US", attempt.ID, oldGrade); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = repo.InstallBank(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = repo.InstallBank(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var active bool
|
||||
var checksum string
|
||||
if err = db.QueryRow(`SELECT active,checksum FROM course_v2_bank WHERE id=$1`, old.ID).Scan(&active, &checksum); err != nil || active || checksum != hex.EncodeToString(sum[:]) {
|
||||
t.Fatal("old template rewritten/active", err, active)
|
||||
}
|
||||
actual, err := repo.Task(ctx, user.ID, "en-US", assigned.ID)
|
||||
if err != nil || actual.Prompt != assigned.Prompt {
|
||||
t.Fatal("assigned instruction changed", err, actual)
|
||||
}
|
||||
result, err := repo.Attempt(ctx, user.ID, "en-US", attempt.ID)
|
||||
if err != nil || result.Evaluation.Score != 70 || result.Evaluation.Feedback != oldGrade.Feedback || result.Speech.OverallScore != 94 {
|
||||
t.Fatal("historical grade changed", err, result)
|
||||
}
|
||||
var count int
|
||||
if err = db.QueryRow(`SELECT count(*) FROM course_v2_bank WHERE active`).Scan(&count); err != nil || count != 840 {
|
||||
t.Fatal("incorrect active inventory", count, err)
|
||||
}
|
||||
var currentPrompt string
|
||||
if err = db.QueryRow(`SELECT data->'task'->>'prompt' FROM course_v2_bank WHERE id='a1bank_en_v2_introductions_speaking_17' AND active`).Scan(¤tPrompt); err != nil || strings.Contains(currentPrompt, "Situation") {
|
||||
t.Fatal("new template missing", err, currentPrompt)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user