test_cli_argparse.py python
107 lines 2.9 KB
Raw
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439 feat: K1-P1 complete — agent provenance, build-verification… Sonnet 4.6 patch 56 days 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_verify_step_argparse() -> None:
95 from cli.args import extract_global_args
96
97 parser = build_parser()
98 raw = ["verify-step", "--step", "alpha", "--dry-run", "--json"]
99 global_argv, rest_argv = extract_global_args(raw)
100 args = parser.parse_args(global_argv + rest_argv)
101 assert args.command == "verify-step"
102 assert args.step == "alpha"
103 assert args.dry_run is True
104 assert args.json is True
105 through_args = parser.parse_args(["verify-step", "--through", "current"])
106 assert through_args.through == "current"
107
File History 1 commit
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439 feat: K1-P1 complete — agent provenance, build-verification… Sonnet 4.6 patch 56 days ago