buntrail-engine 0.3.0

Authoritative document and workspace orchestration.
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
use super::*;
use buntrail_core::workspaces::{GitRecoveryKind, GitRecoveryReference};
use buntrail_services::{
    connections::local::LocalConnection, git::worktree_proof::WorktreePreparation,
};
use sha2::{Digest, Sha256};
use std::sync::{RwLockReadGuard, atomic::AtomicBool};

impl Runtime {
    pub fn document_admission(&self) -> Result<RwLockReadGuard<'_, ()>> {
        self.admission.try_read().map_err(|_| {
            fail(
                "busy",
                "A Git worktree change is pending; retry after it finishes",
            )
        })
    }
    pub(super) fn git_call(
        &self,
        route: Option<&str>,
        r: &Value,
        cancel: Option<Arc<AtomicBool>>,
    ) -> Result<Value> {
        let cancel = cancel.unwrap_or_else(|| Arc::new(AtomicBool::new(false)));
        let local = self
            .services
            .local_connection()
            .map_err(|e| fail("unavailable", e))?;
        let remote = route
            .map(|route| self.route(route))
            .transpose()?
            .map(|s| Arc::new(s.with_cancellation(cancel.clone())));
        if let Some(remote) = &remote {
            remote.validate_environment_ready().map_err(error)?;
        }
        let target = remote
            .as_ref()
            .map_or_else(|| local.identity.clone(), |s| s.target().clone());
        let backend = GitBackend {
            local: &local,
            remote: remote.as_deref(),
            cancel: &cancel,
        };
        let command = string(r, "command")?;
        if command == "git.pending" {
            let entries = local
                .store
                .load()
                .map_err(error)?
                .records
                .into_iter()
                .flat_map(|w| w.git_recoveries)
                .filter(|p| p.worktree.target == target)
                .collect::<Vec<_>>();
            return Ok(json!({"entries":entries}));
        }
        if command == "git.inspect" {
            let operation: OperationID = serde_json::from_value(r["operation"].clone())
                .map_err(|e| fail("invalid_request", e.to_string()))?;
            let reference = local
                .store
                .load()
                .map_err(error)?
                .records
                .into_iter()
                .flat_map(|w| w.git_recoveries)
                .find(|p| p.operation == operation && p.worktree.target == target)
                .ok_or_else(|| {
                    fail(
                        "not_found",
                        "Retained Git operation not found for this target",
                    )
                })?;
            let receipt = match &remote {
                Some(s) => run(s.inspect(operation, target.clone())),
                None => run(local.files.inspect(operation, target.clone())),
            }
            .map_err(error)?;
            Self::validate_git_receipt(&reference, &receipt)?;
            if resolved(&receipt.state) {
                local
                    .store
                    .resolve_git_recovery(reference.owner.workspace, &reference)
                    .map_err(error)?;
            }
            return Ok(
                json!({"receipt":receipt,"resolved":resolved(&receipt.state),"repository_action":reference.repository_action}),
            );
        }
        let root = FileRef {
            target: target.clone(),
            path: TargetPath::posix(string(r, "root")?.as_bytes().to_vec()).map_err(error)?,
            resolved_identity: None,
        };
        let worktree = backend
            .discover(root)?
            .ok_or_else(|| fail("not_git", "This folder is not a Git worktree"))?;
        if command == "git.repository" || command == "git.merge_state" {
            let snapshot = match &remote {
                Some(s) => run(s.repository(worktree)),
                None => local.git.repository_sync(worktree, &cancel),
            }
            .map_err(error)?;
            if command == "git.merge_state" {
                return Ok(json!(snapshot.merge));
            }
            let pending = local.store.load().map(|catalog| {
                catalog
                    .records
                    .into_iter()
                    .flat_map(|w| w.git_recoveries)
                    .filter(|p| p.worktree == snapshot.worktree)
                    .map(|p| p.operation)
                    .collect::<Vec<_>>()
            });
            let mut value = json!(snapshot);
            match pending {
                Ok(entries) => value["pending_operations"] = json!(entries),
                Err(error) => {
                    value["pending_operations"] = Value::Null;
                    value["pending_error"] = json!(error.message);
                }
            }
            return Ok(value);
        }
        if command == "git.commit" {
            let query = CommitQuery {
                worktree,
                oid: string(r, "oid")?.into(),
                cursor: r
                    .get("cursor")
                    .filter(|v| !v.is_null())
                    .map(|v| {
                        v.as_u64()
                            .ok_or_else(|| fail("invalid_request", "Invalid file cursor"))
                    })
                    .transpose()?,
            };
            return Ok(json!(
                match &remote {
                    Some(s) => run(s.commit(query)),
                    None => local.git.commit_sync(query, &cancel),
                }
                .map_err(error)?
            ));
        }
        if command == "git.commit_diff" {
            let path: TargetPath = serde_json::from_value(r["path"].clone())
                .map_err(|e| fail("invalid_request", e.to_string()))?;
            let query = DiffRequest {
                worktree,
                path,
                source: DiffSource::Commit(string(r, "oid")?.into()),
            };
            return Ok(json!(
                match &remote {
                    Some(s) => run(s.diff(query)),
                    None => local.git.diff_sync(query, &cancel),
                }
                .map_err(error)?
            ));
        }
        if command == "git.history" {
            let refs = r
                .get("refs")
                .map(|v| {
                    serde_json::from_value(v.clone())
                        .map_err(|e| fail("invalid_request", e.to_string()))
                })
                .transpose()?
                .unwrap_or_default();
            let cursor = r
                .get("cursor")
                .filter(|v| !v.is_null())
                .map(|v| {
                    serde_json::from_value(v.clone())
                        .map_err(|e| fail("invalid_request", e.to_string()))
                })
                .transpose()?;
            let query = HistoryQuery {
                filter: r
                    .get("filter")
                    .filter(|v| !v.is_null())
                    .map(|v| {
                        serde_json::from_value(v.clone())
                            .map_err(|e| fail("invalid_request", e.to_string()))
                    })
                    .transpose()?,
                worktree,
                ref_filter: refs,
                cursor,
            };
            return Ok(json!(
                match &remote {
                    Some(s) => run(s.history(query)),
                    None => local.git.history_sync(query, &cancel),
                }
                .map_err(error)?
            ));
        }
        let args = if command != "git.mutate" {
            let args = r["args"]
                .as_array()
                .ok_or_else(|| fail("invalid_request", "Git args must be an array"))?
                .iter()
                .map(|v| {
                    v.as_str()
                        .ok_or_else(|| fail("invalid_request", "Git args must be strings"))
                })
                .collect::<Result<Vec<_>>>()?;
            if let Some(query) = GitRead::from_args(&args) {
                let output = backend.read(worktree, query)?;
                return Ok(
                    json!({"stdout":String::from_utf8_lossy(&output.stdout),"stderr":String::from_utf8_lossy(&output.stderr),"status":if output.success{0}else{1},"truncated":false}),
                );
            }
            Some(args)
        } else {
            None
        };
        let initial = backend.status(worktree.clone())?;
        let mutation = if let Some(args) = args {
            mutation(&backend, &worktree, &initial.state, &args)?
        } else {
            let ExpectedState::Git {
                worktree: observed,
                state: expected,
            } = serde_json::from_value(r["expected"].clone())
                .map_err(|e| fail("invalid_request", e.to_string()))?
            else {
                return Err(fail(
                    "invalid_request",
                    "Expected a Git repository observation",
                ));
            };
            if observed != worktree {
                return Err(fail(
                    "target_changed",
                    "Repository identity changed; refresh and review this repository before applying an action",
                ));
            }
            if initial.state != expected {
                return Err(fail(
                    "stale_revision",
                    "Repository changed; refresh before applying this action",
                ));
            }
            GitMutation::Repository(
                serde_json::from_value(r["action"].clone())
                    .map_err(|e| fail("invalid_request", e.to_string()))?,
            )
        };
        if matches!(mutation, GitMutation::Repository(_))
            && let Some(remote) = &remote
        {
            remote.require_repository().map_err(error)?;
        }
        if local
            .store
            .load()
            .map_err(error)?
            .records
            .iter()
            .flat_map(|w| &w.git_recoveries)
            .any(|p| p.worktree == worktree)
        {
            return Err(fail(
                "mutation_uncertain",
                "Inspect pending Git operations for this repository before another mutation",
            ));
        }
        let changing = mutation.changes_worktree();
        let staging = matches!(mutation, GitMutation::Stage(_));
        let _exclusive = if changing || staging {
            Some(self.admission.try_write().map_err(|_| {
                fail(
                    "busy",
                    "Documents or filesystem operations are still active",
                )
            })?)
        } else {
            None
        };
        if changing || staging {
            let docs = self
                .documents
                .lock()
                .map_err(|_| fail("engine_failed", "Document registry poisoned"))?;
            if docs.open.values().any(|d| {
                d.path.is_some()
                    && (changing
                        || d.saving
                        || d.pending_save.is_some()
                        || d.buffer.checkpoint() != d.saved_state)
            }) {
                return Err(fail(
                    "busy",
                    if changing {
                        "Close bound documents before changing the worktree"
                    } else {
                        "Save bound documents and inspect pending saves before staging"
                    },
                ));
            }
        }
        let _worktree_lease = if changing {
            Some(self.git_gate.acquire(worktree.clone()).map_err(error)?)
        } else {
            None
        };
        let workspace = self.terminal_workspace(route, r)?;
        let owner = workspace.lock().unwrap().owner.clone();
        let mut local_observation = None;
        let mut remote_observation = None;
        let expected = if changing {
            if let Some(remote) = &remote {
                let observed = remote
                    .observe_owned(worktree.clone(), std::iter::empty(), |_| Ok(()))
                    .map_err(error)?;
                let state = observed.state.clone();
                remote_observation = Some(observed);
                state
            } else {
                let authority = local.observation_owner(owner.lease).map_err(error)?;
                let observed = local
                    .git
                    .observe_owned_sync(&authority, worktree.clone(), std::iter::empty(), &cancel)
                    .map_err(error)?;
                let state = observed.snapshot.state.clone();
                local_observation = Some((authority, observed));
                state
            }
        } else {
            initial.state.clone()
        };
        if let Err(error) = validate_repository_observation(&mutation, &initial.state, &expected) {
            if let Some((authority, observed)) = &local_observation {
                local.git.release_observation(authority, observed.id);
            }
            if let Some(observed) = &remote_observation {
                let _ = remote.as_ref().unwrap().release_observation(observed.id);
            }
            return Err(error);
        }
        if matches!(mutation, GitMutation::PullFastForward { .. })
            && expected.head != initial.state.head
        {
            return Err(fail(
                "stale_revision",
                "Branch changed while preparing pull",
            ));
        }
        let operation = OperationID(new_id().map_err(error)?);
        let request = GitMutationRequest {
            operation,
            worktree: worktree.clone(),
            expected,
            command: mutation,
        };
        let kind = match request.command {
            GitMutation::Repository(_) => GitRecoveryKind::Repository,
            GitMutation::Stage(_) => GitRecoveryKind::Stage,
            GitMutation::Unstage(_) => GitRecoveryKind::Unstage,
            GitMutation::Commit { .. } => GitRecoveryKind::Commit,
            GitMutation::Checkout { .. } => GitRecoveryKind::Checkout,
            GitMutation::Fetch { .. } => GitRecoveryKind::Fetch,
            GitMutation::Push { .. } => GitRecoveryKind::Push,
            GitMutation::PullFastForward { .. } => GitRecoveryKind::Pull,
        };
        let reference = GitRecoveryReference {
            repository_action: match &request.command {
                GitMutation::Repository(action) => Some(action.clone()),
                _ => None,
            },
            operation,
            worktree,
            kind,
            request_digest: Sha256::digest(
                serde_json::to_vec(&request).map_err(|e| fail("invalid_request", e.to_string()))?,
            )
            .into(),
            owner,
        };
        let mut retained = false;
        let mut submitted = false;
        let result = (|| {
            local
                .store
                .retain_git_recovery(reference.owner.workspace, reference.clone())
                .map_err(error)?;
            retained = true;
            if let Some((authority, observed)) = &local_observation {
                let digest = local
                    .git
                    .observation_alias_digest(authority, observed.id)
                    .map_err(error)?;
                let prepare = local
                    .git
                    .prepare_worktree_sync(
                        authority,
                        &request,
                        observed.id,
                        digest,
                        local
                            .git
                            .save_approval_input(authority, [])
                            .map_err(error)?,
                        &cancel,
                    )
                    .map_err(error)?;
                match prepare {
                    WorktreePreparation::Existing(receipt) => Ok(*receipt),
                    WorktreePreparation::Prepared(plan) => {
                        let approvals = local
                            .git
                            .save_approval_input(authority, [])
                            .map_err(error)?;
                        submitted = true;
                        let receipt = local
                            .git
                            .execute_worktree_sync(
                                authority, request, plan, digest, approvals, &cancel,
                            )
                            .map_err(error);
                        local.git.cancel_worktree_plan(authority, plan);
                        receipt
                    }
                }
            } else if let Some(observed) = &remote_observation {
                let remote = remote.as_ref().unwrap();
                match remote
                    .prepare_worktree(
                        &request,
                        observed.id,
                        observed.alias_digest,
                        std::iter::empty(),
                    )
                    .map_err(error)?
                {
                    WorktreePreparation::Existing(receipt) => Ok(*receipt),
                    WorktreePreparation::Prepared(plan) => {
                        submitted = true;
                        let receipt = remote
                            .execute_worktree(
                                request,
                                plan,
                                observed.alias_digest,
                                std::iter::empty(),
                            )
                            .map_err(error);
                        let _ = remote.cancel_worktree_plan(plan);
                        receipt
                    }
                }
            } else {
                submitted = true;
                Ok(backend.mutate(request))
            }
        })();
        if let Some((authority, observed)) = &local_observation {
            local.git.release_observation(authority, observed.id);
        }
        if let Some(observed) = &remote_observation {
            let _ = remote.as_ref().unwrap().release_observation(observed.id);
        }
        if result.is_err() && !submitted {
            if retained {
                local
                    .store
                    .resolve_git_recovery(reference.owner.workspace, &reference)
                    .map_err(error)?;
            }
            return result.map(|_| Value::Null);
        }
        let receipt = result.map_err(|e| {
            fail(
                "mutation_uncertain",
                format!(
                    "{}; inspect Git operation {} before retrying",
                    e.message,
                    buntrail_protocol::services::uuid(operation.0)
                ),
            )
        })?;
        Self::validate_git_receipt(&reference, &receipt)?;
        let resolved = resolved(&receipt.state);
        let success = matches!(receipt.state, OperationState::Confirmed(_));
        if matches!(
            &receipt.state,
            OperationState::Failed(OperationFailure {
                effect: FailureEffect::ProvenNoEffect,
                ..
            })
        ) {
            local
                .store
                .resolve_git_recovery(reference.owner.workspace, &reference)
                .map_err(error)?;
        }
        let diagnostic = match &receipt.state {
            OperationState::Failed(failure) => failure.error.message.clone(),
            OperationState::Unknown(evidence) => evidence.explanation.clone(),
            _ => "Inspect this operation before continuing".into(),
        };
        Ok(
            json!({"stdout":if success {"Git operation confirmed"}else{""},"stderr":if success {String::new()}else{diagnostic},"status":if success{0}else{1},"truncated":false,"operation":operation,"receipt":receipt,"pending":!resolved}),
        )
    }
    fn validate_git_receipt(
        reference: &GitRecoveryReference,
        receipt: &OperationReceipt,
    ) -> Result<()> {
        if receipt.id != reference.operation
            || matches!(&receipt.state,OperationState::Failed(f) if f.target!=reference.worktree.target)
            || matches!(&receipt.state,OperationState::Unknown(e) if e.target!=reference.worktree.target)
            || matches!(&receipt.state,OperationState::Confirmed(result) if !matches!(result,MutationResult::GitChanged {worktree,..} if worktree==&reference.worktree))
        {
            return Err(fail(
                "mutation_uncertain",
                "Git receipt identity differs; preserve pending inspection",
            ));
        }
        Ok(())
    }
}
fn resolved(state: &OperationState) -> bool {
    matches!(
        state,
        OperationState::Confirmed(_)
            | OperationState::Failed(OperationFailure {
                effect: FailureEffect::ProvenNoEffect,
                ..
            })
    )
}
struct GitBackend<'a> {
    local: &'a LocalConnection,
    remote: Option<&'a RemoteServices>,
    cancel: &'a AtomicBool,
}
impl GitBackend<'_> {
    fn discover(&self, root: FileRef) -> Result<Option<WorktreeIdentity>> {
        match self.remote {
            Some(s) => run(s.discover(root)),
            None => self.local.git.discover_sync(root, self.cancel),
        }
        .map_err(error)
    }
    fn status(&self, worktree: WorktreeIdentity) -> Result<GitSnapshot> {
        match self.remote {
            Some(s) => run(s.status(worktree)),
            None => self.local.git.status_sync(worktree, self.cancel),
        }
        .map_err(error)
    }
    fn read(&self, worktree: WorktreeIdentity, query: GitRead) -> Result<GitReadOutput> {
        match self.remote {
            Some(s) => run(s.read_query(worktree, query)),
            None => self.local.git.read_sync(worktree, query, self.cancel),
        }
        .map_err(error)
    }
    fn mutate(&self, request: GitMutationRequest) -> OperationReceipt {
        match self.remote {
            Some(s) => run(GitService::mutate(s, request)),
            None => self.local.git.mutate_sync(request, self.cancel),
        }
    }
}

