piphi-runtime-testkit-python 0.2.0__tar.gz → 0.3.0__tar.gz

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.
Files changed (30) hide show
  1. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/PKG-INFO +102 -5
  2. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/README.md +99 -4
  3. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/pyproject.toml +6 -1
  4. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/src/piphi_runtime_testkit_python/__init__.py +50 -0
  5. piphi_runtime_testkit_python-0.3.0/src/piphi_runtime_testkit_python/assertions.py +434 -0
  6. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/src/piphi_runtime_testkit_python/behavior_contract.py +4 -0
  7. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/src/piphi_runtime_testkit_python/builders.py +56 -0
  8. piphi_runtime_testkit_python-0.3.0/src/piphi_runtime_testkit_python/cross_contract.py +78 -0
  9. piphi_runtime_testkit_python-0.3.0/src/piphi_runtime_testkit_python/harness.py +334 -0
  10. piphi_runtime_testkit_python-0.3.0/src/piphi_runtime_testkit_python/mock_core.py +415 -0
  11. piphi_runtime_testkit_python-0.3.0/src/piphi_runtime_testkit_python/waits.py +83 -0
  12. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_assertions.py +11 -0
  13. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_behavior_contract.py +10 -0
  14. piphi_runtime_testkit_python-0.3.0/tests/test_command_contract.py +74 -0
  15. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_fastapi_runtime_example.py +2 -12
  16. piphi_runtime_testkit_python-0.3.0/tests/test_mock_core_sequences.py +70 -0
  17. piphi_runtime_testkit_python-0.3.0/tests/test_runtime_harness.py +98 -0
  18. piphi_runtime_testkit_python-0.3.0/tests/test_strict_contracts.py +140 -0
  19. piphi_runtime_testkit_python-0.2.0/src/piphi_runtime_testkit_python/assertions.py +0 -204
  20. piphi_runtime_testkit_python-0.2.0/src/piphi_runtime_testkit_python/mock_core.py +0 -228
  21. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/LICENSE +0 -0
  22. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/src/piphi_runtime_testkit_python/camera.py +0 -0
  23. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/src/piphi_runtime_testkit_python/pytest_plugin.py +0 -0
  24. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/__init__.py +0 -0
  25. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_builders.py +0 -0
  26. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_camera.py +0 -0
  27. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_mock_core.py +0 -0
  28. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_pytest_plugin.py +0 -0
  29. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_runtime_config_contract.py +0 -0
  30. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.0}/tests/test_runtime_flow.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: piphi-runtime-testkit-python
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Pytest-first helpers for testing PiPhi runtime integrations
5
5
  Keywords: piphi,pytest,testing,runtime,iot
6
6
  Author-Email: KelvinSan <support@piphi.network>
@@ -18,12 +18,88 @@ Project-URL: Repository, https://github.com/PiPhi-io/piphi-runtime-testkit-pytho
18
18
  Project-URL: Issues, https://github.com/PiPhi-io/piphi-runtime-testkit-python/issues
19
19
  Requires-Python: >=3.11
20
20
  Requires-Dist: pytest<9.0,>=8.3
21
+ Provides-Extra: asgi
22
+ Requires-Dist: httpx<1.0,>=0.27; extra == "asgi"
21
23
  Description-Content-Type: text/markdown
22
24
 
23
25
  # piphi-runtime-testkit-python
24
26
 
27
+ Validate the closed, Core-owned onboarding declaration before publishing an
28
+ integration manifest:
29
+
30
+ ```python
31
+ from piphi_runtime_testkit_python import assert_onboarding_declaration
32
+
33
+ assert_onboarding_declaration(manifest)
34
+ ```
35
+
36
+ Supported modes are `manual`, `discovery`, `account`, `service`, and `none`.
37
+
25
38
  Pytest-first helpers for testing PiPhi runtime integrations.
26
39
 
