Files
CST-agent/tests/test_json_baseline.c
T
WHCandCursor 1f1fcba7ad Initial CST-Agent: portable Linux/Termux/Windows coding agent.
Vendored sashidown, OpenAI-compatible env (OPENAI_*), and bootstrap scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 22:42:32 +08:00

56 lines
1.4 KiB
C

#include "cst_agent.h"
#include <stdio.h>
#include <string.h>
static int expect(int cond, const char *msg) {
if (!cond) {
fprintf(stderr, "FAIL: %s\n", msg);
return 0;
}
return 1;
}
static int test_complete_json(void) {
const char *j =
"Here is a call {\"name\":\"read_file\",\"arguments\":{\"path\":\"a.c\"}} "
"done";
cst_json_tool_t t;
int ok = cst_json_try_parse_tool(j, strlen(j), &t);
int pass = expect(ok == 1, "parse ok");
pass &= expect(t.ok == 1, "ok flag");
pass &= expect(strcmp(t.name, "read_file") == 0, "name");
pass &= expect(strstr(t.arguments_json, "path") != NULL, "args");
return pass;
}
static int test_truncated_json(void) {
const char *j = "{\"name\":\"read_file\",\"arguments\":{\"path\":\"a";
cst_json_tool_t t;
int ok = cst_json_try_parse_tool(j, strlen(j), &t);
return expect(ok == 0, "truncated must fail");
}
static int test_unclosed_brace(void) {
const char *j = "{\"name\":\"run_shell\",\"arguments\":{\"cmd\":\"ls\"";
cst_json_tool_t t;
int ok = cst_json_try_parse_tool(j, strlen(j), &t);
return expect(ok == 0, "unclosed brace fails");
}
int main(void) {
int nfail = 0;
if (!test_complete_json())
nfail++;
if (!test_truncated_json())
nfail++;
if (!test_unclosed_brace())
nfail++;
if (nfail) {
fprintf(stderr, "%d failed\n", nfail);
return 1;
}
printf("test_json_baseline: OK\n");
return 0;
}