vitrify-cli 0.8.0

vitrify: Rust CLI suite, orchestrator, and harness integration for spec-driven development (SDD)
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
//! Dirty units from git: anchors, one diff per anchor, the core cascade.
//!
//! A [`Snapshot`] is the repository at one commit: every SDD loaded from a
//! checkout of it, the unit graph over them, each SDD's anchors from its
//! journal, and the declared ownership of every path. Asked which Verified
//! units a change reaches ([`Snapshot::dirty`]), it resolves each recorded
//! anchor — a short sha — to a commit, runs `git diff --name-only <anchor>
//! <head>` once per distinct commit (units integrated in one commit share
//! one), drops the paths whose change is protocol state only
//! ([`classify_changes`]), and hands the rest to
//! [`cascade::dirty_set`]. An anchor git cannot resolve — history
//! rewritten, a shallow clone — gets no diff, so its units are dirty with
//! that reason: the cascade never trusts what it cannot compare. Each SDD's
//! §5 Test command is judged the same way against its suite anchor.
//!
//! A graph with a cycle has no closures to cascade along: the cycles are
//! returned instead of a guess. Output is sorted by unit (slug, then id) and
//! SDDs by slug, so the same repository state gives the same answer.

use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};

use vitrify_core::CoreError;
use vitrify_core::cascade::{self, Anchors, Candidate, Changes, Closures, Dirty, Ownership, Why};
use vitrify_core::graph::{self, Cycles, Node, Resolution, UnitGraph};
use vitrify_core::journal;
use vitrify_core::model::{self, Instance, Shape};
use vitrify_core::trace;

use crate::cmd;
use crate::git::Git;

// ------------------------------------------------------ protocol state

/// Where the SDDs of a repository keep their files, repository-relative:
/// what tells protocol state from everything else.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SpecFiles {
    /// Each bundle's directory (`""` for a bundle at the repository root),
    /// sorted.
    pub bundles: Vec<String>,
    /// Each single-file SDD's file, sorted.
    pub singles: Vec<String>,
}

impl SpecFiles {
    /// The spec files of `sdds`, loaded from the checkout at `root`.
    pub fn of(root: &Path, sdds: &[Instance]) -> SpecFiles {
        let mut out = SpecFiles::default();
        for inst in sdds {
            match inst.shape {
                Shape::Bundle => {
                    let dir = cmd::shown(root, &inst.root);
                    out.bundles
                        .push(if dir == "." { String::new() } else { dir });
                }
                Shape::Single => out.singles.push(cmd::shown(root, &inst.file)),
            }
        }
        out.bundles.sort();
        out.bundles.dedup();
        out.singles.sort();
        out.singles.dedup();
        out
    }

    fn is_bundle(&self, dir: &str) -> bool {
        self.bundles
            .binary_search_by(|b| b.as_str().cmp(dir))
            .is_ok()
    }

    fn is_single(&self, path: &str) -> bool {
        self.singles
            .binary_search_by(|s| s.as_str().cmp(path))
            .is_ok()
    }
}

/// The paths that differ between `old` and `new`, sorted, each with whether
/// its change is protocol state only: a bundle's journal, ledger, decision
/// or change log; a bundle's unit file, or a single-file SDD, that differs
/// in nothing but vitrify-managed fields (and, in a single file, those
/// sections). Such changes — claims, renewals, stamps, recorded questions —
/// change nothing a build, a test or a lint reads.
pub fn classify_changes(
    git: &Git,
    old: &str,
    new: &str,
    spec: &SpecFiles,
) -> Result<Vec<(String, bool)>, CoreError> {
    let both = |path: &str| -> Option<(String, String)> {
        Some((
            git.show_text(old, path).ok().flatten()?,
            git.show_text(new, path).ok().flatten()?,
        ))
    };
    let mut paths = git.changed_paths(old, new).map_err(CoreError::from)?;
    paths.sort();
    paths.dedup();
    let mut out = Vec::with_capacity(paths.len());
    for path in paths {
        let (dir, name) = path.rsplit_once('/').unwrap_or(("", path.as_str()));
        let state_only = if matches!(
            name,
            "journal.ndjson" | "ledger.md" | "decisions.md" | "changelog.md"
        ) {
            spec.is_bundle(dir)
        } else if spec.is_single(&path) {
            both(&path).is_some_and(|(a, b)| single_state_masked(&a) == single_state_masked(&b))
        } else if (dir == "units" || dir.ends_with("/units"))
            && name.starts_with("U-")
            && name.ends_with(".md")
            && spec.is_bundle(dir.trim_end_matches("units").trim_end_matches('/'))
        {
            both(&path).is_some_and(|(a, b)| {
                trace::mask_unit_fields(Shape::Bundle, &a, "", &trace::VOLATILE)
                    == trace::mask_unit_fields(Shape::Bundle, &b, "", &trace::VOLATILE)
            })
        } else {
            false
        };
        out.push((path, state_only));
    }
    Ok(out)
}

