openclaw/scripts/docs-i18n/tm_test.go
Peter Steinberger 3aab4de286
refactor(scripts): deslop tooling scripts fourth pass (#161525)
Share documentation translation response cleanup, simplify sorted translation-memory JSONL writing, use canonical Node inspector types, and remove redundant benchmark and preview-fixture state.

Preserve CLI flags, exit codes, output formats, generated bytes, fixture responses, and benchmark workloads. Focused tests, exact before/after JSONL and mock-response checks, and both import-cycle gates passed. The optional cron-reaper smoke reproduced the same existing worker timeout before and after the refactor.

Release notes: internal tooling cleanup only.

Hosted CI exception: run 36661925129 failed before tests because the trusted CI harness omitted ci-build-manifest.mjs. Current unrelated run 36663040449 failed identically. Security/dependency review and security-fast passed; skipped CI lanes remain unrun. Merged under the maintainer-authorized pre-existing-failure exception.
2026-09-29 20:26:21 -07:00

40 lines
1.2 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
)
func TestTranslationMemorySavePreservesJSONL(t *testing.T) {
t.Parallel()
file := filepath.Join(t.TempDir(), "memory.jsonl")
memory, err := LoadTranslationMemory(file)
if err != nil {
t.Fatal(err)
}
memory.Put(TMEntry{CacheKey: "z", Text: "<tag>\n&", Translated: "日本語\u2028"})
memory.Put(TMEntry{CacheKey: "a", Translated: "first"})
if err := memory.Save(); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}
want := `{"cache_key":"a","segment_id":"","source_path":"","text_hash":"","text":"","translated":"first","src_lang":"","tgt_lang":"","updated_at":""}` + "\n" +
`{"cache_key":"z","segment_id":"","source_path":"","text_hash":"","text":"\u003ctag\u003e\n\u0026","translated":"日本語\u2028","src_lang":"","tgt_lang":"","updated_at":""}` + "\n"
if string(data) != want {
t.Fatalf("translation memory bytes changed:\n%s", data)
}
reloaded, err := LoadTranslationMemory(file)
if err != nil {
t.Fatal(err)
}
for _, key := range []string{"a", "z"} {
want, _ := memory.Get(key)
if got, ok := reloaded.Get(key); !ok || got != want {
t.Fatalf("translation memory entry %q did not round trip: %+v", key, got)
}
}
}