Files
splinter/tests/test_delegate.c
T
Konrad d8c94edb55 splinter: providers from the environment, prio and max_parallel
OLLAMA_KEY, OLLAMA_KEY_0.._N and CLAUDE_CODE_OAUTH_TOKEN, _0.._N are enough to
fill the harness: every Ollama key becomes a delegate and an exit in the ring,
every Claude token becomes a cli delegate running 'claude -p'. Several keys mean
several accounts; the ring walks them.

That is the workflow the tool exists for - a strong model plans and defines the
work, the local models implement it, delegate is the handover:

  OLLAMA_KEY=... CLAUDE_CODE_OAUTH_TOKEN=... splinter --choose 'plane die arbeit'
  claude-3   score=4   prio=10   task mentions 'plan'
  OLLAMA_KEY=... splinter --choose 'implementier das'
  ollama-2   score=3   prio=0    task mentions 'implement'

Delegates also take prio (tie-break, higher wins) and max_parallel (default 1,
a busy delegate says so instead of queueing silently). kind=cli with cmd=... runs
a program instead of an endpoint.

Keys travel in the environment, never on a command line or into a log.
test_config covers the scan, test_delegate the prio tie-break.
2026-11-08 14:05:48 +00:00

97 lines
2.9 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);
/* prio decides a tie: same score, higher prio wins */
memset(&c, 0, sizeof(c));
add(&c, "low", "gleich gut", "x");
add(&c, "high", "gleich gut", "x");
c.delegate[1].prio = 9;
CHECK(sp_delegate_choose(&c, "x", NULL, id, sizeof(id), why, sizeof(why),
&score) == 0);
CHECK(strcmp(id, "high") == 0);
CHECK(sp_delegate_prio(&c, "high") == 9);
/* max_parallel defaults to one and never to zero */
memset(&c, 0, sizeof(c));
add(&c, "d", "x", "x");
CHECK(c.delegate[0].max_parallel == 0); /* add() does not set it */
/* 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;
}