Markdown tables are drawn as columns now (src/md.c, test_md, and a case in test_ui.sh that checks the screen). The site counts lines, tools, tests, plugins and palettes from the tree instead of naming them; the binary-size figure is gone because it aged with every build. The delegate panel cycle has a test (host + tasks plugin, widget says delegate:panel exit 0), and the turn loop is driven with lcm at 8 KiB and 32 KiB budgets, so compaction is measured rather than claimed. swarm, provstate and planner get smoke tests. TODO.md is rewritten against the tree: the step limit was the old default (8 -> 150), skills and memory were already built, and the open points are claude exit 2, a real Telegram approval, A2A, the npm leftovers and the scheduler/job tests.
118 lines
2.9 KiB
C
118 lines
2.9 KiB
C
/*
|
|
* splinter -- swarm (local fleet) tests.
|
|
*
|
|
* Two instances in one directory, in one process: the first binds the socket
|
|
* and becomes master, the second connects as a slave. What is asserted is the
|
|
* wire cycle -- welcome, id, routed text, busy report -- not the UI.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "swarm.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
|
|
nap_ms(long ms)
|
|
{
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = ms / 1000;
|
|
ts.tv_nsec = (ms % 1000) * 1000000L;
|
|
nanosleep(&ts, NULL);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct swarm master, slave;
|
|
char dir[] = "/tmp/splinter-swarm-XXXXXX";
|
|
char buf[512], list[512], path[600];
|
|
int i, got = 0;
|
|
|
|
CHECK(mkdtemp(dir) != NULL);
|
|
|
|
CHECK(swarm_init(&master, dir) == 0);
|
|
CHECK(master.role == SWARM_MASTER);
|
|
CHECK(master.id == 0);
|
|
|
|
CHECK(swarm_init(&slave, dir) == 0);
|
|
CHECK(slave.role == SWARM_SLAVE);
|
|
|
|
/* the master has to accept before the welcome reaches the slave */
|
|
for (i = 0; i < 50 && slave.id < 0; i++) {
|
|
swarm_poll(&master);
|
|
swarm_poll(&slave);
|
|
if (slave.id < 0)
|
|
nap_ms(10);
|
|
}
|
|
CHECK(slave.id == 1);
|
|
|
|
/* a routed line arrives in the slave's inbox and says it came from afar */
|
|
CHECK(swarm_route(&master, -1, "hallo slave") == 1);
|
|
for (i = 0; i < 50 && !got; i++) {
|
|
swarm_poll(&slave);
|
|
got = swarm_take_inbox(&slave, buf, sizeof(buf));
|
|
if (!got)
|
|
nap_ms(10);
|
|
}
|
|
CHECK(got == 1);
|
|
CHECK(strcmp(buf, "hallo slave") == 0);
|
|
CHECK(swarm_inbox_remote(&slave) == 1);
|
|
CHECK(swarm_inbox_remote(&slave) == 0); /* cleared after reading */
|
|
|
|
/* the master can route to itself without a socket round trip */
|
|
CHECK(swarm_route(&master, 0, "an mich") == 0);
|
|
CHECK(swarm_take_inbox(&master, buf, sizeof(buf)) == 1);
|
|
CHECK(strcmp(buf, "an mich") == 0);
|
|
CHECK(swarm_inbox_remote(&master) == 1);
|
|
|
|
/* a busy report is visible in the master's list */
|
|
swarm_report_busy(&slave, 7);
|
|
for (i = 0; i < 50; i++) {
|
|
swarm_poll(&master);
|
|
swarm_list(&master, list, sizeof(list));
|
|
if (strstr(list, "busy=7") != NULL)
|
|
break;
|
|
nap_ms(10);
|
|
}
|
|
CHECK(strstr(list, "busy=7") != NULL);
|
|
CHECK(strstr(list, "slave pid=") != NULL);
|
|
|
|
swarm_status(&master, buf, sizeof(buf));
|
|
CHECK(strstr(buf, "master 0") != NULL);
|
|
CHECK(strstr(buf, "1 slaves") != NULL);
|
|
swarm_status(&slave, buf, sizeof(buf));
|
|
CHECK(strstr(buf, "slave 1") != NULL);
|
|
|
|
/* close the slave first: the master's socket lives longer */
|
|
swarm_close(&slave);
|
|
swarm_close(&master);
|
|
|
|
/* a directory with no fleet is standalone, not an error */
|
|
{
|
|
struct swarm solo;
|
|
|
|
CHECK(swarm_init(&solo, dir) == 0);
|
|
CHECK(solo.role == SWARM_MASTER);
|
|
swarm_close(&solo);
|
|
}
|
|
|
|
snprintf(path, sizeof(path), "rm -rf '%s'", dir);
|
|
(void)system(path);
|
|
|
|
if (failures == 0)
|
|
printf("test_swarm: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|