Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(cli): keep a user-owned OpenCode module out of the install plan

Martin Vogel3f612f6b710f
diff --git a/src/cli/cli.c b/src/cli/cli.c
index 9abd26f9a..2aae26080 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -9415,20 +9415,27 @@ static void install_generated_client_extension(const char *label, const char *pa
* through to the write, which reports it through the usual error path. */
bool foreign =
cbm_text_managed_block_status(path, CBM_ADAPTER_MARKER_START, CBM_ADAPTER_MARKER_END) == 1;
- if (g_install_plan) {
- plan_record(label, "extension", path);
- if (foreign) {
+ if (foreign) {
+ /* The --plan receipt (#388) lists only writes the run will make, and
+ * its stdout carries the receipt JSON, so plan mode records nothing
+ * and prints nothing here. The dry run names the skip instead. */
+ if (g_install_plan) {
+ return;
+ }
+ if (dry_run) {
printf(" extension: %s would be skipped — the file there is not ours (no "
"codebase-memory-mcp markers), so it is left untouched; delete it or add the "
"markers to let the installer manage it\n",
path);
+ } else {
+ printf(" extension: %s left untouched — the file there is not ours (no "
+ "codebase-memory-mcp markers)\n",
+ path);
}
return;
}
- if (foreign) {
- printf(" extension: %s left untouched — the file there is not ours (no "
- "codebase-memory-mcp markers)\n",
- path);
+ if (g_install_plan) {
+ plan_record(label, "extension", path);
return;
}
char *content = generate(binary_path);
diff --git a/tests/test_cli.c b/tests/test_cli.c
index 96936d0dd..d13002cd9 100644
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@ -9259,13 +9259,33 @@ TEST(cli_extension_leaves_user_owned_module_untouched_issue2204) {
fflush(stdout);
redirected = dup2(fileno(capture), STDOUT_FILENO) >= 0;
}
+ long plan_output_start = -1;
+ char *plan = NULL;
if (redirected) {
(void)cbm_install_agent_configs(home, "/opt/other/codebase-memory-mcp", false, true);
fflush(stdout);
+ /* The --plan receipt (#388) replays the same path with writes off. It
+ * must not list a module the run leaves alone, and it must print
+ * nothing: stdout carries the receipt JSON. */
+ plan_output_start = (long)lseek(STDOUT_FILENO, 0, SEEK_CUR);
+ plan = cbm_build_install_plan_json(home, "/opt/other/codebase-memory-mcp");
+ fflush(stdout);
(void)dup2(saved_stdout, STDOUT_FILENO);
}
if (saved_stdout >= 0)
close(saved_stdout);
+
+ char bytes[512] = {0};
+ FILE *file = cbm_fopen(plugin_path, "rb");
+ size_t got = file ? fread(bytes, 1U, sizeof(bytes) - 1U, file) : 0U;
+ if (file)
+ fclose(file);
+
+ /* Control: with the user's module gone the receipt does list the path, so
+ * the omission above cannot pass just because OpenCode went undetected. */
+ char *control_plan = NULL;
+ if (unlink(plugin_path) == 0)
+ control_plan = cbm_build_install_plan_json(home, "/opt/other/codebase-memory-mcp");
client_detect_env_restore(&saved);
char output[16384] = {0};
@@ -9276,13 +9296,14 @@ TEST(cli_extension_leaves_user_owned_module_untouched_issue2204) {
fclose(capture);
}
- char bytes[512] = {0};
- FILE *file = cbm_fopen(plugin_path, "rb");
- size_t got = file ? fread(bytes, 1U, sizeof(bytes) - 1U, file) : 0U;
- if (file)
- fclose(file);
bool warned = strstr(output, "cbm-augment.ts") != NULL && strstr(output, "not ours") != NULL;
bool untouched = got == sizeof(foreign) - 1U && memcmp(bytes, foreign, got) == 0;
+ bool plan_omits = plan && strstr(plan, "cbm-augment.ts") == NULL;
+ bool plan_silent = plan_output_start >= 0 && (size_t)plan_output_start <= strlen(output) &&
+ strstr(output + plan_output_start, "cbm-augment.ts") == NULL;
+ bool control_lists = control_plan && strstr(control_plan, "cbm-augment.ts") != NULL;
+ free(plan);
+ free(control_plan);
test_rmdir_r(home);
if (!redirected)
@@ -9291,6 +9312,12 @@ TEST(cli_extension_leaves_user_owned_module_untouched_issue2204) {
FAIL("dry-run must predict an untouched user-owned OpenCode module (#2204)");
if (!untouched)
FAIL("the user-owned OpenCode module must not be modified (#2204)");
+ if (!plan_omits)
+ FAIL("the install plan must not list a module the run leaves untouched (#2204)");
+ if (!plan_silent)
+ FAIL("plan mode must keep stdout for the receipt JSON (#2204)");
+ if (!control_lists)
+ FAIL("control: the install plan must list the module once it is not user-owned");
PASS();
}
#endif