fn mutation(
    backend: &GitBackend<'_>,
    worktree: &WorktreeIdentity,
    state: &GitExpectedState,
    args: &[&str],
) -> Result<GitMutation> {
    let path = |relative: &str| -> Result<TargetPath> {
        if relative.is_empty()
            || std::path::Path::new(relative)
                .components()
                .any(|c| !matches!(c, std::path::Component::Normal(_)))
        {
            return Err(fail(
                "invalid_request",
                "Git file paths must be relative children",
            ));
        }
        TargetPath::posix(
            format!(
                "{}/{}",
                files_adapter::text_path(&worktree.canonical_path)?.trim_end_matches('/'),
                relative
            )
            .into_bytes(),
        )
        .map_err(error)
    };
    Ok(match args {
        ["add", "--", paths @ ..] if !paths.is_empty() => {
            GitMutation::Stage(paths.iter().map(|p| path(p)).collect::<Result<Vec<_>>>()?)
        }
        ["reset", "HEAD", "--", paths @ ..] if !paths.is_empty() => {
            GitMutation::Unstage(paths.iter().map(|p| path(p)).collect::<Result<Vec<_>>>()?)
        }
        ["commit", "-m", message] if !message.trim().is_empty() && message.len() <= 1024 * 1024 => {
            GitMutation::Commit {
                message: (*message).into(),
            }
        }
        ["checkout", "--no-guess", reference]
            if !reference.is_empty() && !reference.starts_with('-') =>
        {
            GitMutation::Checkout {
                reference: reference.as_bytes().to_vec(),
            }
        }
        ["fetch"] | ["push"] | ["pull", "--ff-only"] => {
            let branch = match &state.head {
                GitHead::Branch { name, .. } => name,
                _ => {
                    return Err(fail(
                        "invalid_request",
                        "Select a checked-out branch for network operations",
                    ));
                }
            };
            let full = [b"refs/heads/".as_slice(), branch].concat();
            let output = backend.read(worktree.clone(), GitRead::Upstream)?;
            if !output.success {
                return Err(fail("unavailable", "Cannot read branch upstream"));
            }
            let upstream = output.stdout.split(|b| *b == b'\n').find_map(|line| {
                let fields = line.split(|b| *b == 0).collect::<Vec<_>>();
                (fields.len() == 3
                    && fields[0] == full
                    && !fields[1].is_empty()
                    && !fields[2].is_empty())
                .then(|| (fields[1].to_vec(), fields[2].to_vec()))
            });
            let (remote, reference) = match upstream {
                Some(pair) => pair,
                None if args == ["fetch"] => (b"origin".to_vec(), full),
                None => {
                    return Err(fail(
                        "invalid_request",
                        "Configure a branch upstream before pushing or pulling",
                    ));
                }
            };
            match args[0] {
                "fetch" => GitMutation::Fetch { remote },
                "push" => GitMutation::Push { remote, reference },
                _ => GitMutation::PullFastForward { remote, reference },
            }
        }
        _ => {
            return Err(fail(
                "invalid_request",
                "Unsupported Git command; arbitrary mutation flags are not accepted",
            ));
        }
    })
}

fn validate_repository_observation(
    mutation: &GitMutation,
    approved: &GitExpectedState,
    captured: &GitExpectedState,
) -> Result<()> {
    if matches!(mutation, GitMutation::Repository(_)) && approved != captured {
        return Err(fail(
            "stale_revision",
            "Repository changed after confirmation; refresh and review the changes before applying this action",
        ));
    }
    Ok(())
}

#[cfg(test)]
mod repository_observation_tests {
    use super::*;
    #[test]
    fn abort_cannot_adopt_saved_edits_after_confirmation() {
        let approved = GitExpectedState {
            head: GitHead::Branch {
                name: b"refs/heads/main".to_vec(),
                oid: "a".repeat(40),
            },
            index_fingerprint: [1; 32],
            worktree_fingerprint: [2; 32],
        };
        let mut saved = approved.clone();
        saved.worktree_fingerprint = [3; 32];
        let abort = GitMutation::Repository(RepositoryAction::AbortMerge {
            session: OperationID([4; 16]),
        });
        assert!(
            validate_repository_observation(&abort, &approved, &saved).is_err(),
            "newly saved tracked edits were never listed in the abort confirmation"
        );
        assert!(validate_repository_observation(&abort, &approved, &approved).is_ok());
    }
}