from central.app.operational_state import classify_product_state, summarize_operational_states def test_twenty_thousand_products_keep_agent_healthy_with_safe_blocks(): states = [{"state": "COMPLETE"}] * 19900 + [{"state": "BLOCKED_MISSING_EVIDENCE"}] * 100 summary = summarize_operational_states(states) assert summary["AUTONOMOUSLY_PROCESSABLE_PRODUCTS"] == 20000 assert summary["SAFE_BLOCKED"] == 100 assert summary["AGENT_HEALTH"] == "HEALTHY" def test_new_evidence_changes_product_state_without_global_failure(): blocked = classify_product_state({"CODIGO": "P1"}, {"status": "INVALID_NCM"}) resolved = classify_product_state({"CODIGO": "P1"}, {"status": "EXACT_NCM"}) assert blocked["state"] == "BLOCKED_MISSING_EVIDENCE" assert resolved["state"] == "COMPLETE"