Skip to main content

devicerail_protocol/
fixtures.rs

1//! Canonical cross-language Golden Fixtures embedded for consistency suites.
2//!
3//! This module is available only with the non-default `fixtures` feature.
4//! Every value is embedded directly from `crates/protocol/fixtures`, so users
5//! do not need repository-relative filesystem paths and there is no copied
6//! fixture body that can drift from the canonical source.
7
8/// One canonical fixture embedded in the protocol crate.
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub struct CanonicalFixture {
11    /// Path relative to the canonical fixture manifest.
12    pub path: &'static str,
13    /// Exact UTF-8 JSON source.
14    pub json: &'static str,
15}
16
17impl CanonicalFixture {
18    const fn new(path: &'static str, json: &'static str) -> Self {
19        Self { path, json }
20    }
21}
22
23macro_rules! fixture {
24    ($path:literal) => {
25        CanonicalFixture::new($path, include_str!(concat!("../fixtures/", $path)))
26    };
27}
28
29/// Exact canonical fixture manifest JSON.
30pub const MANIFEST_JSON: &str = include_str!("../fixtures/manifest.json");
31/// Canonical `system.hello` request fixture.
32pub const SYSTEM_HELLO_REQUEST_JSON: &str =
33    include_str!("../fixtures/system-hello-v1.request.json");
34/// Canonical `system.hello` response fixture.
35pub const SYSTEM_HELLO_RESPONSE_JSON: &str =
36    include_str!("../fixtures/system-hello-v1.response.json");
37/// Canonical `devices.list` request fixture.
38pub const DEVICES_LIST_REQUEST_JSON: &str =
39    include_str!("../fixtures/rpc/devices-list-v1.request.json");
40/// Canonical `devices.list` response fixture.
41pub const DEVICES_LIST_RESPONSE_JSON: &str =
42    include_str!("../fixtures/rpc/devices-list-v1.response.json");
43/// Canonical `device.connect` request fixture.
44pub const DEVICE_CONNECT_REQUEST_JSON: &str =
45    include_str!("../fixtures/rpc/device-connect-v1.request.json");
46/// Canonical `device.connect` response fixture.
47pub const DEVICE_CONNECT_RESPONSE_JSON: &str =
48    include_str!("../fixtures/rpc/device-connect-v1.response.json");
49/// Canonical JSON-RPC failure fixture.
50pub const RPC_FAILURE_JSON: &str = include_str!("../fixtures/rpc/failure-v1.json");
51/// Canonical event-stream event notification fixture.
52pub const EVENTS_STREAM_EVENT_NOTIFICATION_JSON: &str =
53    include_str!("../fixtures/stream/events-stream-event-v1.notification.json");
54/// Canonical event-stream terminal notification fixture.
55pub const EVENTS_STREAM_TERMINAL_NOTIFICATION_JSON: &str =
56    include_str!("../fixtures/stream/events-stream-terminal-v1.notification.json");
57
58/// Every JSON fixture named by [`MANIFEST_JSON`], in stable path order.
59pub const CANONICAL_FIXTURES: &[CanonicalFixture] = &[
60    fixture!("events/action-completed-cancelled-v1.json"),
61    fixture!("events/action-completed-failed-v1.json"),
62    fixture!("events/action-completed-succeeded-v1.json"),
63    fixture!("events/action-completed-timed-out-v1.json"),
64    fixture!("events/action-started-cancelled-v1.json"),
65    fixture!("events/action-started-failed-v1.json"),
66    fixture!("events/action-started-succeeded-v1.json"),
67    fixture!("events/action-started-timed-out-v1.json"),
68    fixture!("events/error-v1.json"),
69    fixture!("events/media-frame-captured-v1.json"),
70    fixture!("events/media-stream-ended-v1.json"),
71    fixture!("events/media-stream-started-v1.json"),
72    fixture!("events/observation-captured-v1.json"),
73    fixture!("events/session-ended-v1.json"),
74    fixture!("events/session-started-v1.json"),
75    fixture!("events/verdict-recorded-v1.json"),
76    fixture!("models/action-call-v1.json"),
77    fixture!("models/action-definition-protected-v1.json"),
78    fixture!("models/action-definition-v1.json"),
79    fixture!("models/action-result-v1.json"),
80    fixture!("models/clear-element-arguments-v1.json"),
81    fixture!("models/clear-element-result-v1.json"),
82    fixture!("models/device-info-v1.json"),
83    fixture!("models/error-info-v1.json"),
84    fixture!("models/find-element-arguments-v1.json"),
85    fixture!("models/find-element-result-v1.json"),
86    fixture!("models/manual-recording-v1.json"),
87    fixture!("models/observation-omitted-v1.json"),
88    fixture!("models/observation-v1.json"),
89    fixture!("models/set-element-value-arguments-v1.json"),
90    fixture!("models/set-element-value-result-v1.json"),
91    fixture!("models/tap-element-arguments-v1.json"),
92    fixture!("models/tap-element-result-v1.json"),
93    fixture!("models/ui-snapshot-v1.json"),
94    fixture!("models/wait-for-element-arguments-v1.json"),
95    fixture!("models/wait-for-element-result-v1.json"),
96    fixture!("rpc/device-capabilities-v1.request.json"),
97    fixture!("rpc/device-capabilities-v1.response.json"),
98    fixture!("rpc/device-connect-v1.request.json"),
99    fixture!("rpc/device-connect-v1.response.json"),
100    fixture!("rpc/device-disconnect-v1.request.json"),
101    fixture!("rpc/device-disconnect-v1.response.json"),
102    fixture!("rpc/device-execute-timeout-v1.json"),
103    fixture!("rpc/device-execute-timeout-v1.response.json"),
104    fixture!("rpc/device-observe-v1.request.json"),
105    fixture!("rpc/device-observe-v1.response.json"),
106    fixture!("rpc/device-select-v1.request.json"),
107    fixture!("rpc/device-select-v1.response.json"),
108    fixture!("rpc/devices-list-v1.request.json"),
109    fixture!("rpc/devices-list-v1.response.json"),
110    fixture!("rpc/events-clear-v1.request.json"),
111    fixture!("rpc/events-clear-v1.response.json"),
112    fixture!("rpc/events-list-v1.request.json"),
113    fixture!("rpc/events-list-v1.response.json"),
114    fixture!("rpc/failure-v1.json"),
115    fixture!("rpc/media-stream-capture-v1.request.json"),
116    fixture!("rpc/media-stream-capture-v1.response.json"),
117    fixture!("rpc/media-stream-end-v1.request.json"),
118    fixture!("rpc/media-stream-end-v1.response.json"),
119    fixture!("rpc/media-stream-start-v1.request.json"),
120    fixture!("rpc/media-stream-start-v1.response.json"),
121    fixture!("rpc/request-cancel-v1.request.json"),
122    fixture!("rpc/request-cancel-v1.response.json"),
123    fixture!("rpc/session-current-v1.request.json"),
124    fixture!("rpc/session-current-v1.response.json"),
125    fixture!("rpc/session-end-v1.request.json"),
126    fixture!("rpc/session-end-v1.response.json"),
127    fixture!("rpc/session-export-v1.request.json"),
128    fixture!("rpc/session-export-v1.response.json"),
129    fixture!("rpc/session-start-v1.request.json"),
130    fixture!("rpc/session-start-v1.response.json"),
131    fixture!("rpc/sessions-list-v1.request.json"),
132    fixture!("rpc/sessions-list-v1.response.json"),
133    fixture!("rpc/system-describe-v1.request.json"),
134    fixture!("rpc/system-describe-v1.response.json"),
135    fixture!("rpc/ui-snapshot-get-v1.request.json"),
136    fixture!("rpc/ui-snapshot-get-v1.response.json"),
137    fixture!("rpc/verdict-record-v1.request.json"),
138    fixture!("rpc/verdict-record-v1.response.json"),
139    fixture!("stream/events-stream-event-v1.notification.json"),
140    fixture!("stream/events-stream-open-v1.request.json"),
141    fixture!("stream/events-stream-open-v1.response.json"),
142    fixture!("stream/events-stream-terminal-v1.notification.json"),
143    fixture!("stream/events-subscribe-v1.request.json"),
144    fixture!("stream/events-subscribe-v1.response.json"),
145    fixture!("stream/websocket-system-hello-v1.request.json"),
146    fixture!("stream/websocket-system-hello-v1.response.json"),
147    fixture!("system-hello-v1.request.json"),
148    fixture!("system-hello-v1.response.json"),
149];
150
151/// Returns the exact canonical JSON for a manifest-relative fixture path.
152#[must_use]
153pub fn fixture_json(path: &str) -> Option<&'static str> {
154    CANONICAL_FIXTURES
155        .iter()
156        .find(|fixture| fixture.path == path)
157        .map(|fixture| fixture.json)
158}