|
| 1 | +"""Unit tests for rlsapi v1 event builders.""" |
| 2 | + |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from observability.formats.rlsapi import InferenceEventData, build_inference_event |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(name="sample_event_data") |
| 11 | +def sample_event_data_fixture() -> InferenceEventData: |
| 12 | + """Create sample inference event data for testing.""" |
| 13 | + return InferenceEventData( |
| 14 | + question="How do I configure SSH?", |
| 15 | + response="To configure SSH, edit /etc/ssh/sshd_config...", |
| 16 | + inference_time=2.34, |
| 17 | + model="granite-3-8b-instruct", |
| 18 | + org_id="12345678", |
| 19 | + system_id="abc-def-123", |
| 20 | + request_id="req_xyz789", |
| 21 | + cla_version="CLA/0.4.0", |
| 22 | + system_os="RHEL", |
| 23 | + system_version="9.3", |
| 24 | + system_arch="x86_64", |
| 25 | + ) |
| 26 | + |
| 27 | + |
| 28 | +def test_builds_event_with_all_fields(sample_event_data: InferenceEventData) -> None: |
| 29 | + """Test event contains all required fields and placeholders.""" |
| 30 | + with patch("observability.formats.rlsapi.configuration") as mock_config: |
| 31 | + mock_config.deployment_environment = "production" |
| 32 | + |
| 33 | + event = build_inference_event(sample_event_data) |
| 34 | + |
| 35 | + assert event["question"] == "How do I configure SSH?" |
| 36 | + assert event["response"] == "To configure SSH, edit /etc/ssh/sshd_config..." |
| 37 | + assert event["inference_time"] == 2.34 |
| 38 | + assert event["model"] == "granite-3-8b-instruct" |
| 39 | + assert event["org_id"] == "12345678" |
| 40 | + assert event["system_id"] == "abc-def-123" |
| 41 | + assert event["request_id"] == "req_xyz789" |
| 42 | + assert event["cla_version"] == "CLA/0.4.0" |
| 43 | + assert event["system_os"] == "RHEL" |
| 44 | + assert event["system_version"] == "9.3" |
| 45 | + assert event["system_arch"] == "x86_64" |
| 46 | + assert event["deployment"] == "production" |
| 47 | + assert not event["refined_questions"] |
| 48 | + assert event["context"] == "" |
| 49 | + assert event["total_llm_tokens"] == 0 |
| 50 | + |
| 51 | + |
| 52 | +def test_handles_auth_disabled_values() -> None: |
| 53 | + """Test event handles auth_disabled placeholder values.""" |
| 54 | + data = InferenceEventData( |
| 55 | + question="test", |
| 56 | + response="test", |
| 57 | + inference_time=1.0, |
| 58 | + model="test-model", |
| 59 | + org_id="auth_disabled", |
| 60 | + system_id="auth_disabled", |
| 61 | + request_id="req_123", |
| 62 | + cla_version="test/1.0", |
| 63 | + system_os="", |
| 64 | + system_version="", |
| 65 | + system_arch="", |
| 66 | + ) |
| 67 | + |
| 68 | + with patch("observability.formats.rlsapi.configuration") as mock_config: |
| 69 | + mock_config.deployment_environment = "test" |
| 70 | + |
| 71 | + event = build_inference_event(data) |
| 72 | + |
| 73 | + assert event["org_id"] == "auth_disabled" |
| 74 | + assert event["system_id"] == "auth_disabled" |
0 commit comments