The garden learns which language a card is in, and read-aloud stops guessing
Phase 28 (c), the last of the phase. A word met inside a Portuguese document is a Portuguese card: migration 0018 mirrors documents.doc_lang onto vocab_words, set server-side from the ownership lookup capture was already making. Every card still reviews — filtering the queue to the half she is learning would drop the words she actually met. Read-aloud was the larger surprise. detectLang routed Han/kana to Chinese and everything else to en-US, so the zh pair was accidentally right and every Latin pair wrong. doc_lang now reaches the client read-only on the document JSON, and docLang(text, verdict) answers for a passage taken out of it — with the script test still winning, because quoted Chinese must never be spelled out one "Chinese letter" at a time. Claude-Session: https://claude.ai/code/session_01GJHNvirh7Hzhc9RL3HAvz7
This commit is contained in:
@@ -184,3 +184,60 @@ func TestCorrectedSentence(t *testing.T) {
|
||||
t.Errorf("unterminated doc: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlantedPhraseCarriesTheDocumentLanguage: a chunk planted out of a document
|
||||
// written in her own language is a card in that language. The collocation pass
|
||||
// itself deliberately did not flip in Phase 28 — its prompt is per-language
|
||||
// knowledge, not framing — but the phrase it hands over is still lifted from her
|
||||
// prose, so the card has to know what language that prose was in or the garden
|
||||
// will read it aloud in the wrong voice.
|
||||
func TestPlantedPhraseCarriesTheDocumentLanguage(t *testing.T) {
|
||||
srv, docID, h := newTestServer(t, &stubClient{})
|
||||
if _, err := h.DB.Exec(`UPDATE documents SET doc_lang = 'pair' WHERE id = ?`, docID); err != nil {
|
||||
t.Fatalf("set doc_lang: %v", err)
|
||||
}
|
||||
id := seedSuggestion(t, h, docID,
|
||||
"Ontem foi difícil. Tive de tomar uma decisão sobre o trabalho.",
|
||||
db.SuggestionTypeCollocation, "tomar uma decisão", "tomar uma decisão",
|
||||
"Em português diz-se “tomar” uma decisão.")
|
||||
|
||||
if rec := do(t, srv, http.MethodPost, "/suggestions/"+id+"/accept", ""); rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("accept: got %d, want 204", rec.Code)
|
||||
}
|
||||
|
||||
var lang string
|
||||
if err := h.DB.QueryRow(
|
||||
`SELECT lang FROM vocab_words WHERE user_id = ? AND word = ?`,
|
||||
db.LocalUserID, "tomar uma decisão",
|
||||
).Scan(&lang); err != nil {
|
||||
t.Fatalf("read planted card: %v", err)
|
||||
}
|
||||
if lang != "pair" {
|
||||
t.Fatalf("planted card lang = %q, want pair", lang)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlantedPhraseOnAnEnglishDocumentIsUnchanged is the other half, and the one
|
||||
// every account is on today: an English document plants an English card, and the
|
||||
// empty backfill and 'en' both mean that.
|
||||
func TestPlantedPhraseOnAnEnglishDocumentIsUnchanged(t *testing.T) {
|
||||
srv, docID, h := newTestServer(t, &stubClient{})
|
||||
id := seedSuggestion(t, h, docID, "I had to do a decision about the job.",
|
||||
db.SuggestionTypeCollocation, "do a decision", "make a decision",
|
||||
"English pairs “make” with “decision”.")
|
||||
|
||||
if rec := do(t, srv, http.MethodPost, "/suggestions/"+id+"/accept", ""); rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("accept: got %d, want 204", rec.Code)
|
||||
}
|
||||
|
||||
var lang string
|
||||
if err := h.DB.QueryRow(
|
||||
`SELECT lang FROM vocab_words WHERE user_id = ? AND word = ?`,
|
||||
db.LocalUserID, "make a decision",
|
||||
).Scan(&lang); err != nil {
|
||||
t.Fatalf("read planted card: %v", err)
|
||||
}
|
||||
if lang == "pair" {
|
||||
t.Fatalf("planted card lang = %q on an English document, want en or empty", lang)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user