Skip to main content

adk_kernel/conformance/
mod.rs

1//! Conformance suites for kernel store backends (spec 3.2 §11, §13 Q8; feature
2//! `conformance`).
3//!
4//! `adk-core` cannot depend on `adk-kernel`, so the kernel's suites live here, in the form
5//! of `adk_core::conformance`: a harness trait that opens the backend, one public function
6//! per case, and a macro that generates one `#[tokio::test]` per case.
7//!
8//! | Store | Harness | Test macro | Cases |
9//! |-------|---------|------------|-------|
10//! | [`ProcessStore`](crate::ProcessStore) | [`ProcessStoreHarness`] | [`process_store_conformance_tests!`](crate::process_store_conformance_tests) | [`process_store`] |
11//! | [`AgendaStore`](crate::AgendaStore) | [`AgendaStoreHarness`] | [`agenda_store_conformance_tests!`](crate::agenda_store_conformance_tests) | [`agenda_store`] |
12//! | [`AgentStore`](crate::agents::AgentStore) (spec 3.3 §10 K7) | [`AgentStoreHarness`] | [`agent_store_conformance_tests!`](crate::agent_store_conformance_tests) | [`agent_store`] |
13//! | `drivers::DriverStore` (feature `drivers`) | `DriverStoreHarness` | `driver_store_conformance_tests!` | `driver_store` |
14//! | `proc::LedgerStore` (feature `proc`) | `LedgerStoreHarness` | `ledger_store_conformance_tests!` | `ledger_store` |
15//! | [`DeviceStore`](crate::pairing::DeviceStore) (spec 3.3 §10 K2) | [`DeviceStoreHarness`] | [`device_store_conformance_tests!`](crate::device_store_conformance_tests) | [`device_store`] |
16//! | `channels::ChannelBindingStore` (feature `channels`; spec 3.3 §10 K1) | `ChannelBindingStoreHarness` | `channel_binding_store_conformance_tests!` | `channel_binding_store` |
17//! | [`PartitionStore`](crate::PartitionStore) | [`PartitionStoreHarness`] | [`partition_store_conformance_tests!`](crate::partition_store_conformance_tests) | [`partition_store`] |
18//! | [`ControlStore`](crate::control::ControlStore) (spec 3.3 §10 K3, K4) | [`ControlStoreHarness`] | [`control_store_conformance_tests!`](crate::control_store_conformance_tests) | [`control_store`] |
19//! | [`CronWatermarkStore`](crate::CronWatermarkStore) | [`CronWatermarkStoreHarness`] | [`cron_watermark_store_conformance_tests!`](crate::cron_watermark_store_conformance_tests) | [`cron_watermark_store`] |
20//! | The charter, KPI, autonomy and signal stores (feature `charter`; spec 3.5 §7.10, §7.11) | `charter::*Harness` | `charter_store_conformance_tests!`, `kpi_store_conformance_tests!`, `autonomy_store_conformance_tests!`, `signal_store_conformance_tests!` | `charter` |
21//!
22//! Chat channel adapters pass `channel_contract` (feature `channels`; spec 3.3 §10 K1): a
23//! `ChannelAdapterHarness` makes a fresh adapter per case and `channel_contract_tests!`
24//! generates the tests, which run the adapter under the kernel's gateway and check what it
25//! put on the wire.
26//!
27//! In-memory and SQLite run on the PR tier; PostgreSQL and Redis run in the CI `postgres`
28//! job, `#[ignore]`d elsewhere.
29//!
30//! A harness opens the backend; each call to `open` returns a new handle over the same
31//! data, as a restarted or second process would see it. Each case writes under fresh
32//! process ids, so a harness may point every case at one shared database. The macros need
33//! `tokio` with the `macros` and `rt-multi-thread` features in the calling crate, and
34//! apply the attributes written before `harness =` to every generated test.
35//!
36//! # Example
37//!
38//! ```rust,ignore
39//! use std::sync::Arc;
40//! use adk_kernel::conformance::ProcessStoreHarness;
41//! use adk_kernel::{InMemoryProcessStore, ProcessStore};
42//!
43//! struct InMemory;
44//!
45//! #[async_trait::async_trait]
46//! impl ProcessStoreHarness for InMemory {
47//!     async fn open(&self) -> Arc<dyn ProcessStore> {
48//!         Arc::new(InMemoryProcessStore::new())
49//!     }
50//!
51//!     fn is_durable(&self) -> bool {
52//!         false
53//!     }
54//! }
55//!
56//! adk_kernel::process_store_conformance_tests! { harness = InMemory }
57//! ```
58
59pub mod agenda_store;
60pub mod agent_store;
61#[cfg(feature = "channels")]
62pub mod channel_binding_store;
63#[cfg(feature = "channels")]
64pub mod channel_contract;
65#[cfg(feature = "charter")]
66pub mod charter;
67pub mod control_store;
68pub mod cron_watermark_store;
69pub mod device_store;
70#[cfg(feature = "drivers")]
71pub mod driver_store;
72#[cfg(feature = "proc")]
73pub mod ledger_store;
74pub mod partition_store;
75pub mod process_store;
76
77pub use agenda_store::AgendaStoreHarness;
78pub use agent_store::AgentStoreHarness;
79#[cfg(feature = "channels")]
80pub use channel_binding_store::ChannelBindingStoreHarness;
81#[cfg(feature = "channels")]
82pub use channel_contract::{ChannelAdapter, ChannelAdapterHarness, ContractHost};
83pub use control_store::ControlStoreHarness;
84pub use cron_watermark_store::CronWatermarkStoreHarness;
85pub use device_store::DeviceStoreHarness;
86#[cfg(feature = "drivers")]
87pub use driver_store::DriverStoreHarness;
88#[cfg(feature = "proc")]
89pub use ledger_store::LedgerStoreHarness;
90pub use partition_store::PartitionStoreHarness;
91pub use process_store::ProcessStoreHarness;
92
93/// Generates one test per [`agenda_store`] case for an [`AgendaStoreHarness`] (spec 3.2
94/// §7.5, §11).
95///
96/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
97/// see the [module documentation](crate::conformance).
98#[macro_export]
99macro_rules! agenda_store_conformance_tests {
100    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
101        $(#[$attr])*
102        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
103        async fn agenda_store_put_get_round_trip() {
104            $crate::conformance::agenda_store::put_get_round_trip(&$harness).await;
105        }
106        $(#[$attr])*
107        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
108        async fn agenda_store_put_replaces() {
109            $crate::conformance::agenda_store::put_replaces(&$harness).await;
110        }
111        $(#[$attr])*
112        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
113        async fn agenda_store_list_filters_and_orders() {
114            $crate::conformance::agenda_store::list_filters_and_orders(&$harness).await;
115        }
116        $(#[$attr])*
117        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
118        async fn agenda_store_transition_compares_the_state() {
119            $crate::conformance::agenda_store::transition_compares_the_state(&$harness).await;
120        }
121        $(#[$attr])*
122        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
123        async fn agenda_store_concurrent_transitions_move_once() {
124            $crate::conformance::agenda_store::concurrent_transitions_move_once(&$harness).await;
125        }
126        $(#[$attr])*
127        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
128        async fn agenda_store_delete() {
129            $crate::conformance::agenda_store::delete(&$harness).await;
130        }
131        $(#[$attr])*
132        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
133        async fn agenda_store_records_survive_a_restart() {
134            $crate::conformance::agenda_store::records_survive_a_restart(&$harness).await;
135        }
136        $(#[$attr])*
137        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
138        async fn agenda_store_concurrent_writers() {
139            $crate::conformance::agenda_store::concurrent_writers(&$harness).await;
140        }
141    };
142}
143
144/// Generates one test per `ledger_store` case for a `LedgerStoreHarness` (spec 3.2 §7.10,
145/// §11; feature `proc`).
146///
147/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
148/// see the [module documentation](crate::conformance).
149#[cfg(feature = "proc")]
150#[macro_export]
151macro_rules! ledger_store_conformance_tests {
152    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
153        $(#[$attr])*
154        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
155        async fn ledger_store_append_round_trips() {
156            $crate::conformance::ledger_store::append_round_trips(&$harness).await;
157        }
158        $(#[$attr])*
159        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
160        async fn ledger_store_list_filters_and_pages() {
161            $crate::conformance::ledger_store::list_filters_and_pages(&$harness).await;
162        }
163        $(#[$attr])*
164        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
165        async fn ledger_store_records_survive_a_restart() {
166            $crate::conformance::ledger_store::records_survive_a_restart(&$harness).await;
167        }
168        $(#[$attr])*
169        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
170        async fn ledger_store_concurrent_appends() {
171            $crate::conformance::ledger_store::concurrent_appends(&$harness).await;
172        }
173        $(#[$attr])*
174        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
175        async fn ledger_store_sustained_appends() {
176            $crate::conformance::ledger_store::sustained_appends(&$harness).await;
177        }
178        $(#[$attr])*
179        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
180        async fn ledger_store_observations_replace_and_order() {
181            $crate::conformance::ledger_store::observations_replace_and_order(&$harness).await;
182        }
183        $(#[$attr])*
184        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
185        async fn ledger_store_pass_states_round_trip() {
186            $crate::conformance::ledger_store::pass_states_round_trip(&$harness).await;
187        }
188    };
189}
190
191/// Generates one test per [`cron_watermark_store`] case for a [`CronWatermarkStoreHarness`]
192/// (spec 3.2 §7.4, §11).
193///
194/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
195/// see the [module documentation](crate::conformance).
196#[macro_export]
197macro_rules! cron_watermark_store_conformance_tests {
198    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
199        $(#[$attr])*
200        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
201        async fn cron_watermark_store_unknown_source() {
202            $crate::conformance::cron_watermark_store::unknown_source(&$harness).await;
203        }
204        $(#[$attr])*
205        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
206        async fn cron_watermark_store_advance_then_read() {
207            $crate::conformance::cron_watermark_store::advance_then_read(&$harness).await;
208        }
209        $(#[$attr])*
210        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
211        async fn cron_watermark_store_never_moves_back() {
212            $crate::conformance::cron_watermark_store::never_moves_back(&$harness).await;
213        }
214        $(#[$attr])*
215        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
216        async fn cron_watermark_store_delete() {
217            $crate::conformance::cron_watermark_store::delete(&$harness).await;
218        }
219        $(#[$attr])*
220        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
221        async fn cron_watermark_store_cursors_survive_a_restart() {
222            $crate::conformance::cron_watermark_store::cursors_survive_a_restart(&$harness).await;
223        }
224        $(#[$attr])*
225        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
226        async fn cron_watermark_store_concurrent_advances_keep_the_latest() {
227            $crate::conformance::cron_watermark_store::concurrent_advances_keep_the_latest(
228                &$harness,
229            )
230            .await;
231        }
232    };
233}
234
235/// Generates one test per [`partition_store`] case for a [`PartitionStoreHarness`] (spec 3.2
236/// §7.8, §11).
237///
238/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
239/// see the [module documentation](crate::conformance).
240#[macro_export]
241macro_rules! partition_store_conformance_tests {
242    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
243        $(#[$attr])*
244        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
245        async fn partition_store_put_get_round_trip() {
246            $crate::conformance::partition_store::put_get_round_trip(&$harness).await;
247        }
248        $(#[$attr])*
249        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
250        async fn partition_store_put_replaces() {
251            $crate::conformance::partition_store::put_replaces(&$harness).await;
252        }
253        $(#[$attr])*
254        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
255        async fn partition_store_list_orders_by_id() {
256            $crate::conformance::partition_store::list_orders_by_id(&$harness).await;
257        }
258        $(#[$attr])*
259        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
260        async fn partition_store_delete() {
261            $crate::conformance::partition_store::delete(&$harness).await;
262        }
263        $(#[$attr])*
264        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
265        async fn partition_store_unknown_partition() {
266            $crate::conformance::partition_store::unknown_partition(&$harness).await;
267        }
268        $(#[$attr])*
269        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
270        async fn partition_store_crossings_filter_and_order() {
271            $crate::conformance::partition_store::crossings_filter_and_order(&$harness).await;
272        }
273        $(#[$attr])*
274        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
275        async fn partition_store_crossing_records_round_trip() {
276            $crate::conformance::partition_store::crossing_records_round_trip(&$harness).await;
277        }
278        $(#[$attr])*
279        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
280        async fn partition_store_run_grants_stay_in_their_run() {
281            $crate::conformance::partition_store::run_grants_stay_in_their_run(&$harness).await;
282        }
283        $(#[$attr])*
284        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
285        async fn partition_store_released_runs_hold_no_grants() {
286            $crate::conformance::partition_store::released_runs_hold_no_grants(&$harness).await;
287        }
288        $(#[$attr])*
289        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
290        async fn partition_store_records_survive_a_restart() {
291            $crate::conformance::partition_store::records_survive_a_restart(&$harness).await;
292        }
293        $(#[$attr])*
294        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
295        async fn partition_store_concurrent_writers() {
296            $crate::conformance::partition_store::concurrent_writers(&$harness).await;
297        }
298    };
299}
300
301/// Generates one test per [`process_store`] case for a [`ProcessStoreHarness`].
302///
303/// See the [module documentation](crate::conformance) for an example.
304#[macro_export]
305macro_rules! process_store_conformance_tests {
306    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
307        $(#[$attr])*
308        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
309        async fn process_store_put_get_round_trip() {
310            $crate::conformance::process_store::put_get_round_trip(&$harness).await;
311        }
312        $(#[$attr])*
313        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
314        async fn process_store_put_replaces() {
315            $crate::conformance::process_store::put_replaces(&$harness).await;
316        }
317        $(#[$attr])*
318        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
319        async fn process_store_list_filters_and_orders() {
320            $crate::conformance::process_store::list_filters_and_orders(&$harness).await;
321        }
322        $(#[$attr])*
323        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
324        async fn process_store_set_wake_and_queue() {
325            $crate::conformance::process_store::set_wake_and_queue(&$harness).await;
326        }
327        $(#[$attr])*
328        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
329        async fn process_store_unknown_pid() {
330            $crate::conformance::process_store::unknown_pid(&$harness).await;
331        }
332        $(#[$attr])*
333        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
334        async fn process_store_delete() {
335            $crate::conformance::process_store::delete(&$harness).await;
336        }
337        $(#[$attr])*
338        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
339        async fn process_store_records_survive_a_restart() {
340            $crate::conformance::process_store::records_survive_a_restart(&$harness).await;
341        }
342        $(#[$attr])*
343        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
344        async fn process_store_concurrent_writers() {
345            $crate::conformance::process_store::concurrent_writers(&$harness).await;
346        }
347        $(#[$attr])*
348        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
349        async fn process_store_sustained_writes() {
350            $crate::conformance::process_store::sustained_writes(&$harness).await;
351        }
352        $(#[$attr])*
353        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
354        async fn process_store_suspend_request_round_trips() {
355            $crate::conformance::process_store::suspend_request_round_trips(&$harness).await;
356        }
357        $(#[$attr])*
358        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
359        async fn process_store_spend_sums_by_day_and_scope() {
360            $crate::conformance::process_store::spend_sums_by_day_and_scope(&$harness).await;
361        }
362        $(#[$attr])*
363        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
364        async fn process_store_usage_sums_counters_by_day_and_scope() {
365            $crate::conformance::process_store::usage_sums_counters_by_day_and_scope(&$harness)
366                .await;
367        }
368    };
369}
370
371/// Generates one test per `driver_store` case for a `DriverStoreHarness` (feature
372/// `drivers`).
373///
374/// See the [module documentation](crate::conformance) for the form; the harness implements
375/// `DriverStoreHarness` instead.
376#[cfg(feature = "drivers")]
377#[macro_export]
378macro_rules! driver_store_conformance_tests {
379    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
380        $(#[$attr])*
381        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
382        async fn driver_store_put_get_round_trip() {
383            $crate::conformance::driver_store::put_get_round_trip(&$harness).await;
384        }
385        $(#[$attr])*
386        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
387        async fn driver_store_put_replaces() {
388            $crate::conformance::driver_store::put_replaces(&$harness).await;
389        }
390        $(#[$attr])*
391        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
392        async fn driver_store_list_orders_by_id() {
393            $crate::conformance::driver_store::list_orders_by_id(&$harness).await;
394        }
395        $(#[$attr])*
396        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
397        async fn driver_store_unknown_id() {
398            $crate::conformance::driver_store::unknown_id(&$harness).await;
399        }
400        $(#[$attr])*
401        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
402        async fn driver_store_delete() {
403            $crate::conformance::driver_store::delete(&$harness).await;
404        }
405        $(#[$attr])*
406        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
407        async fn driver_store_records_survive_a_restart() {
408            $crate::conformance::driver_store::records_survive_a_restart(&$harness).await;
409        }
410        $(#[$attr])*
411        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
412        async fn driver_store_concurrent_writers() {
413            $crate::conformance::driver_store::concurrent_writers(&$harness).await;
414        }
415        $(#[$attr])*
416        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
417        async fn driver_store_park_round_trip_per_kind() {
418            $crate::conformance::driver_store::park_round_trip_per_kind(&$harness).await;
419        }
420        $(#[$attr])*
421        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
422        async fn driver_store_parks_are_keyed_by_scope_and_call() {
423            $crate::conformance::driver_store::parks_are_keyed_by_scope_and_call(&$harness).await;
424        }
425        $(#[$attr])*
426        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
427        async fn driver_store_list_parks_filters_by_driver() {
428            $crate::conformance::driver_store::list_parks_filters_by_driver(&$harness).await;
429        }
430        $(#[$attr])*
431        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
432        async fn driver_store_delete_park() {
433            $crate::conformance::driver_store::delete_park(&$harness).await;
434        }
435    };
436}