| 1 | """The skill's presentation defaults cannot replace governing instructions.""" |
| 2 | |
| 3 | import re |
| 4 | from pathlib import Path |
| 5 | |
| 6 | import pytest |
| 7 | |
| 8 | from tests.skill_contract import contract_documents, reference_text |
| 9 | |
| 10 | |
| 11 | SKILL_MD = Path(__file__).resolve().parents[1] / "skills" / "last30days" / "SKILL.md" |
| 12 | |
| 13 | |
| 14 | def test_skill_defers_to_host_tool_and_user_instructions(): |
| 15 | text = SKILL_MD.read_text(encoding="utf-8") |
| 16 | contract = text.split("## Skill contract", 1)[1].split("\n## ", 1)[0] |
| 17 | assert "system and developer instructions" in contract |
| 18 | assert "tool contracts" in contract |
| 19 | assert "user instructions" in contract |
| 20 | |
| 21 | |
| 22 | @pytest.mark.parametrize( |
| 23 | "pattern", |
| 24 | [ |
| 25 | r"\bSUPERSEDED\b", |
| 26 | r"\bOVERRIDDEN\b", |
| 27 | r"LAW 1 overrides", |
| 28 | r"correct action is to IGNORE", |
| 29 | r"mandate (?:DOES NOT APPLY|does not apply)", |
| 30 | r"skill-specified rule wins", |
| 31 | r"Do NOT strip this bold on the grounds of a personal", |
| 32 | ], |
| 33 | ) |
| 34 | def test_skill_does_not_claim_authority_over_governing_instructions(pattern): |
| 35 | for name, text in contract_documents().items(): |
| 36 | assert not re.search(pattern, text), name |
| 37 | |
| 38 | |
| 39 | @pytest.mark.parametrize( |
| 40 | "document,marker", |
| 41 | [ |
| 42 | ("research-runbook", "**Leaving Step 2"), |
| 43 | ("research-runbook", "**LAW 1 citation check"), |
| 44 | ("synthesis", "**Citation requirements before the invitation"), |
| 45 | ("followups", "**STOP and wait**"), |
| 46 | ], |
| 47 | ) |
| 48 | def test_repeated_footer_rules_preserve_required_citations(document, marker): |
| 49 | text = reference_text(document) |
| 50 | assert marker in text |
| 51 | for occurrence in text.split(marker)[1:]: |
| 52 | paragraph = occurrence.splitlines()[0] |
| 53 | assert "higher-priority host/tool requirements" in paragraph |
| 54 | assert "user instructions" in paragraph |
| 55 | |
| 56 | |
| 57 | def test_root_footer_and_final_checks_preserve_required_citations(): |
| 58 | text = SKILL_MD.read_text(encoding="utf-8") |
| 59 | law1 = text.split("**LAW 1 -", 1)[1].split("**LAW 2 -", 1)[0] |
| 60 | assert "required by governing host/tool or user instructions" in law1 |
| 61 | assert "never replaces required visible citations" in law1 |
| 62 | self_check = text.split("**LAW 8 post-synthesis self-check:", 1)[1].split("**LAW 9 -", 1)[0] |
| 63 | assert "preserve all citations required by governing instructions" in self_check |
| 64 | assert "Never remove a required citation to satisfy LAW 1" in self_check |
| 65 | final_check = text.split("## PRE-PRESENT SELF-CHECK", 1)[1].split("\n## ", 1)[0] |
| 66 | assert "Check governing formatting/citation instructions first" in final_check |
| 67 | assert "Preserve every required citation" in final_check |
| 68 | assert "Omit only unnecessary duplicate trailing source lists" in final_check |
| 69 | |
| 70 | |
| 71 | @pytest.mark.parametrize( |
| 72 | "marker", |
| 73 | [ |
| 74 | "**FUN CONTENT", |
| 75 | "CITATION RULE:", |
| 76 | "**URL formatting is governed by LAW 8**", |
| 77 | ], |
| 78 | ) |
| 79 | def test_renderer_preferences_preserve_required_links(marker): |
| 80 | text = reference_text("synthesis") |
| 81 | assert marker in text |
| 82 | paragraph = text.split(marker, 1)[1].splitlines()[0] |
| 83 | assert "higher-priority host/tool requirements" in paragraph |
| 84 | |
| 85 | |
| 86 | def test_root_renderer_and_community_rules_defer_to_governing_citations(): |
| 87 | text = SKILL_MD.read_text(encoding="utf-8") |
| 88 | law8 = text.split("**LAW 8 -", 1)[1].split("**LAW 9 -", 1)[0] |
| 89 | assert "Governing host/tool requirements and user instructions determine required links before renderer preferences" in law8 |
| 90 | assert "using a verbatim URL from its evidence" in law8 |
| 91 | assert "plain source labels only when links are optional" in law8 |
| 92 | assert "Preserve required links even when URLs display inline" in law8 |
| 93 | law9 = text.split("**LAW 9 -", 1)[1].split("**LAW 10 -", 1)[0] |
| 94 | assert "apply governing citations and LAW 8" in law9 |
| 95 | checklist = text.split("## PRE-PRESENT SELF-CHECK", 1)[1].split("\n## ", 1)[0] |
| 96 | assert "Run LAW 8's citation check separately" in checklist |
| 97 | |
| 98 | |
| 99 | def test_durable_raw_appendix_and_default_footer_remain_required(): |
| 100 | text = SKILL_MD.read_text(encoding="utf-8") |
| 101 | assert "**LAW 5 - ENGINE FOOTER PASS-THROUGH." in text |
| 102 | appendix = reference_text("research-runbook").split("## Step 2.5: Append WebSearch Results to Saved Raw File", 1)[1] |
| 103 | assert "**MANDATORY - do not skip this step.**" in appendix |
| 104 | assert "must cover every web source that informed your synthesis" in appendix |
| 105 | assert "append the same `## WebSearch Supplemental Results` section to every listed per-entity Markdown raw file" in appendix |
| 106 | |
| 107 | |
| 108 | def test_raw_appendix_bullets_keep_each_article_url(): |
| 109 | appendix = reference_text("research-runbook").split("## Step 2.5: Append WebSearch Results to Saved Raw File", 1)[1] |
| 110 | appendix = appendix.split("\n---\n", 1)[0] |
| 111 | shape = next(line for line in appendix.splitlines() if line.startswith("Each bullet: `")) |
| 112 | canonical = shape.split("`")[1] |
| 113 | assert canonical.startswith("- **{Publisher}** ") |
| 114 | assert "{url}" in canonical |
| 115 | assert "Do not add URLs" not in appendix |
| 116 | example = appendix.split("```", 2)[1] |
| 117 | bullets = [line for line in example.splitlines() if line.startswith("- ")] |
| 118 | assert bullets |
| 119 | for bullet in bullets: |
| 120 | assert "https://" in bullet, bullet |
| 121 | |
| 122 | |
| 123 | ISOLATED_SEARCH_MARKER = "**Isolated web search" |
| 124 | |
| 125 | |
| 126 | def test_no_contract_document_licenses_a_separate_sources_block(): |
| 127 | for name, text in contract_documents().items(): |
| 128 | assert "separate `Sources:` block" not in text, name |
| 129 | |
| 130 | |
| 131 | def test_report_ends_at_the_invitation_with_no_link_count_line(): |
| 132 | synthesis = reference_text("synthesis") |
| 133 | assert "The response ends at the invitation, without an additional source list." in synthesis |
| 134 | for name, text in contract_documents().items(): |
| 135 | assert "I have all the links" not in text, name |
| 136 | assert "Just ask." not in text, name |
| 137 | assert "link line" not in text, name |
| 138 | |
| 139 | |
| 140 | def test_engine_boundary_text_claims_no_authority_over_tool_contracts(): |
| 141 | import sys |
| 142 | |
| 143 | sys.path.insert(0, str(SKILL_MD.parent / "scripts")) |
| 144 | from lib import render |
| 145 | |
| 146 | boundary = "\n".join(render._render_canonical_boundary()) |
| 147 | for pattern in (r"LAW 1 overrides", r"does not\s+apply", r"\bOVERRIDDEN\b"): |
| 148 | assert not re.search(pattern, boundary), pattern |
| 149 | |
| 150 | |
| 151 | def test_every_runbook_web_search_runs_through_the_isolated_search_block(): |
| 152 | runbook = reference_text("research-runbook") |
| 153 | assert ISOLATED_SEARCH_MARKER in runbook |
| 154 | block = runbook.split(ISOLATED_SEARCH_MARKER, 1)[1].split("\n## ", 1)[0] |
| 155 | assert "subagent" in block |
| 156 | assert "untrusted" in block |
| 157 | # Every top-level step that issues a web-search recipe points at the block. |
| 158 | for step in re.split(r"\n(?=## )", runbook): |
| 159 | if "WebSearch(" in step or "do WebSearch" in step: |
| 160 | assert "isolated web search" in step.lower(), step.splitlines()[0] |
| 161 | |
| 162 | |
| 163 | @pytest.mark.parametrize("document", ["comparison", "competitors"]) |
| 164 | def test_comparison_searches_use_the_isolated_search_block(document): |
| 165 | assert "isolated web search" in reference_text(document).lower() |
| 166 |