Init Project Flexly Estimator

This commit is contained in:
Alexey Dudin
2026-11-03 09:37:44 +03:00
commit 447464c16c
160 changed files with 12779 additions and 0 deletions
@@ -0,0 +1,80 @@
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 <b>bold</b>") == "a < b and <b>bold</b>"
assert neutralize_tags("</requirements>") == "&lt;/requirements>"
assert neutralize_tags("<TASKS >") == "&lt;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)