40
+ ## Runtime conformance harness
41
+
42
+ Install the ASGI/HTTP adapter extra and exercise the same public runtime routes
43
+ that Core uses:
44
+
45
+ ```bash
46
+ pip install "piphi-runtime-testkit-python[asgi]"
47
+ ```
48
+
49
+ ```python
50
+ import pytest
51
+
52
+ from piphi_runtime_testkit_python import (
53
+ ConformanceProfile,
54
+ RuntimeHarness,
55
+ build_command_payload,
56
+ build_config_payload,
57
+ )
58
+
59
+
60
+ @pytest.mark.asyncio
61
+ async def test_actuator_contract(app):
62
+ config = build_config_payload(
63
+ config_id="shelly-kitchen",
64
+ container_id="runtime-123",
65
+ extra={"host": "192.0.2.10"},
66
+ )
67
+ command = build_command_payload(
68
+ command="refresh",
69
+ config_id="shelly-kitchen",
70
+ device_id="shelly-kitchen",
71
+ )
72
+ harness = RuntimeHarness.for_asgi(
73
+ app,
74
+ headers={
75
+ "X-Container-Id": "runtime-123",
76
+ "X-PiPhi-Integration-Token": "test-token",
77
+ },
78
+ )
79
+ async with harness:
80
+ report = await harness.run_profile(
81
+ ConformanceProfile.ACTUATOR,
82
+ config=config,
83
+ command=command,
84
+ )
85
+ report.assert_passed()
86
+ ```
87
+
88
+ Pass an app factory instead of an app to make `await harness.restart()` create a
89
+ fresh process-local runtime. Use `RuntimeHarness.for_http(...)` for a running
90
+ container or process without changing scenario code.
91
+
92
+ The profiles are intentionally small and readable:
93
+
94
+ - `basic`: health, auth rejection, config, entities, and deconfigure
95
+ - `monitoring`: basic plus state
96
+ - `actuator`: monitoring plus a supplied command
97
+ - `restorable`: monitoring plus config sync and restart
98
+ - `sidecar`: health-only process conformance
99
+
100
+ See [the API guide](docs/API.md) for strict contracts, programmable Core
101
+ responses, deterministic waits, and cross-contract checks.
102
+
27
103
  This package exists to make integration tests easier to write, easier to read,
28
104
  and easier to debug. It is designed for developers who are building PiPhi
29
105
  runtimes and want a simple way to simulate PiPhi Core, build realistic request
@@ -67,9 +143,14 @@ This package gives you helpers for exactly those jobs.
67
143
  It includes:
68
144
 
69
145
  - a local mock Core server that captures outbound HTTP requests
146
+ - an ASGI-first runtime harness with a black-box HTTP seam
147
+ - conformance profiles for common runtime shapes
70
148
  - builder functions for runtime headers, `/config` payloads, and `/config/sync` snapshots
149
+ - canonical command builders and command outcome/replay assertions
71
150
  - readable assertion helpers for telemetry and event delivery
151
+ - strict entity, telemetry, event, auth, unit, timestamp, and secret-redaction checks
72
152
  - a behavior/telemetry conformance gate that catches unusable automation conditions
153
+ - manifest/runtime/behavior/observed-output cross-contract checks
73
154
  - a pytest plugin so the fixtures are available automatically
74
155
 
75
156
  It does not try to replace:
@@ -727,8 +808,8 @@ client.post("/config", json=payload, headers=headers)
727
808
  client.post("/telemetry/example")
728
809
  client.post("/events/example")
729
810
 
730
- wait_for(lambda: len(mock_core.telemetry_requests) >= 1)
731
- wait_for(lambda: len(mock_core.event_requests) >= 1)
811
+ await wait_for_telemetry(mock_core, device_id="sensor-1")
812
+ await wait_for_event(mock_core, event_type="device.configured")
732
813
 
733
814
  telemetry_request = mock_core.assert_telemetry_sent(device_id="sensor-1")
