Skip to content

Commit 82adbd7

Browse files
hassiebpniklassemmlerclaudecursoragent
authored
chore: merge main into prepare-v5-release (#1986)
* docs(api): document metadata is set / is not set filter operators (#1946) Regenerated langfuse/api from the upstream Fern definition: baseline langfuse/langfuse 619dbe3 (last sync, #1866) plus langfuse/langfuse#17357 and #18404. Split out of the bundled API-spec bot PR #1943. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(api): type Dataset JSON-schema response fields as objects (#1949) Regenerated langfuse/api from the upstream Fern definition: baseline langfuse/langfuse 619dbe3 (last sync, #1866) plus langfuse/langfuse#17892 and the datasets.yml/opentelemetry.yml part of #18406. Split out of the bundled API-spec bot PR #1943. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(api): share cursor pagination meta via CursorMetaResponse (#1948) Regenerated langfuse/api from the upstream Fern definition: baseline langfuse/langfuse 619dbe3 (last sync, #1866) plus langfuse/langfuse#17888. Split out of the bundled API-spec bot PR #1943. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(api): document fromStartTime as required on experiments endpoints (#1947) * docs(api): document fromStartTime as required on experiments endpoints Regenerated langfuse/api from the upstream Fern definition: baseline langfuse/langfuse 619dbe3 (last sync, #1866) plus langfuse/langfuse#17603. Split out of the bundled API-spec bot PR #1943. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(api): use language-neutral wording for experiments time window Regenerated from langfuse/langfuse branch docs/experiments-from-start-time-neutral-wording. The fromStartTime docstrings named `toStartTime`, but the Python parameter is `to_start_time`; they now say "an upper bound" instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(api): type read-side metadata as optional objects (#1950) * fix(api): type read-side metadata as optional objects Regenerated langfuse/api from the upstream Fern definition: baseline langfuse/langfuse 619dbe3 (last sync, #1866) plus langfuse/langfuse#18122 and the commons.yml part of #18406. Split out of the bundled API-spec bot PR #1943. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(api): pin read-side metadata parsing on generated models Cover omitted, null, empty and nested-JSON metadata plus rejection of non-object metadata for Trace, Observation, ObservationV2, BaseScore, BaseScoreV1 and every Score / ScoreV1 / GetScoresResponseData variant. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Niklas Semmler <1880943+niklassemmler@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 4c845f8 commit 82adbd7

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""Response parsing of read-side ``metadata`` on generated API models.
2+
3+
The server returns read-side metadata as a JSON object, ``null``, or omits it.
4+
These tests pin that contract so a future regeneration that makes the field
5+
required or narrows its values is caught.
6+
"""
7+
8+
import typing
9+
10+
import pydantic
11+
import pytest
12+
13+
from langfuse.api import BaseScore, ObservationV2, Score
14+
from langfuse.api.core import parse_obj_as
15+
16+
TIMESTAMP = "2026-01-01T00:00:00.000Z"
17+
18+
SCORE_BASE: typing.Dict[str, typing.Any] = {
19+
"id": "score-1",
20+
"name": "quality",
21+
"source": "API",
22+
"timestamp": TIMESTAMP,
23+
"createdAt": TIMESTAMP,
24+
"updatedAt": TIMESTAMP,
25+
"environment": "default",
26+
}
27+
28+
SCORE_VARIANTS: typing.Dict[str, typing.Dict[str, typing.Any]] = {
29+
"NUMERIC": {"value": 0.5},
30+
"CATEGORICAL": {"value": 1, "stringValue": "good"},
31+
"BOOLEAN": {"value": 1, "stringValue": "True"},
32+
"CORRECTION": {"value": 0, "stringValue": "corrected output"},
33+
"TEXT": {"stringValue": "free text"},
34+
}
35+
36+
37+
def _score_payload(
38+
base: typing.Dict[str, typing.Any], data_type: str
39+
) -> typing.Dict[str, typing.Any]:
40+
return {**base, "dataType": data_type, **SCORE_VARIANTS[data_type]}
41+
42+
43+
CASES: typing.List[typing.Any] = [
44+
pytest.param(
45+
ObservationV2,
46+
{
47+
"id": "obs-1",
48+
"startTime": TIMESTAMP,
49+
"projectId": "project-1",
50+
"type": "SPAN",
51+
},
52+
id="ObservationV2",
53+
),
54+
pytest.param(BaseScore, SCORE_BASE, id="BaseScore"),
55+
*[
56+
pytest.param(Score, _score_payload(SCORE_BASE, dt), id=f"Score-{dt}")
57+
for dt in SCORE_VARIANTS
58+
],
59+
]
60+
61+
NESTED_METADATA = {
62+
"str": "value",
63+
"int": 1,
64+
"float": 1.5,
65+
"bool": True,
66+
"null": None,
67+
"list": [1, "two", {"three": 3}],
68+
"nested": {"deeper": {"key": ["a", "b"]}},
69+
}
70+
71+
72+
@pytest.mark.parametrize(("type_", "payload"), CASES)
73+
def test_metadata_omitted_parses_as_none(type_, payload):
74+
assert "metadata" not in payload
75+
76+
parsed = parse_obj_as(type_, payload)
77+
78+
assert parsed.metadata is None
79+
80+
81+
@pytest.mark.parametrize(("type_", "payload"), CASES)
82+
def test_metadata_null_parses_as_none(type_, payload):
83+
parsed = parse_obj_as(type_, {**payload, "metadata": None})
84+
85+
assert parsed.metadata is None
86+
87+
88+
@pytest.mark.parametrize(("type_", "payload"), CASES)
89+
def test_metadata_empty_object_parses(type_, payload):
90+
parsed = parse_obj_as(type_, {**payload, "metadata": {}})
91+
92+
assert parsed.metadata == {}
93+
94+
95+
@pytest.mark.parametrize(("type_", "payload"), CASES)
96+
def test_metadata_object_with_nested_json_values_parses(type_, payload):
97+
parsed = parse_obj_as(type_, {**payload, "metadata": NESTED_METADATA})
98+
99+
assert parsed.metadata == NESTED_METADATA
100+
101+
102+
@pytest.mark.parametrize(("type_", "payload"), CASES)
103+
@pytest.mark.parametrize(
104+
"metadata",
105+
["a string", 1, 1.5, True, ["a", "list"]],
106+
ids=["str", "int", "float", "bool", "list"],
107+
)
108+
def test_metadata_non_object_is_rejected(type_, payload, metadata):
109+
with pytest.raises(pydantic.ValidationError) as exc_info:
110+
parse_obj_as(type_, {**payload, "metadata": metadata})
111+
112+
# The discriminated unions prefix the location with the variant tag.
113+
assert exc_info.value.errors()
114+
assert all("metadata" in error["loc"] for error in exc_info.value.errors())

0 commit comments

Comments
 (0)