/// What a run's dirty sets found at one head, kept for the next: each
/// anchor's commit, and the paths that differ between it and the head.
/// Moving to a new head diffs only the commits in between; a path they
/// touched is compared, anchor by anchor, in one batch.
#[derive(Debug, Default)]
pub struct DiffCache {
    head: String,
    /// Anchor as recorded → its commit (`None`: it names none).
    full_of: BTreeMap<String, Option<String>>,
    /// Anchor commit → the paths that differ between it and `head`, sorted.
    paths: BTreeMap<String, Vec<String>>,
}

impl DiffCache {
    /// Bring every kept diff from the old head to `head`. Anything that
    /// cannot be carried over is dropped, and diffed afresh when asked.
    fn advance(&mut self, git: &Git, head: &str) -> Result<(), CoreError> {
        if self.head == head {
            return Ok(());
        }
        let old = std::mem::replace(&mut self.head, head.to_string());
        if old.is_empty()
            || self.paths.is_empty()
            || !git.is_ancestor(&old, head).map_err(CoreError::from)?
        {
            self.paths.clear();
            return Ok(());
        }
        let moved = git.changed_paths(&old, head).map_err(CoreError::from)?;
        if moved.is_empty() {
            return Ok(());
        }
        if moved.iter().any(|p| p.contains('\n')) {
            self.paths.clear();
            return Ok(());
        }
        // a path the new commits touched differs from an anchor when its
        // object there is not its object at the head
        let mut names: Vec<String> = moved.iter().map(|p| format!("{head}:{p}")).collect();
        let anchors: Vec<String> = self.paths.keys().cloned().collect();
        for a in &anchors {
            names.extend(moved.iter().map(|p| format!("{a}:{p}")));
        }
        let ids = git.object_ids(&names).map_err(CoreError::from)?;
        let at_head = &ids[..moved.len()];
        for (k, a) in anchors.iter().enumerate() {
            let at_anchor = &ids[(k + 1) * moved.len()..(k + 2) * moved.len()];
            let Some(paths) = self.paths.get_mut(a) else {
                continue;
            };
            let mut set: BTreeSet<String> = std::mem::take(paths).into_iter().collect();
            for (i, p) in moved.iter().enumerate() {
                if at_anchor[i] == at_head[i] {
                    set.remove(p);
                } else {
                    set.insert(p.clone());
                }
            }
            *paths = set.into_iter().collect();
        }
        Ok(())
    }
}

/// The paths that differ between `old` and `new` beyond protocol state,
/// sorted.
pub fn substantive_changes(
    git: &Git,
    old: &str,
    new: &str,
    spec: &SpecFiles,
) -> Result<Vec<String>, CoreError> {
    Ok(classify_changes(git, old, new, spec)?
        .into_iter()
        .filter(|(_, state_only)| !state_only)
        .map(|(path, _)| path)
        .collect())
}

/// Whether `old..new` moved nothing but protocol state: `new` descends
/// from `old`, and no path changed beyond it. What was established at
/// `old` then holds at `new`.
pub fn benign(git: &Git, old: &str, new: &str, spec: &SpecFiles) -> Result<bool, CoreError> {
    if old == new {
        return Ok(true);
    }
    if !git.is_ancestor(old, new).map_err(CoreError::from)? {
        return Ok(false);
    }
    Ok(substantive_changes(git, old, new, spec)?.is_empty())
}

/// A single-file SDD's text with everything vitrify itself writes removed:
/// each unit's managed fields, the journal, the ledger, the decision and
/// change logs.
fn single_state_masked(text: &str) -> String {
    let mut t = text.to_string();
    let ids: Vec<String> = model::split_h3_regions(&t, "Work Units")
        .into_iter()
        .map(|(id, _)| id)
        .collect();
    for id in ids {
        if let Some(masked) = trace::mask_unit_fields(Shape::Single, &t, &id, &trace::VOLATILE) {
            t = masked;
        }
    }
    for heading in [
        "Journal",
        "State Ledger",
        "Decisions & Open Questions",
        "Changelog",
    ] {
        if let Some((s, e)) = model::section_span(&t, heading) {
            t = format!("{}{}", &t[..s], &t[e..]);
        }
    }
    t
}

