gooddata-eval 1.80.1.dev1__py3-none-any.whl → 1.80.1.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gooddata_eval/cli/agentic_runner.py +3 -3
- gooddata_eval/cli/main.py +2 -2
- gooddata_eval/core/agentic/_filters.py +50 -0
- gooddata_eval/core/agentic/_langfuse.py +3 -3
- gooddata_eval/core/agentic/_trace_linker.py +2 -2
- gooddata_eval/core/agentic/dashboard_skill.py +234 -66
- gooddata_eval/core/agentic/document_skill.py +308 -23
- gooddata_eval/core/dataset/from_insights.py +2 -2
- gooddata_eval/core/langfuse/client.py +2 -2
- gooddata_eval/core/langfuse/observations.py +2 -2
- gooddata_eval/core/langfuse/otlp.py +3 -3
- gooddata_eval/core/langfuse/sink.py +2 -2
- gooddata_eval/core/reporting/html_report.py +2 -2
- gooddata_eval/core/runner.py +3 -3
- {gooddata_eval-1.80.1.dev1.dist-info → gooddata_eval-1.80.1.dev2.dist-info}/METADATA +5 -4
- {gooddata_eval-1.80.1.dev1.dist-info → gooddata_eval-1.80.1.dev2.dist-info}/RECORD +19 -18
- {gooddata_eval-1.80.1.dev1.dist-info → gooddata_eval-1.80.1.dev2.dist-info}/WHEEL +0 -0
- {gooddata_eval-1.80.1.dev1.dist-info → gooddata_eval-1.80.1.dev2.dist-info}/entry_points.txt +0 -0
- {gooddata_eval-1.80.1.dev1.dist-info → gooddata_eval-1.80.1.dev2.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -6,7 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
import sys
|
|
7
7
|
import time
|
|
8
8
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
9
|
-
from datetime import
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
10
|
from typing import Any, TypedDict
|
|
11
11
|
|
|
12
12
|
from gooddata_eval.core.agentic._gate import DEFAULT_GATE, EvalGate, normalize_gate
|
|
@@ -496,7 +496,7 @@ def run_agentic_items(
|
|
|
496
496
|
# latency. Drained below before this function returns, so every score is written
|
|
497
497
|
# before the caller renders a report or decides an exit code.
|
|
498
498
|
linker = BackgroundTraceLinker()
|
|
499
|
-
report.started_at = datetime.now(
|
|
499
|
+
report.started_at = datetime.now(UTC)
|
|
500
500
|
_t0 = time.perf_counter()
|
|
501
501
|
|
|
502
502
|
def _process_item(index: int, item: DatasetItem) -> ItemReport:
|
|
@@ -692,7 +692,7 @@ def run_agentic_items(
|
|
|
692
692
|
flush=True,
|
|
693
693
|
)
|
|
694
694
|
report.wall_clock_s = time.perf_counter() - _t0
|
|
695
|
-
report.finished_at = datetime.now(
|
|
695
|
+
report.finished_at = datetime.now(UTC)
|
|
696
696
|
|
|
697
697
|
if langfuse is not None:
|
|
698
698
|
try:
|
gooddata_eval/cli/main.py
CHANGED
|
@@ -5,7 +5,7 @@ import argparse
|
|
|
5
5
|
import os
|
|
6
6
|
import sys
|
|
7
7
|
import threading
|
|
8
|
-
from datetime import
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import Any, get_args
|
|
11
11
|
|
|
@@ -516,7 +516,7 @@ def _run(config: RunConfig) -> int:
|
|
|
516
516
|
_reject_power_gate_on_ungated_items(config, items)
|
|
517
517
|
_warn_if_local_dataset_cannot_link(config, agentic_items)
|
|
518
518
|
models = config.models or []
|
|
519
|
-
run_ts = datetime.now(
|
|
519
|
+
run_ts = datetime.now(UTC).strftime("%Y-%m-%d-%H-%M")
|
|
520
520
|
n_models = len(models) if models else 1
|
|
521
521
|
|
|
522
522
|
controller = WorkspaceModelController(config.host, config.token, config.workspace_id)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# (C) 2026 GoodData Corporation
|
|
2
|
+
"""Attribute filter selections and filter values, shared by the dashboard and document graders.
|
|
3
|
+
|
|
4
|
+
Both read a selection with ``selection_of``. Only the document grader compares two selections with
|
|
5
|
+
``same_selection``, ignoring the order of their values; the dashboard grader compares them as read.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def selection_of(attribute_filter: dict) -> tuple[str, list] | None:
|
|
12
|
+
"""The elements an attribute filter restricts to, or ``None`` when it restricts nothing.
|
|
13
|
+
|
|
14
|
+
An unrestricted filter is spelled as the absence of a selection, and an empty list means
|
|
15
|
+
the same thing, so both read as "all".
|
|
16
|
+
"""
|
|
17
|
+
state = attribute_filter.get("state") or {}
|
|
18
|
+
for kind in ("include", "exclude"):
|
|
19
|
+
values = state.get(kind)
|
|
20
|
+
if values:
|
|
21
|
+
return kind, list(values)
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def describe_selection(selection: tuple[str, list] | None) -> str:
|
|
26
|
+
return "all" if selection is None else f"{selection[0]} {selection[1]!r}"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def same_selection(actual: tuple[str, list] | None, expected: tuple[str, list] | None) -> bool:
|
|
30
|
+
"""Whether two selections restrict to the same elements: an include or exclude list is a set, not a sequence."""
|
|
31
|
+
if actual is None or expected is None:
|
|
32
|
+
return actual is None and expected is None
|
|
33
|
+
return actual[0] == expected[0] and same_unordered_values(expected[1], actual[1])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def same_unordered_values(want: list, got: list) -> bool:
|
|
37
|
+
"""One-to-one match in any order, with each pair of the same type.
|
|
38
|
+
|
|
39
|
+
Not sorted: AAC allows `null` among the values, and Python cannot order it with strings.
|
|
40
|
+
Not stringified: `1` and `"1"` are different values.
|
|
41
|
+
"""
|
|
42
|
+
remaining = list(got)
|
|
43
|
+
for expected in want:
|
|
44
|
+
index = next(
|
|
45
|
+
(i for i, actual in enumerate(remaining) if type(actual) is type(expected) and actual == expected), None
|
|
46
|
+
)
|
|
47
|
+
if index is None:
|
|
48
|
+
return False
|
|
49
|
+
del remaining[index]
|
|
50
|
+
return not remaining
|
|
@@ -11,7 +11,7 @@ import threading
|
|
|
11
11
|
import time
|
|
12
12
|
from collections.abc import Iterator
|
|
13
13
|
from contextlib import contextmanager
|
|
14
|
-
from datetime import datetime, timedelta
|
|
14
|
+
from datetime import UTC, datetime, timedelta
|
|
15
15
|
from typing import TYPE_CHECKING, Any
|
|
16
16
|
|
|
17
17
|
from gooddata_eval.core.agentic._trace_linker import link_cancel_event, linking_is_inline, warn_from_worker
|
|
@@ -268,7 +268,7 @@ def find_traces_per_conversation(
|
|
|
268
268
|
return dict.fromkeys(conversation_ids)
|
|
269
269
|
|
|
270
270
|
by_conv: dict[str, Any] = dict.fromkeys(conversation_ids)
|
|
271
|
-
window_end = window_end or datetime.now(
|
|
271
|
+
window_end = window_end or datetime.now(UTC)
|
|
272
272
|
pad = timedelta(seconds=_WINDOW_PADDING_SEC)
|
|
273
273
|
|
|
274
274
|
# One budget for the whole item. Per conversation it would multiply by --runs, and the
|
|
@@ -322,7 +322,7 @@ def _span_window(trace: Any, window: tuple[datetime, datetime] | None) -> tuple[
|
|
|
322
322
|
return start, end
|
|
323
323
|
if window is not None:
|
|
324
324
|
return window
|
|
325
|
-
now = datetime.now(
|
|
325
|
+
now = datetime.now(UTC)
|
|
326
326
|
return now, now
|
|
327
327
|
|
|
328
328
|
|
|
@@ -17,7 +17,7 @@ import time
|
|
|
17
17
|
from collections.abc import Callable, Iterable
|
|
18
18
|
from concurrent.futures import ThreadPoolExecutor
|
|
19
19
|
from dataclasses import dataclass
|
|
20
|
-
from datetime import
|
|
20
|
+
from datetime import UTC, datetime
|
|
21
21
|
from typing import Any, Protocol
|
|
22
22
|
|
|
23
23
|
from gooddata_eval.core._output import emit_line
|
|
@@ -100,7 +100,7 @@ def link_cancel_event() -> threading.Event | None:
|
|
|
100
100
|
|
|
101
101
|
def utc_now() -> datetime:
|
|
102
102
|
"""Now, in UTC. One spelling, so a pinned trace window cannot drift by timezone."""
|
|
103
|
-
return datetime.now(
|
|
103
|
+
return datetime.now(UTC)
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
def open_trace_window(langfuse: Any) -> tuple[Any, datetime]:
|
|
@@ -13,6 +13,7 @@ import jsonpatch
|
|
|
13
13
|
from gooddata_eval.core.agentic._clarification import all_questions
|
|
14
14
|
from gooddata_eval.core.agentic._conversation_context import CONFIRMATION_REPLY, asks_in_text, classify_reply, clip
|
|
15
15
|
from gooddata_eval.core.agentic._failed_runs import build_failed_runs
|
|
16
|
+
from gooddata_eval.core.agentic._filters import describe_selection, same_unordered_values, selection_of
|
|
16
17
|
from gooddata_eval.core.agentic._gate import (
|
|
17
18
|
DEFAULT_GATE,
|
|
18
19
|
EvalGate,
|
|
@@ -186,16 +187,41 @@ def _sections_of(dashboard: dict) -> list[dict]:
|
|
|
186
187
|
|
|
187
188
|
|
|
188
189
|
def _widgets_of(dashboard: dict) -> list[dict]:
|
|
189
|
-
"""Every widget of the dashboard, flattened across sections.
|
|
190
|
+
"""Every leaf widget of the dashboard, flattened across sections and the containers in them.
|
|
190
191
|
|
|
191
192
|
Charts are matched dashboard-wide on purpose: the expectation names charts, not a layout,
|
|
192
|
-
so which section or
|
|
193
|
-
the opposite -- ``_check_date_range`` requires *every* tab to match. That one is
|
|
194
|
-
rather than observed: ``draft_dashboard`` copies a single filter onto every tab
|
|
193
|
+
so which section, tab or container one lands on is the agent's call. The date filter is
|
|
194
|
+
deliberately the opposite -- ``_check_date_range`` requires *every* tab to match. That one is
|
|
195
|
+
defensive rather than observed: ``draft_dashboard`` copies a single filter onto every tab
|
|
195
196
|
unconditionally, so a draft cannot currently disagree with itself across tabs, and the
|
|
196
197
|
per-tab check is there to notice if that stops being true.
|
|
197
198
|
"""
|
|
198
|
-
return
|
|
199
|
+
return _leaf_widgets(_sections_of(dashboard))
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _is_container(widget: dict) -> bool:
|
|
203
|
+
"""Whether a widget is a container, named by either of its two keys.
|
|
204
|
+
|
|
205
|
+
The AAC converter writes ``container`` on every container but ``sections`` only when it has
|
|
206
|
+
some, so a saved empty container arrives with ``container`` alone.
|
|
207
|
+
"""
|
|
208
|
+
return "container" in widget or "sections" in widget
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _leaf_widgets(sections: list[dict]) -> list[dict]:
|
|
212
|
+
"""The widgets of ``sections`` in document order, each container replaced by the widgets inside it.
|
|
213
|
+
|
|
214
|
+
A switcher stays one widget, as it does at the top level, so the chart checks reading this
|
|
215
|
+
list do not see its member charts.
|
|
216
|
+
"""
|
|
217
|
+
leaves: list[dict] = []
|
|
218
|
+
for section in sections:
|
|
219
|
+
for widget in section.get("widgets") or []:
|
|
220
|
+
if _is_container(widget):
|
|
221
|
+
leaves.extend(_leaf_widgets(widget.get("sections") or []))
|
|
222
|
+
else:
|
|
223
|
+
leaves.append(widget)
|
|
224
|
+
return leaves
|
|
199
225
|
|
|
200
226
|
|
|
201
227
|
def _apply_patch(base: dict, operations: list[dict]) -> tuple[dict | None, str | None]:
|
|
@@ -468,24 +494,6 @@ def _check_date_range(dashboard: dict, expected: dict | None, is_edit: bool) ->
|
|
|
468
494
|
return [reason for m in mismatches for reason in m]
|
|
469
495
|
|
|
470
496
|
|
|
471
|
-
def _selection_of(attribute_filter: dict) -> tuple[str, list] | None:
|
|
472
|
-
"""The elements an attribute filter restricts to, or ``None`` when it restricts nothing.
|
|
473
|
-
|
|
474
|
-
An unrestricted filter is spelled as the absence of a selection, and an empty list means
|
|
475
|
-
the same thing, so both read as "all".
|
|
476
|
-
"""
|
|
477
|
-
state = attribute_filter.get("state") or {}
|
|
478
|
-
for kind in ("include", "exclude"):
|
|
479
|
-
values = state.get(kind)
|
|
480
|
-
if values:
|
|
481
|
-
return kind, list(values)
|
|
482
|
-
return None
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
def _describe_selection(selection: tuple[str, list] | None) -> str:
|
|
486
|
-
return "all" if selection is None else f"{selection[0]} {selection[1]!r}"
|
|
487
|
-
|
|
488
|
-
|
|
489
497
|
def _check_filters(dashboard: dict, expected: list[dict]) -> list[str]:
|
|
490
498
|
"""Every expected filter must be on the dashboard, with the stated selection or condition.
|
|
491
499
|
|
|
@@ -537,9 +545,9 @@ def _check_filters(dashboard: dict, expected: list[dict]) -> list[str]:
|
|
|
537
545
|
continue
|
|
538
546
|
matches = shown
|
|
539
547
|
wanted = _expected_selection(exp)
|
|
540
|
-
if not any(
|
|
541
|
-
found = ", ".join(
|
|
542
|
-
failures.append(f"filter on {using!r} selects {found}, expected {
|
|
548
|
+
if not any(selection_of(f) == wanted for f in matches):
|
|
549
|
+
found = ", ".join(describe_selection(selection_of(f)) for f in matches)
|
|
550
|
+
failures.append(f"filter on {using!r} selects {found}, expected {describe_selection(wanted)}")
|
|
543
551
|
return failures
|
|
544
552
|
|
|
545
553
|
|
|
@@ -570,7 +578,7 @@ def _filter_value_mismatch(actual: dict, expected: dict) -> list[str]:
|
|
|
570
578
|
continue
|
|
571
579
|
want, got = expected[key], actual.get(key)
|
|
572
580
|
same = (
|
|
573
|
-
|
|
581
|
+
same_unordered_values(want, got)
|
|
574
582
|
if key == "values" and isinstance(want, list) and isinstance(got, list)
|
|
575
583
|
else got == want
|
|
576
584
|
)
|
|
@@ -579,25 +587,8 @@ def _filter_value_mismatch(actual: dict, expected: dict) -> list[str]:
|
|
|
579
587
|
return mismatches
|
|
580
588
|
|
|
581
589
|
|
|
582
|
-
def _same_unordered_values(want: list, got: list) -> bool:
|
|
583
|
-
"""One-to-one match in any order, with each pair of the same type.
|
|
584
|
-
|
|
585
|
-
Not sorted: AAC allows `null` among the values, and Python cannot order it with strings.
|
|
586
|
-
Not stringified: `1` and `"1"` are different values.
|
|
587
|
-
"""
|
|
588
|
-
remaining = list(got)
|
|
589
|
-
for expected in want:
|
|
590
|
-
index = next(
|
|
591
|
-
(i for i, actual in enumerate(remaining) if type(actual) is type(expected) and actual == expected), None
|
|
592
|
-
)
|
|
593
|
-
if index is None:
|
|
594
|
-
return False
|
|
595
|
-
del remaining[index]
|
|
596
|
-
return not remaining
|
|
597
|
-
|
|
598
|
-
|
|
599
590
|
def _expected_selection(expected_filter: dict) -> tuple[str, list] | None:
|
|
600
|
-
"""Read a fixture's filter entry into the same shape ``
|
|
591
|
+
"""Read a fixture's filter entry into the same shape ``selection_of`` produces.
|
|
601
592
|
|
|
602
593
|
Raises:
|
|
603
594
|
ValueError: the entry states no selection the evaluator knows how to check.
|
|
@@ -747,7 +738,7 @@ def _check_tabs(dashboard: dict, new_ids: set[str], expected: list[dict]) -> lis
|
|
|
747
738
|
for index, (tab, exp) in enumerate(zip(tabs, expected)):
|
|
748
739
|
if "title" in exp and _norm(str(tab.get("title") or "")) != _norm(str(exp["title"] or "")):
|
|
749
740
|
failures.append(f"tab {index} is titled {tab.get('title')!r}, expected {exp['title']!r}")
|
|
750
|
-
tab_widgets =
|
|
741
|
+
tab_widgets = _leaf_widgets(tab.get("sections") or [])
|
|
751
742
|
failures.extend(
|
|
752
743
|
f"tab {index} ({tab.get('title')!r}) does not hold chart {chart!r}"
|
|
753
744
|
for chart in exp.get("visualizations") or []
|
|
@@ -773,10 +764,10 @@ def _filter_mismatch(label: str, actual: dict, expected: dict) -> list[str]:
|
|
|
773
764
|
if expected.get("type") == "date_filter":
|
|
774
765
|
keys: tuple[str, ...] = _DATE_FILTER_KEYS
|
|
775
766
|
elif expected.get("type") == "attribute_filter":
|
|
776
|
-
if
|
|
767
|
+
if selection_of(actual) != selection_of(expected):
|
|
777
768
|
return [
|
|
778
|
-
f"{label} selects {
|
|
779
|
-
f"expected {
|
|
769
|
+
f"{label} selects {describe_selection(selection_of(actual))}, "
|
|
770
|
+
f"expected {describe_selection(selection_of(expected))}"
|
|
780
771
|
]
|
|
781
772
|
keys = ("using", "display_as")
|
|
782
773
|
else:
|
|
@@ -902,15 +893,20 @@ def _named_tab(dashboard: dict, tab_id: str | None) -> tuple[dict | None, str]:
|
|
|
902
893
|
|
|
903
894
|
|
|
904
895
|
def _check_layout(dashboard: dict, new_ids: set[str], expected: list[dict]) -> list[str]:
|
|
905
|
-
"""Each named
|
|
896
|
+
"""Each named layout must hold exactly the expected sections, in order, each with exactly its widgets in order.
|
|
906
897
|
|
|
907
898
|
Exact on purpose. A move that leaves the widget where it was, places a second copy, or puts
|
|
908
899
|
it in the wrong section keeps every chart "on the dashboard", and so does a removal that
|
|
909
|
-
never happened; only the whole arrangement tells them apart.
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
900
|
+
never happened; only the whole arrangement tells them apart.
|
|
901
|
+
|
|
902
|
+
The layout is a tab's own, or with ``container_path`` the container that path reaches from
|
|
903
|
+
it, compared on ``layout_direction`` too when the entry states it. A section's ``title`` is
|
|
904
|
+
compared when the entry states it, ``null`` meaning untitled. Its ``visualizations`` list the
|
|
905
|
+
charts, ``[]`` for a section without any, and the widgets that show no visualization are
|
|
906
|
+
left out on both sides. Its ``widgets`` instead list every child: a chart is an id, or
|
|
907
|
+
``{"title": ...}`` for one the agent authored, a note ``{"text": ...}`` and a switcher
|
|
908
|
+
``{"switcher": [charts]}``, which is how a swap of a note and a chart, or a switcher taken
|
|
909
|
+
apart, is told from the arrangement asked for.
|
|
914
910
|
"""
|
|
915
911
|
failures: list[str] = []
|
|
916
912
|
for entry in expected:
|
|
@@ -919,6 +915,16 @@ def _check_layout(dashboard: dict, new_ids: set[str], expected: list[dict]) -> l
|
|
|
919
915
|
failures.append(where)
|
|
920
916
|
continue
|
|
921
917
|
sections = tab.get("sections") or []
|
|
918
|
+
if "container_path" in entry:
|
|
919
|
+
container, where = _container_at(sections, entry["container_path"], where)
|
|
920
|
+
if container is None:
|
|
921
|
+
failures.append(where)
|
|
922
|
+
continue
|
|
923
|
+
sections = container.get("sections") or []
|
|
924
|
+
# The converter writes no direction for a row, and the dashboard lays a container out as one.
|
|
925
|
+
direction = container.get("layout_direction") or "row"
|
|
926
|
+
if "layout_direction" in entry and direction != entry["layout_direction"]:
|
|
927
|
+
failures.append(f"{where} is laid out as a {direction}, expected a {entry['layout_direction']}")
|
|
922
928
|
wanted = entry["sections"]
|
|
923
929
|
if len(sections) != len(wanted):
|
|
924
930
|
titles = ", ".join(repr(s.get("title")) for s in sections)
|
|
@@ -929,6 +935,14 @@ def _check_layout(dashboard: dict, new_ids: set[str], expected: list[dict]) -> l
|
|
|
929
935
|
failures.append(
|
|
930
936
|
f"{where} section {index} is titled {section.get('title')!r}, expected {want['title']!r}"
|
|
931
937
|
)
|
|
938
|
+
if "widgets" in want:
|
|
939
|
+
children = section.get("widgets") or []
|
|
940
|
+
if len(children) != len(want["widgets"]) or not all(
|
|
941
|
+
_holds(w, new_ids, c) for w, c in zip(children, want["widgets"], strict=True)
|
|
942
|
+
):
|
|
943
|
+
shown = [_widget_entry(w) for w in children]
|
|
944
|
+
failures.append(f"{where} section {index} holds {shown}, expected {want['widgets']}")
|
|
945
|
+
continue
|
|
932
946
|
charts = [w for w in section.get("widgets") or [] if w.get("visualization")]
|
|
933
947
|
charts_wanted = want["visualizations"]
|
|
934
948
|
if len(charts) != len(charts_wanted) or not all(
|
|
@@ -939,6 +953,64 @@ def _check_layout(dashboard: dict, new_ids: set[str], expected: list[dict]) -> l
|
|
|
939
953
|
return failures
|
|
940
954
|
|
|
941
955
|
|
|
956
|
+
def _container_at(sections: list[dict], path: list[dict], where: str) -> tuple[dict | None, str]:
|
|
957
|
+
"""The container ``path`` reaches from ``sections``, and how to name it in a failure.
|
|
958
|
+
|
|
959
|
+
Each hop is a section and a widget index inside the layout the previous hop reached. A hop
|
|
960
|
+
that lands on nothing, or on a widget that is not a container, gives ``None`` and the reason:
|
|
961
|
+
the result left no container where the case expects one, which fails the case.
|
|
962
|
+
"""
|
|
963
|
+
container: dict | None = None
|
|
964
|
+
for depth, hop in enumerate(path):
|
|
965
|
+
at = f"section {hop['section']}, widget_index {hop['widget_index']}"
|
|
966
|
+
widgets = (sections[hop["section"]].get("widgets") or []) if hop["section"] < len(sections) else []
|
|
967
|
+
if hop["widget_index"] >= len(widgets):
|
|
968
|
+
return None, f"{where} has no widget at {at}"
|
|
969
|
+
container = widgets[hop["widget_index"]]
|
|
970
|
+
if not _is_container(container):
|
|
971
|
+
return None, f"{where} holds {_widget_entry(container)!r} at {at}, not a container"
|
|
972
|
+
where = f"{where} {'container at' if depth == 0 else '>'} {at}"
|
|
973
|
+
sections = container.get("sections") or []
|
|
974
|
+
return container, where
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
def _holds(widget: dict, new_ids: set[str], expected: str | dict) -> bool:
|
|
978
|
+
"""Whether ``widget`` is the child a layout section's ``widgets`` entry names.
|
|
979
|
+
|
|
980
|
+
The widget is read as the kind ``_widget_entry`` names it, so a widget carrying the keys of
|
|
981
|
+
two kinds matches only the one it renders as.
|
|
982
|
+
"""
|
|
983
|
+
shown = _widget_entry(widget)
|
|
984
|
+
if isinstance(expected, dict) and "text" in expected:
|
|
985
|
+
return shown == expected
|
|
986
|
+
if isinstance(expected, dict) and "switcher" in expected:
|
|
987
|
+
members = widget.get("visualizations") or []
|
|
988
|
+
return (
|
|
989
|
+
isinstance(shown, dict)
|
|
990
|
+
and "switcher" in shown
|
|
991
|
+
and len(members) == len(expected["switcher"])
|
|
992
|
+
and all(
|
|
993
|
+
_matching_widgets([m], new_ids, _chart_entry(c))
|
|
994
|
+
for m, c in zip(members, expected["switcher"], strict=True)
|
|
995
|
+
)
|
|
996
|
+
)
|
|
997
|
+
return not isinstance(shown, dict) and bool(_matching_widgets([widget], new_ids, _chart_entry(expected)))
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
def _widget_entry(widget: dict) -> object:
|
|
1001
|
+
"""A child widget written the way a layout section's ``widgets`` entry names it, for a failure message.
|
|
1002
|
+
|
|
1003
|
+
Kinds are read in the converter's order, container first, so a widget is named as it renders.
|
|
1004
|
+
"""
|
|
1005
|
+
if _is_container(widget):
|
|
1006
|
+
return {"container": widget.get("container")}
|
|
1007
|
+
if "visualizations" in widget:
|
|
1008
|
+
return {"switcher": [m.get("visualization") for m in widget["visualizations"] or []]}
|
|
1009
|
+
if "content" in widget:
|
|
1010
|
+
return {"text": widget["content"]}
|
|
1011
|
+
return widget.get("visualization")
|
|
1012
|
+
|
|
1013
|
+
|
|
942
1014
|
def _check_filter_bar(dashboard: dict, expected: list[dict]) -> list[str]:
|
|
943
1015
|
"""Each named tab must carry exactly the expected filters: the kept ones by key, the new ones by content.
|
|
944
1016
|
|
|
@@ -1416,24 +1488,34 @@ def _validate_layout_expectations(expected_output: dict) -> None:
|
|
|
1416
1488
|
raise ValueError(f"a preserved widget needs its visualization and a key to guard, got {widget!r}")
|
|
1417
1489
|
|
|
1418
1490
|
if "layout" in expected_output:
|
|
1419
|
-
for entry in
|
|
1491
|
+
for entry in _layout_entries(expected_output):
|
|
1420
1492
|
sections = entry.get("sections")
|
|
1421
1493
|
if not isinstance(sections, list):
|
|
1422
1494
|
raise ValueError(f"a layout entry needs its sections as a list, got {entry!r}")
|
|
1423
1495
|
for section in sections:
|
|
1424
|
-
if not isinstance(section, dict) or section.keys() - {"title", "visualizations"}:
|
|
1425
|
-
raise ValueError(
|
|
1496
|
+
if not isinstance(section, dict) or section.keys() - {"title", "visualizations", "widgets"}:
|
|
1497
|
+
raise ValueError(
|
|
1498
|
+
f"a layout section takes only title and visualizations or widgets, got {section!r}"
|
|
1499
|
+
)
|
|
1426
1500
|
if section.get("title") is not None and not isinstance(section["title"], str):
|
|
1427
1501
|
raise ValueError(f"a layout section's title must be a string or null, got {section!r}")
|
|
1428
|
-
if "visualizations"
|
|
1502
|
+
if ("visualizations" in section) == ("widgets" in section):
|
|
1429
1503
|
# Missing would read as "no charts" here but as "any charts" in `tabs`.
|
|
1430
|
-
raise ValueError(
|
|
1504
|
+
raise ValueError(
|
|
1505
|
+
f"a layout section must list either its visualizations or its widgets, [] for none, "
|
|
1506
|
+
f"got {section!r}"
|
|
1507
|
+
)
|
|
1508
|
+
if "widgets" in section:
|
|
1509
|
+
if not isinstance(section["widgets"], list) or not all(
|
|
1510
|
+
_is_widget_entry(w) for w in section["widgets"]
|
|
1511
|
+
):
|
|
1512
|
+
raise ValueError(
|
|
1513
|
+
"a layout section's widgets must be chart ids, {'title': ...}, {'text': ...} or "
|
|
1514
|
+
f"{{'switcher': [charts]}}, got {section!r}"
|
|
1515
|
+
)
|
|
1516
|
+
continue
|
|
1431
1517
|
charts = section["visualizations"]
|
|
1432
|
-
if not isinstance(charts, list) or not all(
|
|
1433
|
-
(isinstance(c, str) and c)
|
|
1434
|
-
or (isinstance(c, dict) and c.keys() == {"title"} and isinstance(c["title"], str) and c["title"])
|
|
1435
|
-
for c in charts
|
|
1436
|
-
):
|
|
1518
|
+
if not isinstance(charts, list) or not all(_is_chart_entry(c) for c in charts):
|
|
1437
1519
|
raise ValueError(
|
|
1438
1520
|
f"a layout section's visualizations must be chart ids or {{'title': ...}}, got {section!r}"
|
|
1439
1521
|
)
|
|
@@ -1470,8 +1552,94 @@ def _validate_bar_filter(label: str, body: object) -> None:
|
|
|
1470
1552
|
_validate_tab_attribute_filter(label, body)
|
|
1471
1553
|
|
|
1472
1554
|
|
|
1555
|
+
def _layout_entries(expected_output: dict) -> list[dict]:
|
|
1556
|
+
"""The entries of ``layout``, each naming one layout: a tab's own, or a container on it by path.
|
|
1557
|
+
|
|
1558
|
+
Raises:
|
|
1559
|
+
ValueError: not a non-empty list of objects, an unknown key, a malformed tab, path or
|
|
1560
|
+
direction, or one layout named twice. A layout is its tab and its path, the tab's own
|
|
1561
|
+
layout having none, so one tab can hold several entries. An entry without ``tab`` is
|
|
1562
|
+
for a dashboard with one tab, so it cannot sit beside an entry that names a tab: both
|
|
1563
|
+
could name that one tab.
|
|
1564
|
+
"""
|
|
1565
|
+
entries = expected_output["layout"]
|
|
1566
|
+
if not isinstance(entries, list) or not entries or not all(isinstance(e, dict) for e in entries):
|
|
1567
|
+
raise ValueError(f"layout must be a non-empty list of layout objects, got {entries!r}")
|
|
1568
|
+
seen: set[tuple[str | None, tuple[tuple[int, int], ...]]] = set()
|
|
1569
|
+
for entry in entries:
|
|
1570
|
+
unknown = sorted(entry.keys() - {"tab", "container_path", "layout_direction", "sections"})
|
|
1571
|
+
if unknown:
|
|
1572
|
+
raise ValueError(f"a layout entry cannot state {unknown}, got {entry!r}")
|
|
1573
|
+
tab = entry.get("tab")
|
|
1574
|
+
if tab is not None and not (isinstance(tab, str) and tab):
|
|
1575
|
+
raise ValueError(f"a layout entry's tab must be a tab id, got {entry!r}")
|
|
1576
|
+
path = _container_path(entry)
|
|
1577
|
+
if "layout_direction" in entry and (not path or entry["layout_direction"] not in ("row", "column")):
|
|
1578
|
+
raise ValueError(f"a layout entry's layout_direction is 'row' or 'column' on a container, got {entry!r}")
|
|
1579
|
+
if (tab, path) in seen:
|
|
1580
|
+
target = f"the container at {entry['container_path']}" if path else "the layout"
|
|
1581
|
+
owner = "the dashboard" if tab is None else f"tab {tab!r}"
|
|
1582
|
+
raise ValueError(f"layout names {target} of {owner} more than once")
|
|
1583
|
+
seen.add((tab, path))
|
|
1584
|
+
tabs = {tab for tab, _ in seen}
|
|
1585
|
+
if None in tabs and len(tabs) > 1:
|
|
1586
|
+
raise ValueError(f"a layout entry without tab cannot sit beside one that names a tab, got {entries!r}")
|
|
1587
|
+
return entries
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
def _container_path(entry: dict) -> tuple[tuple[int, int], ...]:
|
|
1591
|
+
"""A layout entry's ``container_path`` as ``(section, widget_index)`` hops, ``()`` for the tab's own layout.
|
|
1592
|
+
|
|
1593
|
+
Raises:
|
|
1594
|
+
ValueError: present, but not a non-empty list of hops that each carry exactly a
|
|
1595
|
+
non-negative ``section`` and ``widget_index``. ``null`` and ``[]`` are refused rather
|
|
1596
|
+
than read as the tab's own layout: leaving the key out says that.
|
|
1597
|
+
"""
|
|
1598
|
+
if "container_path" not in entry:
|
|
1599
|
+
return ()
|
|
1600
|
+
path = entry["container_path"]
|
|
1601
|
+
# bool is an int, so `True` would otherwise read as index 1.
|
|
1602
|
+
if (
|
|
1603
|
+
not isinstance(path, list)
|
|
1604
|
+
or not path
|
|
1605
|
+
or not all(
|
|
1606
|
+
isinstance(hop, dict)
|
|
1607
|
+
and hop.keys() == {"section", "widget_index"}
|
|
1608
|
+
and all(isinstance(i, int) and not isinstance(i, bool) and i >= 0 for i in hop.values())
|
|
1609
|
+
for hop in path
|
|
1610
|
+
)
|
|
1611
|
+
):
|
|
1612
|
+
raise ValueError(
|
|
1613
|
+
f"a layout entry's container_path must be a non-empty list of {{'section', 'widget_index'}} hops, "
|
|
1614
|
+
f"got {entry!r}"
|
|
1615
|
+
)
|
|
1616
|
+
return tuple((hop["section"], hop["widget_index"]) for hop in path)
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
def _is_chart_entry(entry: object) -> bool:
|
|
1620
|
+
"""A chart as a layout section names it: an id, or ``{"title": ...}`` for one the agent authored."""
|
|
1621
|
+
return (isinstance(entry, str) and bool(entry)) or (
|
|
1622
|
+
isinstance(entry, dict)
|
|
1623
|
+
and entry.keys() == {"title"}
|
|
1624
|
+
and isinstance(entry["title"], str)
|
|
1625
|
+
and bool(entry["title"])
|
|
1626
|
+
)
|
|
1627
|
+
|
|
1628
|
+
|
|
1629
|
+
def _is_widget_entry(entry: object) -> bool:
|
|
1630
|
+
"""A child as a layout section's ``widgets`` names it: a chart, ``{"text": ...}`` or ``{"switcher": [charts]}``."""
|
|
1631
|
+
if _is_chart_entry(entry):
|
|
1632
|
+
return True
|
|
1633
|
+
if not isinstance(entry, dict) or len(entry) != 1:
|
|
1634
|
+
return False
|
|
1635
|
+
if "text" in entry:
|
|
1636
|
+
return isinstance(entry["text"], str)
|
|
1637
|
+
charts = entry.get("switcher")
|
|
1638
|
+
return isinstance(charts, list) and bool(charts) and all(_is_chart_entry(c) for c in charts)
|
|
1639
|
+
|
|
1640
|
+
|
|
1473
1641
|
def _tab_entries(expected_output: dict, key: str, allowed: set[str]) -> list[dict]:
|
|
1474
|
-
"""The entries of a per-tab expectation
|
|
1642
|
+
"""The entries of a per-tab expectation such as ``filter_bar``, checked for the shape they share.
|
|
1475
1643
|
|
|
1476
1644
|
Raises:
|
|
1477
1645
|
ValueError: not a non-empty list of objects, a key outside ``allowed``, or a tab named
|