diff --git a/Makefile b/Makefile index c73d0fe..0b2e9dd 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \ plugins/tmux/tmux.so TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \ tests/test_transport tests/test_agent tests/test_openai \ - tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_swarm tests/test_provstate tests/test_planner + tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_swarm tests/test_provstate tests/test_planner tests/test_jobs RPATH = -Wl,-rpath,'$$ORIGIN' PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..' @@ -186,6 +186,8 @@ tests/test_provstate: tests/test_provstate.c $(LIB) $(CC) $(CFLAGS) -o $@ tests/test_provstate.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_planner: tests/test_planner.c $(LIB) $(PLUGIN) $(CC) $(CFLAGS) -o $@ tests/test_planner.c -L. -lsplinter $(TEST_RPATH) $(LIBS) +tests/test_jobs: tests/test_jobs.c $(LIB) $(PLUGIN) + $(CC) $(CFLAGS) -o $@ tests/test_jobs.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_config: tests/test_config.c $(LIB) $(CC) $(CFLAGS) -o $@ tests/test_config.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_sse: tests/test_sse.c $(LIB) diff --git a/README.md b/README.md index cf7a31f..8f36bc2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ the screen, a sidebar on one quarter, plugins that can put tools and widgets into both. make # libsplinter.so, the binary, the plugins - make check # every test binary (30), no network, no model + make check # every test binary (31), no network, no model splinter # starts the chat from ~/.config/splinter/config diff --git a/TODO.md b/TODO.md index b4c2ee9..af500e6 100644 --- a/TODO.md +++ b/TODO.md @@ -49,18 +49,6 @@ Installationsziel. Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code. -### 5. Scheduler und die Job-Werkzeuge sind noch ungetestet - -`plugins/scheduler/` hat keinen Test; es braucht einen faelligen -Delegations-Job und eine Gegenstelle, die den Retry sieht. Von den -Job-Werkzeugen sind `delegate_submit`, `delegate_jobs`, `delegate_result`, -`delegate_due`, `delegate_retry` und `delegate_list` ungetestet; -`test_delegate` deckt Auswahl, Fallback, Panel und `delegate_parallel` ab. -`plugins/tmux/` wird nur indirekt ueber `test_ui.sh` beruehrt. - -Naechster Schritt: Job-Persistenz submit -> jobs -> result als Test, danach -einen faelligen Job fuer den Scheduler. - ## Erledigt (2026-11-09) - **Markdown-Tabellen**: `src/md.c` erkennt Kopf + Trenner, rechnet die Breite @@ -68,7 +56,7 @@ einen faelligen Job fuer den Scheduler. `tests/test_md.c` (Kopf, Trenner, ungleich lange Zeilen, UTF-8, zwei Bloecke) und ein Fall in `tests/test_ui.sh`, der die Spalten auf dem Schirm prueft. - **Website zaehlt**: `tools/gen_www.py` liest Zeilen, Werkzeuge, Tests, Plugins - und Paletten aus dem Baum. Die meta-Zeile nennt jetzt 30 Test-Programme, + und Paletten aus dem Baum. Die meta-Zeile nennt jetzt 31 Test-Programme, 23 Werkzeuge und 15 Plugins; die alte Binärgroesse ist durch die Werkzeugzahl ersetzt, weil sie mit jedem Build altert. - **Delegate im Task-Panel**: `tests/test_delegate.c` uebergibt einen Host mit @@ -82,8 +70,13 @@ einen faelligen Job fuer den Scheduler. scheduler und tmux; `README.md` nennt `swarm` und die aktuelle Testzahl; `docs/ROADMAP.md` fuehrt Remote/Jumphost und die 8k-Messung als erledigt. - **Neue Tests**: `test_swarm` (master/slave, route, busy, standalone), - `test_provstate` (429/503, getrennte Keys, Dateimodus, Fingerprint) und - `test_planner` (add/list/update, `/tasks`, Datei, Widget). + `test_provstate` (429/503, getrennte Keys, Dateimodus, Fingerprint), + `test_planner` (add/list/update, `/tasks`, Datei, Widget) und `test_jobs` + (submit/jobs/result, force-Retry, faelliger Job im Scheduler-Tick, + Scheduler-Widget). +- **Fehler dabei gefunden und behoben**: `delegate_retry` las `id` und `force` + in denselben Puffer; `json_str` haengt an, also wurde aus `job-1` mit + `force=1` die Id `job-11` (`src/delegate.c`, `tool_delegate_retry`). - **Skills und Memory**: `src/skills.c`, `src/memory.c`, registriert in `src/main.c:908-909`, `test_skills` und `test_memory` laufen gruen. - **Kompression verdrahtet**: `ag->host` wird gesetzt (`src/main.c:635`). diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index d5edaa1..6e31edc 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -7,12 +7,7 @@ Stand: 2026-11-09. Die geprüfte, ausführliche Liste mit Belegen steht in als Server, damit die Flotte splinter rufen kann. `swarm` ist nur lokale IPC im selben Verzeichnis, kein A2A. -2. **Restliche Tests** — `scheduler` und die Job-Werkzeuge - (`delegate_submit`/`jobs`/`result`) haben noch keinen Test; `swarm`, - `provstate` und `planner` sind abgedeckt, `tmux` nur indirekt über - `test_ui.sh`. - -3. **Echte Gegenstellen** — die Kids-Zustimmung gegen einen echten Telegram-Bot +2. **Echte Gegenstellen** — die Kids-Zustimmung gegen einen echten Telegram-Bot (nicht `fake_telegram.py`), und die Ursache von `claude` Exit 2. ## Erledigt diff --git a/src/delegate.c b/src/delegate.c index d72a1d9..c93f420 100644 --- a/src/delegate.c +++ b/src/delegate.c @@ -1963,19 +1963,24 @@ sp_delegate_retry_job(const char *id, int force, struct sp_buf *out) static int tool_delegate_retry(const char *args, struct sp_buf *out, void *ctx) { - struct sp_buf keep; + struct sp_buf keep, fkeep; const char *id, *force_s; int force = 0; (void)ctx; - if (sp_buf_init(&keep)!=0) return -1; + if (sp_buf_init(&keep)!=0 || sp_buf_init(&fkeep)!=0) return -1; id = json_str(args,"id",&keep); if (!id||!*id) id = json_str(args,"job_id",&keep); - force_s = json_str(args,"force",&keep); + /* + * force gets its own buffer: json_str appends, so parsing it into + * 'keep' turned id "job-1" plus force "1" into "job-11". + */ + force_s = json_str(args,"force",&fkeep); force = (force_s && (strcmp(force_s,"1")==0||strcmp(force_s,"true")==0)); - if (!id||!*id) { sp_buf_free(&keep); return sp_buf_puts(out,"error: 'id' required"); } + if (!id||!*id) { sp_buf_free(&keep); sp_buf_free(&fkeep); return sp_buf_puts(out,"error: 'id' required"); } { int rc = sp_delegate_retry_job(id, force, out); sp_buf_free(&keep); + sp_buf_free(&fkeep); return rc; } } diff --git a/src/www/index.en.html b/src/www/index.en.html index 61ff8a7..ab78e85 100644 --- a/src/www/index.en.html +++ b/src/www/index.en.html @@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }

