checkpoint: 0.3.0 ui header, history persistence and history filter
This commit is contained in:
@@ -2,7 +2,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.history import SessionHistory
|
||||
from app.history import SessionHistory, default_history_path
|
||||
|
||||
|
||||
def test_visit_records_current_directory(tmp_path: Path) -> None:
|
||||
@@ -82,3 +82,48 @@ def test_select_raises_for_invalid_index() -> None:
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
history.select(0)
|
||||
|
||||
|
||||
def test_persistent_history_loads_entries_from_disk(tmp_path: Path) -> None:
|
||||
first = tmp_path / "first"
|
||||
second = tmp_path / "second"
|
||||
for directory in (first, second):
|
||||
directory.mkdir()
|
||||
history_file = tmp_path / "history.txt"
|
||||
history_file.write_text(f"{first}\n{second}\n", encoding="utf-8")
|
||||
|
||||
history = SessionHistory.persistent(storage_path=history_file)
|
||||
|
||||
assert history.entries() == (first.resolve(), second.resolve())
|
||||
assert history.current == second.resolve()
|
||||
|
||||
|
||||
def test_persistent_history_visit_writes_to_disk_and_applies_limit(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
first = tmp_path / "first"
|
||||
second = tmp_path / "second"
|
||||
third = tmp_path / "third"
|
||||
for directory in (first, second, third):
|
||||
directory.mkdir()
|
||||
history_file = tmp_path / "state" / "history.txt"
|
||||
|
||||
history = SessionHistory.persistent(storage_path=history_file, max_entries=2)
|
||||
history.visit(first)
|
||||
history.visit(second)
|
||||
history.visit(third)
|
||||
|
||||
assert history.entries() == (second.resolve(), third.resolve())
|
||||
assert history_file.read_text(encoding="utf-8").splitlines() == [
|
||||
str(second.resolve()),
|
||||
str(third.resolve()),
|
||||
]
|
||||
|
||||
|
||||
def test_default_history_path_uses_override_env(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
override = tmp_path / "custom-history.txt"
|
||||
monkeypatch.setenv("CD_BROWSER_HISTORY_FILE", str(override))
|
||||
|
||||
assert default_history_path() == override
|
||||
|
||||
Reference in New Issue
Block a user