mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 22:15:57 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
108
openclaw/scripts/docs-i18n/main_test.go
Normal file
108
openclaw/scripts/docs-i18n/main_test.go
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type fakeDocsTranslator struct{}
|
||||
|
||||
func (fakeDocsTranslator) Translate(_ context.Context, text, _, _ string) (string, error) {
|
||||
return text, nil
|
||||
}
|
||||
|
||||
func (fakeDocsTranslator) TranslateRaw(_ context.Context, text, _, _ string) (string, error) {
|
||||
// Keep the fake translator deterministic so this test exercises the
|
||||
// docs-i18n pipeline wiring and final link relocalization, not model output.
|
||||
replaced := strings.NewReplacer(
|
||||
"Gateway", "网关",
|
||||
"See ", "参见 ",
|
||||
).Replace(text)
|
||||
return replaced, nil
|
||||
}
|
||||
|
||||
func (fakeDocsTranslator) Close() {}
|
||||
|
||||
type invalidFrontmatterTranslator struct{}
|
||||
|
||||
func (invalidFrontmatterTranslator) Translate(_ context.Context, text, _, _ string) (string, error) {
|
||||
return "<body>\n" + text + "\n</body>\n", nil
|
||||
}
|
||||
|
||||
func (invalidFrontmatterTranslator) TranslateRaw(_ context.Context, text, _, _ string) (string, error) {
|
||||
return text, nil
|
||||
}
|
||||
|
||||
func (invalidFrontmatterTranslator) Close() {}
|
||||
|
||||
func TestRunDocsI18NRewritesFinalLocalizedPageLinks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
docsRoot := t.TempDir()
|
||||
writeFile(t, filepath.Join(docsRoot, ".i18n", "glossary.zh-CN.json"), "[]")
|
||||
writeFile(t, filepath.Join(docsRoot, "docs.json"), `{"redirects":[]}`)
|
||||
writeFile(t, filepath.Join(docsRoot, "gateway", "index.md"), stringsJoin(
|
||||
"---",
|
||||
"title: Gateway",
|
||||
"---",
|
||||
"",
|
||||
"See [Troubleshooting](/gateway/troubleshooting).",
|
||||
"",
|
||||
"See [Example provider](/providers/example-provider).",
|
||||
))
|
||||
writeFile(t, filepath.Join(docsRoot, "gateway", "troubleshooting.md"), "# Troubleshooting\n")
|
||||
writeFile(t, filepath.Join(docsRoot, "providers", "example-provider.md"), "# Example provider\n")
|
||||
writeFile(t, filepath.Join(docsRoot, "zh-CN", "gateway", "troubleshooting.md"), "# 故障排除\n")
|
||||
writeFile(t, filepath.Join(docsRoot, "zh-CN", "providers", "example-provider.md"), "# 示例 provider\n")
|
||||
|
||||
// This is the higher-level regression for the bug fixed in this PR:
|
||||
// if the pipeline stops wiring postprocess through the main flow, the final
|
||||
// localized output page will keep stale English-root links and this test fails.
|
||||
err := runDocsI18N(context.Background(), runConfig{
|
||||
targetLang: "zh-CN",
|
||||
sourceLang: "en",
|
||||
docsRoot: docsRoot,
|
||||
mode: "doc",
|
||||
thinking: "high",
|
||||
overwrite: true,
|
||||
parallel: 1,
|
||||
}, []string{filepath.Join(docsRoot, "gateway", "index.md")}, func(_, _ string, _ []GlossaryEntry, _ string) (docsTranslator, error) {
|
||||
return fakeDocsTranslator{}, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("runDocsI18N failed: %v", err)
|
||||
}
|
||||
|
||||
got := mustReadFile(t, filepath.Join(docsRoot, "zh-CN", "gateway", "index.md"))
|
||||
expected := []string{
|
||||
"参见 [Troubleshooting](/zh-CN/gateway/troubleshooting).",
|
||||
"参见 [Example provider](/zh-CN/providers/example-provider).",
|
||||
}
|
||||
for _, want := range expected {
|
||||
if !containsLine(got, want) {
|
||||
t.Fatalf("expected final localized page link %q in output:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslateSnippetDoesNotCacheFallbackToSource(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tm := &TranslationMemory{entries: map[string]TMEntry{}}
|
||||
source := "Gateway"
|
||||
|
||||
translated, err := translateSnippet(context.Background(), invalidFrontmatterTranslator{}, tm, "gateway/index.md:frontmatter:title", source, "en", "zh-CN")
|
||||
if err != nil {
|
||||
t.Fatalf("translateSnippet returned error: %v", err)
|
||||
}
|
||||
if translated != source {
|
||||
t.Fatalf("expected fallback to source text, got %q", translated)
|
||||
}
|
||||
|
||||
cacheKey := cacheKey(cacheNamespace(), "en", "zh-CN", "gateway/index.md:frontmatter:title", hashText(source))
|
||||
if _, ok := tm.Get(cacheKey); ok {
|
||||
t.Fatalf("expected fallback translation not to be cached")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue