release: 0.3.0 persistent history, configurable openers, and dev info panel
This commit is contained in:
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from app.opener import (
|
||||
OpenWithOption,
|
||||
_reset_openers_config_cache,
|
||||
available_openers,
|
||||
is_blocking_option,
|
||||
launch_background_option,
|
||||
@@ -14,6 +15,11 @@ from app.opener import (
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_openers_config_cache() -> None:
|
||||
_reset_openers_config_cache()
|
||||
|
||||
|
||||
def test_available_openers_headless_file_excludes_gui(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
@@ -65,6 +71,107 @@ def test_available_openers_gui_directory_filters_file_only_tools(
|
||||
assert labels == ["VS Code", "Antigravity", "Neovim"]
|
||||
|
||||
|
||||
def test_available_openers_respects_configured_order(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
config_path = tmp_path / "config.toml"
|
||||
config_path.write_text(
|
||||
('[open_with]\nfiles = ["nvim", "code"]\ndirectories = ["opencode", "code"]\n'),
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("CD_BROWSER_CONFIG_FILE", str(config_path))
|
||||
monkeypatch.delenv("SSH_CONNECTION", raising=False)
|
||||
monkeypatch.setattr("app.opener.sys.platform", "darwin")
|
||||
|
||||
available = {
|
||||
"opencode": "/usr/local/bin/opencode",
|
||||
"nvim": "/usr/local/bin/nvim",
|
||||
"code": "/usr/local/bin/code",
|
||||
}
|
||||
monkeypatch.setattr("app.opener.shutil.which", lambda name: available.get(name))
|
||||
|
||||
folder = tmp_path / "project"
|
||||
folder.mkdir()
|
||||
file_path = tmp_path / "notes.txt"
|
||||
file_path.write_text("hello", encoding="utf-8")
|
||||
|
||||
folder_labels = [option.label for option in available_openers(folder)]
|
||||
file_labels = [option.label for option in available_openers(file_path)]
|
||||
|
||||
assert folder_labels == ["OpenCode", "VS Code"]
|
||||
assert file_labels == ["Neovim", "VS Code"]
|
||||
|
||||
|
||||
def test_available_openers_invalid_config_falls_back_to_defaults(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
config_path = tmp_path / "config.toml"
|
||||
config_path.write_text("[open_with\n", encoding="utf-8")
|
||||
monkeypatch.setenv("CD_BROWSER_CONFIG_FILE", str(config_path))
|
||||
monkeypatch.setenv("SSH_CONNECTION", "1")
|
||||
|
||||
available = {
|
||||
"antigravity": "/usr/local/bin/antigravity",
|
||||
"nvim": "/usr/local/bin/nvim",
|
||||
"nano": "/usr/bin/nano",
|
||||
"less": "/usr/bin/less",
|
||||
"bat": "/usr/local/bin/bat",
|
||||
}
|
||||
monkeypatch.setattr("app.opener.shutil.which", lambda name: available.get(name))
|
||||
|
||||
file_path = tmp_path / "notes.txt"
|
||||
file_path.write_text("hello", encoding="utf-8")
|
||||
labels = [option.label for option in available_openers(file_path)]
|
||||
|
||||
assert labels == ["Antigravity", "Neovim", "Nano", "Less", "Bat"]
|
||||
|
||||
|
||||
def test_available_openers_creates_default_config_when_missing(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
config_path = tmp_path / "config.toml"
|
||||
monkeypatch.setenv("CD_BROWSER_CONFIG_FILE", str(config_path))
|
||||
monkeypatch.setenv("SSH_CONNECTION", "1")
|
||||
monkeypatch.setattr(
|
||||
"app.opener.shutil.which",
|
||||
lambda name: (
|
||||
"/usr/bin/true" if name in {"nvim", "nano", "less", "bat"} else None
|
||||
),
|
||||
)
|
||||
|
||||
file_path = tmp_path / "notes.txt"
|
||||
file_path.write_text("hello", encoding="utf-8")
|
||||
available_openers(file_path)
|
||||
|
||||
assert config_path.exists()
|
||||
config_text = config_path.read_text(encoding="utf-8")
|
||||
assert "[open_with]" in config_text
|
||||
assert (
|
||||
'files = ["code", "open", "antigravity", "nvim", "nano", "less", "bat"]'
|
||||
in config_text
|
||||
)
|
||||
|
||||
|
||||
def test_available_openers_does_not_override_existing_config(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
config_path = tmp_path / "config.toml"
|
||||
original = '[open_with]\nfiles = ["nvim"]\ndirectories = ["opencode"]\n'
|
||||
config_path.write_text(original, encoding="utf-8")
|
||||
monkeypatch.setenv("CD_BROWSER_CONFIG_FILE", str(config_path))
|
||||
monkeypatch.setenv("SSH_CONNECTION", "1")
|
||||
monkeypatch.setattr(
|
||||
"app.opener.shutil.which",
|
||||
lambda name: "/usr/bin/true" if name in {"nvim", "opencode"} else None,
|
||||
)
|
||||
|
||||
file_path = tmp_path / "notes.txt"
|
||||
file_path.write_text("hello", encoding="utf-8")
|
||||
available_openers(file_path)
|
||||
|
||||
assert config_path.read_text(encoding="utf-8") == original
|
||||
|
||||
|
||||
def test_launch_background_option_returns_success(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
|
||||
@@ -121,7 +121,7 @@ def test_toggle_history_mode_selects_current_history_entry(tmp_path: Path) -> No
|
||||
ui._toggle_history_mode(navigator)
|
||||
|
||||
assert ui._history_mode is True
|
||||
assert ui._history_selected_index == 1
|
||||
assert ui._history_selected_index == 0
|
||||
|
||||
|
||||
def test_history_mode_enter_selects_entry_and_exits(tmp_path: Path) -> None:
|
||||
@@ -141,7 +141,7 @@ def test_history_mode_enter_selects_entry_and_exits(tmp_path: Path) -> None:
|
||||
|
||||
ui = TerminalUI()
|
||||
ui._toggle_history_mode(navigator)
|
||||
ui._handle_history_key(curses.KEY_UP, navigator)
|
||||
ui._handle_history_key(curses.KEY_DOWN, navigator)
|
||||
ui._handle_history_key(10, navigator)
|
||||
|
||||
assert ui._history_mode is False
|
||||
@@ -149,6 +149,30 @@ def test_history_mode_enter_selects_entry_and_exits(tmp_path: Path) -> None:
|
||||
assert navigator.selected_index == 0
|
||||
|
||||
|
||||
def test_history_mode_renders_most_recent_entry_first(tmp_path: Path) -> None:
|
||||
root = tmp_path / "root"
|
||||
first = root / "first"
|
||||
second = root / "second"
|
||||
root.mkdir()
|
||||
first.mkdir()
|
||||
second.mkdir()
|
||||
|
||||
navigator = Navigator(root)
|
||||
navigator.set_selected_index(1)
|
||||
navigator.enter_selected_directory()
|
||||
navigator.go_to_parent_directory()
|
||||
navigator.set_selected_index(2)
|
||||
navigator.enter_selected_directory()
|
||||
|
||||
ui = TerminalUI()
|
||||
ui._toggle_history_mode(navigator)
|
||||
lines, _selected_index = ui._build_history_lines_for_render(
|
||||
navigator.history.entries()
|
||||
)
|
||||
|
||||
assert lines[0].text == str(second.resolve())
|
||||
|
||||
|
||||
def test_history_mode_slash_activates_history_filter() -> None:
|
||||
ui = TerminalUI()
|
||||
navigator = Navigator(Path.cwd())
|
||||
@@ -329,7 +353,12 @@ def test_build_status_line_shows_filter_off_when_filter_mode_is_disabled(
|
||||
root.mkdir()
|
||||
navigator = Navigator(root)
|
||||
|
||||
status_line = build_status_line(navigator, filter_mode=False, filter_query="")
|
||||
status_line = build_status_line(
|
||||
navigator,
|
||||
filter_mode=False,
|
||||
filter_query="",
|
||||
dev_summary="git:- stack:-",
|
||||
)
|
||||
|
||||
assert "filter: off" in status_line
|
||||
|
||||
@@ -341,7 +370,12 @@ def test_build_status_line_shows_empty_filter_without_off_when_filter_is_active(
|
||||
root.mkdir()
|
||||
navigator = Navigator(root)
|
||||
|
||||
status_line = build_status_line(navigator, filter_mode=True, filter_query="")
|
||||
status_line = build_status_line(
|
||||
navigator,
|
||||
filter_mode=True,
|
||||
filter_query="",
|
||||
dev_summary="git:- stack:-",
|
||||
)
|
||||
|
||||
assert "filter: |" in status_line
|
||||
|
||||
@@ -422,6 +456,20 @@ def test_end_key_jumps_to_last_entry(tmp_path: Path) -> None:
|
||||
assert navigator.selected_index == len(navigator.visible_entries) - 1
|
||||
|
||||
|
||||
def test_info_mode_toggles_with_i_and_escape(tmp_path: Path) -> None:
|
||||
root = tmp_path / "root"
|
||||
root.mkdir()
|
||||
navigator = Navigator(root)
|
||||
ui = TerminalUI()
|
||||
|
||||
assert ui._info_mode is False
|
||||
assert ui._handle_tree_key(ord("i"), navigator) is None
|
||||
assert ui._info_mode is True
|
||||
|
||||
ui._handle_info_key(ESCAPE_KEY)
|
||||
assert ui._info_mode is False
|
||||
|
||||
|
||||
def test_open_terminal_streams_raises_without_terminal(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user