|
| 1 | +"""Cross-category Primary workflow surface / thinking-lens link registry anti-drift.""" |
| 2 | + |
| 3 | +import sys |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +sys.path.insert(0, str(Path(__file__).parent)) |
| 9 | + |
| 10 | +from prompt_eval_helpers import PROMPT_LIBRARY_CATEGORIES # noqa: E402 |
| 11 | +from test_prompt_cross_links import ( # noqa: E402 |
| 12 | + AGENT_PROMPTS, |
| 13 | + AGENT_SKILL_LINKS, |
| 14 | + AGENT_THINKING_LINKS, |
| 15 | + CONTEXT_PROMPTS, |
| 16 | + CONTEXT_SKILL_LINKS, |
| 17 | + CONTEXT_THINKING_LINKS, |
| 18 | + CORE_PROMPTS, |
| 19 | + CORE_SKILL_LINKS, |
| 20 | + CORE_THINKING_LINKS, |
| 21 | + DOMAIN_PROMPTS, |
| 22 | + DOMAIN_SKILL_LINKS, |
| 23 | + DOMAIN_THINKING_LINKS, |
| 24 | + ENGINEERING_PROMPTS, |
| 25 | + ENGINEERING_SKILL_LINKS, |
| 26 | + ENGINEERING_THINKING_LINKS, |
| 27 | + REPO_PROMPTS, |
| 28 | + REPO_SKILL_LINKS, |
| 29 | + REPO_THINKING_LINKS, |
| 30 | + THINKING_LENS_SKILL_CONSUMERS, |
| 31 | + THINKING_PROMPTS, |
| 32 | +) |
| 33 | + |
| 34 | +LIBRARY_ROOT = Path(__file__).parent.parent.parent |
| 35 | + |
| 36 | +CROSS_LINK_CATEGORY_REGISTRY = ( |
| 37 | + ("00-core", CORE_PROMPTS, CORE_SKILL_LINKS, CORE_THINKING_LINKS), |
| 38 | + ( |
| 39 | + "02-engineering", |
| 40 | + ENGINEERING_PROMPTS, |
| 41 | + ENGINEERING_SKILL_LINKS, |
| 42 | + ENGINEERING_THINKING_LINKS, |
| 43 | + ), |
| 44 | + ( |
| 45 | + "03-context", |
| 46 | + CONTEXT_PROMPTS, |
| 47 | + CONTEXT_SKILL_LINKS, |
| 48 | + CONTEXT_THINKING_LINKS, |
| 49 | + ), |
| 50 | + ("04-agent", AGENT_PROMPTS, AGENT_SKILL_LINKS, AGENT_THINKING_LINKS), |
| 51 | + ( |
| 52 | + "05-domain", |
| 53 | + DOMAIN_PROMPTS, |
| 54 | + DOMAIN_SKILL_LINKS, |
| 55 | + DOMAIN_THINKING_LINKS, |
| 56 | + ), |
| 57 | + ("06-repo", REPO_PROMPTS, REPO_SKILL_LINKS, REPO_THINKING_LINKS), |
| 58 | +) |
| 59 | + |
| 60 | + |
| 61 | +def test_cross_link_registry_lists_composable_categories_except_thinking(): |
| 62 | + assert tuple(cat for cat, *_ in CROSS_LINK_CATEGORY_REGISTRY) == tuple( |
| 63 | + c for c in PROMPT_LIBRARY_CATEGORIES if c != "01-thinking" |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +@pytest.mark.parametrize( |
| 68 | + "category,prompts,skill_links,thinking_links", |
| 69 | + CROSS_LINK_CATEGORY_REGISTRY, |
| 70 | + ids=[row[0] for row in CROSS_LINK_CATEGORY_REGISTRY], |
| 71 | +) |
| 72 | +def test_cross_link_registry_category_dicts_cover_prompts( |
| 73 | + category: str, |
| 74 | + prompts: tuple[Path, ...], |
| 75 | + skill_links: dict[str, tuple[str, ...]], |
| 76 | + thinking_links: dict[str, tuple[str, ...]], |
| 77 | +): |
| 78 | + prompt_names = {p.name for p in prompts} |
| 79 | + assert set(skill_links) == prompt_names, f"{category}: SKILL_LINKS keys != prompts" |
| 80 | + assert set(thinking_links) == prompt_names, ( |
| 81 | + f"{category}: THINKING_LINKS keys != prompts" |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +def test_cross_link_registry_library_wide_unique_filenames(): |
| 86 | + basenames: list[str] = [] |
| 87 | + for _category, prompts, _skill_links, _thinking_links in CROSS_LINK_CATEGORY_REGISTRY: |
| 88 | + basenames.extend(p.name for p in prompts) |
| 89 | + basenames.extend(p.name for p in THINKING_PROMPTS) |
| 90 | + assert len(basenames) == len(frozenset(basenames)), ( |
| 91 | + "duplicate prompt basenames across categories" |
| 92 | + ) |
| 93 | + |
| 94 | + |
| 95 | +def test_cross_link_registry_matches_library_glob(): |
| 96 | + globbed: list[Path] = [] |
| 97 | + for category in PROMPT_LIBRARY_CATEGORIES: |
| 98 | + globbed.extend(sorted((LIBRARY_ROOT / category).glob("*.md"))) |
| 99 | + registry_paths = [ |
| 100 | + p |
| 101 | + for _category, prompts, _skill_links, _thinking_links in CROSS_LINK_CATEGORY_REGISTRY |
| 102 | + for p in prompts |
| 103 | + ] |
| 104 | + registry_paths.extend(THINKING_PROMPTS) |
| 105 | + assert sorted(globbed) == sorted(registry_paths) |
| 106 | + |
| 107 | + |
| 108 | +def test_thinking_lenses_tracked_in_consumer_map(): |
| 109 | + expected = {f"01-thinking/{path.name}" for path in THINKING_PROMPTS} |
| 110 | + assert set(THINKING_LENS_SKILL_CONSUMERS) == expected |
0 commit comments