splinter_

An agent harness you own: chat in the terminal, tools with authorization classes, plugins, any model that speaks OpenAI — built by us so we can change it, instead of getting used to how somebody else's client behaves.

-

21771 lines of C99/POSIX · -23 tools · 30 test programs · +

21776 lines of C99/POSIX · +23 tools · 31 test programs · 15 plugins · 42 palettes · BSD-3-Clause

What it is

@@ -150,7 +150,7 @@ plugin = plugins/reminder/reminder.so

Building

$ git clone ssh://host/home/git/splinter.git
 $ cd splinter && make      small, nothing but libc and curses
-$ make check               30 test programs, plus the i18n checker
+$ make check               31 test programs, plus the i18n checker
 $ ./splinter              chat, the config is read
 $ ./splinter --daemon     Telegram gateway

POSIX make, C99, -Wall -Wextra -Werror. NetBSD curses is vendored, so the binary does not depend on a distribution's mood.

diff --git a/src/www/index.html b/src/www/index.html index 1153955..457a374 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }

splinter_

Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.

-

21771 Zeilen C99/POSIX · -23 Werkzeuge · 30 Test-Programme · +

21776 Zeilen C99/POSIX · +23 Werkzeuge · 31 Test-Programme · 15 Plugins · 42 Farbschemata · BSD-3-Clause

Was es ist

@@ -150,7 +150,7 @@ plugin = plugins/reminder/reminder.so

Bauen

$ git clone ssh://host/home/git/splinter.git
 $ cd splinter && make      klein, nichts ausser libc und curses
-$ make check               30 Test-Programme, plus i18n-Pruefer
+$ make check               31 Test-Programme, plus i18n-Pruefer
 $ ./splinter              Chat, Konfiguration wird gelesen
 $ ./splinter --daemon     Telegram-Gateway

