|
| 1 | +"""Full CLI integration tests using Typer's CliRunner. |
| 2 | +
|
| 3 | +Tests all 15+ CLI commands with real vault operations. |
| 4 | +""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +import pytest |
| 11 | + |
| 12 | +try: |
| 13 | + from typer.testing import CliRunner |
| 14 | + HAS_TYPER = True |
| 15 | +except ImportError: |
| 16 | + HAS_TYPER = False |
| 17 | + |
| 18 | +pytestmark = pytest.mark.skipif(not HAS_TYPER, reason="typer not installed") |
| 19 | + |
| 20 | +if TYPE_CHECKING: |
| 21 | + from pathlib import Path |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def runner(): |
| 26 | + return CliRunner() |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def cli_app(): |
| 31 | + from qp_vault.cli.main import app |
| 32 | + return app |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture |
| 36 | +def vault_path(tmp_path: Path): |
| 37 | + return str(tmp_path / "cli-vault") |
| 38 | + |
| 39 | + |
| 40 | +class TestInit: |
| 41 | + def test_init_creates_vault(self, runner, cli_app, vault_path) -> None: |
| 42 | + result = runner.invoke(cli_app, ["init", vault_path]) |
| 43 | + assert result.exit_code == 0 |
| 44 | + assert "Initialized" in result.stdout or "vault" in result.stdout.lower() |
| 45 | + |
| 46 | + |
| 47 | +class TestAdd: |
| 48 | + def test_add_text(self, runner, cli_app, vault_path) -> None: |
| 49 | + runner.invoke(cli_app, ["init", vault_path]) |
| 50 | + result = runner.invoke(cli_app, ["add", "Hello world content", "--path", vault_path, "--name", "hello.md"]) |
| 51 | + assert result.exit_code == 0 |
| 52 | + assert "Added" in result.stdout |
| 53 | + |
| 54 | + def test_add_with_trust(self, runner, cli_app, vault_path) -> None: |
| 55 | + runner.invoke(cli_app, ["init", vault_path]) |
| 56 | + result = runner.invoke(cli_app, ["add", "Canonical doc", "--path", vault_path, "--trust", "canonical"]) |
| 57 | + assert result.exit_code == 0 |
| 58 | + |
| 59 | + def test_add_with_tags(self, runner, cli_app, vault_path) -> None: |
| 60 | + runner.invoke(cli_app, ["init", vault_path]) |
| 61 | + result = runner.invoke(cli_app, ["add", "Tagged doc", "--path", vault_path, "--tags", "important,reviewed"]) |
| 62 | + assert result.exit_code == 0 |
| 63 | + |
| 64 | + |
| 65 | +class TestSearch: |
| 66 | + def test_search_no_results(self, runner, cli_app, vault_path) -> None: |
| 67 | + runner.invoke(cli_app, ["init", vault_path]) |
| 68 | + result = runner.invoke(cli_app, ["search", "nonexistent", "--path", vault_path]) |
| 69 | + assert result.exit_code == 0 |
| 70 | + assert "No results" in result.stdout |
| 71 | + |
| 72 | + def test_search_with_results(self, runner, cli_app, vault_path) -> None: |
| 73 | + runner.invoke(cli_app, ["init", vault_path]) |
| 74 | + runner.invoke(cli_app, ["add", "Searchable content about testing", "--path", vault_path]) |
| 75 | + result = runner.invoke(cli_app, ["search", "testing", "--path", vault_path]) |
| 76 | + assert result.exit_code == 0 |
| 77 | + |
| 78 | + |
| 79 | +class TestList: |
| 80 | + def test_list_empty(self, runner, cli_app, vault_path) -> None: |
| 81 | + runner.invoke(cli_app, ["init", vault_path]) |
| 82 | + result = runner.invoke(cli_app, ["list", "--path", vault_path]) |
| 83 | + assert result.exit_code == 0 |
| 84 | + |
| 85 | + def test_list_with_resources(self, runner, cli_app, vault_path) -> None: |
| 86 | + runner.invoke(cli_app, ["init", vault_path]) |
| 87 | + runner.invoke(cli_app, ["add", "Doc A", "--path", vault_path]) |
| 88 | + runner.invoke(cli_app, ["add", "Doc B", "--path", vault_path]) |
| 89 | + result = runner.invoke(cli_app, ["list", "--path", vault_path]) |
| 90 | + assert result.exit_code == 0 |
| 91 | + assert "2 resources" in result.stdout or "resource" in result.stdout.lower() |
| 92 | + |
| 93 | + |
| 94 | +class TestStatus: |
| 95 | + def test_status(self, runner, cli_app, vault_path) -> None: |
| 96 | + runner.invoke(cli_app, ["init", vault_path]) |
| 97 | + runner.invoke(cli_app, ["add", "Doc", "--path", vault_path]) |
| 98 | + result = runner.invoke(cli_app, ["status", "--path", vault_path]) |
| 99 | + assert result.exit_code == 0 |
| 100 | + assert "Total" in result.stdout or "total" in result.stdout.lower() |
| 101 | + |
| 102 | + |
| 103 | +class TestVerify: |
| 104 | + def test_verify_vault(self, runner, cli_app, vault_path) -> None: |
| 105 | + runner.invoke(cli_app, ["init", vault_path]) |
| 106 | + runner.invoke(cli_app, ["add", "Doc", "--path", vault_path]) |
| 107 | + result = runner.invoke(cli_app, ["verify", "--path", vault_path]) |
| 108 | + assert result.exit_code == 0 |
| 109 | + |
| 110 | + |
| 111 | +class TestHealth: |
| 112 | + def test_health(self, runner, cli_app, vault_path) -> None: |
| 113 | + runner.invoke(cli_app, ["init", vault_path]) |
| 114 | + runner.invoke(cli_app, ["add", "Doc", "--path", vault_path]) |
| 115 | + result = runner.invoke(cli_app, ["health", "--path", vault_path]) |
| 116 | + assert result.exit_code == 0 |
| 117 | + |
| 118 | + |
| 119 | +class TestExpiring: |
| 120 | + def test_expiring_none(self, runner, cli_app, vault_path) -> None: |
| 121 | + runner.invoke(cli_app, ["init", vault_path]) |
| 122 | + runner.invoke(cli_app, ["add", "Doc", "--path", vault_path]) |
| 123 | + result = runner.invoke(cli_app, ["expiring", "--path", vault_path]) |
| 124 | + assert result.exit_code == 0 |
| 125 | + assert "No resources expiring" in result.stdout |
| 126 | + |
| 127 | + |
| 128 | +class TestCollections: |
| 129 | + def test_collections_empty(self, runner, cli_app, vault_path) -> None: |
| 130 | + runner.invoke(cli_app, ["init", vault_path]) |
| 131 | + result = runner.invoke(cli_app, ["collections", "--path", vault_path]) |
| 132 | + assert result.exit_code == 0 |
| 133 | + |
| 134 | + |
| 135 | +class TestExport: |
| 136 | + def test_export(self, runner, cli_app, vault_path, tmp_path) -> None: |
| 137 | + runner.invoke(cli_app, ["init", vault_path]) |
| 138 | + runner.invoke(cli_app, ["add", "Export content", "--path", vault_path]) |
| 139 | + export_path = str(tmp_path / "export.json") |
| 140 | + result = runner.invoke(cli_app, ["export", export_path, "--path", vault_path]) |
| 141 | + assert result.exit_code == 0 |
0 commit comments