from django.test import SimpleTestCase

from core.observability.tracing import ensure_trace_id


class TracingHelpersTests(SimpleTestCase):
    def test_ensure_trace_id_prefers_explicit_value(self):
        self.assertEqual(
            "abc123",
            ensure_trace_id("abc123", {"trace_id": "payload"}),
        )

    def test_ensure_trace_id_uses_payload_value(self):
        self.assertEqual(
            "payload-value",
            ensure_trace_id("", {"trace_id": "payload-value"}),
        )

    def test_ensure_trace_id_generates_when_missing(self):
        trace_id = ensure_trace_id("", {})
        self.assertEqual(32, len(trace_id))