POSIX make, C99, -Wall -Wextra -Werror. Die NetBSD-curses liegt im Baum, damit das Binary nicht von der Laune einer Distribution abhaengt.

diff --git a/src/www/index.pt.html b/src/www/index.pt.html index 6540837..fcae8e5 100644 --- a/src/www/index.pt.html +++ b/src/www/index.pt.html @@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }

splinter_

Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.

-

21771 linhas C99/POSIX · -23 ferramentas · 30 programas de teste · +

21776 linhas C99/POSIX · +23 ferramentas · 31 programas de teste · 15 plugins · 42 paletas · BSD-3-Clause

O que e

@@ -114,7 +114,7 @@ mesmos slash commands do terminal.

Compilar

make
-make check   # 30 binarios de teste, i18n, site
+make check # 31 binarios de teste, i18n, site

Sem dependencias alem de libc e pthread; ncurses vem do vendor.

O que nao e

diff --git a/tests/test_jobs.c b/tests/test_jobs.c new file mode 100644 index 0000000..1b70bfe --- /dev/null +++ b/tests/test_jobs.c @@ -0,0 +1,229 @@ +/* + * splinter -- durable delegation jobs and the scheduler's view. + * + * submit writes a job before it runs, result can be polled later, jobs lists + * the store, retry resumes a job, and sp_delegate_tick is the one step the + * scheduler plugin takes when a job is due. The fake ssh is the far side. + */ +#include +#include +#include +#include +#include + +#include "splinter.h" +#include "splinter_plugin.h" +#include "config.h" + +static int failures; + +#define CHECK(cond) do { \ + if (!(cond)) { \ + fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ + failures++; \ + } \ +} while (0) + +static void +add(struct sp_config *c, const char *id, const char *about, const char *tags) +{ + struct sp_delegate *d = &c->delegate[c->ndelegates++]; + + memset(d, 0, sizeof(*d)); + snprintf(d->id, sizeof(d->id), "%s", id); + snprintf(d->about, sizeof(d->about), "%s", about); + snprintf(d->tags, sizeof(d->tags), "%s", tags); + snprintf(d->endpoint, sizeof(d->endpoint), "http://example/v1"); + snprintf(d->model, sizeof(d->model), "m"); + d->max_parallel = 1; +} + +static void +job_id_from(const char *s, char *id, size_t cap) +{ + const char *p = s != NULL ? strstr(s, "job job-") : NULL; + size_t n = 0; + + id[0] = '\0'; + if (p == NULL) + return; + p += 4; /* "job " */ + while (p[n] != '\0' && p[n] != ' ' && p[n] != ',' && + p[n] != '\n' && n + 1 < cap) + n++; + memcpy(id, p, n); + id[n] = '\0'; +} + +int +main(void) +{ + struct sp_config c; + struct sp_registry r; + struct sp_session_info sess; + struct sp_agent ag; + struct sp_host *host; + struct sp_buf out, err, tick; + const struct sp_tool *t; + char tdir[] = "/tmp/splinter-job-XXXXXX"; + char path[600], line[700], id[80], args[256]; + char manual[700], snap[512]; + const char *oldpath = getenv("PATH"); + FILE *f; + + CHECK(mkdtemp(tdir) != NULL); + memset(&sess, 0, sizeof(sess)); + snprintf(sess.dir, sizeof(sess.dir), "%s", tdir); + memset(&r, 0, sizeof(r)); + memset(&ag, 0, sizeof(ag)); + memset(&c, 0, sizeof(c)); + + /* the far side answers */ + snprintf(path, sizeof(path), "%s/ssh", tdir); + f = fopen(path, "w"); + CHECK(f != NULL); + if (f != NULL) { + fputs("#!/bin/sh\necho 'antwort vom job'\n", f); + fclose(f); + } + (void)chmod(path, 0755); + snprintf(line, sizeof(line), "%s:%s", tdir, + oldpath != NULL ? oldpath : "/usr/bin:/bin"); + (void)setenv("PATH", line, 1); + + add(&c, "jobber", "jobs erledigen", "job"); + snprintf(c.delegate[0].host, sizeof(c.delegate[0].host), "jobsrv"); + + CHECK(sp_buf_init(&out) == 0); + CHECK(sp_buf_init(&err) == 0); + CHECK(sp_buf_init(&tick) == 0); + host = sp_host_new(&r, &ag, &sess); + CHECK(host != NULL); + CHECK(sp_delegate_register(&r, &c, host) == 0); + + /* delegate_list names the configured delegate */ + t = sp_registry_find(&r, "delegate_list"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run("{}", &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "jobber") != NULL); + + /* submit: a job exists before and after the run, and it is done */ + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_submit"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run("{\"task\":\"mach was\",\"tags\":\"job\"}", &out, + t->ctx); + if (getenv("TEST_VERBOSE") != NULL) + fprintf(stderr, "submit: %s\n", out.p); + CHECK(out.p != NULL && strstr(out.p, "[delegate_submit job ") != NULL); + CHECK(out.p != NULL && strstr(out.p, "state=done") != NULL); + job_id_from(out.p, id, sizeof(id)); + CHECK(id[0] != '\0'); + + /* jobs: the store names it, its delegate and its state */ + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_jobs"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run("{}", &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, id) != NULL); + CHECK(out.p != NULL && strstr(out.p, "state=done") != NULL); + CHECK(out.p != NULL && strstr(out.p, "delegate=jobber") != NULL); + + /* result: pollable after the fact */ + snprintf(args, sizeof(args), "{\"id\":\"%s\"}", id); + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_result"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run(args, &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "state=done") != NULL); + CHECK(out.p != NULL && strstr(out.p, "antwort vom job") != NULL); + + /* a done job is not retried by accident; force does it */ + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_retry"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run(args, &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "already done") != NULL); + + snprintf(args, sizeof(args), "{\"id\":\"%s\",\"force\":\"1\"}", id); + sp_buf_clear(&out); + if (t != NULL) + (void)t->run(args, &out, t->ctx); + if (getenv("TEST_VERBOSE") != NULL) + fprintf(stderr, "force: %s\n", out.p); + CHECK(out.p != NULL && strstr(out.p, "[retry job ") != NULL); + CHECK(out.p != NULL && strstr(out.p, "antwort vom job") != NULL); + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_result"); + if (t != NULL) + (void)t->run(args, &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "attempts=2") != NULL); + + /* a hand-written due job: the scheduler view sees it and the tick retries */ + snprintf(path, sizeof(path), "%s/jobs", tdir); + CHECK(mkdir(path, 0755) == 0 || access(path, F_OK) == 0); + snprintf(manual, sizeof(manual), "%s/job-due.json", path); + f = fopen(manual, "w"); + CHECK(f != NULL); + if (f != NULL) { + fputs("{\"id\":\"job-due\",\"state\":\"waiting_poll\"," + "\"delegate\":\"jobber\",\"task\":\"retry me\"," + "\"next_poll_at\":\"1\",\"run_after\":\"\"," + "\"attempts\":1}\n", f); + fclose(f); + } + + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_due"); + CHECK(t != NULL); + if (t != NULL) + (void)t->run("{}", &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "job-due") != NULL); + CHECK(out.p != NULL && strstr(out.p, "state=waiting_poll") != NULL); + + CHECK(sp_delegate_tick(&tick) == 0); + if (getenv("TEST_VERBOSE") != NULL) + fprintf(stderr, "tick: %s\n", tick.p); + CHECK(tick.p != NULL && strstr(tick.p, "scheduler: retrying job-due") != NULL); + + sp_buf_clear(&out); + t = sp_registry_find(&r, "delegate_result"); + if (t != NULL) + (void)t->run("{\"id\":\"job-due\"}", &out, t->ctx); + CHECK(out.p != NULL && strstr(out.p, "state=done") != NULL); + CHECK(out.p != NULL && strstr(out.p, "antwort vom job") != NULL); + + /* the delegate host is done; the scheduler gets its own registry */ + sp_host_free(host); + sp_registry_free(&r); + + /* the scheduler plugin is a widget around that tick: it starts idle */ + { + struct sp_host *sh; + + memset(&r, 0, sizeof(r)); + sh = sp_host_new(&r, &ag, &sess); + CHECK(sh != NULL); + CHECK(sp_plugin_load(sh, "plugins/scheduler/scheduler.so", &err) == 0); + CHECK(sp_host_widget_snapshot(sh, snap, sizeof(snap)) > 0); + CHECK(strstr(snap, "sched: idle") != NULL); + sp_host_free(sh); + sp_registry_free(&r); + } + + sp_buf_free(&out); + sp_buf_free(&err); + sp_buf_free(&tick); + (void)setenv("PATH", oldpath != NULL ? oldpath : "/usr/bin:/bin", 1); + snprintf(line, sizeof(line), "rm -rf '%s'", tdir); + (void)system(line); + + if (failures == 0) + printf("test_jobs: ok\n"); + return failures == 0 ? 0 : 1; +}