@@ -16335,6 +16335,60 @@ TEST(cli_update_only_names_an_installer_that_exists_issue1632) {
1633516335 PASS();
1633616336}
1633716337
16338+ /* #2200: on 0.9.0, `update -y` in a non-interactive shell auto-confirmed
16339+ * "Delete these indexes and continue with update?", removed every project
16340+ * index, and THEN failed at the variant chooser -- no binary, no indexes.
16341+ * The release dispatch now hands off to install.sh (which keeps indexes by
16342+ * default, #607) and never asks a variant question. Pin that on every
16343+ * platform: `update -y` and `update -y --standard`, with the activation seam
16344+ * OFF (the exact path a release binary ships), exit 0 and leave every .db in
16345+ * the cache byte-for-byte intact. A generic -y must never be read as consent
16346+ * to delete indexes. */
16347+ TEST(cli_update_yes_keeps_every_index_issue2200) {
16348+ char tmpdir[256];
16349+ snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-update-2200-XXXXXX");
16350+ if (!cbm_mkdtemp(tmpdir)) {
16351+ FAIL("cbm_mkdtemp failed");
16352+ }
16353+ char *old_home = NULL;
16354+ char *old_cache = NULL;
16355+ cli_activation_save_env(&old_home, &old_cache);
16356+ cbm_setenv("HOME", tmpdir, 1);
16357+ char cache_dir[512];
16358+ snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmpdir);
16359+ cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
16360+ test_mkdirp(cache_dir);
16361+
16362+ static const char *const projects[] = {"alpha", "beta", "gamma"};
16363+ enum { PROJECT_COUNT = 3 };
16364+ char db_paths[PROJECT_COUNT][640];
16365+ for (int i = 0; i < PROJECT_COUNT; i++) {
16366+ snprintf(db_paths[i], sizeof(db_paths[i]), "%s/%s.db", cache_dir, projects[i]);
16367+ write_test_file(db_paths[i], projects[i]);
16368+ }
16369+
16370+ char *yes_argv[] = {"-y"};
16371+ char *legacy_argv[] = {"-y", "--standard"};
16372+ int yes_rc = cbm_cmd_update(1, yes_argv);
16373+ int legacy_rc = cbm_cmd_update(2, legacy_argv);
16374+ cbm_set_auto_answer_for_test(0);
16375+
16376+ int kept = 0;
16377+ for (int i = 0; i < PROJECT_COUNT; i++) {
16378+ const char *content = read_test_file(db_paths[i]);
16379+ if (content && strcmp(content, projects[i]) == 0) {
16380+ kept++;
16381+ }
16382+ }
16383+ cli_activation_restore_env(old_home, old_cache);
16384+ test_rmdir_r(tmpdir);
16385+
16386+ ASSERT_EQ(yes_rc, 0);
16387+ ASSERT_EQ(legacy_rc, 0);
16388+ ASSERT_EQ(kept, PROJECT_COUNT);
16389+ PASS();
16390+ }
16391+
1633816392SUITE(cli) {
1633916393 if (!th_secure_runtime_parent_new(g_cli_suite_runtime_parent,
1634016394 sizeof(g_cli_suite_runtime_parent), "cli-suite")) {
@@ -16347,6 +16401,7 @@ SUITE(cli) {
1634716401
1634816402 RUN_TEST(cli_suite_uses_private_activation_runtime);
1634916403 RUN_TEST(cli_update_only_names_an_installer_that_exists_issue1632);
16404+ RUN_TEST(cli_update_yes_keeps_every_index_issue2200);
1635016405#ifndef _WIN32
1635116406 RUN_TEST(cli_hook_deadline_ignores_an_unreadable_value);
1635216407#endif
0 commit comments