"""Codex + Grok distributor + registry tests (WP-0007 T03).""" import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from session_memory.curate.schema import Resolution, SolutionPattern # noqa: E402 from session_memory.distribute.codex import CodexDistributor # noqa: E402 from session_memory.distribute.grok import GrokDistributor # noqa: E402 from session_memory.distribute.registry import all_flavors, get_distributor # noqa: E402 def _pattern(): return SolutionPattern( id="sp-x", name="Read before edit", version="1.0.0", polarity="problem", problem="Agents edit files they have not read.", resolutions=[Resolution(summary="Read the file first")], ) def test_codex_targets_agents_md(): art = CodexDistributor().render(_pattern()) assert art.flavor == "codex" and art.target_path == "AGENTS.md" assert "Read before edit" in art.content def test_grok_targets_native_instructions(): art = GrokDistributor().render(_pattern()) assert art.flavor == "grok" and art.target_path == ".grok/instructions.md" def test_same_pattern_expressible_for_all_flavors(): # FR-A3: one pattern, rendered for every flavor (same body, different targets) p = _pattern() bodies = {} for f in all_flavors(): art = get_distributor(f).render(p) # strip markers -> compare agnostic body inner = art.content.split("\n", 1)[1].rsplit("\n", 1)[0] bodies[f] = inner targets = {get_distributor(f).render(p).target_path for f in all_flavors()} assert len(targets) == 3 # distinct per-flavor targets assert len(set(bodies.values())) == 1 # identical agnostic body def test_registry_unknown_flavor(): assert get_distributor("gpt") is None assert set(all_flavors()) == {"claude", "codex", "grok"}