test_init.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """Unit tests for ``overseer init``.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from cli.kit_root import kit_root |
| 10 | from cli.version_lock import read_version_lock |
| 11 | from tests.support import FIXTURES, run_cli |
| 12 | |
| 13 | |
| 14 | def test_init_creates_footprint_and_lock(tmp_path: Path) -> None: |
| 15 | code = run_cli( |
| 16 | ["init", "--regime", "git-only", "--repo-name", "demo", "--non-interactive"], |
| 17 | cwd=tmp_path, |
| 18 | ) |
| 19 | assert code == 0 |
| 20 | assert (tmp_path / ".overseer" / "config.yaml").is_file() |
| 21 | assert (tmp_path / ".overseer" / "version.lock").is_file() |
| 22 | assert (tmp_path / ".overseer" / "STANDING-DECISIONS.reference.md").is_file() |
| 23 | lock = read_version_lock(tmp_path / ".overseer" / "version.lock") |
| 24 | assert lock.kit_version == "0.1.0" |
| 25 | |
| 26 | |
| 27 | def test_init_missing_regime_non_interactive_fails_closed(tmp_path: Path) -> None: |
| 28 | code = run_cli(["init", "--non-interactive"], cwd=tmp_path) |
| 29 | assert code == 2 |
| 30 | |
| 31 | |
| 32 | def test_init_refuse_without_force(tmp_path: Path) -> None: |
| 33 | run_cli( |
| 34 | ["init", "--regime", "git-only", "--repo-name", "demo", "--non-interactive"], |
| 35 | cwd=tmp_path, |
| 36 | ) |
| 37 | (tmp_path / "docs" / "DEMO-OVERSEER-HANDOVER.md").write_text("hand edit\n", encoding="utf-8") |
| 38 | code = run_cli( |
| 39 | ["init", "--regime", "git-only", "--repo-name", "demo", "--non-interactive"], |
| 40 | cwd=tmp_path, |
| 41 | ) |
| 42 | assert code == 4 |
| 43 | |
| 44 | |
| 45 | def test_init_force_reinits(tmp_path: Path) -> None: |
| 46 | run_cli( |
| 47 | ["init", "--regime", "git-only", "--repo-name", "demo", "--non-interactive"], |
| 48 | cwd=tmp_path, |
| 49 | ) |
| 50 | (tmp_path / "docs" / "DEMO-OVERSEER-HANDOVER.md").write_text("hand edit\n", encoding="utf-8") |
| 51 | code = run_cli( |
| 52 | ["init", "--regime", "git-only", "--repo-name", "demo", "--non-interactive", "--force"], |
| 53 | cwd=tmp_path, |
| 54 | ) |
| 55 | assert code == 0 |
| 56 | assert "hand edit" not in (tmp_path / "docs" / "DEMO-OVERSEER-HANDOVER.md").read_text( |
| 57 | encoding="utf-8" |
| 58 | ) |
| 59 | |
| 60 | |
| 61 | def test_init_noop_when_current(tmp_path: Path) -> None: |
| 62 | run_cli( |
| 63 | ["init", "--regime", "git-only", "--non-interactive"], |
| 64 | cwd=tmp_path, |
| 65 | ) |
| 66 | lock_path = tmp_path / ".overseer" / "version.lock" |
| 67 | before = lock_path.read_text(encoding="utf-8") |
| 68 | code = run_cli( |
| 69 | ["init", "--regime", "git-only", "--non-interactive"], |
| 70 | cwd=tmp_path, |
| 71 | ) |
| 72 | assert code == 0 |
| 73 | assert lock_path.read_text(encoding="utf-8") == before |
| 74 | |
| 75 | |
| 76 | def test_init_from_config(tmp_path: Path) -> None: |
| 77 | code = run_cli( |
| 78 | [ |
| 79 | "init", |
| 80 | "--from-config", |
| 81 | str(FIXTURES / "config-git-only.yaml"), |
| 82 | "--non-interactive", |
| 83 | ], |
| 84 | cwd=tmp_path, |
| 85 | kit=kit_root(), |
| 86 | ) |
| 87 | assert code == 0 |
| 88 | |
| 89 | |
| 90 | def test_init_dry_run_writes_nothing(tmp_path: Path) -> None: |
| 91 | code = run_cli( |
| 92 | ["init", "--regime", "git-only", "--non-interactive", "--dry-run"], |
| 93 | cwd=tmp_path, |
| 94 | ) |
| 95 | assert code == 0 |
| 96 | assert not (tmp_path / ".overseer" / "version.lock").exists() |