Everything that was uncommitted in the shared tree, in one commit because the changes are interleaved across the same files (lcm, engine, frontend, locales). lcm: a continuation prompt is not the task. After /resume the newest user message is "Continue with the task ...", and pinning it kept the keystroke while the question it continues was cut away -- measured: a resumed session woke up with the prompt, one tool call and its error, and no task at all. The pin now skips the harness's own continuation prompts, so the real question is pinned again. test_compactor drives it: with the skip disabled the task is lost (red), with it the task comes back after the summary (green). engine: /self-check and the exact tool-argument parse are in a1794fb; this commit carries the tests for them (a failed tool observation must appear in the self-check prompt; mcp_parse_exact rejects two objects in one string) and the i18n keys the new code uses: cmd.script.*, main.no_profile, tg.busy, tg.interview.running, ui.agent_busy in all three catalogues. The rest is the in-flight work from the shared session: engine/frontend, plugins, telegram/a2a, and their tests. make check: all tests passed; check_i18n ok, 204 keys in 3 catalogues.
99 lines
2.4 KiB
C
99 lines
2.4 KiB
C
/*
|
|
* splinter -- the self plugin: the session's own resource use.
|
|
*
|
|
* The numbers come from /proc, so the test proves the shape and that both the
|
|
* widget and /self answer; the exact values belong to the machine.
|
|
*/
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.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)
|
|
|
|
static void
|
|
nap_ms(long ms)
|
|
{
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = ms / 1000;
|
|
ts.tv_nsec = (ms % 1000) * 1000000L;
|
|
nanosleep(&ts, NULL);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct sp_registry reg;
|
|
struct sp_agent ag;
|
|
struct sp_host *host;
|
|
struct sp_buf err, out;
|
|
char snap[2048];
|
|
pid_t kid;
|
|
|
|
memset(®, 0, sizeof(reg));
|
|
memset(&ag, 0, sizeof(ag));
|
|
if (sp_buf_init(&err) != 0 || sp_buf_init(&out) != 0)
|
|
return 1;
|
|
host = sp_host_new(®, &ag, NULL);
|
|
CHECK(host != NULL);
|
|
CHECK(sp_plugin_load(host, "plugins/self/self.so", &err) == 0);
|
|
CHECK(sp_registry_find(®, "session_usage") != NULL);
|
|
|
|
/*
|
|
* A child of ours must be counted. The scan of /proc used to stop
|
|
* after 256 entries; on a machine with more processes it never got
|
|
* to our own pid and saw no children at all.
|
|
*/
|
|
kid = fork();
|
|
if (kid == 0) {
|
|
nap_ms(10000);
|
|
_exit(0);
|
|
}
|
|
CHECK(kid > 0);
|
|
|
|
/* the widget samples on its first tick and every two seconds */
|
|
nap_ms(2400);
|
|
snap[0] = '\0';
|
|
CHECK(sp_host_widget_snapshot(host, snap, sizeof(snap)) > 0);
|
|
CHECK(strstr(snap, "self: ") != NULL);
|
|
CHECK(strstr(snap, "memory") != NULL);
|
|
CHECK(strstr(snap, "threads") != NULL);
|
|
CHECK(strstr(snap, "open files") != NULL);
|
|
CHECK(strstr(snap, "children") != NULL);
|
|
CHECK(strstr(snap, "no children") == NULL);
|
|
if (kid > 0) {
|
|
(void)kill(kid, SIGKILL);
|
|
(void)waitpid(kid, NULL, 0);
|
|
}
|
|
|
|
/* /self and the tool carry the same numbers, with the child count */
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "self", "", &out) == 0);
|
|
CHECK(strstr(out.p, "memory (RSS):") != NULL);
|
|
CHECK(strstr(out.p, "threads:") != NULL);
|
|
CHECK(strstr(out.p, "children:") != NULL);
|
|
CHECK(strstr(out.p, "cpu:") != NULL);
|
|
|
|
sp_host_free(host);
|
|
sp_buf_free(&err);
|
|
sp_buf_free(&out);
|
|
sp_registry_free(®);
|
|
|
|
if (failures == 0)
|
|
printf("test_self: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|