// ------------------------------------------------------------ snapshot

/// One SDD of a [`Snapshot`].
#[derive(Debug, Clone)]
pub struct SddAt {
    /// Its `sdd:` slug.
    pub slug: String,
    /// Its root as output names it: repository-relative (`specs/calc`,
    /// `specs/x.sdd.md`).
    pub root: String,
    pub inst: Instance,
    /// Its recorded checks, from its journal.
    pub anchors: Anchors,
}

/// The repository at one commit, as the re-check cascade reads it.
#[derive(Debug, Clone)]
pub struct Snapshot {
    /// The checkout the SDDs were loaded from.
    pub checkout: PathBuf,
    /// The commit, in full.
    pub head: String,
    /// Every SDD of the repository, sorted by slug, then root.
    pub sdds: Vec<SddAt>,
    pub graph: UnitGraph,
    /// The graph's order and closures, or its cycles.
    pub resolved: Result<Resolution, Cycles>,
    pub ownership: Ownership,
    pub spec: SpecFiles,
}

/// How far recorded checks are trusted.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
    /// Each until a path it is checked against changes.
    Changes,
    /// Not at all: every Verified unit and every suite is dirty
    /// (`vitrify run --recheck`).
    Everything,
}

/// One SDD's §5 Test command, against its suite anchor.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SuiteState {
    pub slug: String,
    /// The anchor its journal records: the commit of its latest `audit`
    /// event with `suite: "pass"`.
    pub anchor: Option<String>,
    /// Why it must run again; `None` when the recorded pass holds.
    pub dirty: Option<Why>,
}

/// Which Verified units — and which suites — a change reaches.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DirtySet {
    /// The commit judged, in full.
    pub head: String,
    /// The dirty units, sorted by node, each with its reason.
    pub units: Vec<Dirty>,
    /// Every SDD's suite state, sorted by slug.
    pub suites: Vec<SuiteState>,
    /// The recorded anchors git could not resolve, sorted.
    pub unresolved: Vec<String>,
}

impl DirtySet {
    /// The dirty units of the SDD `slug`, sorted by unit id.
    pub fn of_sdd<'a>(&'a self, slug: &'a str) -> impl Iterator<Item = &'a Dirty> + 'a {
        self.units.iter().filter(move |d| d.node.slug == slug)
    }

    /// Whether `node` is dirty.
    pub fn is_dirty(&self, node: &Node) -> bool {
        self.units.binary_search_by(|d| d.node.cmp(node)).is_ok()
    }

    /// The suite state of `slug`'s SDD.
    pub fn suite(&self, slug: &str) -> Option<&SuiteState> {
        self.suites.iter().find(|s| s.slug == slug)
    }
}

/// What the cascade made of a [`Snapshot`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Cascade {
    Resolved(DirtySet),
    /// The unit graph has a cycle: there is no closure to cascade along,
    /// so nothing is computed.
    Cycles(Cycles),
}

/// One human line for why a unit or a suite is dirty: the changed paths
/// with their owners, `no recorded check`, `every recorded check is
/// distrusted`, or `anchor <c> cannot be resolved …`.
pub fn describe(why: &Why) -> String {
    match why {
        Why::NoDiff(anchor) => {
            format!("anchor {anchor} cannot be resolved (rewritten history, or a shallow clone)")
        }
        other => other.describe(),
    }
}

impl Snapshot {
    /// Load every SDD of the repository from `checkout`, which holds the
    /// tree of the commit `head` names (a lane checkout reset to it, or the
    /// primary checkout at `HEAD`). An SDD that cannot be read is an error:
    /// without it the graph, and every closure through it, is incomplete.
    pub fn load(git: &Git, checkout: &Path, head: &str) -> Result<Snapshot, CoreError> {
        let head = git
            .resolve_commit(head)
            .map_err(CoreError::from)?
            .ok_or_else(|| CoreError::refusal(1, format!("error: {head} names no commit")))?;
        let mut sdds: Vec<SddAt> = Vec::new();
        for handle in cmd::discover(checkout) {
            let inst = Instance::load(handle)?;
            let (events, _) = journal::read(&inst.handle())?;
            sdds.push(SddAt {
                slug: graph::slug_of(&inst).to_string(),
                root: cmd::shown(checkout, &inst.root),
                anchors: Anchors::from_events(&events),
                inst,
            });
        }
        sdds.sort_by(|a, b| (&a.slug, &a.root).cmp(&(&b.slug, &b.root)));
        let instances: Vec<Instance> = sdds.iter().map(|s| s.inst.clone()).collect();
        let graph = UnitGraph::build(&instances)?;
        let resolved = graph.resolve();
        let ownership =
            Ownership::build(checkout, sdds.iter().map(|s| (s.slug.as_str(), &s.inst)))?;
        let spec = SpecFiles::of(checkout, &instances);
        Ok(Snapshot {
            checkout: checkout.to_path_buf(),
            head,
            sdds,
            graph,
            resolved,
            ownership,
            spec,
        })
    }

