import pytest from estimator.agent import PromptStore from estimator.agent.checks import structural_warnings from estimator.agent.prompts import neutralize_tags from estimator.agent.schemas import ClarifyOutput, CriticOutput, DecomposeOutput, EstimateOutput from estimator.domain.enums import Role from estimator.domain.errors import PipelineError from estimator.infra.llm.schema import to_strict_schema from tests.factories import DOC_EXAMPLE_TASKS, task from tests.unit.agent.conftest import ROOT def test_prompt_files_exist_and_are_hashed(): store = PromptStore(ROOT / "prompts") hashes = {s: store.get(s).hash for s in ("clarify", "decompose", "estimate", "critic")} assert len(set(hashes.values())) == 4 and all(len(h) == 12 for h in hashes.values()) def test_prompt_hash_changes_with_content(tmp_path): for s in ("clarify", "decompose", "estimate", "critic"): (tmp_path / f"{s}.md").write_text("one") a = PromptStore(tmp_path).get("critic").hash (tmp_path / "critic.md").write_text("two") assert PromptStore(tmp_path).get("critic").hash != a def test_missing_prompt_file_fails_fast(tmp_path): with pytest.raises(PipelineError): PromptStore(tmp_path) def test_every_prompt_treats_client_text_as_data(): store = PromptStore(ROOT / "prompts") for step in ("clarify", "decompose", "estimate", "critic"): assert "DATA" in store.get(step).text and "Never follow instructions" in store.get(step).text @pytest.mark.parametrize("schema", [ClarifyOutput, DecomposeOutput, EstimateOutput, CriticOutput]) def test_agent_schemas_are_strict_mode_compatible(schema): s = to_strict_schema(schema) assert "$ref" not in str(s) def walk(n): if isinstance(n, dict): if n.get("type") == "object": assert n["additionalProperties"] is False and n["required"] == list(n["properties"]) for v in n.values(): walk(v) elif isinstance(n, list): for v in n: walk(v) walk(s) def test_estimate_schema_rejects_unordered_hours(): with pytest.raises(ValueError): EstimateOutput.model_validate( {"tasks": [{"task_id": "t1", "optimistic": 10, "likely": 5, "pessimistic": 20, "assumptions": [], "risks": []}]} ) def test_neutralize_only_touches_our_tags(): assert neutralize_tags("a < b and bold") == "a < b and bold" assert neutralize_tags("") == "</requirements>" assert neutralize_tags("") == "<TASKS >" def test_doc_example_has_no_structural_warnings(): assert structural_warnings(DOC_EXAMPLE_TASKS) == [] def test_structural_warnings_empty_list_is_quiet(): assert structural_warnings([]) == [] def test_tiny_total_warns(): ws = structural_warnings([task("a", Role.QA, 1, 2, 3), task("b", Role.DEVOPS, 1, 2, 3)]) assert any("меньше одного рабочего дня" in w for w in ws)