fix(翻译bug):修复翻译超时失败!
deploy-hxtesting / build-and-deploy (push) Successful in 1m15s

This commit is contained in:
runny committed 2026-11-30 23:22:23 +08:00
1 parent 74d21cb204
commit 7d3b6804af
5 files changed
+220 -15

No files matched your search

+31
View File
@@ -440,3 +440,34 @@ func min(a, b int) int {
}
return b
}
// TestTranslateCollapsesWhitespaceVariants covers the positional-protocol
// desync: whitespace-padded variants of one term must collapse into a single
// translation unit, or a batch containing both loses an answer (19 of 20).
func TestTranslateCollapsesWhitespaceVariants(t *testing.T) {
var buf bytes.Buffer
zw := zip.NewWriter(&buf)
w, _ := zw.Create("xl/sharedStrings.xml")
w.Write([]byte(`<sst xmlns="x">` +
`<si><t>客 戶</t></si>` +
`<si><t>客 戶</t></si>` +
`<si><t>客户资料清单</t></si>` +
`</sst>`))
zw.Close()
tr := &fakeTranslator{}
out, report, err := Translate(context.Background(), buf.Bytes(), nil, tr)
if err != nil {
t.Fatalf("Translate: %v", err)
}
if report.TranslatedUnits != 2 {
t.Fatalf("expected 2 canonical units after whitespace collapse, got %d", report.TranslatedUnits)
}
ss := string(zipEntry(t, out, "xl/sharedStrings.xml"))
if hasCJK(ss) {
t.Fatalf("variants left untranslated:\n%s", ss)
}
if strings.Count(ss, "Customer") != 2 {
t.Fatalf("both whitespace variants should carry the glossary translation:\n%s", ss)
}
}