返回 last30days-skill
test_skill_flag_contract.py
根目录 / tests / test_skill_flag_contract.py
1 """Every engine CLI flag must be reachable from SKILL.md.
2
3 AGENTS.md: "A new engine flag with no SKILL.md integration is incomplete."
4 This test enforces that rule: each non-suppressed long option registered by
5 build_parser() must appear in the root or an explicitly routed reference, so the
6 model invoking the skill can discover every flag a user might pass through.
7
8 Suppressed (argparse.SUPPRESS-help) flags are exempt: they are hidden from
9 --help on purpose and must never be promoted into the runtime spec.
10 """
11 import re
12 from pathlib import Path
13
14 import last30days as cli
15 from tests.skill_contract import contract_documents
16
17 REPO_ROOT = Path(__file__).resolve().parents[1]
18 SKILL_MD = REPO_ROOT / "skills" / "last30days" / "SKILL.md"
19
20
21 def _documented_flags():
22 """Long options from the parser, minus hidden (--help) and suppressed."""
23 flags = set()
24 for action in cli.build_parser()._actions:
25 if action.help == "==SUPPRESS==":
26 continue
27 for opt in action.option_strings:
28 if opt.startswith("--") and opt != "--help":
29 flags.add(opt)
30 return flags
31
32
33 def test_all_parser_flags_documented_in_skill_md():
34 skill = "\n".join(contract_documents().values())
35 missing = [
36 flag
37 for flag in sorted(_documented_flags())
38 # A trailing [^-\w] lookahead keeps --deep from matching
39 # --deep-research (and --days from --days-suffix style collisions)
40 # while still matching --flag=value, --flag`, --flag , etc.
41 if not re.search(re.escape(flag) + r"(?![-\w])", skill)
42 ]
43 assert not missing, (
44 "engine flags missing from SKILL.md (document them or suppress "
45 f"with reason in build_parser): {', '.join(missing)}"
46 )
47
47 lines PYTHON