From ed769f07729b981c78b23c3359b0f7b7cc730359 Mon Sep 17 00:00:00 2001 From: "Henrique F. Simoes" Date: Tue, 4 Aug 2026 19:20:35 -0300 Subject: [PATCH 1/2] micromamba: remove duplicate deactivate from shell completion When implementing the shell completion, the "deactivate" command is introduced manually in add_activate_completion(). When first introduced by 821de6b5 (also complete for deactivate command (#1557), 2022-03-03) this was needed (although probably in the wrong function), because micromamba didn't have a proper "deactivate" command. However, commit 5206c2a9 (fix: Add `deactivate` command to the help message (#4350), 2026-07-29) added this missing command to set_umamba_command() (that is also used for handling the "completer" command), but it didn't remove the extra "deactivate". Because of that, running the autocompletion triggers the following error: terminate called after throwing an instance of 'CLI::OptionAlreadyAdded' what(): subcommand name or alias matches existing subcommand: deactivate is already added Drop the manual and redundant addition of "deactivate" command in the completer implementation, so the autocompletion gets back to working as expected. Fixes: 5206c2a9 (fix: Add `deactivate` command to the help message (#4350), 2026-07-29) Signed-off-by: Henrique F. Simoes --- micromamba/src/completer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/micromamba/src/completer.cpp b/micromamba/src/completer.cpp index 7895ce84a8..978b480f41 100644 --- a/micromamba/src/completer.cpp +++ b/micromamba/src/completer.cpp @@ -134,7 +134,6 @@ add_activate_completion( // Mock functions just for completion CLI::App* activate_subcom = app->add_subcommand("activate"); - app->add_subcommand("deactivate"); activate_subcom->callback( [app, &completer_args, &completed, &config]() { From b5f3fd5a8b66e033b7a87387c91be68cd29f6f07 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 6 Aug 2026 11:43:34 +0200 Subject: [PATCH 2/2] test: Add micromamba completer regression coverage Exercise top-level, prefix, env-name, shell, and option completion so a duplicate deactivate subcommand (CLI::OptionAlreadyAdded) cannot regress. --- micromamba/tests/test_completer.py | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 micromamba/tests/test_completer.py diff --git a/micromamba/tests/test_completer.py b/micromamba/tests/test_completer.py new file mode 100644 index 0000000000..2bcd6c3056 --- /dev/null +++ b/micromamba/tests/test_completer.py @@ -0,0 +1,59 @@ +import pytest + +from . import helpers + + +def test_completer_lists_top_level_commands(tmp_home, tmp_root_prefix): + """Regression: duplicate deactivate must not abort completer (CLI::OptionAlreadyAdded).""" + umamba = helpers.get_umamba() + out = helpers.subprocess_run(umamba, "completer", "").decode() + + for command in ( + "activate", + "deactivate", + "create", + "install", + "env", + "shell", + "update", + "remove", + "list", + "info", + ): + assert command in out + + +@pytest.mark.parametrize( + "prefix, expected", + [ + ("a", ("activate", "auth")), + ("de", ("deactivate",)), + ("in", ("info", "install")), + ("rem", ("remove",)), + ("sh", ("shell",)), + ], +) +def test_completer_prefix_matches_commands(tmp_home, tmp_root_prefix, prefix, expected): + umamba = helpers.get_umamba() + out = helpers.subprocess_run(umamba, "completer", prefix).decode() + for command in expected: + assert command in out + + +def test_completer_activate_lists_env_names(tmp_home, tmp_root_prefix, tmp_empty_env, tmp_env_name): + umamba = helpers.get_umamba() + out = helpers.subprocess_run(umamba, "completer", "-n", "").decode() + assert tmp_env_name in out + + +def test_completer_shell_lists_subcommands(tmp_home, tmp_root_prefix): + umamba = helpers.get_umamba() + out = helpers.subprocess_run(umamba, "completer", "shell", "").decode() + for command in ("activate", "deactivate", "hook", "init"): + assert command in out + + +def test_completer_install_option_prefix(tmp_home, tmp_root_prefix): + umamba = helpers.get_umamba() + out = helpers.subprocess_run(umamba, "completer", "install", "--c").decode() + assert "--channel" in out