piphi-runtime-testkit-python 0.3.1__py3-none-any.whl → 0.3.3__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.
- piphi_runtime_testkit_python/__init__.py +4 -0
- piphi_runtime_testkit_python/behavior_contract.py +116 -13
- piphi_runtime_testkit_python/cross_contract.py +26 -7
- {piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/METADATA +1 -1
- {piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/RECORD +8 -8
- {piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/WHEEL +0 -0
- {piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/entry_points.txt +0 -0
- {piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -32,6 +32,8 @@ from .camera import (
|
|
|
32
32
|
from .behavior_contract import (
|
|
33
33
|
BehaviorTelemetryIssue,
|
|
34
34
|
assert_behavior_conditions_match_telemetry,
|
|
35
|
+
assert_behavior_conditions_match_state,
|
|
36
|
+
find_behavior_state_issues,
|
|
35
37
|
find_behavior_telemetry_issues,
|
|
36
38
|
)
|
|
37
39
|
from .mock_core import CapturedRequest, MockCoreServer, RUNTIME_CONFIG_FETCH_PATH
|
|
@@ -77,6 +79,7 @@ __all__ = [
|
|
|
77
79
|
"assert_onboarding_declaration",
|
|
78
80
|
"assert_camera_capability",
|
|
79
81
|
"assert_behavior_conditions_match_telemetry",
|
|
82
|
+
"assert_behavior_conditions_match_state",
|
|
80
83
|
"assert_event_sent",
|
|
81
84
|
"assert_event_payload",
|
|
82
85
|
"assert_never_event",
|
|
@@ -95,6 +98,7 @@ __all__ = [
|
|
|
95
98
|
"build_core_config_row",
|
|
96
99
|
"build_runtime_headers",
|
|
97
100
|
"find_behavior_telemetry_issues",
|
|
101
|
+
"find_behavior_state_issues",
|
|
98
102
|
"wait_for_event",
|
|
99
103
|
"wait_for_request",
|
|
100
104
|
"wait_for_telemetry",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Conformance checks between automation behaviors and
|
|
1
|
+
"""Conformance checks between automation behaviors and runtime observations."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ from typing import Any
|
|
|
9
9
|
|
|
10
10
|
@dataclass(frozen=True)
|
|
11
11
|
class BehaviorTelemetryIssue:
|
|
12
|
-
"""One behavior condition that cannot be evaluated from runtime
|
|
12
|
+
"""One behavior condition that cannot be evaluated from runtime samples."""
|
|
13
13
|
|
|
14
14
|
device_id: str
|
|
15
15
|
condition_id: str
|
|
@@ -55,6 +55,52 @@ def _metric_samples(
|
|
|
55
55
|
return samples
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
def _runtime_state_samples(
|
|
59
|
+
state_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any],
|
|
60
|
+
) -> list[Mapping[str, Any]]:
|
|
61
|
+
raw_samples = (
|
|
62
|
+
[state_samples] if isinstance(state_samples, Mapping) else list(state_samples)
|
|
63
|
+
)
|
|
64
|
+
samples: list[Mapping[str, Any]] = []
|
|
65
|
+
|
|
66
|
+
def append_state(value: Any) -> None:
|
|
67
|
+
state = _as_mapping(value)
|
|
68
|
+
if not state:
|
|
69
|
+
return
|
|
70
|
+
nested_state = state.get("state")
|
|
71
|
+
if isinstance(nested_state, Mapping):
|
|
72
|
+
state = nested_state
|
|
73
|
+
samples.append(state)
|
|
74
|
+
components = state.get("components")
|
|
75
|
+
if isinstance(components, Mapping):
|
|
76
|
+
samples.extend(
|
|
77
|
+
component for component in components.values() if isinstance(component, Mapping)
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
samples.extend(
|
|
81
|
+
component
|
|
82
|
+
for component in _as_list(components)
|
|
83
|
+
if isinstance(component, Mapping)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
for raw_sample in raw_samples:
|
|
87
|
+
payload = _as_mapping(raw_sample)
|
|
88
|
+
entries = payload.get("entries")
|
|
89
|
+
if isinstance(entries, Mapping):
|
|
90
|
+
entry_values = entries.values()
|
|
91
|
+
elif isinstance(entries, (list, tuple)):
|
|
92
|
+
entry_values = entries
|
|
93
|
+
else:
|
|
94
|
+
entry_values = None
|
|
95
|
+
if entry_values is not None:
|
|
96
|
+
for entry in entry_values:
|
|
97
|
+
mapped_entry = _as_mapping(entry)
|
|
98
|
+
append_state(mapped_entry.get("latest_state", mapped_entry))
|
|
99
|
+
else:
|
|
100
|
+
append_state(payload.get("latest_state", payload))
|
|
101
|
+
return samples
|
|
102
|
+
|
|
103
|
+
|
|
58
104
|
def _field_aliases(runtime: Mapping[str, Any]) -> tuple[str, ...]:
|
|
59
105
|
raw_aliases = runtime.get("fieldAliases", runtime.get("field_aliases"))
|
|
60
106
|
return tuple(
|
|
@@ -85,6 +131,7 @@ def _condition_issue(
|
|
|
85
131
|
device_id: str,
|
|
86
132
|
samples: list[Mapping[str, Any]],
|
|
87
133
|
dynamic_condition_ids: set[str],
|
|
134
|
+
sample_kind: str = "telemetry",
|
|
88
135
|
template_id: str | None = None,
|
|
89
136
|
) -> BehaviorTelemetryIssue | None:
|
|
90
137
|
condition_id = str(condition.get("id") or condition.get("field") or "condition").strip()
|
|
@@ -134,7 +181,7 @@ def _condition_issue(
|
|
|
134
181
|
condition_id=condition_id,
|
|
135
182
|
field=field,
|
|
136
183
|
aliases=aliases,
|
|
137
|
-
reason="field was not emitted by any representative
|
|
184
|
+
reason=f"field was not emitted by any representative {sample_kind} sample",
|
|
138
185
|
template_id=template_id,
|
|
139
186
|
)
|
|
140
187
|
|
|
@@ -169,20 +216,13 @@ def _condition_leaves(node: Any) -> Iterable[Mapping[str, Any]]:
|
|
|
169
216
|
yield current
|
|
170
217
|
|
|
171
218
|
|
|
172
|
-
def
|
|
219
|
+
def _find_behavior_sample_issues(
|
|
173
220
|
behaviors: Mapping[str, Any],
|
|
174
|
-
|
|
221
|
+
samples: list[Mapping[str, Any]],
|
|
175
222
|
*,
|
|
176
223
|
dynamic_condition_ids: Iterable[str] = (),
|
|
224
|
+
sample_kind: str,
|
|
177
225
|
) -> list[BehaviorTelemetryIssue]:
|
|
178
|
-
"""Return conditions that representative runtime telemetry cannot evaluate.
|
|
179
|
-
|
|
180
|
-
``telemetry_samples`` may contain raw metric mappings or Core telemetry
|
|
181
|
-
payloads with a ``metrics`` object. Parameter-driven dynamic conditions must
|
|
182
|
-
be named explicitly in ``dynamic_condition_ids`` and tested separately.
|
|
183
|
-
"""
|
|
184
|
-
|
|
185
|
-
samples = _metric_samples(telemetry_samples)
|
|
186
226
|
dynamic_ids = {
|
|
187
227
|
str(condition_id or "").strip()
|
|
188
228
|
for condition_id in dynamic_condition_ids
|
|
@@ -216,6 +256,7 @@ def find_behavior_telemetry_issues(
|
|
|
216
256
|
device_id=device_id,
|
|
217
257
|
samples=samples,
|
|
218
258
|
dynamic_condition_ids=dynamic_ids,
|
|
259
|
+
sample_kind=sample_kind,
|
|
219
260
|
)
|
|
220
261
|
if issue:
|
|
221
262
|
issues.append(issue)
|
|
@@ -245,6 +286,7 @@ def find_behavior_telemetry_issues(
|
|
|
245
286
|
device_id=device_id,
|
|
246
287
|
samples=samples,
|
|
247
288
|
dynamic_condition_ids=dynamic_ids,
|
|
289
|
+
sample_kind=sample_kind,
|
|
248
290
|
template_id=template_id,
|
|
249
291
|
)
|
|
250
292
|
if issue:
|
|
@@ -252,6 +294,47 @@ def find_behavior_telemetry_issues(
|
|
|
252
294
|
return issues
|
|
253
295
|
|
|
254
296
|
|
|
297
|
+
def find_behavior_telemetry_issues(
|
|
298
|
+
behaviors: Mapping[str, Any],
|
|
299
|
+
telemetry_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any],
|
|
300
|
+
*,
|
|
301
|
+
dynamic_condition_ids: Iterable[str] = (),
|
|
302
|
+
) -> list[BehaviorTelemetryIssue]:
|
|
303
|
+
"""Return conditions that representative runtime telemetry cannot evaluate.
|
|
304
|
+
|
|
305
|
+
``telemetry_samples`` may contain raw metric mappings or Core telemetry
|
|
306
|
+
payloads with a ``metrics`` object. Parameter-driven dynamic conditions must
|
|
307
|
+
be named explicitly in ``dynamic_condition_ids`` and tested separately.
|
|
308
|
+
"""
|
|
309
|
+
|
|
310
|
+
return _find_behavior_sample_issues(
|
|
311
|
+
behaviors,
|
|
312
|
+
_metric_samples(telemetry_samples),
|
|
313
|
+
dynamic_condition_ids=dynamic_condition_ids,
|
|
314
|
+
sample_kind="telemetry",
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def find_behavior_state_issues(
|
|
319
|
+
behaviors: Mapping[str, Any],
|
|
320
|
+
state_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any],
|
|
321
|
+
*,
|
|
322
|
+
dynamic_condition_ids: Iterable[str] = (),
|
|
323
|
+
) -> list[BehaviorTelemetryIssue]:
|
|
324
|
+
"""Return state-backed conditions absent from representative runtime state.
|
|
325
|
+
|
|
326
|
+
Samples may be individual state mappings or a runtime ``/state`` response
|
|
327
|
+
containing ``entries`` with ``latest_state`` and nested ``components``.
|
|
328
|
+
"""
|
|
329
|
+
|
|
330
|
+
return _find_behavior_sample_issues(
|
|
331
|
+
behaviors,
|
|
332
|
+
_runtime_state_samples(state_samples),
|
|
333
|
+
dynamic_condition_ids=dynamic_condition_ids,
|
|
334
|
+
sample_kind="state",
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
|
|
255
338
|
def assert_behavior_conditions_match_telemetry(
|
|
256
339
|
behaviors: Mapping[str, Any],
|
|
257
340
|
telemetry_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any],
|
|
@@ -270,3 +353,23 @@ def assert_behavior_conditions_match_telemetry(
|
|
|
270
353
|
raise AssertionError(
|
|
271
354
|
"Behavior conditions do not match emitted telemetry:\n" + details
|
|
272
355
|
)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def assert_behavior_conditions_match_state(
|
|
359
|
+
behaviors: Mapping[str, Any],
|
|
360
|
+
state_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any],
|
|
361
|
+
*,
|
|
362
|
+
dynamic_condition_ids: Iterable[str] = (),
|
|
363
|
+
) -> None:
|
|
364
|
+
"""Fail when advertised state-backed conditions lack representative state."""
|
|
365
|
+
|
|
366
|
+
issues = find_behavior_state_issues(
|
|
367
|
+
behaviors,
|
|
368
|
+
state_samples,
|
|
369
|
+
dynamic_condition_ids=dynamic_condition_ids,
|
|
370
|
+
)
|
|
371
|
+
if issues:
|
|
372
|
+
details = "\n".join(f"- {issue.describe()}" for issue in issues)
|
|
373
|
+
raise AssertionError(
|
|
374
|
+
"Behavior conditions do not match representative runtime state:\n" + details
|
|
375
|
+
)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from collections.abc import Mapping, Set
|
|
3
|
+
from collections.abc import Iterable, Mapping, Set
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
from .assertions import assert_entities_response
|
|
7
|
-
from .behavior_contract import
|
|
7
|
+
from .behavior_contract import (
|
|
8
|
+
assert_behavior_conditions_match_state,
|
|
9
|
+
assert_behavior_conditions_match_telemetry,
|
|
10
|
+
)
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
def _mapping_keys(value: Any) -> set[str]:
|
|
@@ -18,10 +21,15 @@ def assert_cross_contract(
|
|
|
18
21
|
behaviors: Mapping[str, Any],
|
|
19
22
|
exercised_commands: Set[str],
|
|
20
23
|
captured_event_types: Set[str],
|
|
21
|
-
telemetry_samples:
|
|
24
|
+
telemetry_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any] | None = None,
|
|
25
|
+
state_samples: Iterable[Mapping[str, Any]] | Mapping[str, Any] | None = None,
|
|
22
26
|
dynamic_condition_ids: Set[str] = frozenset(),
|
|
23
27
|
) -> None:
|
|
24
|
-
"""Check manifest, runtime, behaviors, and observed execution as one contract.
|
|
28
|
+
"""Check manifest, runtime, behaviors, and observed execution as one contract.
|
|
29
|
+
|
|
30
|
+
State samples take precedence for state-backed behavior conditions. Existing
|
|
31
|
+
telemetry-only callers retain the legacy validation path.
|
|
32
|
+
"""
|
|
25
33
|
|
|
26
34
|
assert_entities_response(runtime_entities, strict=True)
|
|
27
35
|
manifest_capabilities = _mapping_keys(manifest.get("capabilities"))
|
|
@@ -63,9 +71,16 @@ def assert_cross_contract(
|
|
|
63
71
|
for device in behaviors.get("devices", [])
|
|
64
72
|
)
|
|
65
73
|
if has_conditions:
|
|
66
|
-
if
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
if state_samples is not None:
|
|
75
|
+
try:
|
|
76
|
+
assert_behavior_conditions_match_state(
|
|
77
|
+
behaviors,
|
|
78
|
+
state_samples,
|
|
79
|
+
dynamic_condition_ids=dynamic_condition_ids,
|
|
80
|
+
)
|
|
81
|
+
except AssertionError as exc:
|
|
82
|
+
issues.append(str(exc))
|
|
83
|
+
elif telemetry_samples is not None:
|
|
69
84
|
try:
|
|
70
85
|
assert_behavior_conditions_match_telemetry(
|
|
71
86
|
behaviors,
|
|
@@ -74,5 +89,9 @@ def assert_cross_contract(
|
|
|
74
89
|
)
|
|
75
90
|
except AssertionError as exc:
|
|
76
91
|
issues.append(str(exc))
|
|
92
|
+
else:
|
|
93
|
+
issues.append(
|
|
94
|
+
"behavior conditions were advertised but no state or telemetry samples were supplied"
|
|
95
|
+
)
|
|
77
96
|
if issues:
|
|
78
97
|
raise AssertionError("Cross-contract conformance failed:\n- " + "\n- ".join(issues))
|
{piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/RECORD
RENAMED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
piphi_runtime_testkit_python-0.3.
|
|
2
|
-
piphi_runtime_testkit_python-0.3.
|
|
3
|
-
piphi_runtime_testkit_python-0.3.
|
|
4
|
-
piphi_runtime_testkit_python-0.3.
|
|
5
|
-
piphi_runtime_testkit_python/__init__.py,sha256=
|
|
1
|
+
piphi_runtime_testkit_python-0.3.3.dist-info/METADATA,sha256=XqX-IsfYRcTflxIranLQdCv1JHu1wpKrmAVMoVq31r4,29685
|
|
2
|
+
piphi_runtime_testkit_python-0.3.3.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
|
|
3
|
+
piphi_runtime_testkit_python-0.3.3.dist-info/entry_points.txt,sha256=zTIXoQOJK3VVIMOfKpB5Y3vnSbyFgyU45GZCb7fLGHI,120
|
|
4
|
+
piphi_runtime_testkit_python-0.3.3.dist-info/licenses/LICENSE,sha256=pS6szQI4X7qAin1ODdoDp-XwZvsFy6ZZ28-JAwGHgzo,1070
|
|
5
|
+
piphi_runtime_testkit_python/__init__.py,sha256=Qx_XdzyZvbUnPmsfQCdaZflW5nGjLAu88WqPDQYP5iQ,2907
|
|
6
6
|
piphi_runtime_testkit_python/assertions.py,sha256=eeGhnl0yj7u7l8_svZaaSsaM87SLyEYDfYI2FbTndFM,19778
|
|
7
|
-
piphi_runtime_testkit_python/behavior_contract.py,sha256=
|
|
7
|
+
piphi_runtime_testkit_python/behavior_contract.py,sha256=uezJgOXAY5VoHK9aPtc8yvtd3fjW3NAfn-jyty5XJVI,12617
|
|
8
8
|
piphi_runtime_testkit_python/builders.py,sha256=L0ytJ4fyQyv9QOuyXYulGBfQMhQiK8tnhbXymHdRxQM,4881
|
|
9
9
|
piphi_runtime_testkit_python/camera.py,sha256=h0bKfAOuD9s8gWtVM7ONcolu_euX120DjrSH0i4p1bA,5356
|
|
10
|
-
piphi_runtime_testkit_python/cross_contract.py,sha256=
|
|
10
|
+
piphi_runtime_testkit_python/cross_contract.py,sha256=_cnbIKkng5wZcr5GlOW-LoTQOvQUfaeOVN2uBTYWX0E,4273
|
|
11
11
|
piphi_runtime_testkit_python/harness.py,sha256=Bpi0FCcOnqPCBjGDdSxWWyefle8Ub-Pfk1V5R4Mp3Mw,13067
|
|
12
12
|
piphi_runtime_testkit_python/mock_core.py,sha256=FJf2d6zJ7_ETgUk1R5CVu_O02PgJjUwZ_JBvkmzdLrc,15803
|
|
13
13
|
piphi_runtime_testkit_python/pytest_plugin.py,sha256=8LUxO-2o7PZOQeMLQ2THbtfwn2HJ91vXkwGiYipmNuw,965
|
|
14
14
|
piphi_runtime_testkit_python/waits.py,sha256=OROOtcg2JmBzvQMQWF2ftR9m0fcujLVuT_YykUF5g7c,1953
|
|
15
|
-
piphi_runtime_testkit_python-0.3.
|
|
15
|
+
piphi_runtime_testkit_python-0.3.3.dist-info/RECORD,,
|
{piphi_runtime_testkit_python-0.3.1.dist-info → piphi_runtime_testkit_python-0.3.3.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|