78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Tests for flow.commands.completion dynamic suggestions."""
|
|
|
|
from flow.commands import completion
|
|
|
|
|
|
def test_complete_top_level_prefix():
|
|
out = completion.complete(["flow", "do"], 2)
|
|
assert "dotfiles" in out
|
|
assert "dot" in out
|
|
|
|
|
|
def test_complete_bootstrap_profiles(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_bootstrap_profiles", lambda: ["linux-vm", "macos-host"])
|
|
out = completion.complete(["flow", "bootstrap", "show", "li"], 4)
|
|
assert out == ["linux-vm"]
|
|
|
|
|
|
def test_complete_bootstrap_packages_options(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_bootstrap_profiles", lambda: ["linux-vm", "macos-host"])
|
|
out = completion.complete(["flow", "bootstrap", "packages", "--p"], 4)
|
|
assert out == ["--profile"]
|
|
|
|
out = completion.complete(["flow", "bootstrap", "packages", "--profile", "m"], 5)
|
|
assert out == ["macos-host"]
|
|
|
|
|
|
def test_complete_package_install(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_manifest_packages", lambda: ["neovim", "fzf"])
|
|
out = completion.complete(["flow", "package", "install", "n"], 4)
|
|
assert out == ["neovim"]
|
|
|
|
|
|
def test_complete_package_remove(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_installed_packages", lambda: ["hello", "jq"])
|
|
out = completion.complete(["flow", "package", "remove", "h"], 4)
|
|
assert out == ["hello"]
|
|
|
|
|
|
def test_complete_dotfiles_profile_value(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_dotfiles_profiles", lambda: ["work", "personal"])
|
|
out = completion.complete(["flow", "dotfiles", "link", "--profile", "w"], 5)
|
|
assert out == ["work"]
|
|
|
|
|
|
def test_complete_dotfiles_repo_subcommands():
|
|
out = completion.complete(["flow", "dotfiles", "repo", "p"], 4)
|
|
assert out == ["pull", "push"]
|
|
|
|
|
|
def test_complete_enter_targets(monkeypatch):
|
|
monkeypatch.setattr(completion, "_list_targets", lambda: ["personal@orb", "work@ec2"])
|
|
out = completion.complete(["flow", "enter", "p"], 3)
|
|
assert out == ["personal@orb"]
|
|
|
|
|
|
def test_complete_dev_subcommands():
|
|
out = completion.complete(["flow", "dev", "c"], 3)
|
|
assert out == ["connect", "create"]
|
|
|
|
|
|
def test_complete_completion_subcommands():
|
|
out = completion.complete(["flow", "completion", "i"], 3)
|
|
assert out == ["install-zsh"]
|
|
|
|
|
|
def test_rc_snippet_is_idempotent(tmp_path):
|
|
rc_path = tmp_path / ".zshrc"
|
|
completion_dir = tmp_path / "completions"
|
|
|
|
first = completion._ensure_rc_snippet(rc_path, completion_dir)
|
|
second = completion._ensure_rc_snippet(rc_path, completion_dir)
|
|
|
|
assert first is True
|
|
assert second is False
|
|
text = rc_path.read_text()
|
|
assert text.count(completion.ZSH_RC_START) == 1
|
|
assert text.count(completion.ZSH_RC_END) == 1
|