feat(platform): add new services, tools, tests and crews modules
New router intelligence modules (26 files): alert_ingest/store, audit_store, architecture_pressure, backlog_generator/store, cost_analyzer, data_governance, dependency_scanner, drift_analyzer, incident_* (5 files), llm_enrichment, platform_priority_digest, provider_budget, release_check_runner, risk_* (6 files), signature_state_store, sofiia_auto_router, tool_governance New services: - sofiia-console: Dockerfile, adapters/, monitor/nodes/ops/voice modules, launchd, react static - memory-service: integration_endpoints, integrations, voice_endpoints, static UI - aurora-service: full app suite (analysis, job_store, orchestrator, reporting, schemas, subagents) - sofiia-supervisor: new supervisor service - aistalk-bridge-lite: Telegram bridge lite - calendar-service: CalDAV calendar service with reminders - mlx-stt-service / mlx-tts-service: Apple Silicon speech services - binance-bot-monitor: market monitor service - node-worker: STT/TTS memory providers New tools (9): agent_email, browser_tool, contract_tool, observability_tool, oncall_tool, pr_reviewer_tool, repo_tool, safe_code_executor, secure_vault New crews: agromatrix_crew (10 modules: depth_classifier, doc_facts, doc_focus, farm_state, light_reply, llm_factory, memory_manager, proactivity, reflection_engine, session_context, style_adapter, telemetry) Tests: 85+ test files for all new modules Made-with: Cursor
This commit is contained in:
76
tests/test_stepan_self_correction.py
Normal file
76
tests/test_stepan_self_correction.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""Tests for Self-Correction Policy (PROMPT 26)."""
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
# doc_facts has no heavy deps — import directly
|
||||
from crews.agromatrix_crew.doc_facts import extract_fact_claims, build_self_correction
|
||||
from crews.agromatrix_crew import session_context as sc
|
||||
|
||||
# Aliases for test readability
|
||||
_extract_fact_claims = extract_fact_claims
|
||||
_build_self_correction = build_self_correction
|
||||
|
||||
|
||||
def _make_session_with_claim(key: str, value: bool) -> dict:
|
||||
sess = sc._default_session()
|
||||
sess["fact_claims"] = [{"key": key, "value": value, "ts": time.time()}]
|
||||
return sess
|
||||
|
||||
|
||||
def test_extract_claims_no_profit():
|
||||
text = "У документі немає прибутку, лише витрати."
|
||||
claims = _extract_fact_claims(text)
|
||||
assert any(c["key"] == "profit_present" and c["value"] is False for c in claims), \
|
||||
f"Expected profit_present=False, got {claims}"
|
||||
|
||||
|
||||
def test_extract_claims_has_profit():
|
||||
text = "У звіті є прибуток — 5 972 016 грн."
|
||||
claims = _extract_fact_claims(text)
|
||||
assert any(c["key"] == "profit_present" and c["value"] is True for c in claims), \
|
||||
f"Expected profit_present=True, got {claims}"
|
||||
|
||||
|
||||
def test_self_correction_triggers_when_contradicts():
|
||||
"""
|
||||
Попереднє твердження: profit_present=False.
|
||||
Нова відповідь: "є прибуток".
|
||||
Очікуємо: _build_self_correction повертає correction prefix.
|
||||
"""
|
||||
prev_session = _make_session_with_claim("profit_present", False)
|
||||
new_response = "У звіті є прибуток — 5 972 016 грн на 497 га."
|
||||
correction = _build_self_correction(new_response, {}, prev_session)
|
||||
assert correction, f"Expected self-correction prefix, got empty string"
|
||||
assert "неточно" in correction.lower() or "написав" in correction.lower(), \
|
||||
f"Correction phrase unexpected: {correction}"
|
||||
|
||||
|
||||
def test_self_correction_no_trigger_when_consistent():
|
||||
"""Той самий твердження — не виправляємо."""
|
||||
prev_session = _make_session_with_claim("profit_present", True)
|
||||
new_response = "У звіті є прибуток — 5 972 016 грн."
|
||||
correction = _build_self_correction(new_response, {}, prev_session)
|
||||
assert correction == "", f"Should not trigger, got: {correction}"
|
||||
|
||||
|
||||
def test_self_correction_no_trigger_without_claims():
|
||||
"""Порожня сесія — нема чого виправляти."""
|
||||
prev_session = sc._default_session()
|
||||
new_response = "У звіті є прибуток — 5 972 016 грн."
|
||||
correction = _build_self_correction(new_response, {}, prev_session)
|
||||
assert correction == ""
|
||||
|
||||
|
||||
def test_self_correction_fail_safe():
|
||||
"""Зламаний session → не кидаємо виняток."""
|
||||
bad_session = {"fact_claims": "not_a_list"}
|
||||
try:
|
||||
result = _build_self_correction("текст", {}, bad_session)
|
||||
# Може повернути "" або щось — головне не Exception
|
||||
assert isinstance(result, str)
|
||||
except Exception as e:
|
||||
assert False, f"Should not raise: {e}"
|
||||
Reference in New Issue
Block a user