返回 last30days-skill
test_doc_security_contract.py
根目录 / tests / test_doc_security_contract.py
1 """Security-copy contract tests for local reads and credential destinations."""
2
3 from __future__ import annotations
4
5 from pathlib import Path
6
7 from tests.skill_contract import contract_documents, reference_text
8
9 ROOT = Path(__file__).resolve().parents[1]
10 CONFIGURATION = ROOT / "CONFIGURATION.md"
11 README = ROOT / "README.md"
12 SKILL_MD = ROOT / "skills" / "last30days" / "SKILL.md"
13 UI_PY = ROOT / "skills" / "last30days" / "scripts" / "lib" / "ui.py"
14
15
16 def test_cookie_setup_requires_explicit_allow_flag_in_docs():
17 config = CONFIGURATION.read_text(encoding="utf-8")
18 skill = reference_text("setup-wizard")
19 assert "setup --allow-browser-cookies" in config
20 assert "setup --allow-browser-cookies" in skill
21 assert "Unset = no browser-cookie reads" in config
22
23
24 def test_project_config_trust_is_documented():
25 config = CONFIGURATION.read_text(encoding="utf-8")
26 skill = reference_text("setup-wizard")
27 assert "LAST30DAYS_TRUST_PROJECT_CONFIG=1" in config
28 assert "LAST30DAYS_TRUST_PROJECT_CONFIG=1" in skill
29 assert "Folder-mode hosts such as Codex desktop do not trust hidden project config by default" in config
30
31
32 def test_codex_auth_not_advertised_as_openai_fallback():
33 config = CONFIGURATION.read_text(encoding="utf-8")
34 assert "Codex ChatGPT auth" in config
35 assert "intentionally not used" in config
36 assert "or Codex auth" not in config
37
38
39 def test_preflight_permission_contract_is_documented():
40 config = CONFIGURATION.read_text(encoding="utf-8")
41 skill = SKILL_MD.read_text(encoding="utf-8")
42 readme = README.read_text(encoding="utf-8")
43
44 for text in (config, skill, readme):
45 assert "--preflight" in text
46 assert "without reading browser cookies, writing setup/config/report files, or running research" in config
47 assert "does not read browser-cookie values" in skill
48 assert "without reading cookies, writing files, or running research" in readme
49
50
51 def test_security_copy_avoids_stale_cookie_and_endpoint_claims():
52 skill = SKILL_MD.read_text(encoding="utf-8")
53 for document in contract_documents().values():
54 assert "no browser session access" not in document
55 assert "OpenAI key only goes to api.openai.com" not in document
56 assert "pass `--agent` for non-interactive report output" not in document
57 assert "Codex ChatGPT auth" in skill
58 assert "Endpoint destinations follow configured provider base URLs" in skill
59 assert "do not read browser-cookie values" in skill
60
61
62 def test_security_copy_names_official_x_api_and_host_envelope():
63 """The always-loaded security contract identifies both official X lanes."""
64 skill = SKILL_MD.read_text(encoding="utf-8")
65 security = skill[skill.index("## Security & Permissions"):]
66 assert "api.x.com" in security
67 assert "X_BEARER_TOKEN" in security
68 assert "--x-posts" in security
69 assert "sent only in the Authorization header" in security
70 assert "no X backend is called" in security
71
72
73 def test_security_copy_discloses_company_lookup_and_share_price_calls():
74 """Both keyless company calls are named with what each one receives."""
75 skill = SKILL_MD.read_text(encoding="utf-8")
76 security = (ROOT / "SECURITY.md").read_text(encoding="utf-8")
77 skill_section = skill[skill.index("## Security & Permissions"):]
78 network = security[security.index("### Network"):security.index("### Hosted reasoning models")]
79 for text in (skill_section, network):
80 assert "wikidata.org" in text
81 assert "yahoo-finance-pp-cli" in text
82 assert "ticker" in text
83 assert "company name" in text
84 assert "topic text" in text
85 setup_installs = next(
86 line for line in security.splitlines() if line.startswith("- First-run setup installs")
87 )
88 assert "Yahoo Finance" in setup_installs
89 assert "`yahoo-finance-pp-cli`" in security[: security.index("## Supported versions")]
90
91
92 def test_configuration_documents_the_yahoo_finance_requirement():
93 config = CONFIGURATION.read_text(encoding="utf-8")
94 row = next(line for line in config.splitlines() if line.startswith("| Yahoo Finance |"))
95 assert "`yahoo-finance-pp-cli` on PATH" in row
96 assert "install yahoo-finance --cli-only" in row
97 assert "listed company" in row
98 assert row.count("|") == 5
99
100
101 def test_scrapecreators_copy_uses_canonical_free_call_count():
102 text = "\n".join(
103 [
104 CONFIGURATION.read_text(encoding="utf-8"),
105 README.read_text(encoding="utf-8"),
106 *contract_documents().values(),
107 UI_PY.read_text(encoding="utf-8"),
108 ]
109 )
110 assert "10,000 free calls" in text
111 assert "100 free credits" not in text
112 assert "1,000 free" not in text
113
114
115 def test_security_policy_documents_lifecycle_hooks_and_harvest():
116 security = (ROOT / "SECURITY.md").read_text(encoding="utf-8")
117 skill = SKILL_MD.read_text(encoding="utf-8")
118 for token in (
119 "hook_installer.py",
120 "capture_brief_hook.py",
121 ".claude-plugin/hooks.json",
122 "setup --install-hooks",
123 "setup --uninstall-hooks",
124 "LAST30DAYS_AUTO_CAPTURE=off",
125 "library harvest",
126 "<save_dir>/finished/*.md",
127 ):
128 assert token in security, f"missing {token!r} in SECURITY.md"
129 security_section = skill[skill.index("## Security & Permissions"):]
130 assert "capture_brief_hook.py" in security_section
131 assert "setup --install-hooks" in security_section
132 assert "LAST30DAYS_AUTO_CAPTURE=off" in security_section
133
134
135 def test_skill_tree_avoids_digg_shortlinks_and_remote_shell_installer_urls():
136 skill_dir = ROOT / "skills" / "last30days"
137 for path in sorted(skill_dir.rglob("*")):
138 if not path.is_file() or path.suffix in {".png", ".jpg", ".jpeg", ".gif", ".mp3", ".pyc"}:
139 continue
140 text = path.read_text(encoding="utf-8", errors="ignore")
141 assert "di.gg/" not in text, f"shortlink di.gg/ found in {path.relative_to(ROOT)}"
142 assert "x.ai/cli/install.sh" not in text, (
143 f"remote installer script URL found in {path.relative_to(ROOT)}"
144 )
145
146
147 def test_skill_md_avoids_failure_suppression_wording_and_states_setup_credential_boundary():
148 skill = SKILL_MD.read_text(encoding="utf-8")
149 assert "internal failures in the deliverable" not in skill
150 assert "Never add debug/data-quality warnings" not in skill
151 assert "never load raw key, token, or cookie values into model context" in skill
152
152 lines PYTHON