    /// [`Snapshot::load`] for a run that must go on whatever one SDD holds:
    /// an SDD that cannot be read is left out, and when the unit graph has
    /// a cycle the SDDs with a unit on one are left out of the graph — so
    /// the rest still get their closures, dirty sets and priorities — and
    /// the cycles are returned. Ownership and spec files still count every
    /// SDD read, so a change to a left-out SDD's files is still its own.
    pub fn load_resolvable(
        git: &Git,
        checkout: &Path,
        head: &str,
    ) -> Result<(Snapshot, Option<Cycles>), CoreError> {
        let full = git
            .resolve_commit(head)
            .map_err(CoreError::from)?
            .ok_or_else(|| CoreError::refusal(1, format!("error: {head} names no commit")))?;
        let mut all: Vec<SddAt> = Vec::new();
        for handle in cmd::discover(checkout) {
            let Ok(inst) = Instance::load(handle) else {
                continue;
            };
            let (events, _) = journal::read(&inst.handle()).unwrap_or_default();
            all.push(SddAt {
                slug: graph::slug_of(&inst).to_string(),
                root: cmd::shown(checkout, &inst.root),
                anchors: Anchors::from_events(&events),
                inst,
            });
        }
        all.sort_by(|a, b| (&a.slug, &a.root).cmp(&(&b.slug, &b.root)));
        let every: Vec<Instance> = all.iter().map(|s| s.inst.clone()).collect();
        let ownership = Ownership::build(checkout, all.iter().map(|s| (s.slug.as_str(), &s.inst)))?;
        let spec = SpecFiles::of(checkout, &every);
        let mut graph = UnitGraph::build(&every)?;
        let mut resolved = graph.resolve();
        let mut cycles = None;
        if let Err(c) = &resolved {
            let on_cycle: BTreeSet<&str> =
                c.cycles.iter().flatten().map(|n| n.slug.as_str()).collect();
            let kept: Vec<SddAt> = all
                .iter()
                .filter(|s| !on_cycle.contains(s.slug.as_str()))
                .cloned()
                .collect();
            cycles = Some(c.clone());
            let instances: Vec<Instance> = kept.iter().map(|s| s.inst.clone()).collect();
            graph = UnitGraph::build(&instances)?;
            resolved = graph.resolve();
            all = kept;
        }
        Ok((
            Snapshot {
                checkout: checkout.to_path_buf(),
                head: full,
                sdds: all,
                graph,
                resolved,
                ownership,
                spec,
            },
            cycles,
        ))
    }

    /// The SDD with `slug`.
    pub fn sdd(&self, slug: &str) -> Option<&SddAt> {
        self.sdds.iter().find(|s| s.slug == slug)
    }

    /// Every unit Verified at the head, with its anchor; sorted by node.
    pub fn candidates(&self) -> Vec<Candidate> {
        let mut out: Vec<Candidate> = self
            .sdds
            .iter()
            .flat_map(|s| {
                s.inst
                    .units
                    .iter()
                    .filter(|u| u.meta.get_str_or("status", "Draft") == "Verified")
                    .map(|u| Candidate {
                        node: Node::new(&s.slug, &u.unit),
                        anchor: s.anchors.unit(&u.unit).map(str::to_string),
                    })
            })
            .collect();
        out.sort_by(|a, b| a.node.cmp(&b.node));
        out
    }

    /// Which Verified units, and which suites, must be checked again at the
    /// head. In [`Mode::Changes`] git is asked for one diff per distinct
    /// anchor; in [`Mode::Everything`] nothing is asked and everything is
    /// dirty.
    pub fn dirty(&self, git: &Git, mode: Mode) -> Result<Cascade, CoreError> {
        self.dirty_with(git, mode, &mut DiffCache::default())
    }

