Files
splinter/tests/test_delegate.c
T
Konrad 781e7eb514 splinter: delegation to configured models, chosen by splinter
A delegate is a line in the config - id, what it is good at, tags, endpoint,
model. No profiles: a profile is a directory of files, and this needs a line you
can read at 2 a.m.

The delegate tool takes a task and optional tags. The pick is code, not a guess:
requested tag 5, tag in the task 3, description word 1, ties to the earlier
entry. The observation opens with the choice and the reason, and --choose prints
the same decision without running anything:

  coder   7   task mentions 'code'
  quick   5   task mentions 'chat'
  coder   3   task mentions 'refactor'

The child is splinter itself in one-shot mode - same tools, own context, own
endpoint and model. Classed destructive, because it runs a whole agent; the
operator approves the delegation once.

test_delegate pins the decisions, including the two cases that must not pick
anything: no matching tag and no delegates at all.
2026-11-08 12:38:57 +00:00

82 lines
2.3 KiB
C

/*
* splinter -- delegate selection.
*
* The choice is code, so it is tested like code: given a task and a set of
* delegates, the same one must win every time, and the reason must name what
* decided it.
*/
#include <stdio.h>
#include <string.h>
#include "splinter.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");
}
int
main(void)
{
struct sp_config c;
char id[64], why[192];
int score;
memset(&c, 0, sizeof(c));
add(&c, "coder", "C99, POSIX, kennt den Quellbaum", "code,c99,review");
add(&c, "quick", "kurze Antworten, Chat", "chat,cheap,summary");
/* a tag in the task wins by tag */
CHECK(sp_delegate_choose(&c, "pruefe den code auf fehler", NULL, id, sizeof(id),
why, sizeof(why), &score) == 0);
CHECK(strcmp(id, "coder") == 0);
CHECK(score >= 3);
CHECK(strstr(why, "code") != NULL);
CHECK(sp_delegate_choose(&c, "mach eine kurze summary", NULL, id, sizeof(id),
why, sizeof(why), &score) == 0);
CHECK(strcmp(id, "quick") == 0);
/* a requested tag outweighs the wording */
CHECK(sp_delegate_choose(&c, "irgendwas mit code", "chat", id, sizeof(id),
why, sizeof(why), &score) == 0);
CHECK(strcmp(id, "quick") == 0);
CHECK(strstr(why, "requested") != NULL);
/* a description word is weaker than a tag but still counts */
CHECK(sp_delegate_choose(&c, "kennt jemand den quellbaum", NULL, id,
sizeof(id), why, sizeof(why), &score) == 0);
CHECK(strcmp(id, "coder") == 0);
/* nothing matches: no pick rather than a random one */
CHECK(sp_delegate_choose(&c, "xyzzy", NULL, id, sizeof(id), why,
sizeof(why), &score) != 0);
/* an empty set is not a match either */
c.ndelegates = 0;
CHECK(sp_delegate_choose(&c, "code", NULL, id, sizeof(id), why,
sizeof(why), &score) != 0);
if (failures == 0)
printf("test_delegate: ok\n");
return failures == 0 ? 0 : 1;
}