test_cli_argparse.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
| 1 | """Unit tests for CLI argument parsing.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from cli.main import build_parser, main |
| 8 | from cli.context import CliContext |
| 9 | from cli.output import OutputContext |
| 10 | |
| 11 | |
| 12 | def test_help_exits_zero() -> None: |
| 13 | assert main(["--help"]) == 0 |
| 14 | |
| 15 | |
| 16 | def test_version_exits_zero(capsys) -> None: |
| 17 | code = main(["--version"]) |
| 18 | captured = capsys.readouterr() |
| 19 | assert code == 0 |
| 20 | assert captured.out.strip() == "0.1.0" |
| 21 | |
| 22 | |
| 23 | def test_unknown_command_exits_one() -> None: |
| 24 | assert main(["nope"]) == 1 |
| 25 | |
| 26 | |
| 27 | def test_unknown_flag_exits_one() -> None: |
| 28 | assert main(["status", "--not-a-flag"]) == 1 |
| 29 | |
| 30 | |
| 31 | def test_init_global_options_parsed() -> None: |
| 32 | from cli.args import extract_global_args |
| 33 | |
| 34 | parser = build_parser() |
| 35 | raw = [ |
| 36 | "init", |
| 37 | "-C", |
| 38 | ".", |
| 39 | "--config", |
| 40 | "cfg.yaml", |
| 41 | "--json", |
| 42 | "-q", |
| 43 | "-v", |
| 44 | "--no-color", |
| 45 | "--dry-run", |
| 46 | "--force", |
| 47 | "--non-interactive", |
| 48 | "--regime", |
| 49 | "git-only", |
| 50 | "--repo-name", |
| 51 | "x", |
| 52 | "--docs-dir", |
| 53 | "docs", |
| 54 | ] |
| 55 | global_argv, rest_argv = extract_global_args(raw) |
| 56 | args = parser.parse_args(global_argv + rest_argv) |
| 57 | assert args.command == "init" |
| 58 | assert args.repo == "." |
| 59 | assert args.json is True |
| 60 | assert args.dry_run is True |
| 61 | assert args.regime == "git-only" |
| 62 | |
| 63 | |
| 64 | def test_sync_options_parsed() -> None: |
| 65 | parser = build_parser() |
| 66 | args = parser.parse_args( |
| 67 | ["sync", "--only", ".overseer/policy/*", "--only", "docs/*", "--force", "-y", "--dry-run"] |
| 68 | ) |
| 69 | assert args.only == [".overseer/policy/*", "docs/*"] |
| 70 | assert args.yes is True |
| 71 | |
| 72 | |
| 73 | def test_migrate_and_include_preserved_flags_parsed() -> None: |
| 74 | parser = build_parser() |
| 75 | args = parser.parse_args( |
| 76 | ["init", "--migrate", "--include-preserved", "--force", "--non-interactive"] |
| 77 | ) |
| 78 | assert args.migrate is True |
| 79 | assert args.include_preserved is True |
| 80 | assert args.force is True |
| 81 | sync_args = parser.parse_args(["sync", "--include-preserved", "--force", "-y"]) |
| 82 | assert sync_args.include_preserved is True |
| 83 | |
| 84 | |
| 85 | def test_governance_sync_argparse() -> None: |
| 86 | parser = build_parser() |
| 87 | args = parser.parse_args(["governance-sync"]) |
| 88 | assert args.command == "governance-sync" |
| 89 | assert args.write is False |
| 90 | args_write = parser.parse_args(["governance-sync", "--write"]) |
| 91 | assert args_write.write is True |
| 92 | |
| 93 | |
| 94 | def test_workspace_argparse() -> None: |
| 95 | parser = build_parser() |
| 96 | status = parser.parse_args(["workspace", "status", "--strict-all"]) |
| 97 | assert status.command == "workspace" |
| 98 | assert status.workspace_action == "status" |
| 99 | assert status.strict_all is True |
| 100 | check = parser.parse_args(["workspace", "check-next", "--lane", "security"]) |
| 101 | assert check.workspace_action == "check-next" |
| 102 | assert check.lane == "security" |
| 103 | doctor = parser.parse_args(["workspace", "doctor"]) |
| 104 | assert doctor.workspace_action == "doctor" |
| 105 | composed = parser.parse_args(["status", "--workspace", "--exit-code"]) |
| 106 | assert composed.workspace is True |
| 107 | assert composed.exit_code is True |
| 108 | |
| 109 | |
| 110 | def test_verify_step_argparse() -> None: |
| 111 | from cli.args import extract_global_args |
| 112 | |
| 113 | parser = build_parser() |
| 114 | raw = ["verify-step", "--step", "alpha", "--dry-run", "--json"] |
| 115 | global_argv, rest_argv = extract_global_args(raw) |
| 116 | args = parser.parse_args(global_argv + rest_argv) |
| 117 | assert args.command == "verify-step" |
| 118 | assert args.step == "alpha" |
| 119 | assert args.dry_run is True |
| 120 | assert args.json is True |
| 121 | through_args = parser.parse_args(["verify-step", "--through", "current"]) |
| 122 | assert through_args.through == "current" |
| 123 |
File History
2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
52 days ago