tinyagents 1.0.0

A recursive language-model (RLM) harness for Rust.
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
//! Unit tests for the in-memory checkpointer: `put`/`get`/`list` roundtrips
//! (including latest-vs-specific lookup and missing threads) and the shared
//! storage guarantee across cheap clones.

use super::*;
use crate::harness::ids::NodeId;
use serde_json::json;

fn checkpoint(thread: &str, id: &str, parent: Option<&str>, step: usize) -> Checkpoint<i32> {
    Checkpoint {
        thread_id: thread.to_string(),
        checkpoint_id: id.to_string(),
        run_id: None,
        parent_checkpoint_id: parent.map(|s| s.to_string()),
        namespace: vec![],
        state: step as i32,
        next_nodes: vec![NodeId::from("n")],
        completed_tasks: vec![],
        pending_writes: vec![],
        interrupts: vec![],
        metadata: json!({ "source": "loop", "step": step }),
    }
}

#[tokio::test]
async fn put_get_list_roundtrip() {
    let cp = InMemoryCheckpointer::<i32>::new();

    cp.put(checkpoint("t1", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("t1", "c2", Some("c1"), 2)).await.unwrap();

    // latest
    let latest = cp.get("t1", None).await.unwrap().unwrap();
    assert_eq!(latest.checkpoint_id, "c2");
    assert_eq!(latest.state, 2);

    // specific
    let first = cp.get("t1", Some("c1")).await.unwrap().unwrap();
    assert_eq!(first.checkpoint_id, "c1");

    // missing thread
    assert!(cp.get("other", None).await.unwrap().is_none());

    // list
    let list = cp.list("t1").await.unwrap();
    assert_eq!(list.len(), 2);
    assert_eq!(list[0].checkpoint_id, "c1");
    assert_eq!(list[1].parent_checkpoint_id.as_deref(), Some("c1"));
    assert_eq!(list[1].step, 2);
}

#[tokio::test]
async fn clones_share_storage() {
    let cp = InMemoryCheckpointer::<i32>::new();
    let cp2 = cp.clone();
    cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
    assert_eq!(cp2.count("t"), 1);
}

#[test]
fn checkpoint_source_roundtrips_string_and_display() {
    for src in [
        CheckpointSource::Input,
        CheckpointSource::Loop,
        CheckpointSource::Update,
        CheckpointSource::Fork,
    ] {
        let s = src.to_string();
        assert_eq!(s, src.as_str());
        assert_eq!(CheckpointSource::parse(&s), Some(src));
        // serde wire form matches the Display/string form.
        let json = serde_json::to_string(&src).unwrap();
        assert_eq!(json, format!("\"{s}\""));
    }
    assert_eq!(CheckpointSource::parse("nope"), None);
}

#[test]
fn durability_mode_defaults_to_sync() {
    assert_eq!(DurabilityMode::default(), DurabilityMode::Sync);
}

#[tokio::test]
async fn list_metadata_parses_source_enum() {
    let cp = InMemoryCheckpointer::<i32>::new();
    let mut c = checkpoint("t1", "c1", None, 0);
    c.metadata = json!({ "source": "input", "step": 0 });
    cp.put(c).await.unwrap();
    // Unknown/missing source falls back to `loop`.
    let mut c2 = checkpoint("t1", "c2", Some("c1"), 1);
    c2.metadata = json!({ "step": 1 });
    cp.put(c2).await.unwrap();

    let list = cp.list("t1").await.unwrap();
    assert_eq!(list[0].source, CheckpointSource::Input);
    assert_eq!(list[1].source, CheckpointSource::Loop);
}

#[tokio::test]
async fn get_tuple_composes_config_and_parent() {
    let cp = InMemoryCheckpointer::<i32>::new();
    cp.put(checkpoint("t1", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("t1", "c2", Some("c1"), 2)).await.unwrap();

    // Latest tuple resolves the concrete id and its parent config.
    let tuple = cp
        .get_tuple(CheckpointConfig::latest("t1"))
        .await
        .unwrap()
        .unwrap();
    assert_eq!(tuple.config.checkpoint_id.as_deref(), Some("c2"));
    assert_eq!(tuple.checkpoint.checkpoint_id, "c2");
    let parent = tuple.parent_config.unwrap();
    assert_eq!(parent.checkpoint_id.as_deref(), Some("c1"));
    assert_eq!(parent.thread_id, "t1");

    // The root checkpoint has no parent config.
    let root = cp
        .get_tuple(CheckpointConfig {
            thread_id: "t1".to_string(),
            checkpoint_id: Some("c1".to_string()),
            namespace: vec![],
        })
        .await
        .unwrap()
        .unwrap();
    assert!(root.parent_config.is_none());

    // Missing thread yields no tuple.
    assert!(
        cp.get_tuple(CheckpointConfig::latest("missing"))
            .await
            .unwrap()
            .is_none()
    );
}

#[tokio::test]
async fn list_threads_and_delete_thread() {
    let cp = InMemoryCheckpointer::<i32>::new();
    cp.put(checkpoint("a", "a1", None, 1)).await.unwrap();
    cp.put(checkpoint("b", "b1", None, 1)).await.unwrap();

    let mut threads = cp.list_threads().await.unwrap();
    threads.sort();
    assert_eq!(threads, vec!["a".to_string(), "b".to_string()]);

    cp.delete_thread("a").await.unwrap();
    assert_eq!(cp.list_threads().await.unwrap(), vec!["b".to_string()]);
    assert!(cp.get("a", None).await.unwrap().is_none());
    // Deleting a missing thread is a no-op.
    cp.delete_thread("missing").await.unwrap();
}

#[tokio::test]
async fn delete_by_run_removes_only_matching_run() {
    let cp = InMemoryCheckpointer::<i32>::new();
    let mut c1 = checkpoint("t", "c1", None, 1);
    c1.run_id = Some("run-1".to_string());
    let mut c2 = checkpoint("t", "c2", Some("c1"), 2);
    c2.run_id = Some("run-2".to_string());
    let mut c3 = checkpoint("t", "c3", Some("c2"), 3);
    c3.run_id = Some("run-2".to_string());
    cp.put(c1).await.unwrap();
    cp.put(c2).await.unwrap();
    cp.put(c3).await.unwrap();

    let removed = cp.delete_by_run("t", "run-2").await.unwrap();
    assert_eq!(removed, 2);
    let remaining: Vec<String> = cp
        .list("t")
        .await
        .unwrap()
        .into_iter()
        .map(|m| m.checkpoint_id)
        .collect();
    assert_eq!(remaining, vec!["c1".to_string()]);
    // Records with no run id are never matched.
    assert_eq!(cp.delete_by_run("t", "run-1").await.unwrap(), 1);
}

#[tokio::test]
async fn copy_thread_preserves_lineage() {
    let cp = InMemoryCheckpointer::<i32>::new();
    cp.put(checkpoint("src", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("src", "c2", Some("c1"), 2))
        .await
        .unwrap();
    cp.put(checkpoint("src", "c3", Some("c2"), 3))
        .await
        .unwrap();

    cp.copy_thread("src", "dst").await.unwrap();

    // The source is untouched.
    assert_eq!(cp.count("src"), 3);

    // The target carries the same records (ids + parent chain) under a new
    // thread id, so time-travel walks the copied thread identically.
    let copied = cp.list("dst").await.unwrap();
    assert_eq!(copied.len(), 3);
    assert!(copied.iter().all(|m| m.thread_id == "dst"));
    assert_eq!(copied[0].checkpoint_id, "c1");
    assert_eq!(copied[0].parent_checkpoint_id, None);
    assert_eq!(copied[2].checkpoint_id, "c3");
    assert_eq!(copied[2].parent_checkpoint_id.as_deref(), Some("c2"));

    // The copied checkpoint's state and addressing are intact.
    let tip = cp.get("dst", None).await.unwrap().unwrap();
    assert_eq!(tip.thread_id, "dst");
    assert_eq!(tip.state, 3);
}

#[tokio::test]
async fn prune_keeps_window_and_full_ancestor_chain() {
    let cp = InMemoryCheckpointer::<i32>::new();
    // Linear lineage c1 <- c2 <- c3 <- c4 <- c5.
    cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("t", "c2", Some("c1"), 2)).await.unwrap();
    cp.put(checkpoint("t", "c3", Some("c2"), 3)).await.unwrap();
    cp.put(checkpoint("t", "c4", Some("c3"), 4)).await.unwrap();
    cp.put(checkpoint("t", "c5", Some("c4"), 5)).await.unwrap();

    // Keep the last 2 (c4, c5). Their ancestor chain (c3, c2, c1) must be
    // retained too — a linear lineage protects everything, deleting nothing.
    let removed = cp.prune("t", 2).await.unwrap();
    assert_eq!(removed, 0);
    assert_eq!(cp.count("t"), 5);
}

#[tokio::test]
async fn prune_drops_off_lineage_branches() {
    let cp = InMemoryCheckpointer::<i32>::new();
    // c1 is the shared root. A dead fork b2 branches off c1 and is never an
    // ancestor of the kept tip; the live spine is c1 <- m2 <- m3.
    cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("t", "b2", Some("c1"), 2)).await.unwrap();
    cp.put(checkpoint("t", "m2", Some("c1"), 3)).await.unwrap();
    cp.put(checkpoint("t", "m3", Some("m2"), 4)).await.unwrap();

    // Keep the last 1 (m3). Protected = {m3} ∪ ancestors {m2, c1}. The dead
    // fork b2 is not an ancestor of anything kept, so it is pruned, but the
    // ancestor chain a kept delta depends on (m2, c1) survives.
    let removed = cp.prune("t", 1).await.unwrap();
    assert_eq!(removed, 1);
    let remaining: std::collections::HashSet<String> = cp
        .list("t")
        .await
        .unwrap()
        .into_iter()
        .map(|m| m.checkpoint_id)
        .collect();
    assert_eq!(
        remaining,
        ["c1", "m2", "m3"].iter().map(|s| s.to_string()).collect()
    );
}

#[tokio::test]
async fn prune_zero_keeps_latest_and_its_chain() {
    let cp = InMemoryCheckpointer::<i32>::new();
    cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
    cp.put(checkpoint("t", "c2", Some("c1"), 2)).await.unwrap();

    // keep_last == 0 is clamped to 1: the latest checkpoint (and its ancestor
    // chain) is always retained so the thread stays resumable.
    let removed = cp.prune("t", 0).await.unwrap();
    assert_eq!(removed, 0);
    assert_eq!(cp.count("t"), 2);
}

// ---- File-backed checkpointer ---------------------------------------------

mod file_backend {
    use super::checkpoint;
    use crate::graph::checkpoint::{CheckpointConfig, Checkpointer, FileCheckpointer};
    use std::path::PathBuf;

    /// A unique-per-test temp dir derived from the test name + pid (no clock).
    struct TempDir(PathBuf);

    impl TempDir {
        fn new(test_name: &str) -> Self {
            let dir = std::env::temp_dir().join(format!(
                "tinyagents-ckpt-{}-{}",
                test_name,
                std::process::id()
            ));
            let _ = std::fs::remove_dir_all(&dir);
            Self(dir)
        }

        fn path(&self) -> &std::path::Path {
            &self.0
        }
    }

    impl Drop for TempDir {
        fn drop(&mut self) {
            let _ = std::fs::remove_dir_all(&self.0);
        }
    }

    #[tokio::test]
    async fn put_get_list_roundtrip_survives_a_fresh_handle() {
        let tmp = TempDir::new("roundtrip");
        let cp = FileCheckpointer::<i32>::new(tmp.path());

        cp.put(checkpoint("t1", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("t1", "c2", Some("c1"), 2)).await.unwrap();

        // A brand-new handle over the same dir reads what was persisted —
        // proving the records hit disk rather than living in memory.
        let reopened = FileCheckpointer::<i32>::new(tmp.path());
        let latest = reopened.get("t1", None).await.unwrap().unwrap();
        assert_eq!(latest.checkpoint_id, "c2");
        assert_eq!(latest.state, 2);

        let first = reopened.get("t1", Some("c1")).await.unwrap().unwrap();
        assert_eq!(first.checkpoint_id, "c1");
        assert!(reopened.get("t1", Some("nope")).await.unwrap().is_none());
        assert!(reopened.get("missing", None).await.unwrap().is_none());

        let list = reopened.list("t1").await.unwrap();
        assert_eq!(list.len(), 2);
        assert_eq!(list[0].checkpoint_id, "c1");
        assert_eq!(list[1].parent_checkpoint_id.as_deref(), Some("c1"));
        assert_eq!(list[1].step, 2);

        // The tuple convenience composes config + parent from the persisted record.
        let tuple = reopened
            .get_tuple(CheckpointConfig::latest("t1"))
            .await
            .unwrap()
            .unwrap();
        assert_eq!(tuple.config.checkpoint_id.as_deref(), Some("c2"));
        assert_eq!(
            tuple.parent_config.unwrap().checkpoint_id.as_deref(),
            Some("c1")
        );
    }

    #[tokio::test]
    async fn list_threads_and_delete_thread_track_files() {
        let tmp = TempDir::new("threads");
        // A thread id with separators/spaces exercises filename escaping.
        let cp = FileCheckpointer::<i32>::new(tmp.path());
        cp.put(checkpoint("a/b c", "x1", None, 1)).await.unwrap();
        cp.put(checkpoint("b", "b1", None, 1)).await.unwrap();

        let mut threads = cp.list_threads().await.unwrap();
        threads.sort();
        assert_eq!(threads, vec!["a/b c".to_string(), "b".to_string()]);

        cp.delete_thread("a/b c").await.unwrap();
        assert_eq!(cp.list_threads().await.unwrap(), vec!["b".to_string()]);
        assert!(cp.get("a/b c", None).await.unwrap().is_none());
        // Deleting a missing thread is a no-op.
        cp.delete_thread("missing").await.unwrap();
    }

    #[tokio::test]
    async fn prune_rewrites_the_thread_file() {
        let tmp = TempDir::new("prune");
        let cp = FileCheckpointer::<i32>::new(tmp.path());
        cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("t", "b2", Some("c1"), 2)).await.unwrap();
        cp.put(checkpoint("t", "m2", Some("c1"), 3)).await.unwrap();
        cp.put(checkpoint("t", "m3", Some("m2"), 4)).await.unwrap();

        // Keep last 1 (m3) + its ancestors (m2, c1); the dead fork b2 is pruned.
        let removed = cp.prune("t", 1).await.unwrap();
        assert_eq!(removed, 1);
        let remaining: std::collections::HashSet<String> = cp
            .list("t")
            .await
            .unwrap()
            .into_iter()
            .map(|m| m.checkpoint_id)
            .collect();
        assert_eq!(
            remaining,
            ["c1", "m2", "m3"].iter().map(|s| s.to_string()).collect()
        );

        // Deleting everything removes the underlying file, so the thread drops
        // out of the listing.
        cp.delete_checkpoints("t", &["c1".into(), "m2".into(), "m3".into()])
            .await
            .unwrap();
        assert!(cp.list_threads().await.unwrap().is_empty());
    }

    #[tokio::test]
    async fn copy_thread_rewrites_thread_ids_on_disk() {
        let tmp = TempDir::new("copy");
        let cp = FileCheckpointer::<i32>::new(tmp.path());
        cp.put(checkpoint("src", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("src", "c2", Some("c1"), 2))
            .await
            .unwrap();
        cp.put(checkpoint("src", "c3", Some("c2"), 3))
            .await
            .unwrap();

        cp.copy_thread("src", "dst").await.unwrap();

        // Source untouched.
        assert_eq!(cp.list("src").await.unwrap().len(), 3);

        // Target carries the same lineage under the new thread id.
        let copied = cp.list("dst").await.unwrap();
        assert_eq!(copied.len(), 3);
        assert!(copied.iter().all(|m| m.thread_id == "dst"));
        assert_eq!(copied[2].checkpoint_id, "c3");
        assert_eq!(copied[2].parent_checkpoint_id.as_deref(), Some("c2"));
        let tip = cp.get("dst", None).await.unwrap().unwrap();
        assert_eq!(tip.thread_id, "dst");
        assert_eq!(tip.state, 3);
    }
}

// ---- SQLite-backed checkpointer (feature = "sqlite") ----------------------

#[cfg(feature = "sqlite")]
mod sqlite_backend {
    use super::checkpoint;
    use crate::graph::checkpoint::{CheckpointConfig, Checkpointer, SqliteCheckpointer};

    #[tokio::test]
    async fn put_get_list_roundtrip_in_memory() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();

        cp.put(checkpoint("t1", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("t1", "c2", Some("c1"), 2)).await.unwrap();

        // latest
        let latest = cp.get("t1", None).await.unwrap().unwrap();
        assert_eq!(latest.checkpoint_id, "c2");
        assert_eq!(latest.state, 2);

        // specific
        let first = cp.get("t1", Some("c1")).await.unwrap().unwrap();
        assert_eq!(first.checkpoint_id, "c1");

        // missing checkpoint + missing thread
        assert!(cp.get("t1", Some("nope")).await.unwrap().is_none());
        assert!(cp.get("missing", None).await.unwrap().is_none());

        // list preserves insertion order + projects metadata from columns
        let list = cp.list("t1").await.unwrap();
        assert_eq!(list.len(), 2);
        assert_eq!(list[0].checkpoint_id, "c1");
        assert_eq!(list[1].parent_checkpoint_id.as_deref(), Some("c1"));
        assert_eq!(list[1].step, 2);

        // get_tuple composes config + parent from the persisted record
        let tuple = cp
            .get_tuple(CheckpointConfig::latest("t1"))
            .await
            .unwrap()
            .unwrap();
        assert_eq!(tuple.config.checkpoint_id.as_deref(), Some("c2"));
        assert_eq!(
            tuple.parent_config.unwrap().checkpoint_id.as_deref(),
            Some("c1")
        );
    }

    #[tokio::test]
    async fn clones_share_the_in_memory_database() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();
        let cp2 = cp.clone();
        cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
        // The clone observes the write because both share one connection.
        assert!(cp2.get("t", None).await.unwrap().is_some());
    }

    #[tokio::test]
    async fn list_threads_and_delete_thread() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();
        cp.put(checkpoint("a", "a1", None, 1)).await.unwrap();
        cp.put(checkpoint("b", "b1", None, 1)).await.unwrap();

        let mut threads = cp.list_threads().await.unwrap();
        threads.sort();
        assert_eq!(threads, vec!["a".to_string(), "b".to_string()]);

        cp.delete_thread("a").await.unwrap();
        assert_eq!(cp.list_threads().await.unwrap(), vec!["b".to_string()]);
        assert!(cp.get("a", None).await.unwrap().is_none());
        // Deleting a missing thread is a no-op.
        cp.delete_thread("missing").await.unwrap();
    }

    #[tokio::test]
    async fn prune_keeps_window_and_ancestor_chain() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();
        // c1 shared root; b2 is a dead fork; live spine c1 <- m2 <- m3.
        cp.put(checkpoint("t", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("t", "b2", Some("c1"), 2)).await.unwrap();
        cp.put(checkpoint("t", "m2", Some("c1"), 3)).await.unwrap();
        cp.put(checkpoint("t", "m3", Some("m2"), 4)).await.unwrap();

        let removed = cp.prune("t", 1).await.unwrap();
        assert_eq!(removed, 1);
        let remaining: std::collections::HashSet<String> = cp
            .list("t")
            .await
            .unwrap()
            .into_iter()
            .map(|m| m.checkpoint_id)
            .collect();
        assert_eq!(
            remaining,
            ["c1", "m2", "m3"].iter().map(|s| s.to_string()).collect()
        );
    }

    #[tokio::test]
    async fn delete_by_run_removes_only_matching_run() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();
        let mut c1 = checkpoint("t", "c1", None, 1);
        c1.run_id = Some("run-1".to_string());
        let mut c2 = checkpoint("t", "c2", Some("c1"), 2);
        c2.run_id = Some("run-2".to_string());
        cp.put(c1).await.unwrap();
        cp.put(c2).await.unwrap();

        assert_eq!(cp.delete_by_run("t", "run-2").await.unwrap(), 1);
        let remaining: Vec<String> = cp
            .list("t")
            .await
            .unwrap()
            .into_iter()
            .map(|m| m.checkpoint_id)
            .collect();
        assert_eq!(remaining, vec!["c1".to_string()]);
    }

    #[tokio::test]
    async fn copy_thread_preserves_lineage() {
        let cp = SqliteCheckpointer::<i32>::in_memory().unwrap();
        cp.put(checkpoint("src", "c1", None, 1)).await.unwrap();
        cp.put(checkpoint("src", "c2", Some("c1"), 2))
            .await
            .unwrap();
        cp.put(checkpoint("src", "c3", Some("c2"), 3))
            .await
            .unwrap();

        cp.copy_thread("src", "dst").await.unwrap();

        // Source untouched.
        assert_eq!(cp.list("src").await.unwrap().len(), 3);

        // Target carries the same lineage under the new thread id.
        let copied = cp.list("dst").await.unwrap();
        assert_eq!(copied.len(), 3);
        assert!(copied.iter().all(|m| m.thread_id == "dst"));
        assert_eq!(copied[2].checkpoint_id, "c3");
        assert_eq!(copied[2].parent_checkpoint_id.as_deref(), Some("c2"));
        let tip = cp.get("dst", None).await.unwrap().unwrap();
        assert_eq!(tip.thread_id, "dst");
        assert_eq!(tip.state, 3);
    }
}