Everything that was uncommitted in the shared tree, in one commit because the changes are interleaved across the same files (lcm, engine, frontend, locales). lcm: a continuation prompt is not the task. After /resume the newest user message is "Continue with the task ...", and pinning it kept the keystroke while the question it continues was cut away -- measured: a resumed session woke up with the prompt, one tool call and its error, and no task at all. The pin now skips the harness's own continuation prompts, so the real question is pinned again. test_compactor drives it: with the skip disabled the task is lost (red), with it the task comes back after the summary (green). engine: /self-check and the exact tool-argument parse are in a1794fb; this commit carries the tests for them (a failed tool observation must appear in the self-check prompt; mcp_parse_exact rejects two objects in one string) and the i18n keys the new code uses: cmd.script.*, main.no_profile, tg.busy, tg.interview.running, ui.agent_busy in all three catalogues. The rest is the in-flight work from the shared session: engine/frontend, plugins, telegram/a2a, and their tests. make check: all tests passed; check_i18n ok, 204 keys in 3 catalogues.
111 lines
3.0 KiB
C
111 lines
3.0 KiB
C
/*
|
|
* splinter -- message catalogues.
|
|
*
|
|
* The point of these tests: a translation is only useful if it is complete, and
|
|
* a missing key must be visible instead of silently empty. So they check the
|
|
* real catalogues in share/locale, including that de.msg covers every key
|
|
* en.msg has.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "splinter.h"
|
|
#include "i18n.h"
|
|
|
|
static int failures;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct sp_buf err;
|
|
size_t i, n_en;
|
|
|
|
if (sp_buf_init(&err) != 0)
|
|
return 1;
|
|
sp_i18n_add_dir("share/locale");
|
|
|
|
/* ---- English: the fallback ---- */
|
|
CHECK(sp_i18n_load(&err, "en") == 0);
|
|
CHECK(strcmp(sp_i18n_lang(), "en") == 0);
|
|
CHECK(strcmp(sp_t("cmd.available"), "available:") == 0);
|
|
CHECK(strcmp(sp_t("ui.ready"), "ready. Enter sends, Ctrl-D quits.") == 0);
|
|
|
|
/* a key that exists nowhere is shown as itself, never as an empty line */
|
|
CHECK(strcmp(sp_t("does.not.exist"), "does.not.exist") == 0);
|
|
CHECK(strcmp(sp_t(NULL), "") == 0);
|
|
|
|
/* ---- German ---- */
|
|
CHECK(sp_i18n_load(&err, "de") == 0);
|
|
CHECK(strcmp(sp_i18n_lang(), "de") == 0);
|
|
CHECK(strcmp(sp_t("cmd.available"), "verfuegbar:") == 0);
|
|
CHECK(strcmp(sp_t("ui.ready"), "bereit. Enter sendet, Ctrl-D beendet.") == 0);
|
|
|
|
/* format strings keep their placeholders, so printf still works */
|
|
CHECK(strstr(sp_t("model.probe_start"), "%zu") != NULL);
|
|
|
|
/* ---- completeness: every English key has a German one ---- */
|
|
n_en = (size_t)sp_i18n_fallback_count();
|
|
CHECK(n_en > 20);
|
|
for (i = 0; i < n_en; i++) {
|
|
const char *key = sp_i18n_fallback_key(i);
|
|
const char *val;
|
|
|
|
if (key == NULL)
|
|
continue;
|
|
val = sp_t(key);
|
|
if (val == NULL || strcmp(val, key) == 0) {
|
|
fprintf(stderr, "FAIL missing translation: %s\n", key);
|
|
failures++;
|
|
}
|
|
}
|
|
|
|
/* ---- an unknown language falls back to English, without failing ---- */
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_i18n_load(&err, "xx") == 0);
|
|
CHECK(strcmp(sp_t("cmd.available"), "available:") == 0);
|
|
|
|
/* ---- a catalogue is data: it may not change what printf reads ---- */
|
|
{
|
|
char dir[] = "/var/tmp/splinter-i18n-XXXXXX";
|
|
char path[128];
|
|
FILE *f;
|
|
|
|
CHECK(mkdtemp(dir) != NULL);
|
|
snprintf(path, sizeof(path), "%s/zz.msg", dir);
|
|
f = fopen(path, "w");
|
|
CHECK(f != NULL);
|
|
if (f != NULL) {
|
|
fputs("cmd.available=%s%s%s\n"
|
|
"t.bad=hi %s\n"
|
|
"t.ok=hallo %d\n"
|
|
"t.n=x%n\n"
|
|
"t.pos=%1$s\n", f);
|
|
fclose(f);
|
|
}
|
|
sp_i18n_add_dir(dir);
|
|
CHECK(sp_i18n_load(&err, "zz") == 0);
|
|
CHECK(strcmp(sp_t("cmd.available"), "available:") == 0);
|
|
CHECK(strcmp(sp_td("t.bad", "hi %d"), "hi %d") == 0);
|
|
CHECK(strcmp(sp_td("t.ok", "hi %d"), "hallo %d") == 0);
|
|
CHECK(strcmp(sp_td("t.n", "x"), "x") == 0);
|
|
CHECK(strcmp(sp_t("t.n"), "t.n") == 0);
|
|
CHECK(strcmp(sp_td("t.pos", "%s"), "%s") == 0);
|
|
CHECK(remove(path) == 0);
|
|
CHECK(rmdir(dir) == 0);
|
|
}
|
|
|
|
sp_buf_free(&err);
|
|
if (failures == 0)
|
|
printf("test_i18n: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|