jobs: durable jobs and the scheduler tick get a test

test_jobs drives delegate_submit, jobs, result, due and retry against a fake
ssh, writes a due waiting_poll job and lets sp_delegate_tick retry it, and
loads the scheduler plugin to check its idle widget. The test found a real
bug: tool_delegate_retry parsed id and force into the same sp_buf, and
json_str appends, so force=1 turned job-1 into job-11. force now has its own
buffer.
This commit is contained in:
lotherk committed 2026-11-09 23:15:22 +00:00
1 parent 0576d21924
commit 9b249a0eb6
9 files changed
+260 -36

No files matched your search

+3 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+8 -15
View File
@@ -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`).
+1 -6
View File
@@ -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
+9 -4
View File
@@ -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;
}
}
+3 -3
View File
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">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.</p>
<p class="meta"><b>21771</b> lines of C99/POSIX &middot;
<b>23</b> tools &middot; <b>30</b> test programs &middot;
<p class="meta"><b>21776</b> lines of C99/POSIX &middot;
<b>23</b> tools &middot; <b>31</b> test programs &middot;
<b>15</b> plugins &middot; <b>42</b> palettes &middot; BSD-3-Clause</p>
<h2>What it is</h2>
@@ -150,7 +150,7 @@ plugin = plugins/reminder/reminder.so</pre>
<h2>Building</h2>
<pre><span class="u">$</span> git clone ssh://host/home/git/splinter.git
<span class="u">$</span> cd splinter &amp;&amp; make <span class="d">small, nothing but libc and curses</span>
<span class="u">$</span> make check <span class="d">30 test programs, plus the i18n checker</span>
<span class="u">$</span> make check <span class="d">31 test programs, plus the i18n checker</span>
<span class="u">$</span> ./splinter <span class="d">chat, the config is read</span>
<span class="u">$</span> ./splinter --daemon <span class="d">Telegram gateway</span></pre>
<p>POSIX make, C99, <code>-Wall -Wextra -Werror</code>. NetBSD curses is vendored, so the binary does not depend on a distribution's mood.</p>
+3 -3
View File
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">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.</p>
<p class="meta"><b>21771</b> Zeilen C99/POSIX &middot;
<b>23</b> Werkzeuge &middot; <b>30</b> Test-Programme &middot;
<p class="meta"><b>21776</b> Zeilen C99/POSIX &middot;
<b>23</b> Werkzeuge &middot; <b>31</b> Test-Programme &middot;
<b>15</b> Plugins &middot; <b>42</b> Farbschemata &middot; BSD-3-Clause</p>
<h2>Was es ist</h2>
@@ -150,7 +150,7 @@ plugin = plugins/reminder/reminder.so</pre>
<h2>Bauen</h2>
<pre><span class="u">$</span> git clone ssh://host/home/git/splinter.git
<span class="u">$</span> cd splinter &amp;&amp; make <span class="d">klein, nichts ausser libc und curses</span>
<span class="u">$</span> make check <span class="d">30 Test-Programme, plus i18n-Pruefer</span>
<span class="u">$</span> make check <span class="d">31 Test-Programme, plus i18n-Pruefer</span>
<span class="u">$</span> ./splinter <span class="d">Chat, Konfiguration wird gelesen</span>
<span class="u">$</span> ./splinter --daemon <span class="d">Telegram-Gateway</span></pre>
<p>POSIX make, C99, <code>-Wall -Wextra -Werror</code>. Die NetBSD-curses liegt im Baum, damit das Binary nicht von der Laune einer Distribution abhaengt.</p>
+3 -3
View File
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">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.</p>
<p class="meta"><b>21771</b> linhas C99/POSIX &middot;
<b>23</b> ferramentas &middot; <b>30</b> programas de teste &middot;
<p class="meta"><b>21776</b> linhas C99/POSIX &middot;
<b>23</b> ferramentas &middot; <b>31</b> programas de teste &middot;
<b>15</b> plugins &middot; <b>42</b> paletas &middot; BSD-3-Clause</p>
<h2>O que e</h2>
@@ -114,7 +114,7 @@ mesmos slash commands do terminal.</p>
<h2>Compilar</h2>
<pre>make
make check <span class="d"># 30 binarios de teste, i18n, site</span></pre>
make check <span class="d"># 31 binarios de teste, i18n, site</span></pre>
<p>Sem dependencias alem de libc e pthread; ncurses vem do vendor.</p>
<h2>O que nao e</h2>
+229
View File
@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#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;
}