adk-kernel 3.0.0

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

pub mod agenda_store;
pub mod agent_store;
#[cfg(feature = "channels")]
pub mod channel_binding_store;
#[cfg(feature = "channels")]
pub mod channel_contract;
#[cfg(feature = "charter")]
pub mod charter;
pub mod control_store;
pub mod cron_watermark_store;
pub mod device_store;
#[cfg(feature = "drivers")]
pub mod driver_store;
#[cfg(feature = "proc")]
pub mod ledger_store;
pub mod partition_store;
pub mod process_store;

pub use agenda_store::AgendaStoreHarness;
pub use agent_store::AgentStoreHarness;
#[cfg(feature = "channels")]
pub use channel_binding_store::ChannelBindingStoreHarness;
#[cfg(feature = "channels")]
pub use channel_contract::{ChannelAdapter, ChannelAdapterHarness, ContractHost};
pub use control_store::ControlStoreHarness;
pub use cron_watermark_store::CronWatermarkStoreHarness;
pub use device_store::DeviceStoreHarness;
#[cfg(feature = "drivers")]
pub use driver_store::DriverStoreHarness;
#[cfg(feature = "proc")]
pub use ledger_store::LedgerStoreHarness;
pub use partition_store::PartitionStoreHarness;
pub use process_store::ProcessStoreHarness;