    /// [`Snapshot::dirty`], with what an earlier head's diffs found kept in
    /// `cache`: a run reads every head, and most of what changed since an
    /// anchor had changed by the head before.
    pub fn dirty_with(
        &self,
        git: &Git,
        mode: Mode,
        cache: &mut DiffCache,
    ) -> Result<Cascade, CoreError> {
        let resolution = match &self.resolved {
            Ok(r) => r,
            Err(cycles) => return Ok(Cascade::Cycles(cycles.clone())),
        };
        let candidates = self.candidates();
        if mode == Mode::Everything {
            return Ok(Cascade::Resolved(DirtySet {
                head: self.head.clone(),
                units: cascade::dirty_everything(&candidates),
                suites: self
                    .sdds
                    .iter()
                    .map(|s| SuiteState {
                        slug: s.slug.clone(),
                        anchor: s.anchors.suite.clone(),
                        dirty: Some(Why::Everything),
                    })
                    .collect(),
                unresolved: Vec::new(),
            }));
        }
        let closures: Closures = self
            .graph
            .nodes()
            .iter()
            .map(|n| {
                let deps: BTreeSet<Node> = resolution.closure(n).into_iter().cloned().collect();
                (n.clone(), deps)
            })
            .collect();

        // every recorded anchor, once: units and suites
        let mut recorded: BTreeSet<&str> = candidates
            .iter()
            .filter_map(|c| c.anchor.as_deref())
            .collect();
        recorded.extend(self.sdds.iter().filter_map(|s| s.anchors.suite.as_deref()));
        let mut full_of: BTreeMap<&str, String> = BTreeMap::new();
        let mut unresolved: Vec<String> = Vec::new();
        let unknown: Vec<&str> = recorded
            .iter()
            .copied()
            .filter(|a| !cache.full_of.contains_key(*a))
            .collect();
        let names: Vec<String> = unknown.iter().map(|a| format!("{a}^{{commit}}")).collect();
        for (anchor, full) in unknown
            .iter()
            .zip(git.object_ids(&names).map_err(CoreError::from)?)
        {
            cache.full_of.insert(anchor.to_string(), full);
        }
        for anchor in recorded {
            match cache.full_of.get(anchor).cloned().flatten() {
                Some(full) => {
                    full_of.insert(anchor, full);
                }
                None => unresolved.push(anchor.to_string()),
            }
        }
        cache.advance(git, &self.head)?;
        // one diff per distinct commit, whatever names it. Protocol state
        // lives under the SDDs' own roots, and the cascade never takes a
        // spec path as an input (`Owner::Spec`): a plain diff gives the
        // same answer as one with protocol state filtered out, without
        // reading every changed spec file at both ends for every anchor.
        let mut diffs: BTreeMap<&str, Vec<String>> = BTreeMap::new();
        for full in full_of.values() {
            if !diffs.contains_key(full.as_str()) {
                let paths = match cache.paths.get(full.as_str()) {
                    Some(paths) => paths.clone(),
                    None => {
                        let mut paths = git
                            .changed_paths(full, &self.head)
                            .map_err(CoreError::from)?;
                        paths.sort();
                        paths.dedup();
                        cache.paths.insert(full.clone(), paths.clone());
                        paths
                    }
                };
                diffs.insert(full.as_str(), paths);
            }
        }
        // what no anchor names any more is let go
        let named: BTreeSet<&String> = full_of.values().collect();
        cache.paths.retain(|full, _| named.contains(full));
        let changes: Changes = full_of
            .iter()
            .map(|(anchor, full)| {
                let paths = diffs.get(full.as_str()).cloned().unwrap_or_default();
                (anchor.to_string(), paths)
            })
            .collect();

        let units = cascade::dirty_set(&candidates, &changes, &closures, &self.ownership);
        let suites = self
            .sdds
            .iter()
            .map(|s| {
                let nodes: Vec<Node> = s
                    .inst
                    .units
                    .iter()
                    .map(|u| Node::new(&s.slug, &u.unit))
                    .collect();
                let anchor = s.anchors.suite.as_deref();
                let changed = anchor.and_then(|a| changes.get(a)).map(Vec::as_slice);
                SuiteState {
                    slug: s.slug.clone(),
                    anchor: s.anchors.suite.clone(),
                    dirty: cascade::suite_dirty(
                        &s.slug,
                        &nodes,
                        anchor,
                        changed,
                        &closures,
                        &self.ownership,
                    ),
                }
            })
            .collect();
        Ok(Cascade::Resolved(DirtySet {
            head: self.head.clone(),
            units,
            suites,
            unresolved,
        }))
    }
}