@@ -7550,6 +7550,61 @@ TEST(cli_install_warns_about_legacy_mcp_instruction_block) {
75507550 NULL;
75517551#endif
75527552
7553+ /* Codex uninstall removes instructions through its own helper instead of
7554+ * uninstall_agent_mcp_instr, so it needs its own legacy-block warning: same
7555+ * text, in --dry-run and for real, and the legacy bytes must survive both. */
7556+ #ifndef _WIN32
7557+ cli_fd_capture_t uninstall_dry_capture;
7558+ cli_fd_capture_begin(&uninstall_dry_capture, stderr, STDERR_FILENO);
7559+ #endif
7560+ char *uninstall_dry_argv[] = {"--dry-run", "--yes"};
7561+ int uninstall_dry_rc = cbm_cmd_uninstall(2, uninstall_dry_argv);
7562+ #ifndef _WIN32
7563+ char *uninstall_dry_err = cli_fd_capture_end(&uninstall_dry_capture);
7564+ #else
7565+ char *uninstall_dry_err = NULL;
7566+ #endif
7567+ cbm_set_auto_answer_for_test(0);
7568+ char *after_uninstall_dry = read_test_file_alloc(agents_path);
7569+ bool uninstall_dry_preserved =
7570+ after_uninstall_dry && after && strcmp(after_uninstall_dry, after) == 0;
7571+ bool uninstall_dry_warned = true;
7572+ #ifndef _WIN32
7573+ uninstall_dry_warned =
7574+ uninstall_dry_err && strstr(uninstall_dry_err, agents_path) != NULL &&
7575+ strstr(uninstall_dry_err,
7576+ "still contains a legacy codebase-memory-mcp instruction block") != NULL;
7577+ #endif
7578+ free(after_uninstall_dry);
7579+ free(uninstall_dry_err);
7580+
7581+ #ifndef _WIN32
7582+ cli_fd_capture_t uninstall_capture;
7583+ cli_fd_capture_begin(&uninstall_capture, stderr, STDERR_FILENO);
7584+ #endif
7585+ char *uninstall_argv[] = {"--yes"};
7586+ int uninstall_rc = cbm_cmd_uninstall(1, uninstall_argv);
7587+ #ifndef _WIN32
7588+ char *uninstall_err = cli_fd_capture_end(&uninstall_capture);
7589+ #else
7590+ char *uninstall_err = NULL;
7591+ #endif
7592+ cbm_set_auto_answer_for_test(0);
7593+ char *after_uninstall = read_test_file_alloc(agents_path);
7594+ bool uninstall_legacy_preserved =
7595+ after_uninstall && strstr(after_uninstall, legacy_block) != NULL;
7596+ bool uninstall_user_preserved =
7597+ after_uninstall && strstr(after_uninstall, user_guidance) != NULL;
7598+ bool uninstall_warned = true;
7599+ #ifndef _WIN32
7600+ uninstall_warned =
7601+ uninstall_err && strstr(uninstall_err, agents_path) != NULL &&
7602+ strstr(uninstall_err, "still contains a legacy codebase-memory-mcp instruction block") !=
7603+ NULL;
7604+ #endif
7605+ free(after_uninstall);
7606+ free(uninstall_err);
7607+
75537608 free(after);
75547609 free(install_err);
75557610 restore_test_env("HOME", saved_home);
@@ -7558,9 +7613,11 @@ TEST(cli_install_warns_about_legacy_mcp_instruction_block) {
75587613 test_rmdir_r(tmpdir);
75597614
75607615 if (dry_rc != 0 || install_rc != 0 || !dry_preserved || !dry_warned || !legacy_preserved ||
7561- !user_preserved || !cli_block_added_once || !install_warned)
7562- FAIL("Codex install must warn about a legacy codebase-memory-mcp block in --dry-run and "
7563- "on install, keep its bytes and the user's, and add one CLI managed block");
7616+ !user_preserved || !cli_block_added_once || !install_warned || uninstall_dry_rc != 0 ||
7617+ uninstall_rc != 0 || !uninstall_dry_preserved || !uninstall_dry_warned ||
7618+ !uninstall_legacy_preserved || !uninstall_user_preserved || !uninstall_warned)
7619+ FAIL("Codex install and uninstall must warn about a legacy codebase-memory-mcp block "
7620+ "(--dry-run and real), keep its bytes and the user's, and add one CLI managed block");
75647621 PASS();
75657622}
75667623
0 commit comments