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]() { 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