Skip to content

Commit c64ea20

Browse files
committed
test(cli): pin that update -y never deletes project indexes (DeusData#2200)
On 0.9.0, `update -y` in a non-interactive shell auto-confirmed "Delete these indexes and continue with update?", removed every project index, and only then failed at the ui/standard variant chooser: no new binary and no indexes. The behaviour is already gone on main: 9ecabe0 moved self-update out of the product, so a release `update` only hands off to install.sh; install.sh runs `install -y --force`, which keeps existing indexes unless the user passes the explicit --reset-indexes (DeusData#607); and the variant chooser is gone, with --ui/--standard accepted as no-ops (DeusData#1544). The only coverage of the hand-off was a Windows-only test that checks the binary, not the indexes. Add a portable regression test that drives the exact release dispatch (activation seam off) with `update -y` and `update -y --standard` against an isolated HOME/CBM_CACHE_DIR holding three .db indexes, and asserts exit 0 with every index byte-for-byte intact. A generic -y must never be read as consent to delete indexes. Re-injecting the 0.9.0 prompt-then-delete step into the hand-off turns it RED (kept == 0). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 64c23fa commit c64ea20

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

‎tests/test_cli.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16134,6 +16134,60 @@ TEST(cli_update_only_names_an_installer_that_exists_issue1632) {
1613416134
PASS();
1613516135
}
1613616136

16137+
/* #2200: on 0.9.0, `update -y` in a non-interactive shell auto-confirmed
16138+
* "Delete these indexes and continue with update?", removed every project
16139+
* index, and THEN failed at the variant chooser -- no binary, no indexes.
16140+
* The release dispatch now hands off to install.sh (which keeps indexes by
16141+
* default, #607) and never asks a variant question. Pin that on every
16142+
* platform: `update -y` and `update -y --standard`, with the activation seam
16143+
* OFF (the exact path a release binary ships), exit 0 and leave every .db in
16144+
* the cache byte-for-byte intact. A generic -y must never be read as consent
16145+
* to delete indexes. */
16146+
TEST(cli_update_yes_keeps_every_index_issue2200) {
16147+
char tmpdir[256];
16148+
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-update-2200-XXXXXX");
16149+
if (!cbm_mkdtemp(tmpdir)) {
16150+
FAIL("cbm_mkdtemp failed");
16151+
}
16152+
char *old_home = NULL;
16153+
char *old_cache = NULL;
16154+
cli_activation_save_env(&old_home, &old_cache);
16155+
cbm_setenv("HOME", tmpdir, 1);
16156+
char cache_dir[512];
16157+
snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmpdir);
16158+
cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
16159+
test_mkdirp(cache_dir);
16160+
16161+
static const char *const projects[] = {"alpha", "beta", "gamma"};
16162+
enum { PROJECT_COUNT = 3 };
16163+
char db_paths[PROJECT_COUNT][640];
16164+
for (int i = 0; i < PROJECT_COUNT; i++) {
16165+
snprintf(db_paths[i], sizeof(db_paths[i]), "%s/%s.db", cache_dir, projects[i]);
16166+
write_test_file(db_paths[i], projects[i]);
16167+
}
16168+
16169+
char *yes_argv[] = {"-y"};
16170+
char *legacy_argv[] = {"-y", "--standard"};
16171+
int yes_rc = cbm_cmd_update(1, yes_argv);
16172+
int legacy_rc = cbm_cmd_update(2, legacy_argv);
16173+
cbm_set_auto_answer_for_test(0);
16174+
16175+
int kept = 0;
16176+
for (int i = 0; i < PROJECT_COUNT; i++) {
16177+
const char *content = read_test_file(db_paths[i]);
16178+
if (content && strcmp(content, projects[i]) == 0) {
16179+
kept++;
16180+
}
16181+
}
16182+
cli_activation_restore_env(old_home, old_cache);
16183+
test_rmdir_r(tmpdir);
16184+
16185+
ASSERT_EQ(yes_rc, 0);
16186+
ASSERT_EQ(legacy_rc, 0);
16187+
ASSERT_EQ(kept, PROJECT_COUNT);
16188+
PASS();
16189+
}
16190+
1613716191
SUITE(cli) {
1613816192
if (!th_secure_runtime_parent_new(g_cli_suite_runtime_parent,
1613916193
sizeof(g_cli_suite_runtime_parent), "cli-suite")) {
@@ -16146,6 +16200,7 @@ SUITE(cli) {
1614616200

1614716201
RUN_TEST(cli_suite_uses_private_activation_runtime);
1614816202
RUN_TEST(cli_update_only_names_an_installer_that_exists_issue1632);
16203+
RUN_TEST(cli_update_yes_keeps_every_index_issue2200);
1614916204
#ifndef _WIN32
1615016205
RUN_TEST(cli_hook_deadline_ignores_an_unreadable_value);
1615116206
#endif

0 commit comments

Comments
 (0)