The config moved to ~/.splinter/splinter.conf - next to the sessions, where the state of this thing already lives - and every *.conf in the directory named after it is read after it, in name order. A later file overrides an earlier one, an unknown key is still fatal, and the error now names the file it came from. plugins/ring is the exit ring: several ways to reach a model, walked in order when one is rate limited. exit = go | OpenCode Go | endpoint=... | model=... exit = groq | Groq free tier | endpoint=... | model=... | key_env=GROQ_KEY exit = local | kontron, lokal | endpoint=... | model=... Only pressure moves the ring - 429, 5xx, 'rate limit', 'quota'. A dead host or a bad key stops the turn, because a ring that treats every failure as 'try the next one' hides real breakage behind a random provider. Two things had to be fixed underneath: sp_openai_transport kept its context in a static variable, so building several transports pointed them all at the last one (now one heap context per transport), and plugins had no way to read the config or the registry (sp_host_config, sp_host_registry). Measured against two fake providers: the first answers 429, the ring moves on and the second answers 'Antwort vom zweiten Ausgang.'; a dead port does not move it and the error stands.
185 lines
4.8 KiB
C
185 lines
4.8 KiB
C
/*
|
|
* splinter -- config file tests.
|
|
*
|
|
* The interesting cases are the refusals: an unknown key, a line without '=',
|
|
* a missing file. A config that quietly ignores what it does not understand is
|
|
* a config that lies.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.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
|
|
write_file(const char *path, const char *text)
|
|
{
|
|
FILE *f = fopen(path, "w");
|
|
|
|
if (f == NULL)
|
|
return;
|
|
fputs(text, f);
|
|
fclose(f);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct sp_config c;
|
|
struct sp_buf err;
|
|
char tmpl[] = "/tmp/splinter-cfg-XXXXXX";
|
|
char path[640];
|
|
char *dir;
|
|
|
|
if (sp_buf_init(&err) != 0)
|
|
return 1;
|
|
dir = mkdtemp(tmpl);
|
|
CHECK(dir != NULL);
|
|
if (dir == NULL)
|
|
return 1;
|
|
|
|
/* ---- a full file ---- */
|
|
snprintf(path, sizeof(path), "%s/config", dir);
|
|
write_file(path,
|
|
"# a comment\n"
|
|
"\n"
|
|
"endpoint = http://127.0.0.1:8080/v1/chat/completions\n"
|
|
"model = qwen-test \n"
|
|
"theme = Broica\n"
|
|
"autonomous = 1\n"
|
|
"steps = 12\n"
|
|
"max_bytes = 4096\n"
|
|
"plugin = plugins/lcm/lcm.so\n"
|
|
"plugin = plugins/cps/cps.so\n"
|
|
"cli_cmd = claude -p\n"
|
|
"system_prompt = sei knapp\n");
|
|
|
|
sp_config_init(&c);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_load(&c, path, &err) == 0);
|
|
CHECK(strcmp(c.endpoint,
|
|
"http://127.0.0.1:8080/v1/chat/completions") == 0);
|
|
CHECK(strcmp(c.model, "qwen-test") == 0); /* trimmed */
|
|
CHECK(strcmp(c.theme, "Broica") == 0);
|
|
CHECK(c.autonomous == 1);
|
|
CHECK(c.steps == 12);
|
|
CHECK(c.max_bytes == 4096);
|
|
CHECK(c.nplugins == 2);
|
|
CHECK(strcmp(c.plugins[1], "plugins/cps/cps.so") == 0);
|
|
CHECK(strcmp(c.cli_cmd, "claude -p") == 0);
|
|
CHECK(strcmp(c.system_prompt, "sei knapp") == 0);
|
|
/* untouched defaults survive */
|
|
CHECK(strcmp(c.key_env, "SPLINTER_API_KEY") == 0);
|
|
|
|
/* ---- an unknown key is refused, with its line number ---- */
|
|
write_file(path, "endpoint = x\nwolke = 7\n");
|
|
sp_config_init(&c);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_load(&c, path, &err) == -1);
|
|
CHECK(strstr(err.p, "config") != NULL);
|
|
CHECK(strstr(err.p, ":2:") != NULL);
|
|
CHECK(strstr(err.p, "wolke") != NULL);
|
|
|
|
/* ---- a line without '=' is refused too ---- */
|
|
write_file(path, "endpoint\n");
|
|
sp_config_init(&c);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_load(&c, path, &err) == -1);
|
|
CHECK(strstr(err.p, "no '='") != NULL);
|
|
|
|
/* ---- a missing file says so, distinctly ---- */
|
|
sp_config_init(&c);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_load(&c, "/nonexistent/splinter/config", &err) == -1);
|
|
CHECK(strstr(err.p, "not found") != NULL);
|
|
|
|
/* ---- the example is valid: writing it and reading it back must work ---- */
|
|
snprintf(path, sizeof(path), "%s/sub/example", dir);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_write_example(path, &err) == 0);
|
|
sp_config_init(&c);
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_config_load(&c, path, &err) == 0);
|
|
CHECK(strcmp(c.theme, "Delphinium") == 0);
|
|
CHECK(c.steps == 8);
|
|
CHECK(c.autonomous == 0);
|
|
|
|
/* ---- the path honours SPLINTER_CONFIG ---- */
|
|
setenv("SPLINTER_CONFIG", "/tmp/from-env", 1);
|
|
{
|
|
char buf[256];
|
|
|
|
CHECK(sp_config_path(buf, sizeof(buf)) == 0);
|
|
CHECK(strcmp(buf, "/tmp/from-env") == 0);
|
|
}
|
|
unsetenv("SPLINTER_CONFIG");
|
|
|
|
sp_buf_free(&err);
|
|
/* ---- drop-ins: a directory next to the config, read in name order ---- */
|
|
{
|
|
char dir[512], main_c[600], drop[600];
|
|
FILE *f;
|
|
const char *tmp = getenv("TMPDIR");
|
|
|
|
if (tmp == NULL || *tmp == '\0')
|
|
tmp = "/var/tmp";
|
|
snprintf(dir, sizeof(dir), "%s/splinter-conf-XXXXXX", tmp);
|
|
if (mkdtemp(dir) != NULL) {
|
|
struct sp_config c;
|
|
struct sp_buf e;
|
|
|
|
snprintf(main_c, sizeof(main_c), "%s/splinter.conf", dir);
|
|
write_file(main_c, "theme = Delphinium\n");
|
|
snprintf(drop, sizeof(drop), "%s/splinter.conf.d", dir);
|
|
if (mkdir(drop, 0700) == 0) {
|
|
char one[700], two[700];
|
|
|
|
snprintf(one, sizeof(one), "%s/50-late.conf", drop);
|
|
snprintf(two, sizeof(two), "%s/10-early.conf", drop);
|
|
write_file(one, "theme = Spider\n");
|
|
write_file(two, "locale = de\n");
|
|
/* a file that is not .conf must be ignored */
|
|
{
|
|
char other[700];
|
|
|
|
snprintf(other, sizeof(other),
|
|
"%s/ignored.txt", drop);
|
|
write_file(other, "kaputt = 1\n");
|
|
}
|
|
}
|
|
sp_config_init(&c);
|
|
if (sp_buf_init(&e) == 0) {
|
|
CHECK(sp_config_load(&c, main_c, &e) == 0);
|
|
/* 50-late.conf is read after the main file */
|
|
CHECK(strcmp(c.theme, "Spider") == 0);
|
|
CHECK(strcmp(c.locale, "de") == 0);
|
|
sp_buf_free(&e);
|
|
}
|
|
f = NULL;
|
|
(void)f;
|
|
{
|
|
char cmd[700];
|
|
|
|
snprintf(cmd, sizeof(cmd), "rm -rf '%s'", dir);
|
|
if (system(cmd) != 0)
|
|
fprintf(stderr, "cleanup failed\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
if (failures == 0)
|
|
printf("test_config: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|