Skip to content

Commit 0311189

Browse files
committed
fix(step4): align async, budget and usage tests with the merged daemon frame
Jenkins release-tooling DeusData#61 ran the full suite on sync/upstream-step4 and 5 tests failed. All 5 were stale expectations left after step 2 merged into step 4. - daemon_application async tests (5271, 5321 and the cancelled-sync reply). Daemon application responses are binary frames: an error-flag byte followed by a length-delimited payload with no trailing NUL. The step-4 helpers strdup'd that frame, which reads as "". Add app_async_frame_to_wire(), which converts the frame into an operation result wire so app_async_contains() decodes the payload and error flag. The now-unused app_async_call_response() is removed. - The cancelled-sync reply now asserts the CLI wording "--status" instead of the MCP-style "status: true". - daemon_application_over_budget_response_passes_through_without_recovery asserts the frame's error flag is set and the payload names over_memory_budget. The error travels in the flag, not in a payload key. - cli activation-scope tests (2187, 2238): the kept-daemon notice tells the user to run "codebase-memory-cli daemon stop". The test still expected the upstream binary name. - cli_usage_points_to_tool_format_json_issue2102: port upstream DeusData#2102 to the CLI. CBM_CLI_USAGE now says that tools accepting format support --format tree|json (default tree), and that --format json prints the tool payload JSON. The fork's tools declare format in tool_catalog. The test asserts that text and that the usage never mentions MCP. Upstream's "outer --json prints the MCP envelope" line is not carried over. Local runs: `scripts/test.sh --suites daemon_application` and `scripts/test.sh --suites cli` both pass.
1 parent c8320ce commit 0311189

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

‎src/cli/cli.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const char *cbm_cli_get_version(void);
3333
" --quiet Show errors only; cannot combine with --progress or outer --verbose\n" \
3434
" --progress Show lifecycle progress even when stderr is redirected\n" \
3535
" --verbose Include informational logs (preserves CBM_LOG_LEVEL=debug)\n" \
36-
" --json Print machine-readable output\n"
36+
" --json Print machine-readable output\n" \
37+
" Tools that accept format support --format tree|json (default: tree).\n" \
38+
" --format json prints the tool payload JSON instead of the tree view.\n"
3739

3840
/* Convert `--flag value` / `--flag=value` / bare-boolean `--flag` arguments for
3941
* a tool into a JSON arguments object string, using the tool's input_schema to

‎tests/test_cli.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ static bool cli_scope_kept_notice_names_host(const char *output, pid_t host) {
21462146
snprintf(pid_text, sizeof(pid_text), "(pid %ld, version %s)", (long)host, CBM_VERSION);
21472147
return strstr(output, "Leaving the running CBM daemon untouched") != NULL &&
21482148
strstr(output, pid_text) != NULL &&
2149-
strstr(output, "codebase-memory-mcp daemon stop") != NULL &&
2149+
strstr(output, "codebase-memory-cli daemon stop") != NULL &&
21502150
strstr(output, "Stopping active CBM sessions") == NULL;
21512151
}
21522152

@@ -13140,8 +13140,8 @@ TEST(cli_print_tool_help_issue680) {
1314013140
TEST(cli_usage_points_to_tool_format_json_issue2102) {
1314113141
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--format tree|json"));
1314213142
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "payload JSON"));
13143-
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "full MCP envelope"));
13144-
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--json Print the raw MCP result envelope"));
13143+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--json Print machine-readable output"));
13144+
ASSERT_NULL(strstr(CBM_CLI_USAGE, "MCP"));
1314513145
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "cli [--quiet] [--progress] [--verbose] [--json] "
1314613146
"<tool_name>"));
1314713147
ASSERT_NULL(strstr(CBM_CLI_USAGE, "[--format"));

‎tests/test_daemon_application.c‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,14 +4974,12 @@ TEST(daemon_application_over_budget_response_passes_through_without_recovery) {
49744974
setup
49754975
? app_test_request(&callbacks, session, tool, tool_length, &response, &response_length)
49764976
: CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR;
4977-
/* Binary-safe over the whole frame: the error flag precedes a length-delimited
4978-
* payload, and the result wire spells the flag is_error (operation layer) or
4979-
* isError (passthrough body). */
4977+
/* The frame is one error-flag byte followed by the length-delimited payload.
4978+
* The worker's over-budget answer must arrive as an error carrying its named
4979+
* cause, not be retried or rewritten by recovery. */
49804980
bool passed_through =
4981-
response && response_length > 0 &&
4982-
app_test_response_contains(response, response_length, "over_memory_budget") &&
4983-
(app_test_response_contains(response, response_length, "\"is_error\":true") ||
4984-
app_test_response_contains(response, response_length, "\"isError\":true"));
4981+
response && response_length > 1U && response[0] == 1U &&
4982+
app_test_response_contains(response + 1U, response_length - 1U, "over_memory_budget");
49854983
free(response);
49864984
free(context);
49874985
free(tool);
@@ -5184,10 +5182,6 @@ static bool app_async_call_start(app_async_fixture_t *fixture, app_async_call_t
51845182
return call->started;
51855183
}
51865184

