planner: v0.2, state in plan_task_*.json via libmcp, atomic replace, refused states. tmux: v0.3, in-process capture-pane diff, no watcher helper, tmux_ask/read/capture. tests: test_tmux added, test_delegate_cli no longer hangs without a tty. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
148 lines
4.4 KiB
C
148 lines
4.4 KiB
C
/*
|
|
* splinter -- planner plugin smoke test.
|
|
*
|
|
* The plan belongs to the session: the tools add, list and update tasks, the
|
|
* list is on disk, and a second reader sees the same file. This is not the
|
|
* background-task store; that one owns processes.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_plugin.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_session_info sess;
|
|
struct sp_registry reg;
|
|
struct sp_agent ag;
|
|
struct sp_host *host;
|
|
struct sp_buf out, err;
|
|
const struct sp_tool *t;
|
|
char dir[] = "/tmp/splinter-plan-XXXXXX";
|
|
char path[600], snap[512], text[2048];
|
|
FILE *f;
|
|
size_t n;
|
|
|
|
CHECK(mkdtemp(dir) != NULL);
|
|
memset(&sess, 0, sizeof(sess));
|
|
snprintf(sess.dir, sizeof(sess.dir), "%s", dir);
|
|
memset(®, 0, sizeof(reg));
|
|
memset(&ag, 0, sizeof(ag));
|
|
CHECK(sp_buf_init(&out) == 0);
|
|
CHECK(sp_buf_init(&err) == 0);
|
|
|
|
host = sp_host_new(®, &ag, &sess);
|
|
CHECK(host != NULL);
|
|
CHECK(sp_plugin_load(host, "plugins/planner/planner.so", &err) == 0);
|
|
|
|
t = sp_registry_find(®, "plan_task_add");
|
|
CHECK(t != NULL);
|
|
if (t != NULL)
|
|
(void)t->run("{\"description\":\"write the planner test\"}",
|
|
&out, t->ctx);
|
|
CHECK(out.p != NULL && strstr(out.p, "added plan task #1") != NULL);
|
|
|
|
sp_buf_clear(&out);
|
|
t = sp_registry_find(®, "plan_task_list");
|
|
CHECK(t != NULL);
|
|
if (t != NULL)
|
|
(void)t->run("{}", &out, t->ctx);
|
|
CHECK(out.p != NULL &&
|
|
strstr(out.p, "write the planner test") != NULL);
|
|
CHECK(out.p != NULL && strstr(out.p, "[todo]") != NULL);
|
|
|
|
sp_buf_clear(&out);
|
|
t = sp_registry_find(®, "plan_task_update");
|
|
CHECK(t != NULL);
|
|
if (t != NULL)
|
|
(void)t->run("{\"id\":\"1\",\"status\":\"doing\"}", &out,
|
|
t->ctx);
|
|
CHECK(out.p != NULL && strstr(out.p, "[doing]") != NULL);
|
|
|
|
/* the command path is the same store */
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "tasks", "ls", &out) == 0);
|
|
CHECK(out.p != NULL &&
|
|
strstr(out.p, "write the planner test") != NULL);
|
|
|
|
/* the file is the contract: a second reader sees it */
|
|
snprintf(path, sizeof(path), "%s/plan_tasks.json", dir);
|
|
f = fopen(path, "r");
|
|
CHECK(f != NULL);
|
|
if (f != NULL) {
|
|
n = fread(text, 1, sizeof(text) - 1, f);
|
|
text[n] = '\0';
|
|
fclose(f);
|
|
CHECK(strstr(text, "write the planner test") != NULL);
|
|
CHECK(strstr(text, "\"doing\"") != NULL);
|
|
}
|
|
|
|
/* the schema says id is an integer; a model sends it as one */
|
|
sp_buf_clear(&out);
|
|
t = sp_registry_find(®, "plan_task_update");
|
|
(void)t->run("{\"id\":1,\"note\":\"half done\"}", &out, t->ctx);
|
|
CHECK(strstr(out.p, "task #1") != NULL);
|
|
|
|
/* a state that does not exist is refused, not stored */
|
|
sp_buf_clear(&out);
|
|
(void)t->run("{\"id\":1,\"status\":\"finished\"}", &out, t->ctx);
|
|
CHECK(strstr(out.p, "error: status is one of") != NULL);
|
|
sp_buf_clear(&out);
|
|
(void)t->run("{\"id\":99,\"status\":\"done\"}", &out, t->ctx);
|
|
CHECK(strstr(out.p, "no task #99") != NULL);
|
|
|
|
/* quotes, backslashes and newlines survive the file */
|
|
sp_buf_clear(&out);
|
|
t = sp_registry_find(®, "plan_task_add");
|
|
(void)t->run("{\"description\":\"say \\\"hi\\\" in C:\\\\tmp\\nthen stop\"}",
|
|
&out, t->ctx);
|
|
CHECK(strstr(out.p, "added plan task #2") != NULL);
|
|
sp_buf_clear(&out);
|
|
t = sp_registry_find(®, "plan_task_list");
|
|
(void)t->run("{}", &out, t->ctx);
|
|
CHECK(strstr(out.p, "say \"hi\" in C:\\tmp\nthen stop") != NULL);
|
|
|
|
/* a parked task waits, and the other command forms work */
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "tasks", "wait 2 +3600 job:abc", &out) == 0);
|
|
CHECK(strstr(out.p, "task #2 waiting_quota") != NULL);
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "tasks", "ls", &out) == 0);
|
|
CHECK(strstr(out.p, "[waiting_quota]") != NULL);
|
|
CHECK(strstr(out.p, "# job:abc") != NULL);
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "tasks", "done 1", &out) == 0);
|
|
CHECK(strstr(out.p, "task #1 done") != NULL);
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "tasks", "next", &out) == 0);
|
|
CHECK(strstr(out.p, "no todo tasks") != NULL);
|
|
|
|
n = sp_host_widget_snapshot(host, snap, sizeof(snap));
|
|
CHECK(n > 0);
|
|
CHECK(strstr(snap, "plan:") != NULL);
|
|
|
|
sp_host_free(host);
|
|
sp_registry_free(®);
|
|
sp_buf_free(&out);
|
|
sp_buf_free(&err);
|
|
snprintf(path, sizeof(path), "rm -rf '%s'", dir);
|
|
(void)system(path);
|
|
|
|
if (failures == 0)
|
|
printf("test_planner: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|