Files
CST-agent/tests/test_parliament.c
T
WHCandCursor e853abac5e feat: parliament daemon, login gate, peer context sync (0.9.13)
Login claims the chair, writes a session ticket, and starts a background
service for discovery plus revision-based context sync. Password Realm
opens require --login (or CST_REALM_PASSWORD); --service/--service-stop
manage the resident agent.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-28 23:11:23 +08:00

71 lines
2.3 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_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"));
test_rmrf(dir);
puts("test_parliament: OK");
return 0;
}