/// Generates one test per [`agenda_store`] case for an [`AgendaStoreHarness`] (spec 3.2
/// §7.5, §11).
///
/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
/// see the [module documentation](crate::conformance).
#[macro_export]
macro_rules! agenda_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_put_get_round_trip() {
            $crate::conformance::agenda_store::put_get_round_trip(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_put_replaces() {
            $crate::conformance::agenda_store::put_replaces(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_list_filters_and_orders() {
            $crate::conformance::agenda_store::list_filters_and_orders(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_transition_compares_the_state() {
            $crate::conformance::agenda_store::transition_compares_the_state(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_concurrent_transitions_move_once() {
            $crate::conformance::agenda_store::concurrent_transitions_move_once(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_delete() {
            $crate::conformance::agenda_store::delete(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_records_survive_a_restart() {
            $crate::conformance::agenda_store::records_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn agenda_store_concurrent_writers() {
            $crate::conformance::agenda_store::concurrent_writers(&$harness).await;
        }
    };
}

/// Generates one test per `ledger_store` case for a `LedgerStoreHarness` (spec 3.2 §7.10,
/// §11; feature `proc`).
///
/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
/// see the [module documentation](crate::conformance).
#[cfg(feature = "proc")]
#[macro_export]
macro_rules! ledger_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_append_round_trips() {
            $crate::conformance::ledger_store::append_round_trips(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_list_filters_and_pages() {
            $crate::conformance::ledger_store::list_filters_and_pages(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_records_survive_a_restart() {
            $crate::conformance::ledger_store::records_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_concurrent_appends() {
            $crate::conformance::ledger_store::concurrent_appends(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_sustained_appends() {
            $crate::conformance::ledger_store::sustained_appends(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_observations_replace_and_order() {
            $crate::conformance::ledger_store::observations_replace_and_order(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn ledger_store_pass_states_round_trip() {
            $crate::conformance::ledger_store::pass_states_round_trip(&$harness).await;
        }
    };
}

/// Generates one test per [`cron_watermark_store`] case for a [`CronWatermarkStoreHarness`]
/// (spec 3.2 §7.4, §11).
///
/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
/// see the [module documentation](crate::conformance).
#[macro_export]
macro_rules! cron_watermark_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_unknown_source() {
            $crate::conformance::cron_watermark_store::unknown_source(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_advance_then_read() {
            $crate::conformance::cron_watermark_store::advance_then_read(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_never_moves_back() {
            $crate::conformance::cron_watermark_store::never_moves_back(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_delete() {
            $crate::conformance::cron_watermark_store::delete(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_cursors_survive_a_restart() {
            $crate::conformance::cron_watermark_store::cursors_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn cron_watermark_store_concurrent_advances_keep_the_latest() {
            $crate::conformance::cron_watermark_store::concurrent_advances_keep_the_latest(
                &$harness,
            )
            .await;
        }
    };
}

/// Generates one test per [`partition_store`] case for a [`PartitionStoreHarness`] (spec 3.2
/// §7.8, §11).
///
/// Used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests) is;
/// see the [module documentation](crate::conformance).
#[macro_export]
macro_rules! partition_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_put_get_round_trip() {
            $crate::conformance::partition_store::put_get_round_trip(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_put_replaces() {
            $crate::conformance::partition_store::put_replaces(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_list_orders_by_id() {
            $crate::conformance::partition_store::list_orders_by_id(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_delete() {
            $crate::conformance::partition_store::delete(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_unknown_partition() {
            $crate::conformance::partition_store::unknown_partition(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_crossings_filter_and_order() {
            $crate::conformance::partition_store::crossings_filter_and_order(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_crossing_records_round_trip() {
            $crate::conformance::partition_store::crossing_records_round_trip(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_run_grants_stay_in_their_run() {
            $crate::conformance::partition_store::run_grants_stay_in_their_run(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_released_runs_hold_no_grants() {
            $crate::conformance::partition_store::released_runs_hold_no_grants(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_records_survive_a_restart() {
            $crate::conformance::partition_store::records_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn partition_store_concurrent_writers() {
            $crate::conformance::partition_store::concurrent_writers(&$harness).await;
        }
    };
}

/// Generates one test per [`process_store`] case for a [`ProcessStoreHarness`].
///
/// See the [module documentation](crate::conformance) for an example.
#[macro_export]
macro_rules! process_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_put_get_round_trip() {
            $crate::conformance::process_store::put_get_round_trip(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_put_replaces() {
            $crate::conformance::process_store::put_replaces(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_list_filters_and_orders() {
            $crate::conformance::process_store::list_filters_and_orders(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_set_wake_and_queue() {
            $crate::conformance::process_store::set_wake_and_queue(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_unknown_pid() {
            $crate::conformance::process_store::unknown_pid(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_delete() {
            $crate::conformance::process_store::delete(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_records_survive_a_restart() {
            $crate::conformance::process_store::records_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_concurrent_writers() {
            $crate::conformance::process_store::concurrent_writers(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_sustained_writes() {
            $crate::conformance::process_store::sustained_writes(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_suspend_request_round_trips() {
            $crate::conformance::process_store::suspend_request_round_trips(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_spend_sums_by_day_and_scope() {
            $crate::conformance::process_store::spend_sums_by_day_and_scope(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn process_store_usage_sums_counters_by_day_and_scope() {
            $crate::conformance::process_store::usage_sums_counters_by_day_and_scope(&$harness)
                .await;
        }
    };
}

/// Generates one test per `driver_store` case for a `DriverStoreHarness` (feature
/// `drivers`).
///
/// See the [module documentation](crate::conformance) for the form; the harness implements
/// `DriverStoreHarness` instead.
#[cfg(feature = "drivers")]
#[macro_export]
macro_rules! driver_store_conformance_tests {
    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_put_get_round_trip() {
            $crate::conformance::driver_store::put_get_round_trip(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_put_replaces() {
            $crate::conformance::driver_store::put_replaces(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_list_orders_by_id() {
            $crate::conformance::driver_store::list_orders_by_id(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_unknown_id() {
            $crate::conformance::driver_store::unknown_id(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_delete() {
            $crate::conformance::driver_store::delete(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_records_survive_a_restart() {
            $crate::conformance::driver_store::records_survive_a_restart(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_concurrent_writers() {
            $crate::conformance::driver_store::concurrent_writers(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_park_round_trip_per_kind() {
            $crate::conformance::driver_store::park_round_trip_per_kind(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_parks_are_keyed_by_scope_and_call() {
            $crate::conformance::driver_store::parks_are_keyed_by_scope_and_call(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_list_parks_filters_by_driver() {
            $crate::conformance::driver_store::list_parks_filters_by_driver(&$harness).await;
        }
        $(#[$attr])*
        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
        async fn driver_store_delete_park() {
            $crate::conformance::driver_store::delete_park(&$harness).await;
        }
    };
}