返回 last30days-skill
test_doc_flag_contract.py
根目录 / tests / test_doc_flag_contract.py
1 """Documentation contract for Python CLI and wrapper-only flags."""
2
3 from __future__ import annotations
4
5 from pathlib import Path
6
7 import last30days as cli
8 from tests.skill_contract import reference_text
9
10 ROOT = Path(__file__).resolve().parents[1]
11 CONFIGURATION = ROOT / "CONFIGURATION.md"
12 SKILL_MD = ROOT / "skills" / "last30days" / "SKILL.md"
13 HTML_REFERENCE = ROOT / "skills" / "last30days" / "references" / "save-html-brief.md"
14
15
16 def _parser_flags() -> set[str]:
17 parser = cli.build_parser()
18 flags: set[str] = set()
19 for action in parser._actions:
20 flags.update(action.option_strings)
21 return flags
22
23
24 def test_configuration_documents_new_safety_flags():
25 text = CONFIGURATION.read_text(encoding="utf-8")
26 flags = _parser_flags()
27 assert "--no-browser-cookies" in flags
28 assert "--no-browser-cookies" in text
29 assert "--preflight" in flags
30 assert "--preflight" in text
31 assert "--save-dir" in text
32 assert "--output" in text
33 assert "--publish-html" in flags
34 assert "--publish-html" in text
35 assert "--publish" in flags
36 assert "library feed --publish" in text
37 assert "--publish-password" in flags
38 assert "--publish-password" in text
39 assert "LAST30DAYS_PUBLISH_PASSWORD" in text
40 assert "--record-fixtures" in flags
41 assert "--record-fixtures" in text
42 assert "docs/reference/eval.md" in text
43
44
45 def test_html_publish_reference_prompts_for_password_choice():
46 text = reference_text("save-html-brief")
47 publish_section = text[text.index("## Optional hosted publishing"):text.index("## What ends up in the HTML file")]
48 assert "Respect any existing user, project, or host preference for HTML publishing first" in publish_section
49 assert "If multiple publishing options are available, show each as its own choice" in publish_section
50 assert "label `ht-ml.app` as supporting optional password protection" in publish_section
51 assert "Show the absolute saved path" in publish_section
52 assert "Open HTML file" in publish_section
53 assert "Done for now" in publish_section
54 assert "Do not upload until the user chooses a publishing option" in publish_section
55 assert "ask a second question" in publish_section
56 assert "**Public link** - publish without a password" in publish_section
57 assert "**Password-protected link** - ask the user to type the shared password" in publish_section
58 assert "repeat the shared password they selected" in publish_section
59 assert "LAST30DAYS_PUBLISH_PASSWORD" in publish_section
60 assert '--output "$HTML_PATH"' in publish_section
61 assert "<HTML_PATH>.publish.json" in publish_section
62
63
64 def test_reddit_backend_env_var_is_documented_for_users_and_runtime_skill():
65 config_text = CONFIGURATION.read_text(encoding="utf-8")
66 skill_text = reference_text("setup-wizard")
67
68 assert "LAST30DAYS_REDDIT_BACKEND=scrapecreators" in config_text
69 assert "LAST30DAYS_REDDIT_BACKEND=scrapecreators" in skill_text
70 # Thinness floor shipped with the keyless Reddit path; keep user docs honest.
71 assert "LAST30DAYS_REDDIT_SC_MIN_ITEMS" in config_text
72 assert "LAST30DAYS_REDDIT_SC_MIN_ITEMS" in skill_text
73 # Security copy must not claim transport/rate-limit escalation for Reddit search.
74 assert "when public Reddit is unavailable" not in skill_text
75 # Keyed default: ScrapeCreators backfills below a 5-item floor; 0 opts out.
76 assert "fewer than 5 items" in skill_text
77 assert "LAST30DAYS_REDDIT_SC_MIN_ITEMS=0" in skill_text
78 assert "LAST30DAYS_REDDIT_SC_MIN_ITEMS=0" in config_text
79 for text in (skill_text, config_text):
80 assert "LAST30DAYS_YT_SC_MIN_ITEMS=0" in text
81 assert "YouTube search" in text
82 assert "returns no items" not in text
83 assert "returns **no items**" not in text
84
85
86 def test_save_is_not_documented_as_python_cli_flag():
87 text = CONFIGURATION.read_text(encoding="utf-8")
88 assert "--save-dir <path>" in text
89 assert "--save " not in text
90 assert "`--save`" not in text
91
92
93 def test_agent_is_documented_as_skill_argument_not_python_flag():
94 text = reference_text("agent-mode")
95 start = text.index("## Agent Mode (--agent flag)")
96 agent_section = text[start:start + 2000]
97 assert "If `--agent` appears in ARGUMENTS" in agent_section
98 root = SKILL_MD.read_text(encoding="utf-8")
99 assert "slash-command skill contract" in root
100 assert "not a Python CLI flag" in root
101
102
103 def test_html_reference_documents_structured_cache_reuse():
104 text = reference_text("save-html-brief")
105 assert "~/.config/last30days/last-report.json" in text
106 assert "without re-running source fetchers" in text
107 assert "No matching cached report data" in text
108 assert "LAST30DAYS_REPORT_CACHE_TTL_SECONDS" in text
109 assert "default: one hour" in text
110 assert "--cached-report" in text
111 assert "Do not replay --plan, --competitors-plan" in text
112
113
114 def test_configuration_documents_report_cache_ttl():
115 text = CONFIGURATION.read_text(encoding="utf-8")
116 assert "LAST30DAYS_REPORT_CACHE_TTL_SECONDS" in text
117 assert "defaults to `3600`" in text
118 assert "`0` to disable report-cache reuse" in text
119
120
121 def test_comparison_artifact_contract_documents_actual_paths():
122 text = reference_text("comparison")
123 comparison_start = text.index("\n## If QUERY_TYPE = COMPARISON\n")
124 comparison_section = text[comparison_start:comparison_start + 5000]
125 assert "there is no separate merged Markdown raw file" in comparison_section
126 assert "[last30days] Comparison artifact set: main={path}; peers={path, ...}" in comparison_section
127 assert "Treat that log line as authoritative" in comparison_section
128
129 text = reference_text("research-runbook")
130 step_start = text.index("## Step 2.5: Append WebSearch Results to Saved Raw File")
131 step_section = text[step_start:step_start + 3500]
132 assert "append the same `## WebSearch Supplemental Results` section to every listed per-entity Markdown raw file" in step_section
133 assert "do not append Markdown text to `.html` or `.json`" in step_section
134
134 lines PYTHON