Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
183 lines
5.3 KiB
Go
183 lines
5.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLocalizeBodyLinks(t *testing.T) {
|
|
docsRoot := setupDocsTree(t)
|
|
routes, err := loadRouteIndex(docsRoot, "zh-CN")
|
|
if err != nil {
|
|
t.Fatalf("loadRouteIndex failed: %v", err)
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
}{
|
|
{
|
|
name: "markdown link",
|
|
input: `See [Config](/gateway/configuration).`,
|
|
want: `See [Config](/zh-CN/gateway/configuration).`,
|
|
},
|
|
{
|
|
name: "href attribute",
|
|
input: `<Card href="/gateway/configuration" title="Config" />`,
|
|
want: `<Card href="/zh-CN/gateway/configuration" title="Config" />`,
|
|
},
|
|
{
|
|
name: "redirect source resolves to canonical localized page",
|
|
input: `See [Sandbox](/sandboxing).`,
|
|
want: `See [Sandbox](/zh-CN/gateway/sandboxing).`,
|
|
},
|
|
{
|
|
name: "fragment is preserved",
|
|
input: `See [Hooks](/gateway/configuration#hooks).`,
|
|
want: `See [Hooks](/zh-CN/gateway/configuration#hooks).`,
|
|
},
|
|
{
|
|
name: "images stay unchanged",
|
|
input: ``,
|
|
want: ``,
|
|
},
|
|
{
|
|
name: "already localized stays unchanged",
|
|
input: `See [Config](/zh-CN/gateway/configuration).`,
|
|
want: `See [Config](/zh-CN/gateway/configuration).`,
|
|
},
|
|
{
|
|
name: "vbscript scheme stays unchanged",
|
|
input: `<a href="vbscript:msgbox(1)">bad</a>`,
|
|
want: `<a href="vbscript:msgbox(1)">bad</a>`,
|
|
},
|
|
{
|
|
name: "mixed-case javascript scheme stays unchanged",
|
|
input: `<a href="Javascript:alert(1)">bad</a>`,
|
|
want: `<a href="Javascript:alert(1)">bad</a>`,
|
|
},
|
|
{
|
|
name: "missing localized page stays unchanged",
|
|
input: `See [FAQ](/help/faq).`,
|
|
want: `See [FAQ](/help/faq).`,
|
|
},
|
|
{
|
|
name: "permalink route localizes",
|
|
input: `See [Formal verification](/security/formal-verification).`,
|
|
want: `See [Formal verification](/zh-CN/security/formal-verification).`,
|
|
},
|
|
{
|
|
name: "inline code stays unchanged",
|
|
input: "Use `[Config](/gateway/configuration)` in examples.\n\n" +
|
|
"See [Config](/gateway/configuration).",
|
|
want: "Use `[Config](/gateway/configuration)` in examples.\n\n" +
|
|
"See [Config](/zh-CN/gateway/configuration).",
|
|
},
|
|
{
|
|
name: "fenced code block stays unchanged",
|
|
input: "```md\n[Config](/gateway/configuration)\n```\n\n" +
|
|
"See [Config](/gateway/configuration).",
|
|
want: "```md\n[Config](/gateway/configuration)\n```\n\n" +
|
|
"See [Config](/zh-CN/gateway/configuration).",
|
|
},
|
|
{
|
|
name: "inline code does not swallow later paragraphs",
|
|
input: strings.Join([]string{
|
|
"Use `channels.matrix.accounts` and `name`.",
|
|
"",
|
|
"See [Config](/gateway/configuration).",
|
|
"",
|
|
"Then review [Troubleshooting](/channels/troubleshooting).",
|
|
}, "\n"),
|
|
want: strings.Join([]string{
|
|
"Use `channels.matrix.accounts` and `name`.",
|
|
"",
|
|
"See [Config](/zh-CN/gateway/configuration).",
|
|
"",
|
|
"Then review [Troubleshooting](/zh-CN/channels/troubleshooting).",
|
|
}, "\n"),
|
|
},
|
|
{
|
|
name: "indented fenced code block does not swallow later paragraphs",
|
|
input: strings.Join([]string{
|
|
"1. Setup:",
|
|
"",
|
|
" ```bash",
|
|
" echo hi",
|
|
" ```",
|
|
"",
|
|
"Use `channels.matrix.accounts` and `name`.",
|
|
"",
|
|
"For triage: [/channels/troubleshooting](/channels/troubleshooting).",
|
|
"See [Config](/gateway/configuration).",
|
|
}, "\n"),
|
|
want: strings.Join([]string{
|
|
"1. Setup:",
|
|
"",
|
|
" ```bash",
|
|
" echo hi",
|
|
" ```",
|
|
"",
|
|
"Use `channels.matrix.accounts` and `name`.",
|
|
"",
|
|
"For triage: [/channels/troubleshooting](/zh-CN/channels/troubleshooting).",
|
|
"See [Config](/zh-CN/gateway/configuration).",
|
|
}, "\n"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := routes.localizeBodyLinks(tt.input)
|
|
if got != tt.want {
|
|
t.Fatalf("unexpected rewrite\nwant: %q\ngot: %q", tt.want, got)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func setupDocsTree(t *testing.T) string {
|
|
t.Helper()
|
|
|
|
root := t.TempDir()
|
|
writeFile(t, filepath.Join(root, "docs.json"), `{
|
|
"redirects": [
|
|
{ "source": "/sandboxing", "destination": "/gateway/sandboxing" }
|
|
]
|
|
}`)
|
|
|
|
files := map[string]string{
|
|
"index.md": "# Home\n",
|
|
"channels/troubleshooting.md": "# Troubleshooting\n",
|
|
"gateway/configuration.md": "# Config\n",
|
|
"gateway/sandboxing.md": "# Sandboxing\n",
|
|
"security/formal-verification.md": "---\npermalink: /security/formal-verification/\n---\n\n# Formal verification\n",
|
|
"help/faq.md": "# FAQ\n",
|
|
"zh-CN/index.md": "# Home\n",
|
|
"zh-CN/channels/troubleshooting.md": "# Troubleshooting\n",
|
|
"zh-CN/gateway/configuration.md": "# Config\n",
|
|
"zh-CN/gateway/sandboxing.md": "# Sandboxing\n",
|
|
"zh-CN/security/formal-verification.md": "---\npermalink: /security/formal-verification/\n---\n\n# Formal verification\n",
|
|
"ja-JP/index.md": "# Home\n",
|
|
}
|
|
|
|
for relPath, content := range files {
|
|
writeFile(t, filepath.Join(root, relPath), content)
|
|
}
|
|
|
|
return root
|
|
}
|
|
|
|
func writeFile(t *testing.T, path string, content string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatalf("mkdir failed for %s: %v", path, err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
|
t.Fatalf("write failed for %s: %v", path, err)
|
|
}
|
|
}
|