from src.services.adr100_slo_metrics_service import ( Adr100SloMetricsSnapshot, AutomationOperationSample, VerificationSample, render_adr100_slo_metrics, ) def test_render_adr100_slo_metrics_outputs_required_series() -> None: snapshot = Adr100SloMetricsSnapshot( automation_operations=[ AutomationOperationSample( outcome="auto_executed", operation_type="playbook_executed", count=8, ), AutomationOperationSample( outcome="human_required", operation_type="playbook_executed", count=2, ), ], automation_operations_24h=[ AutomationOperationSample( outcome="auto_executed", operation_type="auto_repair_executed", count=3, ), ], post_execution_verifications=[ VerificationSample(outcome="success", count=7), VerificationSample(outcome="failed", count=1), ], post_execution_verifications_24h=[ VerificationSample(outcome="success", count=5), ], knowledge_entries_total=2161, knowledge_entries_created_24h=25, high_confidence_total=9, high_confidence_success_total=7, emitted_at=1_778_756_000, ) rendered = render_adr100_slo_metrics(snapshot) assert ( 'automation_operation_log_total{outcome="auto_executed",' 'operation_type="playbook_executed"} 8' ) in rendered assert ( 'automation_operation_created_24h{outcome="auto_executed",' 'operation_type="auto_repair_executed"} 3' ) in rendered assert 'post_execution_verification_total{outcome="success"} 7' in rendered assert 'post_execution_verification_created_24h{outcome="success"} 5' in rendered assert "knowledge_entries_total 2161" in rendered assert "knowledge_entries_created_24h 25" in rendered assert "approval_records_high_confidence_total 9" in rendered assert "approval_records_high_confidence_success_total 7" in rendered assert "adr100_slo_emitter_last_success_timestamp 1778756000" in rendered def test_render_adr100_slo_metrics_emits_zero_series_when_empty() -> None: rendered = render_adr100_slo_metrics( Adr100SloMetricsSnapshot(emitted_at=1_778_756_000), ) assert 'automation_operation_log_total{outcome="none",operation_type="none"} 0' in rendered assert 'automation_operation_created_24h{outcome="none",operation_type="none"} 0' in rendered assert 'post_execution_verification_total{outcome="none"} 0' in rendered assert 'post_execution_verification_created_24h{outcome="none"} 0' in rendered assert "knowledge_entries_total 0" in rendered assert "knowledge_entries_created_24h 0" in rendered def test_render_adr100_slo_metrics_escapes_labels() -> None: rendered = render_adr100_slo_metrics( Adr100SloMetricsSnapshot( automation_operations=[ AutomationOperationSample( outcome='auto"executed', operation_type="line\nbreak", count=1, ), ], emitted_at=1_778_756_000, ), ) assert 'outcome="auto\\"executed"' in rendered assert 'operation_type="line\\nbreak"' in rendered