gooddata-eval 1.81.1.dev1__py3-none-any.whl → 1.81.1.dev3__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 +16 -0
- gooddata_eval/core/agentic/__init__.py +12 -0
- gooddata_eval/core/agentic/dashboard_skill.py +289 -24
- gooddata_eval/core/agentic/memory.py +596 -0
- gooddata_eval/core/dataset/langfuse_source.py +34 -2
- gooddata_eval/core/interaction.py +1 -0
- gooddata_eval/core/models.py +37 -1
- {gooddata_eval-1.81.1.dev1.dist-info → gooddata_eval-1.81.1.dev3.dist-info}/METADATA +44 -3
- {gooddata_eval-1.81.1.dev1.dist-info → gooddata_eval-1.81.1.dev3.dist-info}/RECORD +12 -11
- {gooddata_eval-1.81.1.dev1.dist-info → gooddata_eval-1.81.1.dev3.dist-info}/WHEEL +0 -0
- {gooddata_eval-1.81.1.dev1.dist-info → gooddata_eval-1.81.1.dev3.dist-info}/entry_points.txt +0 -0
- {gooddata_eval-1.81.1.dev1.dist-info → gooddata_eval-1.81.1.dev3.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -25,6 +25,7 @@ from gooddata_eval.core.agentic.general_question import evaluate_agentic_general
|
|
|
25
25
|
from gooddata_eval.core.agentic.guardrail import evaluate_agentic_guardrail
|
|
26
26
|
from gooddata_eval.core.agentic.kda_skill import evaluate_agentic_kda_skill
|
|
27
27
|
from gooddata_eval.core.agentic.knowledge import evaluate_agentic_knowledge
|
|
28
|
+
from gooddata_eval.core.agentic.memory import evaluate_agentic_memory
|
|
28
29
|
from gooddata_eval.core.agentic.metric_skill import evaluate_agentic_metric_skill
|
|
29
30
|
from gooddata_eval.core.agentic.search_tool import evaluate_agentic_search_tool
|
|
30
31
|
from gooddata_eval.core.agentic.visualization import evaluate_agentic_visualization
|
|
@@ -67,6 +68,7 @@ AGENTIC_TEST_KINDS = frozenset(
|
|
|
67
68
|
"agentic_what_if",
|
|
68
69
|
"agentic_agent_switcher",
|
|
69
70
|
"agentic_knowledge",
|
|
71
|
+
"agentic_memory",
|
|
70
72
|
}
|
|
71
73
|
)
|
|
72
74
|
|
|
@@ -86,6 +88,7 @@ UNGATED_AGENTIC_TEST_KINDS = frozenset({"agentic_conversation"})
|
|
|
86
88
|
# reads like a model regression.
|
|
87
89
|
#
|
|
88
90
|
# agentic_general_question, agentic_guardrail answer questions only, no tool writes
|
|
91
|
+
# agentic_memory same as agentic_general_question, plus a read of /items
|
|
89
92
|
# agentic_search search_objects, read-only by definition; an item
|
|
90
93
|
# with setup_turns runs serially (item_runs_in_parallel)
|
|
91
94
|
# vis_agentic, agentic_visualization visualizations come back as AAC proposals
|
|
@@ -95,6 +98,7 @@ PARALLEL_SAFE_TEST_KINDS = frozenset(
|
|
|
95
98
|
{
|
|
96
99
|
"agentic_general_question",
|
|
97
100
|
"agentic_guardrail",
|
|
101
|
+
"agentic_memory",
|
|
98
102
|
"agentic_search",
|
|
99
103
|
"vis_agentic",
|
|
100
104
|
"agentic_visualization",
|
|
@@ -400,6 +404,18 @@ def _dispatch_agentic(
|
|
|
400
404
|
gate=gate,
|
|
401
405
|
**lf_kw,
|
|
402
406
|
)
|
|
407
|
+
elif kind == "agentic_memory":
|
|
408
|
+
# The item carries its own memory_input and user_context.
|
|
409
|
+
return evaluate_agentic_memory(
|
|
410
|
+
host=host,
|
|
411
|
+
token=token,
|
|
412
|
+
workspace_id=workspace_id,
|
|
413
|
+
dataset_item=item,
|
|
414
|
+
k=k,
|
|
415
|
+
gate=gate,
|
|
416
|
+
agent_id=agent_id,
|
|
417
|
+
**lf_kw,
|
|
418
|
+
)
|
|
403
419
|
elif kind == "agentic_knowledge":
|
|
404
420
|
return evaluate_agentic_knowledge(
|
|
405
421
|
host=host,
|
|
@@ -61,6 +61,13 @@ from gooddata_eval.core.agentic.kda_skill import (
|
|
|
61
61
|
evaluate_agentic_kda_skill,
|
|
62
62
|
run_agentic_kda_skill,
|
|
63
63
|
)
|
|
64
|
+
from gooddata_eval.core.agentic.memory import (
|
|
65
|
+
AgenticMemorySummary,
|
|
66
|
+
MemoryAssertionError,
|
|
67
|
+
MemoryRunResult,
|
|
68
|
+
evaluate_agentic_memory,
|
|
69
|
+
run_agentic_memory,
|
|
70
|
+
)
|
|
64
71
|
from gooddata_eval.core.agentic.metric_skill import (
|
|
65
72
|
AgenticMetricSummary,
|
|
66
73
|
MetricRunResult,
|
|
@@ -92,6 +99,11 @@ evaluate_agentic_report_skill = evaluate_agentic_document_skill
|
|
|
92
99
|
run_agentic_report_skill = run_agentic_document_skill
|
|
93
100
|
|
|
94
101
|
__all__ = [
|
|
102
|
+
"run_agentic_memory",
|
|
103
|
+
"evaluate_agentic_memory",
|
|
104
|
+
"MemoryRunResult",
|
|
105
|
+
"MemoryAssertionError",
|
|
106
|
+
"AgenticMemorySummary",
|
|
95
107
|
"AgentSwitcherAssertionError",
|
|
96
108
|
"AgentSwitcherRunResult",
|
|
97
109
|
"AgenticAgentSwitcherSummary",
|
|
@@ -448,18 +448,101 @@ def _filters_of_type(dashboard: dict, filter_type: str) -> list[tuple[str, dict]
|
|
|
448
448
|
def _date_filter_mismatch(label: str, date_filter: dict, expected: dict | None) -> list[str]:
|
|
449
449
|
"""Why ``date_filter`` is not the expected range, or nothing.
|
|
450
450
|
|
|
451
|
-
``expected is None`` means all time,
|
|
452
|
-
|
|
451
|
+
``expected is None`` means all time, a date filter with neither bound. So does an
|
|
452
|
+
expectation without ``from`` and ``to``: all time, with the handling of empty dates it
|
|
453
|
+
states. A null bound reads as an absent one, as in gen-ai. An all-time filter's granularity
|
|
454
|
+
is not compared, as gen-ai treats it as the same filter at any granularity; validation
|
|
455
|
+
refuses an all-time expectation that states one.
|
|
453
456
|
"""
|
|
454
|
-
if expected is None:
|
|
455
|
-
if
|
|
457
|
+
if expected is None or _is_all_time(expected):
|
|
458
|
+
if not _is_all_time(date_filter):
|
|
456
459
|
return [f"{label}: expected all time, got from={date_filter.get('from')!r} to={date_filter.get('to')!r}"]
|
|
457
|
-
return []
|
|
460
|
+
return [] if expected is None else _empty_values_mismatch(label, date_filter, expected)
|
|
458
461
|
return [
|
|
459
|
-
f"{label}: date {key} expected {expected
|
|
462
|
+
f"{label}: date {key} expected {_date_key(expected, key)!r}, got {_date_key(date_filter, key)!r}"
|
|
460
463
|
for key in ("granularity", "from", "to")
|
|
461
|
-
if date_filter
|
|
462
|
-
]
|
|
464
|
+
if _date_key(date_filter, key) != _date_key(expected, key)
|
|
465
|
+
] + _empty_values_mismatch(label, date_filter, expected)
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
# A date filter without `granularity` is a day filter: the platform's day granularity
|
|
469
|
+
# converts to AAC with the key left out, and the agent may write it out when it edits the filter.
|
|
470
|
+
_DEFAULT_GRANULARITY = "DAY"
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _is_all_time(date_filter: dict) -> bool:
|
|
474
|
+
"""Whether a date filter, or its expectation, is all time: no bound, absent or null, as gen-ai reads it."""
|
|
475
|
+
return date_filter.get("from") is None and date_filter.get("to") is None
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def _date_key(date_filter: dict, key: str) -> object:
|
|
479
|
+
"""A date filter's value for ``key``, reading an absent ``granularity`` as the default day."""
|
|
480
|
+
if key == "granularity":
|
|
481
|
+
return date_filter.get(key, _DEFAULT_GRANULARITY)
|
|
482
|
+
return date_filter.get(key)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
# What a date filter does with rows that have no date. gen-ai writes `empty_values` only when it
|
|
486
|
+
# differs from the default, so an absent key is the default, not "unknown".
|
|
487
|
+
_EMPTY_VALUES = ("include", "exclude", "only")
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _effective_empty_values(date_filter: dict) -> object:
|
|
491
|
+
"""The filter's ``empty_values``, or the default the document leaves unsaid.
|
|
492
|
+
|
|
493
|
+
The default mirrors gen-ai's: ``include`` for an all-time filter (no bound), ``exclude``
|
|
494
|
+
for one with a range.
|
|
495
|
+
"""
|
|
496
|
+
if "empty_values" in date_filter:
|
|
497
|
+
return date_filter["empty_values"]
|
|
498
|
+
return "include" if _is_all_time(date_filter) else "exclude"
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def _empty_values_mismatch(label: str, date_filter: dict, expected: dict) -> list[str]:
|
|
502
|
+
"""Why ``date_filter`` handles empty dates differently than expected, or nothing.
|
|
503
|
+
|
|
504
|
+
Compared only when the expectation states ``empty_values``, so a case that does not look at
|
|
505
|
+
empty dates is not failed on them. Both sides are compared on their effective value: a filter
|
|
506
|
+
that leaves the key out to mean the default matches an expectation that spells that default.
|
|
507
|
+
"""
|
|
508
|
+
if "empty_values" not in expected:
|
|
509
|
+
return []
|
|
510
|
+
actual = _effective_empty_values(date_filter)
|
|
511
|
+
if actual == expected["empty_values"]:
|
|
512
|
+
return []
|
|
513
|
+
return [f"{label}: date empty_values expected {expected['empty_values']!r}, got {actual!r}"]
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def _validate_date_keys(label: str, date_range: dict, allowed: tuple[str, ...]) -> None:
|
|
517
|
+
"""A date expectation states only keys the check reads.
|
|
518
|
+
|
|
519
|
+
Raises:
|
|
520
|
+
ValueError: a key no check reads, so the case would pass whatever the dashboard holds
|
|
521
|
+
there: a misspelt one (``empty_value`` would drop the empty-dates check), one a date
|
|
522
|
+
filter carries but the check leaves alone, such as ``title`` or ``mode``, or a
|
|
523
|
+
granularity on all time.
|
|
524
|
+
"""
|
|
525
|
+
unknown = sorted(date_range.keys() - set(allowed))
|
|
526
|
+
if unknown:
|
|
527
|
+
raise ValueError(f"{label} states {unknown}, which is not one of {list(allowed)} the check compares")
|
|
528
|
+
if "granularity" in date_range and _is_all_time(date_range):
|
|
529
|
+
raise ValueError(f"{label} states a granularity on all time, which the check does not compare: {date_range!r}")
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def _validate_empty_values(label: str, date_range: dict) -> None:
|
|
533
|
+
"""An expected ``empty_values`` is one gen-ai can write, and ``only`` never sits beside a range.
|
|
534
|
+
|
|
535
|
+
Raises:
|
|
536
|
+
ValueError: an unknown value, or ``only`` with a bound, which gen-ai refuses, so the case
|
|
537
|
+
could never pass.
|
|
538
|
+
"""
|
|
539
|
+
if "empty_values" not in date_range:
|
|
540
|
+
return
|
|
541
|
+
value = date_range["empty_values"]
|
|
542
|
+
if value not in _EMPTY_VALUES:
|
|
543
|
+
raise ValueError(f"{label} empty_values must be one of {list(_EMPTY_VALUES)}, got {value!r}")
|
|
544
|
+
if value == "only" and not _is_all_time(date_range):
|
|
545
|
+
raise ValueError(f"{label} empty_values 'only' cannot sit beside a from/to range, got {date_range!r}")
|
|
463
546
|
|
|
464
547
|
|
|
465
548
|
def _check_date_range(dashboard: dict, expected: dict | None, is_edit: bool) -> list[str]:
|
|
@@ -764,13 +847,17 @@ def _filter_mismatch(label: str, actual: dict, expected: dict) -> list[str]:
|
|
|
764
847
|
"""Why ``actual`` is not the ``expected`` filter, or nothing.
|
|
765
848
|
|
|
766
849
|
A date filter is compared on its range and dataset, an attribute filter on its labels and
|
|
767
|
-
selection, both with absence significant
|
|
768
|
-
|
|
850
|
+
selection, both with absence significant -- except that a date filter without ``granularity``
|
|
851
|
+
reads as DAY, and an all-time one is not compared on granularity at all. A date filter's
|
|
852
|
+
``empty_values`` is compared only when the expectation states it. Any other kind is compared
|
|
853
|
+
on the keys the expectation names.
|
|
769
854
|
"""
|
|
770
855
|
if actual.get("type") != expected.get("type"):
|
|
771
856
|
return [f"{label} is a {actual.get('type')!r}, expected a {expected.get('type')!r}"]
|
|
772
857
|
if expected.get("type") == "date_filter":
|
|
773
|
-
keys: tuple[str, ...] =
|
|
858
|
+
keys: tuple[str, ...] = tuple(
|
|
859
|
+
k for k in _DATE_FILTER_KEYS if not (k == "granularity" and _is_all_time(expected))
|
|
860
|
+
)
|
|
774
861
|
elif expected.get("type") == "attribute_filter":
|
|
775
862
|
if selection_of(actual) != selection_of(expected):
|
|
776
863
|
return [
|
|
@@ -780,15 +867,22 @@ def _filter_mismatch(label: str, actual: dict, expected: dict) -> list[str]:
|
|
|
780
867
|
keys = ("using", "display_as")
|
|
781
868
|
else:
|
|
782
869
|
keys = tuple(k for k in expected if k != "type")
|
|
783
|
-
|
|
784
|
-
|
|
870
|
+
is_date = expected.get("type") == "date_filter"
|
|
871
|
+
failures = [
|
|
872
|
+
f"{label}: {key} expected {_date_key(expected, key) if is_date else expected.get(key)!r}, "
|
|
873
|
+
f"got {_date_key(actual, key) if is_date else actual.get(key)!r}"
|
|
785
874
|
for key in keys
|
|
786
875
|
if not (
|
|
787
876
|
_same_object_ref(actual.get(key), expected.get(key))
|
|
788
877
|
if key in ("using", "display_as")
|
|
878
|
+
else _date_key(actual, key) == _date_key(expected, key)
|
|
879
|
+
if expected.get("type") == "date_filter"
|
|
789
880
|
else actual.get(key) == expected.get(key)
|
|
790
881
|
)
|
|
791
882
|
]
|
|
883
|
+
if expected.get("type") == "date_filter":
|
|
884
|
+
failures.extend(_empty_values_mismatch(label, actual, expected))
|
|
885
|
+
return failures
|
|
792
886
|
|
|
793
887
|
|
|
794
888
|
def _same_object_ref(actual: object, expected: object) -> bool:
|
|
@@ -1019,6 +1113,93 @@ def _widget_entry(widget: dict) -> object:
|
|
|
1019
1113
|
return widget.get("visualization")
|
|
1020
1114
|
|
|
1021
1115
|
|
|
1116
|
+
# The keys a dashboard parameter carries in AAC; an expectation compares the ones it states.
|
|
1117
|
+
_PARAMETER_KEYS = ("id", "type", "value", "title", "mode")
|
|
1118
|
+
_PARAMETER_TYPES = ("STRING", "NUMBER")
|
|
1119
|
+
# AAC leaves an `active` parameter's mode out, so an absent mode is the active one.
|
|
1120
|
+
_PARAMETER_MODES = ("active", "readonly", "hidden")
|
|
1121
|
+
_DEFAULT_PARAMETER_MODE = "active"
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
def _parameter_key(parameter: dict, key: str) -> object:
|
|
1125
|
+
"""A parameter's value for ``key``, reading an absent ``mode`` as the default active one."""
|
|
1126
|
+
if key == "mode":
|
|
1127
|
+
return parameter.get(key, _DEFAULT_PARAMETER_MODE)
|
|
1128
|
+
return parameter.get(key)
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
def _check_parameters(dashboard: dict, expected: list[dict]) -> list[str]:
|
|
1132
|
+
"""The dashboard must hold exactly the expected parameters, each on the expected tab.
|
|
1133
|
+
|
|
1134
|
+
A flat dashboard keeps them at the root, a tabbed one on each tab. The expectation describes
|
|
1135
|
+
every parameter the dashboard holds, so a tab it does not name must hold none: a tab the agent
|
|
1136
|
+
adds has an id minted at run time, and a parameter copied onto it is a change the case has to
|
|
1137
|
+
catch. A tabbed dashboard with root parameters beside its tabs fails too, as the client refuses
|
|
1138
|
+
a document with both.
|
|
1139
|
+
|
|
1140
|
+
A parameter is matched by ``id`` and compared on the other keys its entry states, ``null``
|
|
1141
|
+
asserting the key is absent -- ``"value": null`` is a parameter without its own value. An
|
|
1142
|
+
absent ``mode`` reads as ``active``, the mode AAC leaves out.
|
|
1143
|
+
"""
|
|
1144
|
+
failures: list[str] = []
|
|
1145
|
+
tabbed = bool(dashboard.get("tabs"))
|
|
1146
|
+
if tabbed and dashboard.get("parameters"):
|
|
1147
|
+
failures.append("the dashboard carries root parameters beside its tabs")
|
|
1148
|
+
named: set[str | None] = set()
|
|
1149
|
+
for entry in expected:
|
|
1150
|
+
tab, where = _named_tab(dashboard, entry.get("tab"))
|
|
1151
|
+
if tab is None:
|
|
1152
|
+
failures.append(where)
|
|
1153
|
+
continue
|
|
1154
|
+
named.add(tab.get("id"))
|
|
1155
|
+
actual, held_failures = _parameters_held(tab if tabbed else dashboard, where)
|
|
1156
|
+
failures.extend(held_failures)
|
|
1157
|
+
for want in entry["parameters"]:
|
|
1158
|
+
got = actual.pop(want["id"], None)
|
|
1159
|
+
if got is None:
|
|
1160
|
+
failures.append(f"{where} lost parameter {want['id']!r}")
|
|
1161
|
+
continue
|
|
1162
|
+
failures.extend(
|
|
1163
|
+
f"{where} parameter {want['id']!r}: {key} expected {want[key]!r}, got {_parameter_key(got, key)!r}"
|
|
1164
|
+
for key in want
|
|
1165
|
+
if key != "id" and not _same_parameter_value(_parameter_key(got, key), want[key])
|
|
1166
|
+
)
|
|
1167
|
+
failures.extend(f"{where} carries unexpected parameter {pid!r}" for pid in actual)
|
|
1168
|
+
for tab in dashboard.get("tabs") or []:
|
|
1169
|
+
if tab.get("id") in named:
|
|
1170
|
+
continue
|
|
1171
|
+
actual, held_failures = _parameters_held(tab, f"tab {tab.get('id')!r}")
|
|
1172
|
+
failures.extend(held_failures)
|
|
1173
|
+
failures.extend(f"tab {tab.get('id')!r} carries unexpected parameter {pid!r}" for pid in actual)
|
|
1174
|
+
return failures
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
def _same_parameter_value(actual: object, expected: object) -> bool:
|
|
1178
|
+
"""Equal, without Python's ``True == 1``: a bool on one side only is a different value."""
|
|
1179
|
+
if isinstance(actual, bool) != isinstance(expected, bool):
|
|
1180
|
+
return False
|
|
1181
|
+
return actual == expected
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
def _parameters_held(holder: dict, where: str) -> tuple[dict[str, dict], list[str]]:
|
|
1185
|
+
"""The parameters a tab or flat dashboard holds, by id, and why any of them is unreadable."""
|
|
1186
|
+
held: dict[str, dict] = {}
|
|
1187
|
+
failures: list[str] = []
|
|
1188
|
+
for parameter in holder.get("parameters") or []:
|
|
1189
|
+
if not isinstance(parameter, dict):
|
|
1190
|
+
failures.append(f"{where} carries a parameter that is not an object: {parameter!r}")
|
|
1191
|
+
continue
|
|
1192
|
+
parameter_id = parameter.get("id")
|
|
1193
|
+
if not (isinstance(parameter_id, str) and parameter_id):
|
|
1194
|
+
failures.append(f"{where} carries a parameter without a string id: {parameter!r}")
|
|
1195
|
+
continue
|
|
1196
|
+
if parameter_id in held:
|
|
1197
|
+
failures.append(f"{where} carries parameter {parameter_id!r} more than once")
|
|
1198
|
+
continue
|
|
1199
|
+
held[parameter_id] = parameter
|
|
1200
|
+
return held, failures
|
|
1201
|
+
|
|
1202
|
+
|
|
1022
1203
|
def _check_filter_bar(dashboard: dict, expected: list[dict]) -> list[str]:
|
|
1023
1204
|
"""Each named tab must carry exactly the expected filters: the kept ones by key, the new ones by content.
|
|
1024
1205
|
|
|
@@ -1137,12 +1318,19 @@ def _date_range_text(date_range: dict | None) -> str:
|
|
|
1137
1318
|
"""
|
|
1138
1319
|
if date_range is None:
|
|
1139
1320
|
return "all time"
|
|
1140
|
-
granularity = str(date_range
|
|
1321
|
+
granularity = str(_date_key(date_range, "granularity")).lower()
|
|
1141
1322
|
start, end = date_range.get("from"), date_range.get("to")
|
|
1323
|
+
empty = {
|
|
1324
|
+
"include": ", including rows with no date",
|
|
1325
|
+
"exclude": ", excluding rows with no date",
|
|
1326
|
+
"only": ", only rows with no date",
|
|
1327
|
+
}.get(str(date_range.get("empty_values")), "")
|
|
1328
|
+
if _is_all_time(date_range) and "empty_values" in date_range:
|
|
1329
|
+
return f"all time{empty}"
|
|
1142
1330
|
if start == 0 and end == 0:
|
|
1143
|
-
return f"this {granularity}"
|
|
1331
|
+
return f"this {granularity}{empty}"
|
|
1144
1332
|
if start == -1 and end == -1:
|
|
1145
|
-
return f"last {granularity}"
|
|
1333
|
+
return f"last {granularity}{empty}"
|
|
1146
1334
|
raise ValueError(f"unsupported date_range for the simulated user: {date_range!r}")
|
|
1147
1335
|
|
|
1148
1336
|
|
|
@@ -1379,6 +1567,11 @@ def _validate_expectation(expected_output: dict) -> None:
|
|
|
1379
1567
|
# after the run has already been spent.
|
|
1380
1568
|
if date_range is not None and not isinstance(date_range, dict):
|
|
1381
1569
|
raise ValueError(f"date_range must be an object or null, got {date_range!r}")
|
|
1570
|
+
if date_range == {}:
|
|
1571
|
+
raise ValueError("date_range is empty; use null for all time or state granularity/from/to/empty_values")
|
|
1572
|
+
if date_range is not None:
|
|
1573
|
+
_validate_date_keys("date_range", date_range, ("granularity", "from", "to", "empty_values"))
|
|
1574
|
+
_validate_empty_values("date_range", date_range)
|
|
1382
1575
|
if not _is_edit(expected_output):
|
|
1383
1576
|
_date_range_text(date_range)
|
|
1384
1577
|
|
|
@@ -1472,16 +1665,14 @@ def _validate_layout_expectations(expected_output: dict) -> None:
|
|
|
1472
1665
|
if date_range is not None and not isinstance(date_range, dict):
|
|
1473
1666
|
raise ValueError(f"date_filters[{filter_id!r}] must be an object or null, got {date_range!r}")
|
|
1474
1667
|
if date_range == {}:
|
|
1475
|
-
#
|
|
1476
|
-
#
|
|
1477
|
-
raise ValueError(
|
|
1478
|
-
f"date_filters[{filter_id!r}] is empty; use null for all time or state granularity/from/to"
|
|
1479
|
-
)
|
|
1480
|
-
unknown = sorted((date_range or {}).keys() - set(_DATE_FILTER_KEYS))
|
|
1481
|
-
if unknown:
|
|
1668
|
+
# Says nothing: null already means all time, so an empty object would only hide
|
|
1669
|
+
# a typo or a forgotten range.
|
|
1482
1670
|
raise ValueError(
|
|
1483
|
-
f"date_filters[{filter_id!r}]
|
|
1671
|
+
f"date_filters[{filter_id!r}] is empty; use null for all time or state granularity/from/to/empty_values"
|
|
1484
1672
|
)
|
|
1673
|
+
if date_range:
|
|
1674
|
+
_validate_date_keys(f"date_filters[{filter_id!r}]", date_range, (*_DATE_FILTER_KEYS, "empty_values"))
|
|
1675
|
+
_validate_empty_values(f"date_filters[{filter_id!r}]", date_range)
|
|
1485
1676
|
if date_range and "date" in date_range and not _is_dataset_or_null(date_range["date"]):
|
|
1486
1677
|
raise ValueError(
|
|
1487
1678
|
f"date_filters[{filter_id!r}] date must name a date dataset or be null, got {date_range['date']!r}"
|
|
@@ -1540,6 +1731,69 @@ def _validate_layout_expectations(expected_output: dict) -> None:
|
|
|
1540
1731
|
for label, body in named:
|
|
1541
1732
|
_validate_bar_filter(label, body)
|
|
1542
1733
|
|
|
1734
|
+
if "parameters" in expected_output:
|
|
1735
|
+
for entry in _tab_entries(expected_output, "parameters", {"tab", "parameters"}):
|
|
1736
|
+
_validate_parameter_entry(entry)
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
def _validate_parameter_entry(entry: dict) -> None:
|
|
1740
|
+
"""A ``parameters`` entry lists the tab's parameters, each by a unique id and only AAC keys.
|
|
1741
|
+
|
|
1742
|
+
Raises:
|
|
1743
|
+
ValueError: the list is missing, a parameter has no id, states a key AAC does not carry,
|
|
1744
|
+
names a type or mode AAC does not have, has a title that is not a string or a value
|
|
1745
|
+
its type cannot hold, or repeats an id.
|
|
1746
|
+
"""
|
|
1747
|
+
where = f"parameters[{entry.get('tab')!r}]"
|
|
1748
|
+
parameters = entry.get("parameters")
|
|
1749
|
+
if not isinstance(parameters, list):
|
|
1750
|
+
raise ValueError(f"{where} needs parameters as a list, [] for none, got {entry!r}")
|
|
1751
|
+
seen: set[str] = set()
|
|
1752
|
+
for parameter in parameters:
|
|
1753
|
+
if not isinstance(parameter, dict) or not (isinstance(parameter.get("id"), str) and parameter["id"]):
|
|
1754
|
+
raise ValueError(f"{where} parameter must be an object with an id, got {parameter!r}")
|
|
1755
|
+
unknown = sorted(parameter.keys() - set(_PARAMETER_KEYS))
|
|
1756
|
+
if unknown:
|
|
1757
|
+
raise ValueError(
|
|
1758
|
+
f"{where} parameter {parameter['id']!r} states {unknown}, not one of {list(_PARAMETER_KEYS)}"
|
|
1759
|
+
)
|
|
1760
|
+
if "type" in parameter and parameter["type"] not in _PARAMETER_TYPES:
|
|
1761
|
+
raise ValueError(
|
|
1762
|
+
f"{where} parameter {parameter['id']!r} type must be one of {list(_PARAMETER_TYPES)}, "
|
|
1763
|
+
f"got {parameter['type']!r}"
|
|
1764
|
+
)
|
|
1765
|
+
if parameter.get("title") is not None and not isinstance(parameter["title"], str):
|
|
1766
|
+
raise ValueError(
|
|
1767
|
+
f"{where} parameter {parameter['id']!r} title must be a string, got {parameter['title']!r}"
|
|
1768
|
+
)
|
|
1769
|
+
if "mode" in parameter and parameter["mode"] not in _PARAMETER_MODES:
|
|
1770
|
+
raise ValueError(
|
|
1771
|
+
f"{where} parameter {parameter['id']!r} mode must be one of {list(_PARAMETER_MODES)}, "
|
|
1772
|
+
f"got {parameter['mode']!r}"
|
|
1773
|
+
)
|
|
1774
|
+
if parameter.get("value") is not None and not _value_fits(parameter["value"], parameter.get("type")):
|
|
1775
|
+
raise ValueError(
|
|
1776
|
+
f"{where} parameter {parameter['id']!r} value {parameter['value']!r} "
|
|
1777
|
+
f"does not fit type {parameter.get('type', 'STRING or NUMBER')}"
|
|
1778
|
+
)
|
|
1779
|
+
if parameter["id"] in seen:
|
|
1780
|
+
raise ValueError(f"{where} names parameter {parameter['id']!r} more than once")
|
|
1781
|
+
seen.add(parameter["id"])
|
|
1782
|
+
|
|
1783
|
+
|
|
1784
|
+
def _value_fits(value: object, parameter_type: object) -> bool:
|
|
1785
|
+
"""Whether AAC can hold ``value`` for a parameter of ``parameter_type`` (any type when unstated).
|
|
1786
|
+
|
|
1787
|
+
A NUMBER parameter holds a number, a STRING one a string, so ``"10"`` on a NUMBER parameter
|
|
1788
|
+
could never match what the dashboard stores.
|
|
1789
|
+
"""
|
|
1790
|
+
is_number = isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
1791
|
+
if parameter_type == "NUMBER":
|
|
1792
|
+
return is_number
|
|
1793
|
+
if parameter_type == "STRING":
|
|
1794
|
+
return isinstance(value, str)
|
|
1795
|
+
return is_number or isinstance(value, str)
|
|
1796
|
+
|
|
1543
1797
|
|
|
1544
1798
|
def _validate_bar_filter(label: str, body: object) -> None:
|
|
1545
1799
|
"""A filter ``tab_filters`` or ``filter_bar`` expects: typed, in the AAC shape, and never a group.
|
|
@@ -1558,6 +1812,9 @@ def _validate_bar_filter(label: str, body: object) -> None:
|
|
|
1558
1812
|
raise ValueError(f"{label} group must be the title of the filter group, got {body['group']!r}")
|
|
1559
1813
|
if body["type"] == "attribute_filter":
|
|
1560
1814
|
_validate_tab_attribute_filter(label, body)
|
|
1815
|
+
if body["type"] == "date_filter":
|
|
1816
|
+
_validate_date_keys(label, body, ("type", "group", *_DATE_FILTER_KEYS, "empty_values"))
|
|
1817
|
+
_validate_empty_values(label, body)
|
|
1561
1818
|
|
|
1562
1819
|
|
|
1563
1820
|
def _layout_entries(expected_output: dict) -> list[dict]:
|
|
@@ -1720,6 +1977,7 @@ class _Applies:
|
|
|
1720
1977
|
chart_types: bool = False
|
|
1721
1978
|
layout: bool = False
|
|
1722
1979
|
filter_bar: bool = False
|
|
1980
|
+
parameters: bool = False
|
|
1723
1981
|
forbidden: bool = False
|
|
1724
1982
|
answer: bool = False
|
|
1725
1983
|
# Not a check of its own but a switch over the whole set: a refusal case is scored on the
|
|
@@ -1748,6 +2006,7 @@ class _Applies:
|
|
|
1748
2006
|
chart_types=_has_chart_types(expected_output),
|
|
1749
2007
|
layout="layout" in expected_output,
|
|
1750
2008
|
filter_bar="filter_bar" in expected_output,
|
|
2009
|
+
parameters="parameters" in expected_output,
|
|
1751
2010
|
forbidden=forbidden,
|
|
1752
2011
|
answer=answer,
|
|
1753
2012
|
refusal=refusal,
|
|
@@ -1794,6 +2053,7 @@ class DashboardEvaluation:
|
|
|
1794
2053
|
chart_types_correct: bool = False
|
|
1795
2054
|
layout_correct: bool = False
|
|
1796
2055
|
filter_bar_correct: bool = False
|
|
2056
|
+
parameters_correct: bool = False
|
|
1797
2057
|
forbidden_absent: bool = True
|
|
1798
2058
|
answer_matched: bool = True
|
|
1799
2059
|
# Whether EITHER dashboard-producing tool was called at all, successful or not. Only a
|
|
@@ -1865,6 +2125,8 @@ class DashboardEvaluation:
|
|
|
1865
2125
|
checks["dashboard_layout_correct"] = self.layout_correct
|
|
1866
2126
|
if self.applies.filter_bar:
|
|
1867
2127
|
checks["dashboard_filter_bar_correct"] = self.filter_bar_correct
|
|
2128
|
+
if self.applies.parameters:
|
|
2129
|
+
checks["dashboard_parameters_correct"] = self.parameters_correct
|
|
1868
2130
|
if self.applies.forbidden:
|
|
1869
2131
|
checks["forbidden_charts_absent"] = self.forbidden_absent
|
|
1870
2132
|
if self.applies.answer:
|
|
@@ -2157,6 +2419,7 @@ def evaluate_dashboard_response(
|
|
|
2157
2419
|
)
|
|
2158
2420
|
layout_failures = _check_layout(document, new_ids, expected_output["layout"]) if applies.layout else []
|
|
2159
2421
|
filter_bar_failures = _check_filter_bar(document, expected_output["filter_bar"]) if applies.filter_bar else []
|
|
2422
|
+
parameter_failures = _check_parameters(document, expected_output["parameters"]) if applies.parameters else []
|
|
2160
2423
|
|
|
2161
2424
|
return DashboardEvaluation(
|
|
2162
2425
|
drafted=True,
|
|
@@ -2179,6 +2442,7 @@ def evaluate_dashboard_response(
|
|
|
2179
2442
|
chart_types_correct=not chart_type_failures,
|
|
2180
2443
|
layout_correct=not layout_failures,
|
|
2181
2444
|
filter_bar_correct=not filter_bar_failures,
|
|
2445
|
+
parameters_correct=not parameter_failures,
|
|
2182
2446
|
forbidden_absent=not forbidden_failures,
|
|
2183
2447
|
answer_matched=not answer_failures,
|
|
2184
2448
|
failures=[
|
|
@@ -2195,6 +2459,7 @@ def evaluate_dashboard_response(
|
|
|
2195
2459
|
*chart_type_failures,
|
|
2196
2460
|
*layout_failures,
|
|
2197
2461
|
*filter_bar_failures,
|
|
2462
|
+
*parameter_failures,
|
|
2198
2463
|
*new_failures,
|
|
2199
2464
|
*answer_failures,
|
|
2200
2465
|
],
|