Skip to content

Commit 2ae84e7

Browse files
committed
test(pi): pin result wrap, error throw, and abort in generated adapter
Maintainer asked for in-tree coverage of {content, details} wrapping and how tool errors are surfaced, plus a cheap abort-signal line. String-shape only; no live Pi process. Signed-off-by: Alex Musichen <alex.musichen@gmail.com>
1 parent 495a79d commit 2ae84e7

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎tests/test_agent_clients.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,24 @@ TEST(client_adapter_pi_emits_parameters_and_execute) {
11391139
PASS();
11401140
}
11411141

1142+
/* Result wrap + abort: Pi's TUI reads result.content; a spawn/parse failure
1143+
* must throw rather than return a result without content; AbortSignal must
1144+
* kill the cli child. String-shape only; a live Pi process is not gated. */
1145+
TEST(client_adapter_pi_wraps_result_and_honors_abort) {
1146+
char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp");
1147+
ASSERT_NOT_NULL(js);
1148+
ASSERT_NOT_NULL(strstr(js, "return { content, details: result ?? {} };"));
1149+
ASSERT_NOT_NULL(strstr(js, "if (result && typeof result === 'object' && result.error)"));
1150+
ASSERT_NOT_NULL(strstr(js, "throw new Error(String(result.error));"));
1151+
ASSERT_NOT_NULL(strstr(js, "Array.isArray(result.content)"));
1152+
ASSERT_NOT_NULL(
1153+
strstr(js, "[{ type: 'text', text: JSON.stringify(result ?? null, null, 2) }]"));
1154+
ASSERT_NOT_NULL(strstr(js, "signal?.addEventListener('abort', onAbort, { once: true })"));
1155+
ASSERT_NOT_NULL(strstr(js, "if (!child.killed) child.kill();"));
1156+
free(js);
1157+
PASS();
1158+
}
1159+
11421160
/* #616 rejected `"` in its path template but not `\`, so a Windows home like
11431161
* C:\Users\urs\bin produced `\u` — an invalid unicode escape — and the whole
11441162
* auto-loaded plugin failed to parse. A broken plugin in an auto-load directory
@@ -1230,6 +1248,7 @@ SUITE(agent_clients) {
12301248
RUN_TEST(client_adapter_pi_registers_every_registry_tool);
12311249
RUN_TEST(client_adapter_pi_default_exports_its_factory_issue1550);
12321250
RUN_TEST(client_adapter_pi_emits_parameters_and_execute);
1251+
RUN_TEST(client_adapter_pi_wraps_result_and_honors_abort);
12331252
RUN_TEST(client_adapter_escapes_windows_paths_and_quotes);
12341253
RUN_TEST(client_adapter_opencode_sends_the_required_hook_event);
12351254
RUN_TEST(client_adapter_rejects_missing_binary_path);

0 commit comments

Comments
 (0)