Skip to main content

laser_wire/
fixtures.rs

1// The golden corpus, embedded so a consumer (LaserData Cloud, the Iggy server, a port's
2// conformance suite) can assert against the exact canonical bytes in its own
3// CI without copying files.
4
5macro_rules! corpus {
6    ($($name:literal),+ $(,)?) => {
7        /// Every fixture in the corpus as `(file name, canonical bytes)`.
8        pub const ALL: &[(&str, &[u8])] = &[
9            $(($name, include_bytes!(concat!("../fixtures/", $name)))),+
10        ];
11    };
12}
13
14corpus!(
15    // The agent surface (DRAFT-grade until a real multi-agent application
16    // has bent the envelope: the `agent_invalid_*` negatives must fail
17    // `validate()` identically in every port).
18    "agent_body_ref.bin",
19    "agent_card.bin",
20    "agent_chunk.bin",
21    "agent_chunk_open.bin",
22    "agent_chunk_terminal.bin",
23    "agent_command.bin",
24    "agent_command_signed.bin",
25    "agent_dead_letter.bin",
26    "agent_error.bin",
27    "agent_error_body.bin",
28    "agent_event.bin",
29    "agent_invalid_chunk_late_deadline.bin",
30    "agent_invalid_chunk_no_sequence.bin",
31    "agent_invalid_chunk_open_no_operation.bin",
32    "agent_invalid_command_no_correlation.bin",
33    "agent_invalid_error_last.bin",
34    "agent_invalid_event_task_state.bin",
35    "agent_invalid_response_channel.bin",
36    "agent_invalid_status_bad_operation.bin",
37    "agent_invalid_status_no_operation.bin",
38    "agent_list_page.bin",
39    "agent_must_understand.bin",
40    "agent_presence.bin",
41    "agent_record.bin",
42    "agent_reply_error.bin",
43    "agent_reply_list_page.bin",
44    "agent_reply_status.bin",
45    "agent_response.bin",
46    "agent_submit.bin",
47    "agent_signature.bin",
48    "agent_status_card.bin",
49    "agent_status_run_metadata.bin",
50    "agent_status_task.bin",
51    "authz_bind_roles.bin",
52    "authz_get_role_reply.bin",
53    "authz_history_reply.bin",
54    "authz_history_request.bin",
55    "authz_role.bin",
56    "authz_whoami_reply.bin",
57    "backend_announce.bin",
58    "backend_announce_topology.bin",
59    "backend_announce_unavailable.bin",
60    "batch_reply.bin",
61    "batch_request.bin",
62    "browse_projections.json",
63    "browse_reply_decoded.bin",
64    "browse_reply_projections.bin",
65    "browse_reply_schema_registered.bin",
66    "browse_reply_schemas.bin",
67    "browse_schemas.json",
68    "capabilities.json",
69    "change_record.bin",
70    "client_metadata_list.bin",
71    "client_metadata_query.bin",
72    "control_apply_binding.bin",
73    "control_drop_schema.bin",
74    "control_register_projection.bin",
75    "control_register_schema_avro.bin",
76    "control_register_schema_json.bin",
77    "control_register_schema_protobuf.bin",
78    "control_register_run_source.bin",
79    "control_remove_binding.bin",
80    "control_remove_run_source.bin",
81    "decode_record.bin",
82    "error_body.json",
83    "fold_snapshot.bin",
84    "fork_create.bin",
85    "fork_info.json",
86    "fork_put.bin",
87    "fork_reply_created.bin",
88    "forwarded_command.bin",
89    "forwarded_query.bin",
90    "graph_edge.bin",
91    "graph_edge_conversation.bin",
92    "graph_edge_sourced.bin",
93    "graph_neighbors.bin",
94    "graph_neighbors_conversation.bin",
95    "graph_node.bin",
96    "graph_node_conversation.bin",
97    "graph_node_sourced.bin",
98    "graph_query.bin",
99    "graph_query_conversation.bin",
100    "graph_reply.bin",
101    "graph_upsert.bin",
102    "hello_reply.bin",
103    "hello_reply_agent.bin",
104    "hello_reply_features.bin",
105    "kv_cas.bin",
106    "kv_cas_fenced.bin",
107    "kv_copy.bin",
108    "kv_move.bin",
109    "kv_namespaces.bin",
110    "kv_page_view.json",
111    "kv_reply_committed.bin",
112    "kv_reply_namespaces.bin",
113    "kv_reply_page.bin",
114    "kv_reply_version_conflict.bin",
115    "kv_scan.bin",
116    "kv_set.bin",
117    "key_record.bin",
118    "managed_request.bin",
119    "mutation_command.bin",
120    "query_envelope.bin",
121    "query_envelope_aggregate.bin",
122    "query_envelope_raw_sql.bin",
123    "query_envelope_read_your_writes.bin",
124    "query_envelope_text.bin",
125    "query_reply_err_stale.bin",
126    "query_reply_err_too_large.bin",
127    "query_reply_ok.bin",
128    "query_result.json",
129    "register_schema_managed.bin",
130    "schema_def.json",
131);
132
133/// Canonical bytes of one fixture by name, or `None` if the name is unknown.
134pub fn bytes(name: &str) -> Option<&'static [u8]> {
135    ALL.iter()
136        .find(|(fixture, _)| *fixture == name)
137        .map(|(_, bytes)| *bytes)
138}
139
140/// Assert that `encoded` matches the canonical fixture byte-for-byte.
141/// Panics with a diff-friendly message on drift.
142pub fn assert_matches(name: &str, encoded: &[u8]) {
143    let golden = bytes(name).unwrap_or_else(|| panic!("unknown fixture `{name}`"));
144    assert_eq!(
145        encoded, golden,
146        "fixture `{name}` drifted from the canonical frame"
147    );
148}
149
150#[cfg(test)]
151mod tests {
152    #[test]
153    fn given_the_corpus_when_looked_up_then_should_resolve_known_names() {
154        assert!(super::bytes("hello_reply.bin").is_some());
155        assert!(super::bytes("nope.bin").is_none());
156    }
157}