mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from llm_gateway.request_context import (
|
|
RequestContext,
|
|
_parse_traceparent_trace_id,
|
|
apply_insights_context_from_headers,
|
|
get_traceparent_trace_id,
|
|
rebuild_request_context,
|
|
set_request_context,
|
|
)
|
|
|
|
VALID_TRACEPARENT = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
|
|
VALID_TRACE_UUID = "0af76519-16cd-43dd-8448-eb211c80319c"
|
|
|
|
|
|
class TestParseTraceparentTraceId:
|
|
@pytest.mark.parametrize(
|
|
"value,expected",
|
|
[
|
|
(VALID_TRACEPARENT, VALID_TRACE_UUID),
|
|
# Unknown versions are tolerated per W3C — only the trace-id field is read.
|
|
("cc-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", VALID_TRACE_UUID),
|
|
(None, None),
|
|
("", None),
|
|
("garbage", None),
|
|
("00-shorttraceid-b7ad6b7169203331-01", None),
|
|
("00-zzf7651916cd43dd8448eb211c80319z-b7ad6b7169203331-01", None),
|
|
("00-00000000000000000000000000000000-b7ad6b7169203331-01", None),
|
|
("00-0af7651916cd43dd8448eb211c80319c", None),
|
|
],
|
|
)
|
|
def test_parses_or_rejects(self, value, expected):
|
|
assert _parse_traceparent_trace_id(value) == expected
|
|
|
|
|
|
class TestApplyCapturesTraceparent:
|
|
def test_traceparent_lands_in_context(self):
|
|
set_request_context(RequestContext(request_id="r1"))
|
|
request = SimpleNamespace(headers={"traceparent": VALID_TRACEPARENT})
|
|
apply_insights_context_from_headers(request)
|
|
assert get_traceparent_trace_id() == VALID_TRACE_UUID
|
|
|
|
def test_absent_header_leaves_none(self):
|
|
set_request_context(RequestContext(request_id="r2"))
|
|
apply_insights_context_from_headers(SimpleNamespace(headers={}))
|
|
assert get_traceparent_trace_id() is None
|
|
|
|
def test_malformed_header_leaves_none(self):
|
|
set_request_context(RequestContext(request_id="r3"))
|
|
apply_insights_context_from_headers(SimpleNamespace(headers={"traceparent": "nonsense"}))
|
|
assert get_traceparent_trace_id() is None
|
|
|
|
|
|
class TestRebuildRequestContextCarriesTraceparent:
|
|
def test_survives_the_handler_rebuild(self):
|
|
# handler.py replaces the context mid-request; the traceparent must survive it.
|
|
set_request_context(RequestContext(request_id="r4"))
|
|
request = SimpleNamespace(headers={"traceparent": VALID_TRACEPARENT})
|
|
apply_insights_context_from_headers(request)
|
|
|
|
rebuild_request_context("llm_gateway")
|
|
|
|
assert get_traceparent_trace_id() == VALID_TRACE_UUID
|
|
|
|
rebuild_request_context("llm_gateway")
|
|
|
|
assert get_traceparent_trace_id() == VALID_TRACE_UUID
|