Files
Konrad 10e59f23ac splinter 0.1.0: loop, registry, session, transports, tests
Rebuilt from scratch after the previous attempt left no code behind: what
exists here is what compiles and what the tests prove, and nothing else is
claimed.

What is in it:
- a turn loop that refuses an over-budget request before sending it, reports
  unknown tools instead of guessing, and honours authorization classes
  (read runs, mutate/destructive ask unless --autonomous);
- a registry that is authoritative - the model names a tool, the registry
  decides whether it exists;
- an append-only JSONL session (O_APPEND, fsync per record), where a crash can
  only truncate the tail and the tail is skipped, not repaired;
- two transports: a deterministic mock (queue of replies, last request kept)
  and HTTP via curl(1) with the request body in a temp file;
- two builtins that exist to prove the classes: echo (read) and run
  (destructive, reports its exit status as an observation).

Five test binaries, no external framework, no network: mock driver covers the
answer path, a tool round, an unknown tool, a denial, autonomy, a failing tool,
the step limit, the byte budget (asserting that nothing was sent) and a
non-2xx reply.

The wire format is splinter's own line protocol (user/observe out,
answer/tool in); provider adapters translate. That is why the loop is testable
without a model, and why no vendor JSON is parsed in the core.
2026-11-07 08:06:34 +00:00

65 lines
1.3 KiB
C

/* splinter -- buffer and escaping tests. */
#include <stdio.h>
#include <string.h>
#include "splinter.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 b;
CHECK(sp_buf_init(&b) == 0);
CHECK(b.len == 0);
CHECK(b.p != NULL);
CHECK(strcmp(b.p, "") == 0);
CHECK(sp_buf_puts(&b, "hello") == 0);
CHECK(b.len == 5);
CHECK(strcmp(b.p, "hello") == 0);
CHECK(sp_buf_add(&b, " world", 6) == 0);
CHECK(b.len == 11);
CHECK(strcmp(b.p, "hello world") == 0);
CHECK(sp_buf_printf(&b, " %d", 42) == 0);
CHECK(strcmp(b.p, "hello world 42") == 0);
/* growth: 10k bytes must land, and the NUL must always be there */
{
size_t i;
sp_buf_clear(&b);
for (i = 0; i < 10000; i++)
CHECK(sp_buf_puts(&b, "x") == 0);
CHECK(b.len == 10000);
CHECK(b.p[b.len] == '\0');
CHECK(b.cap > b.len);
}
sp_buf_clear(&b);
CHECK(sp_json_escape(&b, "a\"b\\c\nd\te") == 0);
CHECK(strcmp(b.p, "a\\\"b\\\\c\\nd\\te") == 0);
sp_buf_clear(&b);
CHECK(sp_json_escape(&b, "\x01") == 0);
CHECK(strcmp(b.p, "\\u0001") == 0);
sp_buf_free(&b);
CHECK(b.p == NULL);
CHECK(b.len == 0);
if (failures == 0)
printf("test_buf: ok\n");
return failures == 0 ? 0 : 1;
}