diff --git a/app/emitters.py b/app/emitters.py index f5053f5e..e0da71ea 100644 --- a/app/emitters.py +++ b/app/emitters.py @@ -172,7 +172,6 @@ def _relevant_followups(ir) -> list[str]: "performance", "perf", "memo", - "optimi", "latency", "fps", "profil", diff --git a/tests/test_emitters_utils.py b/tests/test_emitters_utils.py index c7765412..4abdadea 100644 --- a/tests/test_emitters_utils.py +++ b/tests/test_emitters_utils.py @@ -6,11 +6,15 @@ from __future__ import annotations +from types import SimpleNamespace + from app.emitters import ( _clean_domain_suggestion_text, _contains_any_marker, _is_trivial_input, _minimal_greeting_prompt, + _relevant_followups, + _scenario_considerations, ) @@ -133,3 +137,84 @@ def test_whitespace_normalized(self) -> None: def test_ok_prefix_stripped_before_use(self) -> None: assert _clean_domain_suggestion_text("Ok: Use type hints") == "Use type hints" + + +class TestScenarioConsiderations: + """Route conservative scenario guidance only when the right signals appear.""" + + def test_browser_download_requires_all_three_signals(self) -> None: + ir = SimpleNamespace( + goals=["Add a button so users can download CSV exports from the dashboard"], + tasks=[], + ) + + considerations = _scenario_considerations(ir) + + assert len(considerations) == 2 + assert "Blob + an link" in considerations[0] + assert "File System Access API is unsupported in Safari" in considerations[1] + + def test_browser_download_does_not_trigger_without_feature_adding_verb(self) -> None: + ir = SimpleNamespace( + goals=["Fix the Safari CSV download that opens inline instead of saving"], + tasks=[], + ) + + assert _scenario_considerations(ir) == [] + + def test_react_perf_requires_react_and_perf_markers(self) -> None: + ir = SimpleNamespace( + goals=["My React list is slow and re-renders too much when filters change"], + tasks=[], + ) + + considerations = _scenario_considerations(ir) + + assert len(considerations) == 2 + assert "React DevTools Profiler" in considerations[0] + assert "virtualize long lists" in considerations[1] + + +class TestRelevantFollowups: + """Choose the most useful follow-up question set for the prompt context.""" + + def test_react_perf_prompt_prefers_perf_followups_over_browser_keywords(self) -> None: + ir = SimpleNamespace( + goals=["My React button re-renders constantly and the page feels slow"], + tasks=[], + intents=[], + domain="software", + ) + + followups = _relevant_followups(ir) + + assert len(followups) == 3 + assert "React DevTools Profiler" in followups[0] + assert "Which browser and version is affected" not in "\n".join(followups) + + def test_browser_bug_prompt_gets_browser_followups(self) -> None: + ir = SimpleNamespace( + goals=["This Chrome button renders in the wrong place after click"], + tasks=[], + intents=[], + domain="software", + ) + + followups = _relevant_followups(ir) + + assert len(followups) == 3 + assert followups[0].startswith("Which browser and version is affected") + + def test_generic_api_optimization_prompt_falls_back_to_software_followups(self) -> None: + ir = SimpleNamespace( + goals=["Optimize this API and make it better"], + tasks=[], + intents=[], + domain="software", + ) + + followups = _relevant_followups(ir) + + assert len(followups) == 3 + assert followups[0] == "Which language, framework, and version are targeted?" + assert "React DevTools Profiler" not in "\n".join(followups) diff --git a/tests/test_expanded_prompt.py b/tests/test_expanded_prompt.py index f3f206b7..cb87d508 100644 --- a/tests/test_expanded_prompt.py +++ b/tests/test_expanded_prompt.py @@ -13,6 +13,21 @@ def test_expanded_prompt_contains_input_and_example(): assert ("Örnek çıktı formatı" in ep) or ("Example output format" in ep) +def test_expanded_prompt_v2_surfaces_react_perf_domain_guidance(): + ir = compile_text_v2( + "My React table re-renders too much and feels slow with large lists", + offline_only=True, + ) + + ep = emit_expanded_prompt_v2(ir, diagnostics=False) + + assert "Key considerations:" in ep + assert "React DevTools Profiler" in ep + assert "virtualize long lists" in ep + assert "Follow-up Questions:" in ep + assert "Have you profiled it" in ep + + def test_expanded_prompt_v2_surfaces_clarification_questions_without_diagnostics(monkeypatch): monkeypatch.setenv("PROMPT_COMPILER_MODE", "conservative") ir2 = compile_text_v2("Optimize this API and make it better", offline_only=True) @@ -22,6 +37,8 @@ def test_expanded_prompt_v2_surfaces_clarification_questions_without_diagnostics assert "Clarification Questions:" in ep assert "Which metric or aspect should be optimized?" in ep assert "Better in what sense" in ep + assert "Have you profiled it (e.g. React DevTools Profiler)" not in ep + assert "Which language, framework, and version are targeted?" in ep def test_inferred_coding_best_practices_are_optional_not_constraints(monkeypatch):