piphi-runtime-testkit-python 0.2.0__tar.gz → 0.3.1__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.1}/PKG-INFO +106 -5
  2. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/README.md +103 -4
  3. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/pyproject.toml +6 -1
  4. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/src/piphi_runtime_testkit_python/__init__.py +50 -0
  5. piphi_runtime_testkit_python-0.3.1/src/piphi_runtime_testkit_python/assertions.py +434 -0
  6. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/src/piphi_runtime_testkit_python/behavior_contract.py +4 -0
  7. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/src/piphi_runtime_testkit_python/builders.py +56 -0
  8. piphi_runtime_testkit_python-0.3.1/src/piphi_runtime_testkit_python/cross_contract.py +78 -0
  9. piphi_runtime_testkit_python-0.3.1/src/piphi_runtime_testkit_python/harness.py +334 -0
  10. piphi_runtime_testkit_python-0.3.1/src/piphi_runtime_testkit_python/mock_core.py +415 -0
  11. piphi_runtime_testkit_python-0.3.1/src/piphi_runtime_testkit_python/waits.py +83 -0
  12. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_assertions.py +11 -0
  13. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_behavior_contract.py +10 -0
  14. piphi_runtime_testkit_python-0.3.1/tests/test_command_contract.py +74 -0
  15. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_fastapi_runtime_example.py +2 -12
  16. piphi_runtime_testkit_python-0.3.1/tests/test_mock_core_sequences.py +70 -0
  17. piphi_runtime_testkit_python-0.3.1/tests/test_runtime_harness.py +111 -0
  18. piphi_runtime_testkit_python-0.3.1/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.1}/LICENSE +0 -0
  22. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/src/piphi_runtime_testkit_python/camera.py +0 -0
  23. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/src/piphi_runtime_testkit_python/pytest_plugin.py +0 -0
  24. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/__init__.py +0 -0
  25. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_builders.py +0 -0
  26. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_camera.py +0 -0
  27. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_mock_core.py +0 -0
  28. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_pytest_plugin.py +0 -0
  29. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/tests/test_runtime_config_contract.py +0 -0
  30. {piphi_runtime_testkit_python-0.2.0 → piphi_runtime_testkit_python-0.3.1}/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.1
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,92 @@ 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
+ For a canonical on-demand state read, call
93
+ `await harness.state(refresh=True, request_id="refresh-1")`. The harness maps
94
+ that argument to the runtime boundary's `refresh_request_id` query parameter.
95
+
96
+ The profiles are intentionally small and readable:
97
+
98
+ - `basic`: health, auth rejection, config, entities, and deconfigure
99
+ - `monitoring`: basic plus state
100
+ - `actuator`: monitoring plus a supplied command
101
+ - `restorable`: monitoring plus config sync and restart
102
+ - `sidecar`: health-only process conformance
103
+
104
+ See [the API guide](docs/API.md) for strict contracts, programmable Core
105
+ responses, deterministic waits, and cross-contract checks.
106
+
27
107
  This package exists to make integration tests easier to write, easier to read,
28
108
  and easier to debug. It is designed for developers who are building PiPhi
29
109
  runtimes and want a simple way to simulate PiPhi Core, build realistic request
@@ -67,9 +147,14 @@ This package gives you helpers for exactly those jobs.
67
147
  It includes:
68
148
 
69
149
  - a local mock Core server that captures outbound HTTP requests
150
+ - an ASGI-first runtime harness with a black-box HTTP seam
151
+ - conformance profiles for common runtime shapes
70
152
  - builder functions for runtime headers, `/config` payloads, and `/config/sync` snapshots
153
+ - canonical command builders and command outcome/replay assertions
71
154
  - readable assertion helpers for telemetry and event delivery
155
+ - strict entity, telemetry, event, auth, unit, timestamp, and secret-redaction checks
72
156
  - a behavior/telemetry conformance gate that catches unusable automation conditions
157
+ - manifest/runtime/behavior/observed-output cross-contract checks
73
158
  - a pytest plugin so the fixtures are available automatically
74
159
 
75
160
  It does not try to replace:
@@ -727,8 +812,8 @@ client.post("/config", json=payload, headers=headers)
727
812
  client.post("/telemetry/example")
728
813
  client.post("/events/example")
729
814
 
730
- wait_for(lambda: len(mock_core.telemetry_requests) >= 1)
731
- wait_for(lambda: len(mock_core.event_requests) >= 1)
815
+ await wait_for_telemetry(mock_core, device_id="sensor-1")
816
+ await wait_for_event(mock_core, event_type="device.configured")
732
817
 
733
818
  telemetry_request = mock_core.assert_telemetry_sent(device_id="sensor-1")
734
819
  event_request = mock_core.assert_event_sent(
@@ -850,8 +935,8 @@ Symptom:
850
935
  Fix:
851
936
 
852
937
  - 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)
938
+ - use `await wait_for_telemetry(...)` or `await wait_for_event(...)`; both wait
939
+ on Mock Core request notifications instead of test-owned sleeps
855
940
 
856
941
  ## Troubleshooting
857
942
 
@@ -904,12 +989,28 @@ That usually means your runtime is using the wrong endpoint path.
904
989
  Top-level exports:
905
990
 
906
991
  - `CapturedRequest`
992
+ - `CommandPayload`
993
+ - `ConformanceCheck`, `ConformanceProfile`, `ConformanceReport`
994
+ - `RuntimeHarness`, `RuntimeResponse`, `RuntimeTransport`, `HttpxRuntimeTransport`
907
995
  - `MockCoreServer`
