splinter: no text reaches the screen without a catalogue
The last literals were the prompt ("> "), the millisecond format and the
placeholder for a missing session id. They are keys now.
More important than those three: the gate was too weak. check_i18n only proved
that keys used in the code exist in the catalogues - a literal drawn straight
into a curses window passed unseen, which is how 'du' or 'denkt' could have
been hardcoded without anyone noticing. It now scans the drawing calls
(mvwaddstr, mvwaddnstr, mvwprintw, waddstr, wprintw, winsstr) and fails on any
literal argument, and it checks that every role passed to add_entry() is one of
the known identifiers that have a role.<name> label.
Proven red before trusting it: with a literal prompt and a role 'benutzer'
injected, the gate reported both and returned 1; restored, it passes. The gate
also runs in make check now - it had been added to a target that no longer
existed.
This commit is contained in:
1 parent
761cc6f612
commit
c458f02385
6 files changed
+64
-7
No files matched your search
@@ -134,7 +134,8 @@ tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN)
|
||||
$(CC) $(CFLAGS) -o $@ tests/test_plugin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
||||
|
||||
check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
|
||||
@set -e; for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
||||
@set -e; python3 tools/check_i18n.py; \
|
||||
for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
||||
echo "all tests passed"
|
||||
|
||||
install: all
|
||||
|
||||
@@ -54,3 +54,6 @@ cli.no_output = cli: '%s' lieferte keine Ausgabe
|
||||
cli.timeout = cli: '%s' lief nach %s s in das Zeitlimit
|
||||
cli.failed = cli: '%s' scheiterte (exit %d): %.400s
|
||||
focus.widget_none = kein Ziel (/goal <text>)
|
||||
ui.prompt_mark = >
|
||||
sidebar.ms = %ld ms
|
||||
ui.empty = -
|
||||
@@ -53,3 +53,6 @@ cli.no_output = cli: '%s' produced no output
|
||||
cli.timeout = cli: '%s' timed out after %s s
|
||||
cli.failed = cli: '%s' failed (exit %d): %.400s
|
||||
focus.widget_none = no goal (/goal <text>)
|
||||
ui.prompt_mark = >
|
||||
sidebar.ms = %ld ms
|
||||
ui.empty = -
|
||||
@@ -580,7 +580,8 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
werase(ui_side);
|
||||
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.session"));
|
||||
mvwaddnstr(ui_side, y++, 0, id != NULL ? id : "-", cols - 1);
|
||||
mvwaddnstr(ui_side, y++, 0, id != NULL ? id : sp_t("ui.empty"),
|
||||
cols - 1);
|
||||
if (dir != NULL)
|
||||
mvwaddnstr(ui_side, y++, 0, dir, cols - 1);
|
||||
y++;
|
||||
@@ -597,7 +598,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
y++;
|
||||
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.last_turn"));
|
||||
mvwprintw(ui_side, y++, 0, "%ld ms", s->last_ms);
|
||||
mvwprintw(ui_side, y++, 0, sp_t("sidebar.ms"), s->last_ms);
|
||||
mvwprintw(ui_side, y++, 0, sp_t("sidebar.steps"), s->last_steps);
|
||||
mvwprintw(ui_side, y++, 0, sp_t("sidebar.tool_calls"), s->last_calls);
|
||||
y++;
|
||||
@@ -809,7 +810,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name,
|
||||
ag->sess != NULL ? ag->sess->dir : NULL, host);
|
||||
draw_status(&s);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark"));
|
||||
wnoutrefresh(ui_input);
|
||||
doupdate();
|
||||
|
||||
@@ -848,7 +849,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name,
|
||||
if (ch == 3) {
|
||||
len = 0;
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark"));
|
||||
wrefresh(ui_input);
|
||||
continue;
|
||||
}
|
||||
@@ -874,7 +875,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name,
|
||||
}
|
||||
input[len] = '\0';
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark"));
|
||||
ui_add_text(ui_input, input,
|
||||
getmaxx(ui_input) - 3);
|
||||
wrefresh(ui_input);
|
||||
@@ -901,7 +902,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name,
|
||||
input[len++] = (char)ch;
|
||||
input[len] = '\0';
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark"));
|
||||
ui_add_text(ui_input, input, getmaxx(ui_input) - 3);
|
||||
wrefresh(ui_input);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -28,6 +28,43 @@ def catalogue(path):
|
||||
out[k.strip()] = v.strip()
|
||||
return out
|
||||
|
||||
# Anything drawn on the screen must come from a catalogue. These are the calls
|
||||
# that put text into a curses window; a literal there is a string the operator
|
||||
# can never translate.
|
||||
DRAW = re.compile(r'\b(mvwaddstr|mvwaddnstr|mvwprintw|waddstr|wprintw|winsstr)\s*\(')
|
||||
LITERAL_ARG = re.compile(r',\s*"([^"\\]*(?:\\.[^"\\]*)*)"')
|
||||
|
||||
|
||||
def hardcoded():
|
||||
bad = []
|
||||
for path in list(ROOT.glob("src/*.c")):
|
||||
for no, line in enumerate(path.read_text(encoding="utf-8",
|
||||
errors="replace").splitlines(), 1):
|
||||
if not DRAW.search(line) or "sp_t" in line:
|
||||
continue
|
||||
m = LITERAL_ARG.search(line)
|
||||
if m is not None:
|
||||
bad.append(f"{path.name}:{no}: {m.group(1)!r}")
|
||||
return bad
|
||||
|
||||
|
||||
# Roles are keys too: add_entry() takes an identifier, the label comes from the
|
||||
# catalogue. An unknown identifier would ship as untranslated text.
|
||||
ROLE_CALL = re.compile(r'add_entry\(\s*&?[A-Za-z_>.-]*\s*,\s*"([a-z_]+)"')
|
||||
ALLOWED_ROLES = {"you", "agent", "thinking", "tool", "error", "shell", "splinter"}
|
||||
|
||||
|
||||
def unknown_roles():
|
||||
bad = []
|
||||
for path in ROOT.glob("src/*.c"):
|
||||
for no, line in enumerate(path.read_text(encoding="utf-8",
|
||||
errors="replace").splitlines(), 1):
|
||||
for role in ROLE_CALL.findall(line):
|
||||
if role not in ALLOWED_ROLES:
|
||||
bad.append(f"{path.name}:{no}: role {role!r} has no label")
|
||||
return bad
|
||||
|
||||
|
||||
def main():
|
||||
used = used_keys()
|
||||
# role.<x> is built by role_label(), never written literally
|
||||
@@ -51,6 +88,18 @@ def main():
|
||||
unused = sorted(k for k in en if k not in used)
|
||||
if unused:
|
||||
print("en.msg: keys nothing uses: " + ", ".join(unused), file=sys.stderr)
|
||||
roles = unknown_roles()
|
||||
if roles:
|
||||
bad = 1
|
||||
print("unknown role identifiers:", file=sys.stderr)
|
||||
for item in roles:
|
||||
print(" " + item, file=sys.stderr)
|
||||
lit = hardcoded()
|
||||
if lit:
|
||||
bad = 1
|
||||
print("hardcoded text on screen (use sp_t/sp_td):", file=sys.stderr)
|
||||
for item in lit:
|
||||
print(" " + item, file=sys.stderr)
|
||||
if bad == 0:
|
||||
print(f"check_i18n: ok ({len(used)} keys in {len(cats)} catalogues)")
|
||||
return bad
|
||||
|
||||
Reference in new issue
Block a user