Files
microsoft--agent-lightning/tests/emitter/test_annotation.py
T
wehub-resource-sync 85742ab165
Deploy Documentation / deploy (push) Has been cancelled
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, latest, Python 3.13) (push) Has been cancelled
Dashboard / Chromatic (push) Has been cancelled
CPU Test / Lint - fast (push) Has been cancelled
CPU Test / Lint - next (push) Has been cancelled
CPU Test / Lint - slow (push) Has been cancelled
CPU Test / Lint - JavaScript (push) Has been cancelled
CPU Test / Build documentation (push) Has been cancelled
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Others, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Store, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Weave, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Others, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Store, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Utilities, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (JavaScript) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:44:17 +08:00

50 lines
1.6 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
from __future__ import annotations
from typing import Dict
import pytest
from agentlightning.emitter import annotation as annotation_module
from agentlightning.emitter.annotation import emit_annotation
from agentlightning.semconv import AGL_ANNOTATION
from ..common.tracer import RecordingDummyTracer
def _install_tracer(monkeypatch: pytest.MonkeyPatch) -> RecordingDummyTracer:
tracer = RecordingDummyTracer()
monkeypatch.setattr(annotation_module, "get_active_tracer", lambda: tracer)
return tracer
def test_emit_annotation_flattens_and_sanitizes_attributes(monkeypatch: pytest.MonkeyPatch) -> None:
tracer = _install_tracer(monkeypatch)
result = emit_annotation({"meta": {"tag": "foo"}, "score": 1.5})
assert result.name == AGL_ANNOTATION
assert tracer.last_span is not None
assert tracer.last_span.attributes == {"meta.tag": "foo", "score": 1.5}
def test_emit_annotation_propagate_false_bypasses_active_tracer(monkeypatch: pytest.MonkeyPatch) -> None:
captured: Dict[str, bool] = {"called": False}
def fail_get_active_tracer() -> RecordingDummyTracer:
captured["called"] = True
raise AssertionError("Should not resolve active tracer when propagate is False")
monkeypatch.setattr(annotation_module, "get_active_tracer", fail_get_active_tracer)
result = emit_annotation({"score": 1}, propagate=False)
assert result.name == AGL_ANNOTATION
assert captured["called"] is False
def test_emit_annotation_rejects_non_primitive_values() -> None:
with pytest.raises(ValueError):
emit_annotation({"bad": {"set": {1}}})