996
+ - `assert_command_failure`, `assert_command_replay`, `assert_command_success`
997
+ - `assert_cross_contract`
998
+ - `assert_entities_response`
908
999
  - `assert_event_sent`
1000
+ - `assert_event_payload`
1001
+ - `assert_never_event`, `assert_never_request`, `assert_never_telemetry`
1002
+ - `assert_onboarding_declaration`
1003
+ - `assert_state_refresh_response`
909
1004
  - `assert_telemetry_sent`
1005
+ - `assert_telemetry_payload`
1006
+ - `assert_behavior_conditions_match_telemetry`
1007
+ - `assert_camera_capability`, `assert_public_camera_message_redacted`
1008
+ - `build_command_payload`
910
1009
  - `build_config_payload`
911
1010
  - `build_config_snapshot`
1011
+ - `build_core_config_row`
912
1012
  - `build_runtime_headers`
1013
+ - `wait_for_event`, `wait_for_request`, `wait_for_telemetry`
913
1014
 
914
1015
  Pytest fixtures:
915
1016
 
@@ -1,7 +1,85 @@
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
+ For a canonical on-demand state read, call
69
+ `await harness.state(refresh=True, request_id="refresh-1")`. The harness maps
70
+ that argument to the runtime boundary's `refresh_request_id` query parameter.
71
+
72
+ The profiles are intentionally small and readable:
73
+
74
+ - `basic`: health, auth rejection, config, entities, and deconfigure
75
+ - `monitoring`: basic plus state
76
+ - `actuator`: monitoring plus a supplied command
77
+ - `restorable`: monitoring plus config sync and restart
78
+ - `sidecar`: health-only process conformance
79
+
80
+ See [the API guide](docs/API.md) for strict contracts, programmable Core
81
+ responses, deterministic waits, and cross-contract checks.
82
+
5
83
  This package exists to make integration tests easier to write, easier to read,
6
84
  and easier to debug. It is designed for developers who are building PiPhi
7
85
  runtimes and want a simple way to simulate PiPhi Core, build realistic request
@@ -45,9 +123,14 @@ This package gives you helpers for exactly those jobs.
45
123
  It includes:
46
124
 
47
125
  - a local mock Core server that captures outbound HTTP requests
126
+ - an ASGI-first runtime harness with a black-box HTTP seam
127
+ - conformance profiles for common runtime shapes
48
128
  - builder functions for runtime headers, `/config` payloads, and `/config/sync` snapshots
129
+ - canonical command builders and command outcome/replay assertions
49
130
  - readable assertion helpers for telemetry and event delivery
131
+ - strict entity, telemetry, event, auth, unit, timestamp, and secret-redaction checks
50
132
  - a behavior/telemetry conformance gate that catches unusable automation conditions
133
+ - manifest/runtime/behavior/observed-output cross-contract checks
51
134
  - a pytest plugin so the fixtures are available automatically
52
135
 
53
136
  It does not try to replace:
@@ -705,8 +788,8 @@ client.post("/config", json=payload, headers=headers)
705
788
  client.post("/telemetry/example")
706
789
  client.post("/events/example")
707
790
 
708
- wait_for(lambda: len(mock_core.telemetry_requests) >= 1)
709
- wait_for(lambda: len(mock_core.event_requests) >= 1)
791
+ await wait_for_telemetry(mock_core, device_id="sensor-1")
792
+ await wait_for_event(mock_core, event_type="device.configured")
710
793
 
711
794
  telemetry_request = mock_core.assert_telemetry_sent(device_id="sensor-1")
712
795
  event_request = mock_core.assert_event_sent(
@@ -828,8 +911,8 @@ Symptom:
828
911
  Fix:
829
912
 
830
913
  - 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)
914
+ - use `await wait_for_telemetry(...)` or `await wait_for_event(...)`; both wait
915
+ on Mock Core request notifications instead of test-owned sleeps
833
916
 
834
917
  ## Troubleshooting
835
918
 
@@ -882,12 +965,28 @@ That usually means your runtime is using the wrong endpoint path.
882
965
  Top-level exports:
883
966
 
884
967
  - `CapturedRequest`
968
+ - `CommandPayload`
969
+ - `ConformanceCheck`, `ConformanceProfile`, `ConformanceReport`
970
+ - `RuntimeHarness`, `RuntimeResponse`, `RuntimeTransport`, `HttpxRuntimeTransport`
885
971
  - `MockCoreServer`
972
+ - `assert_command_failure`, `assert_command_replay`, `assert_command_success`
973
+ - `assert_cross_contract`
974
+ - `assert_entities_response`
886
975
  - `assert_event_sent`
976
+ - `assert_event_payload`
977
+ - `assert_never_event`, `assert_never_request`, `assert_never_telemetry`
978
+ - `assert_onboarding_declaration`
979
+ - `assert_state_refresh_response`
887
980
  - `assert_telemetry_sent`
981
+ - `assert_telemetry_payload`
982
+ - `assert_behavior_conditions_match_telemetry`
983
+ - `assert_camera_capability`, `assert_public_camera_message_redacted`
984
+ - `build_command_payload`
888
985
  - `build_config_payload`
889
986
  - `build_config_snapshot`
987
+ - `build_core_config_row`
890
988
  - `build_runtime_headers`
989
+ - `wait_for_event`, `wait_for_request`, `wait_for_telemetry`
891
990
 
892
991
  Pytest fixtures:
893
992
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "piphi-runtime-testkit-python"
3
- version = "0.2.0"
3
+ version = "0.3.1"
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
  ]