734
815
  event_request = mock_core.assert_event_sent(
@@ -850,8 +931,8 @@ Symptom:
850
931
  Fix:
851
932
 
852
933
  - wait for delivery to complete before asserting
853
- - use a polling helper like the `wait_for(...)` function in
854
- [`tests/test_fastapi_runtime_example.py`](./tests/test_fastapi_runtime_example.py)
934
+ - use `await wait_for_telemetry(...)` or `await wait_for_event(...)`; both wait
935
+ on Mock Core request notifications instead of test-owned sleeps
855
936
 
856
937
  ## Troubleshooting
857
938
 
@@ -904,12 +985,28 @@ That usually means your runtime is using the wrong endpoint path.
904
985
  Top-level exports:
905
986
 
906
987
  - `CapturedRequest`
988
+ - `CommandPayload`
989
+ - `ConformanceCheck`, `ConformanceProfile`, `ConformanceReport`
990
+ - `RuntimeHarness`, `RuntimeResponse`, `RuntimeTransport`, `HttpxRuntimeTransport`
907
991
  - `MockCoreServer`
992
+ - `assert_command_failure`, `assert_command_replay`, `assert_command_success`
993
+ - `assert_cross_contract`
994
+ - `assert_entities_response`
908
995
  - `assert_event_sent`
996
+ - `assert_event_payload`
997
+ - `assert_never_event`, `assert_never_request`, `assert_never_telemetry`
998
+ - `assert_onboarding_declaration`
999
+ - `assert_state_refresh_response`
909
1000
  - `assert_telemetry_sent`
1001
+ - `assert_telemetry_payload`
1002
+ - `assert_behavior_conditions_match_telemetry`
1003
+ - `assert_camera_capability`, `assert_public_camera_message_redacted`
1004
+ - `build_command_payload`
910
1005
  - `build_config_payload`
911
1006
  - `build_config_snapshot`
1007
+ - `build_core_config_row`
912
1008
  - `build_runtime_headers`
1009
+ - `wait_for_event`, `wait_for_request`, `wait_for_telemetry`
913
1010
 
914
1011
  Pytest fixtures:
915
1012
 
@@ -1,7 +1,81 @@
1
1
  # piphi-runtime-testkit-python
2
2
 
3
+ Validate the closed, Core-owned onboarding declaration before publishing an
4
+ integration manifest:
5
+
6
+ ```python
7
+ from piphi_runtime_testkit_python import assert_onboarding_declaration
8
+
9
+ assert_onboarding_declaration(manifest)
10
+ ```
11
+
12
+ Supported modes are `manual`, `discovery`, `account`, `service`, and `none`.
13
+
3
14
  Pytest-first helpers for testing PiPhi runtime integrations.
4
15
 
16
+ ## Runtime conformance harness
17
+
18
+ Install the ASGI/HTTP adapter extra and exercise the same public runtime routes
19
+ that Core uses:
20
+
21
+ ```bash
22
+ pip install "piphi-runtime-testkit-python[asgi]"
23
+ ```
24
+
25
+ ```python
26
+ import pytest
27
+
28
+ from piphi_runtime_testkit_python import (
29
+ ConformanceProfile,
30
+ RuntimeHarness,
31
+ build_command_payload,
32
+ build_config_payload,
33
+ )
34
+
35
+
36
+ @pytest.mark.asyncio
37
+ async def test_actuator_contract(app):
38
+ config = build_config_payload(
39
+ config_id="shelly-kitchen",
40
+ container_id="runtime-123",
41
+ extra={"host": "192.0.2.10"},
42
+ )
43
+ command = build_command_payload(
44
+ command="refresh",
45
+ config_id="shelly-kitchen",
46
+ device_id="shelly-kitchen",
47
+ )
48
+ harness = RuntimeHarness.for_asgi(
49
+ app,
50
+ headers={
51
+ "X-Container-Id": "runtime-123",
52
+ "X-PiPhi-Integration-Token": "test-token",
53
+ },
54
+ )
55
+ async with harness:
56
+ report = await harness.run_profile(
57
+ ConformanceProfile.ACTUATOR,
58
+ config=config,
59
+ command=command,
60
+ )
61
+ report.assert_passed()
62
+ ```
63
+
64
+ Pass an app factory instead of an app to make `await harness.restart()` create a
65
+ fresh process-local runtime. Use `RuntimeHarness.for_http(...)` for a running
66
+ container or process without changing scenario code.
67
+
68
+ The profiles are intentionally small and readable:
69
+
70
+ - `basic`: health, auth rejection, config, entities, and deconfigure
71
+ - `monitoring`: basic plus state
72
+ - `actuator`: monitoring plus a supplied command
73
+ - `restorable`: monitoring plus config sync and restart
74
+ - `sidecar`: health-only process conformance
75
+
76
+ See [the API guide](docs/API.md) for strict contracts, programmable Core
77
+ responses, deterministic waits, and cross-contract checks.
78
+
5
79
  This package exists to make integration tests easier to write, easier to read,
6
80
  and easier to debug. It is designed for developers who are building PiPhi
7
81
  runtimes and want a simple way to simulate PiPhi Core, build realistic request
@@ -45,9 +119,14 @@ This package gives you helpers for exactly those jobs.
45
119
  It includes:
46
120
 
47
121
  - a local mock Core server that captures outbound HTTP requests
122
+ - an ASGI-first runtime harness with a black-box HTTP seam
123
+ - conformance profiles for common runtime shapes
48
124
  - builder functions for runtime headers, `/config` payloads, and `/config/sync` snapshots
125
+ - canonical command builders and command outcome/replay assertions
49
126
  - readable assertion helpers for telemetry and event delivery
127
+ - strict entity, telemetry, event, auth, unit, timestamp, and secret-redaction checks
50
128
  - a behavior/telemetry conformance gate that catches unusable automation conditions
129
+ - manifest/runtime/behavior/observed-output cross-contract checks
51
130
  - a pytest plugin so the fixtures are available automatically
52
131
 
53
132
  It does not try to replace:
@@ -705,8 +784,8 @@ client.post("/config", json=payload, headers=headers)
705
784
  client.post("/telemetry/example")
706
785
  client.post("/events/example")
707
786
 
708
- wait_for(lambda: len(mock_core.telemetry_requests) >= 1)
709
- wait_for(lambda: len(mock_core.event_requests) >= 1)
787
+ await wait_for_telemetry(mock_core, device_id="sensor-1")
788
+ await wait_for_event(mock_core, event_type="device.configured")
710
789
 
711
790
  telemetry_request = mock_core.assert_telemetry_sent(device_id="sensor-1")
712
791
  event_request = mock_core.assert_event_sent(
@@ -828,8 +907,8 @@ Symptom:
828
907
  Fix:
829
908
 
830
909
  - wait for delivery to complete before asserting
831
- - use a polling helper like the `wait_for(...)` function in
832
- [`tests/test_fastapi_runtime_example.py`](./tests/test_fastapi_runtime_example.py)
910
+ - use `await wait_for_telemetry(...)` or `await wait_for_event(...)`; both wait
911
+ on Mock Core request notifications instead of test-owned sleeps
833
912
 
834
913
  ## Troubleshooting
835
914
 
@@ -882,12 +961,28 @@ That usually means your runtime is using the wrong endpoint path.
882
961
  Top-level exports:
883
962
 
884
963
  - `CapturedRequest`
964
+ - `CommandPayload`
965
+ - `ConformanceCheck`, `ConformanceProfile`, `ConformanceReport`
966
+ - `RuntimeHarness`, `RuntimeResponse`, `RuntimeTransport`, `HttpxRuntimeTransport`
885
967
  - `MockCoreServer`
968
+ - `assert_command_failure`, `assert_command_replay`, `assert_command_success`
969
+ - `assert_cross_contract`
970
+ - `assert_entities_response`
886
971
  - `assert_event_sent`
972
+ - `assert_event_payload`
973
+ - `assert_never_event`, `assert_never_request`, `assert_never_telemetry`
974
+ - `assert_onboarding_declaration`
975
+ - `assert_state_refresh_response`
887
976
  - `assert_telemetry_sent`
977
+ - `assert_telemetry_payload`
978
+ - `assert_behavior_conditions_match_telemetry`
979
+ - `assert_camera_capability`, `assert_public_camera_message_redacted`
980
+ - `build_command_payload`
888
981
  - `build_config_payload`
889
982
  - `build_config_snapshot`
983
+ - `build_core_config_row`
890
984
  - `build_runtime_headers`
985
+ - `wait_for_event`, `wait_for_request`, `wait_for_telemetry`
891
986
 
892
987
  Pytest fixtures:
893
988
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "piphi-runtime-testkit-python"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Pytest-first helpers for testing PiPhi runtime integrations"
5
5
  authors = [
6
6
  { name = "KelvinSan", email = "support@piphi.network" },
@@ -31,6 +31,11 @@ readme = "README.md"
31
31
  [project.license]
32
32
  text = "MIT"
33
33
 
34
+ [project.optional-dependencies]
35
+ asgi = [
36
+ "httpx>=0.27,<1.0",
37
+ ]
38
+
34
39
  [project.urls]
35
40
  Homepage = "https://github.com/PiPhi-io/piphi-runtime-testkit-python#readme"
36
41
  Repository = "https://github.com/PiPhi-io/piphi-runtime-testkit-python"
@@ -1,12 +1,21 @@
1
1
  """Pytest-first helpers for testing PiPhi runtime integrations."""
2
2
 
3
3
  from .assertions import (
4
+ assert_command_failure,
5
+ assert_command_replay,
6
+ assert_command_success,
7
+ assert_config_sync_response,
8
+ assert_event_payload,
4
9
  assert_entities_response,
10
+ assert_onboarding_declaration,
5
11
  assert_event_sent,
6
12
  assert_state_refresh_response,
7
13
  assert_telemetry_sent,
14
+ assert_telemetry_payload,
8
15
  )
9
16
  from .builders import (
17
+ CommandPayload,
18
+ build_command_payload,
10
19
  build_config_payload,
11
20
  build_config_snapshot,
12
21
  build_core_config_row,
@@ -26,26 +35,67 @@ from .behavior_contract import (
26
35
  find_behavior_telemetry_issues,
27
36
  )
28
37
  from .mock_core import CapturedRequest, MockCoreServer, RUNTIME_CONFIG_FETCH_PATH
38
+ from .cross_contract import assert_cross_contract
39
+ from .harness import (
40
+ ConformanceCheck,
41
+ ConformanceProfile,
42
+ ConformanceReport,
43
+ HttpxRuntimeTransport,
44
+ RuntimeHarness,
45
+ RuntimeResponse,
46
+ RuntimeTransport,
47
+ )
48
+ from .waits import (
49
+ assert_never_event,
50
+ assert_never_request,
51
+ assert_never_telemetry,
52
+ wait_for_event,
53
+ wait_for_request,
54
+ wait_for_telemetry,
55
+ )
29
56
 
30
57
  __all__ = [
31
58
  "CapturedRequest",
59
+ "CommandPayload",
60
+ "ConformanceCheck",
61
+ "ConformanceProfile",
62
+ "ConformanceReport",
32
63
  "BehaviorTelemetryIssue",
33
64
  "CAMERA_MEDIA_CONTRACT_VERSION",
34
65
  "MockCoreServer",
66
+ "HttpxRuntimeTransport",
35
67
  "RUNTIME_CONFIG_FETCH_PATH",
68
+ "RuntimeHarness",
69
+ "RuntimeResponse",
70
+ "RuntimeTransport",
36
71
  "assert_entities_response",
72
+ "assert_command_failure",
73
+ "assert_command_replay",
74
+ "assert_command_success",
75
+ "assert_config_sync_response",
76
+ "assert_cross_contract",
77
+ "assert_onboarding_declaration",
37
78
  "assert_camera_capability",
38
79
  "assert_behavior_conditions_match_telemetry",
39
80
  "assert_event_sent",
81
+ "assert_event_payload",
82
+ "assert_never_event",
83
+ "assert_never_request",
84
+ "assert_never_telemetry",
40
85
  "assert_state_refresh_response",
41
86
  "assert_telemetry_sent",
87
+ "assert_telemetry_payload",
42
88
  "assert_public_camera_message_redacted",
43
89
  "build_camera_session_offer",
44
90
  "build_camera_sidecar_session_open",
45
91
  "build_camera_source",
92
+ "build_command_payload",
46
93
  "build_config_payload",
47
94
  "build_config_snapshot",
48
95
  "build_core_config_row",
49
96
  "build_runtime_headers",
50
97
  "find_behavior_telemetry_issues",
98
+ "wait_for_event",
99
+ "wait_for_request",
100
+ "wait_for_telemetry",
51
101
  ]