5187-
static const char *app_async_call_response(app_async_call_t *call) {
5188-
return call->request.response ? (const char *)call->request.response : "";
5189-
}
5190-
51915185
static void app_async_call_join(app_async_call_t *call) {
51925186
if (call->started) {
51935187
(void)cbm_thread_join(&call->thread);
@@ -5203,6 +5197,24 @@ static void app_async_call_free(app_async_call_t *call) {
52035197
}
52045198

52055199
/* A request that must return promptly (status, validation, async start). */
5200+
/* The application answers with a binary frame: one error-flag byte followed by
5201+
* the length-delimited payload (no NUL). Re-encode it as an operation result
5202+
* wire so the assertions below can decode payload and error flag together. */
5203+
static char *app_async_frame_to_wire(const uint8_t *frame, uint32_t frame_length) {
5204+
if (!frame || frame_length < 1U)
5205+
return NULL;
5206+
char *payload = malloc((size_t)frame_length);
5207+
if (!payload)
5208+
return NULL;
5209+
memcpy(payload, frame + 1, (size_t)frame_length - 1U);
5210+
payload[frame_length - 1U] = '\0';
5211+
cbm_operation_result_t result = cbm_operation_result_copy(payload, frame[0] != 0U);
5212+
free(payload);
5213+
char *wire = result.payload ? cbm_operation_result_wire_encode(&result) : NULL;
5214+
cbm_operation_result_dispose(&result);
5215+
return wire;
5216+
}
5217+
52065218
static char *app_async_call_now(app_async_fixture_t *fixture,
52075219
cbm_daemon_runtime_application_session_t *session,
52085220
const char *extra_args) {
@@ -5212,7 +5224,7 @@ static char *app_async_call_now(app_async_fixture_t *fixture,
52125224
if (app_async_call_start(fixture, &call, session, CBM_DAEMON_RUNTIME_APPLICATION_TOKEN_INVALID,
52135225
extra_args) &&
52145226
app_wait_for_atomic_bool(&call.request.done, true)) {
5215-
response = strdup(app_async_call_response(&call));
5227+
response = app_async_frame_to_wire(call.request.response, call.request.response_length);
52165228
}
52175229
/* Never strand a request thread that blocked on the held worker. */
52185230
if (call.started && !atomic_load(&call.request.done)) {
@@ -5441,7 +5453,9 @@ TEST(daemon_application_cancelled_sync_index_reply_offers_async) {
54415453
app_async_call_join(&call);
54425454
}
54435455
cbm_daemon_runtime_application_status_t status = call.request.status;
5444-
char *reply = call_started ? strdup(app_async_call_response(&call)) : NULL;
5456+
char *reply = call_started
5457+
? app_async_frame_to_wire(call.request.response, call.request.response_length)
5458+
: NULL;
54455459
if (call_started) {
54465460
app_async_call_free(&call);
54475461
}
@@ -5456,7 +5470,7 @@ TEST(daemon_application_cancelled_sync_index_reply_offers_async) {
54565470
ASSERT_EQ(status, CBM_DAEMON_RUNTIME_APPLICATION_OK);
54575471
ASSERT_TRUE(app_async_contains(reply, "cancelled"));
54585472
ASSERT_TRUE(app_async_contains(reply, "--async"));
5459-
ASSERT_TRUE(app_async_contains(reply, "status: true"));
5473+
ASSERT_TRUE(app_async_contains(reply, "--status"));
54605474
free(reply);
54615475
PASS();
54625476
}

0 commit comments

Comments
 (0)