Inject shared parliament context into the agent environment, switch prompts away from in-process workers when parliament is active, clear login tickets on chair sync/new-project, and surface realm/chair/service in /status. Tighten empty-reply handling and prefer-tool principles. Co-authored-by: Cursor <cursoragent@cursor.com>
82 lines
2.7 KiB
C
82 lines
2.7 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
#include "cst_parliament.h"
|
|
#include "cst_realm.h"
|
|
#include "cst_test_util.h"
|
|
#include "os_compat.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
char dir[2048], cfg[512];
|
|
assert(!test_tmpdir(dir, sizeof(dir), "parliament"));
|
|
assert(snprintf(cfg, sizeof(cfg), "%s/cfg", dir) < (int)sizeof(cfg));
|
|
assert(!os_mkdir_p(cfg, 0700));
|
|
setenv("XDG_CONFIG_HOME", cfg, 1);
|
|
|
|
char realm[OS_PATH_MAX];
|
|
assert(cst_realm_dir(realm, sizeof(realm)) == 0);
|
|
assert(cst_realm_init_password(realm, "correct horse battery") == 0);
|
|
assert(cst_realm_is_password_mode(realm));
|
|
|
|
cst_realm_keys_t bad, good;
|
|
assert(cst_realm_unlock_password(realm, "wrong", &bad) != 0);
|
|
assert(cst_realm_unlock_password(realm, "correct horse battery", &good) == 0);
|
|
|
|
char err[128];
|
|
char *hand = cst_parliament_login("correct horse battery", "phone-1", "pixel",
|
|
err, sizeof(err));
|
|
assert(hand && strstr(hand, "LOGIN_OK") && strstr(hand, "chair=phone-1"));
|
|
free(hand);
|
|
|
|
cst_parliament_meta_t m;
|
|
assert(cst_parliament_load(&m) == 0);
|
|
assert(!strcmp(m.chair_instance, "phone-1"));
|
|
|
|
assert(cst_parliament_context_put("shared agenda v1") == 0);
|
|
hand = cst_parliament_login("correct horse battery", "laptop-2", "thinkpad",
|
|
err, sizeof(err));
|
|
assert(hand && strstr(hand, "handover_from=phone-1"));
|
|
assert(strstr(hand, "shared agenda v1"));
|
|
free(hand);
|
|
assert(cst_parliament_load(&m) == 0);
|
|
assert(!strcmp(m.chair_instance, "laptop-2"));
|
|
|
|
assert(cst_parliament_session_ok(NULL, 0));
|
|
|
|
assert(cst_parliament_new_project("proj-b") == 0);
|
|
char *ctx = cst_parliament_context_get();
|
|
assert(ctx && ctx[0] == 0);
|
|
free(ctx);
|
|
assert(cst_parliament_load(&m) == 0);
|
|
assert(!strcmp(m.project_id, "proj-b"));
|
|
assert(m.chair_instance[0] == 0);
|
|
assert(!cst_parliament_session_ok(NULL, 0));
|
|
|
|
assert(cst_parliament_session_write("local-a") == 0);
|
|
/* Claim chair so session_ok matches. */
|
|
assert(cst_parliament_claim_chair("local-a", "dev") == 0);
|
|
assert(cst_parliament_session_ok(NULL, 0));
|
|
assert(cst_parliament_apply_sync(9, "parl-x", "proj-c", "chair-z",
|
|
"synced-body") == 0);
|
|
ctx = cst_parliament_context_get();
|
|
assert(ctx && strstr(ctx, "synced-body"));
|
|
free(ctx);
|
|
assert(cst_parliament_load(&m) == 0);
|
|
assert(m.revision == 9);
|
|
assert(!strcmp(m.chair_instance, "chair-z"));
|
|
/* Remote chair takeover clears local login ticket. */
|
|
assert(!cst_parliament_session_ok(NULL, 0));
|
|
|
|
char *st = cst_parliament_status_text();
|
|
assert(st && strstr(st, "parliament"));
|
|
free(st);
|
|
assert(cst_parliament_is_active());
|
|
|
|
test_rmrf(dir);
|
|
puts("test_parliament: OK");
|
|
return 0;
|
|
}
|