@@ -1344,11 +1344,10 @@ TEST(client_adapter_opencode_covers_lifecycle_read_and_compaction) {
13441344
13451345/* #2077/#2089/#2204: the two OpenCode runtimes read different entries of the
13461346 * default export. 1.18.x dispatches the hooks returned by `server(ctx)`; 2.x
1347- * ignores `server` and calls `setup(ctx)`, whose context provides the tool and
1348- * session hook domains. Registrations fail open per domain, so the matching
1349- * server() hook yields once its domain is registered. The post-compaction note
1350- * goes into the compaction request's messages, never the system prompt (pinned
1351- * by the compaction test below). */
1347+ * ignores `server` and calls `setup(ctx)`, whose context provides the tool hook
1348+ * domain. The registration fails open, and the server() tool hook yields once
1349+ * it is registered. OpenCode 2 adds no note to a compaction (pinned by the
1350+ * compaction test below). */
13521351TEST (client_adapter_opencode_exports_the_v2_default_definition_issue2077 ) {
13531352 char * js = cbm_client_adapter_opencode ("/usr/local/bin/codebase-memory-mcp" );
13541353 ASSERT_NOT_NULL (js );
@@ -1360,8 +1359,6 @@ TEST(client_adapter_opencode_exports_the_v2_default_definition_issue2077) {
13601359 * 2.x, so setup is no longer the empty placeholder #2089 pinned. */
13611360 ASSERT_NOT_NULL (strstr (js , "async setup(ctx) {" ));
13621361 ASSERT_NOT_NULL (strstr (js , "ctx.tool.hook('execute.after'" ));
1363- ASSERT_NOT_NULL (strstr (js , "ctx.session.hook('compaction'" ));
1364- ASSERT_NULL (strstr (js , "ctx.session.hook('context'" ));
13651362 /* content is the surface the model reads; prefer it over output, and never
13661363 * synthesize content that would hide the tool's own result. */
13671364 const char * content_first = strstr (js , "if (typeof result.content === 'string') {" );
@@ -1382,11 +1379,9 @@ TEST(client_adapter_opencode_exports_the_v2_default_definition_issue2077) {
13821379 * location in a multi-project server. */
13831380 ASSERT_NULL (strstr (js , "ctx?.location?.directory" ));
13841381 ASSERT_NULL (strstr (js , "pendingReinject" ));
1385- /* Registrations fail open per domain ; the server() hooks yield per domain . */
1382+ /* The registration fails open ; the server() tool hook yields once it is in . */
13861383 ASSERT_NOT_NULL (strstr (js , "toolHooksRegistered = true;" ));
1387- ASSERT_NOT_NULL (strstr (js , "sessionHooksRegistered = true;" ));
13881384 ASSERT_NOT_NULL (strstr (js , "if (toolHooksRegistered) return;" ));
1389- ASSERT_NOT_NULL (strstr (js , "if (sessionHooksRegistered) return;" ));
13901385 ASSERT_NOT_NULL (strstr (js , "catch {" ));
13911386 ASSERT_NOT_NULL (strstr (js , "event.result = appendResult(event.result, extra);" ));
13921387 /* The empty setup placeholder and the old named export must both be gone. */
@@ -1396,38 +1391,23 @@ TEST(client_adapter_opencode_exports_the_v2_default_definition_issue2077) {
13961391 PASS ();
13971392}
13981393
1399- /* #2204: on OpenCode 2 the post-compaction note stays inside the compaction,
1400- * at the level the 1.18.x path uses (output.context). The `compaction` hook
1401- * receives the compaction request, whose `messages` are the input the summary
1402- * is built from , so the note is pushed there as a text message. It must never
1403- * reach the system prompt: not through `event. system`, and not through a
1404- * session instruction entry, which OpenCode renders into the system array of
1405- * every later request . */
1406- TEST (client_adapter_opencode_v2_compaction_note_goes_into_the_compaction_messages ) {
1394+ /* #2204: OpenCode 2 gets no note after compaction until a compaction channel has
1395+ * run on a real 2.x host. A plain object pushed into `event.messages` would be
1396+ * rejected, if at all, inside OpenCode's own compaction, where the plugin's
1397+ * try/catch cannot reach it , so an untested channel could break compaction for
1398+ * every OpenCode 2 user. The note must not reach the system prompt either: not
1399+ * through `event.system`, and not through a session instruction entry. The
1400+ * 1.18.x server() path keeps its documented compaction surface . */
1401+ TEST (client_adapter_opencode_v2_adds_no_note_to_the_compaction ) {
14071402 char * js = cbm_client_adapter_opencode ("/usr/local/bin/codebase-memory-mcp" );
14081403 ASSERT_NOT_NULL (js );
1409- const char * hook = strstr (js , "ctx.session.hook('compaction'" );
1410- const char * push = strstr (js , "event.messages.push({" );
1411- const char * registered = strstr (js , "sessionHooksRegistered = true;" );
1412- ASSERT_NOT_NULL (hook );
1413- ASSERT_NOT_NULL (push );
1414- ASSERT_NOT_NULL (registered );
1415- /* The push lives inside the compaction registration. */
1416- ASSERT_TRUE (hook < push );
1417- ASSERT_TRUE (push < registered );
1418- /* A text message that carries the note. */
1419- const char * role = strstr (push , "role: 'user'," );
1420- const char * text = strstr (push , "content: [{ type: 'text', text: note }]," );
1421- ASSERT_NOT_NULL (role );
1422- ASSERT_NOT_NULL (text );
1423- ASSERT_TRUE (role < registered );
1424- ASSERT_TRUE (text < registered );
1425- /* Fail open: a host whose event has no messages array skips reinjection. */
1426- ASSERT_NOT_NULL (strstr (js , "if (!Array.isArray(event?.messages)) return;" ));
1427- /* Never the system prompt, and no session instruction entry. */
1404+ ASSERT_NULL (strstr (js , "ctx.session.hook(" ));
1405+ ASSERT_NULL (strstr (js , "event.messages" ));
1406+ ASSERT_NULL (strstr (js , "sessionHooksRegistered" ));
14281407 ASSERT_NULL (strstr (js , ".system" ));
14291408 ASSERT_NULL (strstr (js , "instructions" ));
14301409 ASSERT_NULL (strstr (js , "entry.put" ));
1410+ ASSERT_NOT_NULL (strstr (js , "'experimental.session.compacting'" ));
14311411 free (js );
14321412 PASS ();
14331413}
@@ -1529,7 +1509,7 @@ SUITE(agent_clients) {
15291509 RUN_TEST (client_adapter_opencode_sends_the_required_hook_event );
15301510 RUN_TEST (client_adapter_opencode_covers_lifecycle_read_and_compaction );
15311511 RUN_TEST (client_adapter_opencode_exports_the_v2_default_definition_issue2077 );
1532- RUN_TEST (client_adapter_opencode_v2_compaction_note_goes_into_the_compaction_messages );
1512+ RUN_TEST (client_adapter_opencode_v2_adds_no_note_to_the_compaction );
15331513 RUN_TEST (client_adapter_opencode_v2_append_result_never_creates_note_only_content );
15341514 RUN_TEST (client_adapter_opencode_bounds_a_hung_hook_augment_child );
15351515 RUN_TEST (client_adapter_rejects_missing_binary_path );
0 commit comments