agent: a field label with no TUI Chinese fails internal/agent's tests

A new agent field's label with no entry in internal/tui's zh map left
TestEveryWordHasZh red on main twice (e9fcc6229 on 11-15 for
"permission mode", 618bfc1a9 on 11-17 for "subagent pool"), each by a
change that ran internal/agent but not internal/tui.
TestEveryFieldLabelHasTUIZh reads tui's i18n.go and keepAsIs (tui
imports agent) and fails in the package such a change runs. LESSONS and
the code standards' criterion 3 name it.

Run: on mote, go test ./internal/agent: ok (250s). The new test on
Linux (wsl-run) and Windows (win-run): ok. gofmt -l: clean.
Broken by hand: with "subagent pool" taken out of i18n.go, red ("kimi's
field \"subagent_pool\" (label \"subagent pool\") has no Chinese").
This commit is contained in:
yetone
2026-11-17 15:09:29 +08:00
parent 6fbc24a05c
commit c9e8422fa8
3 changed files with 61 additions and 1 deletions
+5
View File
@@ -1702,6 +1702,11 @@ each one.
request (#6688, cd030691a). 0b8c4bfc3's new field left
TestEveryWordHasZh red (e9fcc6229). A change that adds a route or a
label runs internal/cli, internal/gateway and internal/tui whole.
11-17: 618bfc1a9 gave Kimi Code a "subagent pool" field and ran
internal/agent and internal/gui only (both machines were loaded),
so TestEveryWordHasZh was red again (fixed in the commit after
it). internal/agent's TestEveryFieldLabelHasTUIZh now fails on such
a label in the package the change runs.
- A red with an issue still needs an owner. #6677 was red on main for
about three hours. A session that met it commented "Not taking it"
and shipped past it, and the review fixed it in 4c86b0ab4. The four
+2 -1
View File
@@ -77,7 +77,8 @@ listed as not run, never left out.
A guard that keeps being missed gets a twin in the package the change
runs: internal/gui's TestEveryRouteIsNamedForTheCLI for a new route,
internal/agent's TestEveryAgentNamedForTheLibrary for a new agent
(red on main four times before it, last at 00b2c11a6, 11-17).
(red on main four times before it, last at 00b2c11a6, 11-17), and
its TestEveryFieldLabelHasTUIZh for a new field's label (618bfc1a9).
A change under `site/public/docs` ends with `node llms-full.mjs` and
`node search-index.mjs` in site/, then `node --test site/*.test.mjs`
from the repo root: both files are built from those pages and
+54
View File
@@ -0,0 +1,54 @@
package agent
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// Every agent field's label has its Chinese in internal/tui's zh map
// (i18n.go), which the TUI shows it through. internal/tui's
// TestEveryWordHasZh checks it too, but a change that adds a field runs
// this package, and a new label with no Chinese left that test red on
// main (e9fcc6229 for "permission mode", 11-15; "subagent pool" from
// 618bfc1a9, 11-17), each found after the push. tui imports agent, so
// this reads its files.
func TestEveryFieldLabelHasTUIZh(t *testing.T) {
dir := filepath.Join("..", "tui")
zh, err := os.ReadFile(filepath.Join(dir, "i18n.go"))
if err != nil {
t.Fatal(err)
}
tests, err := os.ReadFile(filepath.Join(dir, "i18n_test.go"))
if err != nil {
t.Fatal(err)
}
m := regexp.MustCompile(`var keepAsIs = map\[string\]bool\{([^}]*)\}`).FindSubmatch(tests)
if m == nil {
t.Fatal("internal/tui/i18n_test.go has no keepAsIs line")
}
keep := map[string]bool{}
for _, k := range regexp.MustCompile(`"([^"]*)":`).FindAllSubmatch(m[1], -1) {
keep[string(k[1])] = true
}
n := 0
seen := map[string]bool{}
for _, a := range All() {
for _, f := range a.Fields {
if keep[f.Label] || seen[f.Label] || strings.TrimSpace(f.Label) == "" {
continue
}
seen[f.Label] = true
n++
q := regexp.QuoteMeta(`"` + f.Label + `"`)
if !regexp.MustCompile(`(?m)^\s*` + q + `:\s*"`).Match(zh) {
t.Errorf("%s's field %q (label %q) has no Chinese in internal/tui/i18n.go's zh map", a.ID, f.Key, f.Label)
}
}
}
if n < 30 {
t.Fatalf("read %d labels", n)
}
}