@@ -12636,7 +12636,61 @@ TEST(cli_windows_update_hands_off_to_install_script) {
1263612636 * Suite definition
1263712637 * ═══════════════════════════════════════════════════════════════════ */
1263812638
12639+ /* #1632: `update` derives the installer command from the BINARY's directory,
12640+ * which is not the same question as "is the installer there". A binary in
12641+ * ~/.local/bin with no install.sh beside it still produced:
12642+ *
12643+ * bash "/home/<user>/.local/bin/install.sh"
12644+ * /usr/bin/bash: .../install.sh: No such file or directory
12645+ *
12646+ * reported on discussion #1560 by a user already three releases deep in install
12647+ * trouble. `update` exists to tell someone how to proceed; ending on a command
12648+ * that cannot run is the one outcome it must not produce. */
12649+ TEST(cli_update_only_names_an_installer_that_exists_issue1632) {
12650+ char tmpdir[256];
12651+ snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-installer-probe-XXXXXX");
12652+ if (!cbm_mkdtemp(tmpdir)) {
12653+ FAIL("cbm_mkdtemp failed");
12654+ }
12655+ #ifdef _WIN32
12656+ const char *installer = "install.ps1";
12657+ #else
12658+ const char *installer = "install.sh";
12659+ #endif
12660+
12661+ /* A directory holding the binary but no installer must not be advertised. */
12662+ bool absent_is_refused = !cbm_cli_installer_beside_binary(tmpdir);
12663+
12664+ char script[512];
12665+ snprintf(script, sizeof(script), "%s/%s", tmpdir, installer);
12666+ write_test_file(script, "#!/bin/sh\nexit 0\n");
12667+ bool present_is_accepted = cbm_cli_installer_beside_binary(tmpdir);
12668+
12669+ /* A directory of that name must not count: `bash <dir>` is not a command. */
12670+ char decoy[512];
12671+ snprintf(decoy, sizeof(decoy), "%s/decoy", tmpdir);
12672+ test_mkdirp(decoy);
12673+ char decoy_installer[640];
12674+ snprintf(decoy_installer, sizeof(decoy_installer), "%s/%s", decoy, installer);
12675+ test_mkdirp(decoy_installer);
12676+ bool directory_is_refused = !cbm_cli_installer_beside_binary(decoy);
12677+
12678+ bool empty_is_refused = !cbm_cli_installer_beside_binary("");
12679+ test_rmdir_r(tmpdir);
12680+
12681+ if (!absent_is_refused)
12682+ FAIL("a directory with no installer must not be named as one");
12683+ if (!present_is_accepted)
12684+ FAIL("an installer that is present must be named");
12685+ if (!directory_is_refused)
12686+ FAIL("a DIRECTORY named install.sh is not a runnable installer");
12687+ if (!empty_is_refused)
12688+ FAIL("an empty directory string must be refused");
12689+ PASS();
12690+ }
12691+
1263912692SUITE(cli) {
12693+ RUN_TEST(cli_update_only_names_an_installer_that_exists_issue1632);
1264012694 RUN_TEST(cli_progress_visibility_policy);
1264112695 RUN_TEST(cli_raw_mcp_result_preserves_tool_error_status);
1264212696 RUN_TEST(cli_maintenance_cancellation_forces_failure_status);
0 commit comments