/* * splinter -- a mutating tool runs without asking anyone. * * This test used to guard the opposite: a turn that parked before a mutate * tool and waited for an approval, then resumed with a yes or a no. That * gate is gone, because it was the program deciding what the operator may * do. What stays true, and is guarded here: * * - a mutate tool the registry offers runs in the same turn, no pause; * - a destructive tool runs too; * - the turn never returns a "needs a person" code, so no front end has * to carry a resume path; * - a denial only happens where the operator configured one (the agent's * tool policy), never from a built-in prompt. */ #include #include #include "splinter.h" static int failures; static int ran; #define CHECK(cond) do { \ if (!(cond)) { \ fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ failures++; \ } \ } while (0) static int write_tool(const char *args, struct sp_buf *out, void *ctx) { (void)args; (void)ctx; ran++; return sp_buf_puts(out, "written"); } static int run_turn(struct sp_agent *a, struct sp_conv *conv, struct sp_mock *m, struct sp_buf *answer, struct sp_buf *err) { int rc; sp_conv_init(conv); a->conv = conv; CHECK(sp_mock_init(m) == 0); CHECK(sp_mock_push(m, 200, "tool write x") == 0); CHECK(sp_mock_push(m, 200, "answer done") == 0); a->tr = sp_mock_transport(m); sp_buf_clear(answer); rc = sp_agent_run(a, "go", answer, err); return rc; } int main(void) { struct sp_registry r; struct sp_tool t; struct sp_agent a; struct sp_agent_config cfg; struct sp_conv conv; struct sp_mock m; struct sp_buf answer, err; int rc; memset(&r, 0, sizeof(r)); memset(&t, 0, sizeof(t)); t.name = "write"; t.description = "mutate"; t.auth = SP_AUTH_MUTATE; t.run = write_tool; CHECK(sp_registry_add(&r, &t) == 0); memset(&t, 0, sizeof(t)); t.name = "rm"; t.description = "destructive"; t.auth = SP_AUTH_DESTRUCTIVE; t.run = write_tool; CHECK(sp_registry_add(&r, &t) == 0); memset(&a, 0, sizeof(a)); memset(&cfg, 0, sizeof(cfg)); cfg.max_steps = 5; a.reg = &r; a.cfg = &cfg; CHECK(sp_buf_init(&answer) == 0); CHECK(sp_buf_init(&err) == 0); /* a mutate tool runs in the same turn: no pause, no question, and the * model sees its observation before it answers */ ran = 0; rc = run_turn(&a, &conv, &m, &answer, &err); CHECK(rc == 0); CHECK(ran == 1); CHECK(strcmp(answer.p, "done") == 0); CHECK(strstr(m.last_request.p, "observe write written") != NULL); CHECK(strstr(m.last_request.p, "denied") == NULL); sp_mock_free(&m); sp_conv_free(&conv); /* a destructive tool runs too: the operator decides what the agent may * reach by what is in the registry, not by answering a prompt */ ran = 0; CHECK(run_turn(&a, &conv, &m, &answer, &err) == 0); CHECK(ran == 1); sp_mock_free(&m); sp_conv_free(&conv); /* * The one denial that stays is the operator's own tool policy: a * profile that says "read only" is a configuration, not a prompt. */ memset(&a, 0, sizeof(a)); memset(&cfg, 0, sizeof(cfg)); cfg.max_steps = 5; a.reg = &r; a.cfg = &cfg; ran = 0; { struct sp_tool_policy pol; memset(&pol, 0, sizeof(pol)); pol.max_auth = SP_AUTH_READ; a.policy = &pol; CHECK(run_turn(&a, &conv, &m, &answer, &err) == 0); CHECK(ran == 0); CHECK(strstr(m.last_request.p, "denied") != NULL); sp_mock_free(&m); sp_conv_free(&conv); } sp_buf_free(&answer); sp_buf_free(&err); sp_registry_free(&r); if (failures == 0) printf("test_pause: ok\n"); return failures == 0 ? 0 : 1; }