sui-spec 0.1.15

Declarative Lisp-authored specs for CppNix-parity behaviors. Rust types are the hard boundary; Lisp forms are the free-middle authoring surface. Both engines (tree-walker + VM) drive the same spec, so they cannot drift.
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
//! `(defrebuild-probe …)` — host-aware multi-stage rebuild parity probes.
//!
//! Where [`crate::probe::Probe`] tests a single Nix expression for parity,
//! a [`RebuildProbe`] tests *one stage of the rebuild pipeline* for parity
//! between sui and cppnix.  The set of stages was distilled from the
//! actual `fleet rebuild` driver in `pleme-io/fleet`:
//!
//! ```text
//! sui run .#rebuild
//!   ├── flake show          (FlakeShowKeys)
//!   ├── flake check         (FlakeCheckExit)
//!   ├── eval toplevel       (EvalToplevel { Darwin | NixOS })
//!   ├── eval home-manager   (EvalHomeActivation { user })
//!   ├── dry-run build       (DryRunClosure { Darwin | NixOS })
//!   ├── input lock hashes   (InputLockHash { input })
//!   ├── closure size        (ClosureSize { Darwin | NixOS })
//!   └── closure references  (ClosureReferenceGraph { Darwin | NixOS })
//! ```
//!
//! Each stage carries the kwargs it needs flatly on the probe — there is
//! no nested enum-with-data here, which keeps the Lisp authoring shape
//! consistent with [`crate::derivation::Phase`].  Stages that don't apply
//! to the operator's OS (e.g. `Darwin`-targeted probes on a Linux host)
//! self-skip via [`crate::parity::ParityCheck::applies`] and land as
//! `NotApplicable` records in the report.

use std::path::Path;
use std::process::Command;

use serde::{Deserialize, Serialize};
use tatara_lisp::DeriveTataraDomain;

use crate::SpecError;
use crate::cli::{nix_cli, sui_cli};
use crate::exec::CapturedOutput;
use crate::parity::{
    default_classify, ParityCheck, ProbeContext, ProbeKind, TargetOs, Verdict,
};

// ── Typed border ───────────────────────────────────────────────────

/// One rebuild-stage parity probe.  Authored as `(defrebuild-probe ...)`.
#[derive(DeriveTataraDomain, Serialize, Deserialize, Debug, Clone)]
#[tatara(keyword = "defrebuild-probe")]
pub struct RebuildProbe {
    /// Stable name (must be unique within the rebuild corpus).
    pub name: String,
    /// Which hosts this probe applies to.
    #[serde(rename = "hostMode")]
    pub host_mode: HostMode,
    /// Required when `host_mode = Literal` — the hostname this probe
    /// is pinned to.
    #[serde(default, rename = "hostLiteral")]
    pub host_literal: Option<String>,
    /// Which stage of the rebuild pipeline this probe exercises.
    pub stage: RebuildStage,
    /// How sui's output is compared to nix's.
    pub compare: RebuildCompare,
    /// Tags for include/exclude filtering.  Conventional tags:
    /// `"smoke"`, `"rebuild-phase-1"`..`"rebuild-phase-4"`, `"expensive"`.
    #[serde(default)]
    pub tags: Vec<String>,
}

/// Host applicability selector.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum HostMode {
    /// Applies on whichever host the sweep is running on.
    Current,
    /// Applies only when `ctx.host == host_literal`.
    Literal,
    /// Applies on every host.  (Today the sweep only runs against the
    /// current host; this is the forward-looking case.)
    All,
}

/// Per-stage kwargs container.  Flat fields keep the Lisp authoring
/// surface simple — no nested attrset construction required.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RebuildStage {
    pub kind: RebuildStageKind,
    /// For `EvalToplevel` / `DryRunClosure` / `ClosureSize` /
    /// `ClosureReferenceGraph`: which top-level config to ask about.
    #[serde(default)]
    pub target: Option<ToplevelTarget>,
    /// For `EvalHomeActivation`: which user's `homeConfigurations.<user>`
    /// to evaluate.  Substituted from `ctx.user` if absent.
    #[serde(default)]
    pub user: Option<String>,
    /// For `InputLockHash`: which flake input to compare.
    #[serde(default)]
    pub input: Option<String>,
}

/// The set of rebuild stages the sweep knows how to drive.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RebuildStageKind {
    /// `flake show --json` on the flake.  Compare the top-level
    /// attribute name set.
    FlakeShowKeys,
    /// `flake check` on the flake.  Compare exit code.
    FlakeCheckExit,
    /// `eval --json '.<flake>#darwinConfigurations.<host>.system.build.toplevel.outPath'`
    /// (or the NixOS equivalent).  Compare as JSON.
    EvalToplevel,
    /// `eval --json '.<flake>#homeConfigurations.<user>.activationPackage.outPath'`.
    EvalHomeActivation,
    /// `build --dry-run --print-out-paths .<flake>#<toplevel>`.  Compare
    /// the printed store-path set.
    DryRunClosure,
    /// `eval --json '(getFlake "path:<flake>").inputs.<input>.narHash'`.
    InputLockHash,
    /// `eval --json 'builtins.length (builtins.attrNames ...)'` — a
    /// rough closure-size sentinel that exercises the module system
    /// without requiring a full build.  Compare as integer JSON.
    ClosureSize,
    /// Full closure reference set (after eval+build).  Marked
    /// `expensive` because it builds the toplevel derivation.
    ClosureReferenceGraph,
}

/// Which top-level system configuration to ask about.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToplevelTarget {
    /// `darwinConfigurations.<host>.system.build.toplevel`
    Darwin,
    /// `nixosConfigurations.<host>.config.system.build.toplevel`
    NixOS,
}

impl ToplevelTarget {
    /// Map to the [`TargetOs`] this target requires.
    #[must_use]
    pub fn required_os(self) -> TargetOs {
        match self {
            ToplevelTarget::Darwin => TargetOs::Darwin,
            ToplevelTarget::NixOS  => TargetOs::Linux,
        }
    }

    /// Render the `<flake>#<attr>` selector string (without the
    /// `outPath` / `.<sub>` suffix).
    #[must_use]
    pub fn flake_attr(self, host: &str) -> String {
        match self {
            ToplevelTarget::Darwin => {
                format!("darwinConfigurations.{host}.system.build.toplevel")
            }
            ToplevelTarget::NixOS => {
                format!("nixosConfigurations.{host}.config.system.build.toplevel")
            }
        }
    }
}

/// How the rebuild probe compares sui's output to nix's.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum RebuildCompare {
    /// Exit-code equality — succeed iff both engines exited with the
    /// same `success` status.
    ExitCode,
    /// JSON byte-equality.
    JsonEqual,
    /// Sort-order-insensitive comparison of a JSON array of strings.
    AttrNamesEqual,
    /// Both engines must produce the same set of `/nix/store/...`
    /// paths (sorted comparison).
    StorePathSet,
    /// Both engines must produce equal integer outputs.
    IntegerEqual,
    /// Both engines must produce an isomorphic reference graph.  M0:
    /// graph parity is approximated by store-path-set parity.
    GraphIsomorphic,
}

// ── ParityCheck impl ───────────────────────────────────────────────

impl ParityCheck for RebuildProbe {
    fn name(&self) -> &str { &self.name }
    fn tags(&self) -> &[String] { &self.tags }
    fn kind(&self) -> ProbeKind { ProbeKind::Rebuild }

    fn applies(&self, ctx: &ProbeContext) -> bool {
        // 1. host filter
        match self.host_mode {
            HostMode::Current | HostMode::All => {}
            HostMode::Literal => {
                let Some(literal) = self.host_literal.as_deref() else { return false; };
                if literal != ctx.host { return false; }
            }
        }
        // 2. stage's required OS, if any
        if let Some(target) = self.stage.target {
            if target.required_os() != ctx.os { return false; }
        }
        true
    }

    fn sui_invocation(&self, ctx: &ProbeContext, sui_bin: &Path) -> Command {
        match self.stage.kind {
            RebuildStageKind::FlakeShowKeys =>
                sui_cli::flake_show(sui_bin, &flake_ref(ctx)),
            RebuildStageKind::FlakeCheckExit =>
                sui_cli::flake_check(sui_bin, &flake_ref(ctx)),
            RebuildStageKind::EvalToplevel => {
                let attr = self.toplevel_attr(ctx);
                sui_cli::eval_installable(sui_bin, &installable(ctx, &format!("{attr}.outPath")))
            }
            RebuildStageKind::EvalHomeActivation => {
                let attr = self.home_activation_attr(ctx);
                sui_cli::eval_installable(sui_bin, &installable(ctx, &format!("{attr}.outPath")))
            }
            RebuildStageKind::DryRunClosure | RebuildStageKind::ClosureReferenceGraph => {
                let attr = self.toplevel_attr(ctx);
                sui_cli::build_dry_run(sui_bin, &installable(ctx, &attr))
            }
            RebuildStageKind::InputLockHash => {
                let input = self.stage.input.as_deref().unwrap_or("nixpkgs");
                let expr = format!(
                    "(builtins.getFlake \"path:{}\").inputs.{input}.narHash",
                    ctx.flake_path.display(),
                );
                sui_cli::eval_expr_explicit(sui_bin, &expr)
            }
            RebuildStageKind::ClosureSize => {
                let attr = self.toplevel_attr(ctx);
                let expr = format!(
                    "builtins.length (builtins.attrNames ((builtins.getFlake \"path:{}\").{attr}))",
                    ctx.flake_path.display(),
                );
                sui_cli::eval_expr_explicit(sui_bin, &expr)
            }
        }
    }

    fn nix_invocation(&self, ctx: &ProbeContext, nix_bin: &Path) -> Command {
        match self.stage.kind {
            RebuildStageKind::FlakeShowKeys =>
                nix_cli::flake_show(nix_bin, &flake_ref(ctx)),
            RebuildStageKind::FlakeCheckExit =>
                nix_cli::flake_check(nix_bin, &flake_ref(ctx)),
            RebuildStageKind::EvalToplevel => {
                let attr = self.toplevel_attr(ctx);
                nix_cli::eval_installable(nix_bin, &installable(ctx, &format!("{attr}.outPath")))
            }
            RebuildStageKind::EvalHomeActivation => {
                let attr = self.home_activation_attr(ctx);
                nix_cli::eval_installable(nix_bin, &installable(ctx, &format!("{attr}.outPath")))
            }
            RebuildStageKind::DryRunClosure | RebuildStageKind::ClosureReferenceGraph => {
                let attr = self.toplevel_attr(ctx);
                nix_cli::build_dry_run(nix_bin, &installable(ctx, &attr))
            }
            RebuildStageKind::InputLockHash => {
                let input = self.stage.input.as_deref().unwrap_or("nixpkgs");
                let expr = format!(
                    "(builtins.getFlake \"path:{}\").inputs.{input}.narHash",
                    ctx.flake_path.display(),
                );
                nix_cli::eval_expr(nix_bin, &expr)
            }
            RebuildStageKind::ClosureSize => {
                let attr = self.toplevel_attr(ctx);
                let expr = format!(
                    "builtins.length (builtins.attrNames ((builtins.getFlake \"path:{}\").{attr}))",
                    ctx.flake_path.display(),
                );
                nix_cli::eval_expr(nix_bin, &expr)
            }
        }
    }

    fn classify(&self, sui: &CapturedOutput, nix: &CapturedOutput) -> Verdict {
        let compare = self.compare;
        default_classify(sui, nix, |s, n| {
            compare_outputs(compare, s.stdout.trim(), n.stdout.trim(), s, n)
        })
    }
}

// ── Selector helpers ───────────────────────────────────────────────

impl RebuildProbe {
    fn toplevel_attr(&self, ctx: &ProbeContext) -> String {
        let target = self.stage.target.unwrap_or_else(|| match ctx.os {
            TargetOs::Darwin => ToplevelTarget::Darwin,
            _                => ToplevelTarget::NixOS,
        });
        target.flake_attr(&ctx.host)
    }

    fn home_activation_attr(&self, ctx: &ProbeContext) -> String {
        let user = self.stage.user.as_deref().unwrap_or(ctx.user.as_str());
        format!("homeConfigurations.\"{user}\".activationPackage")
    }
}

fn flake_ref(ctx: &ProbeContext) -> String {
    format!("path:{}", ctx.flake_path.display())
}

fn installable(ctx: &ProbeContext, attr: &str) -> String {
    format!("path:{}#{attr}", ctx.flake_path.display())
}

// ── Comparison dispatch ────────────────────────────────────────────

fn compare_outputs(
    mode: RebuildCompare,
    sui: &str,
    nix: &str,
    sui_out: &CapturedOutput,
    nix_out: &CapturedOutput,
) -> bool {
    match mode {
        RebuildCompare::ExitCode => sui_out.success == nix_out.success,
        RebuildCompare::JsonEqual => sui == nix,
        RebuildCompare::AttrNamesEqual => {
            // `nix flake show --json` emits a JSON OBJECT keyed by
            // output name (e.g. `{"nixosConfigurations":{...}}`);
            // the parity test is over the top-level key set.  We also
            // accept the flat `["k1","k2"]` shape for back-compat with
            // older callers that pre-extracted the names.
            let sui_keys = top_level_keys(sui);
            let nix_keys = top_level_keys(nix);
            match (sui_keys, nix_keys) {
                (Some(mut a), Some(mut b)) => {
                    a.sort();
                    b.sort();
                    a == b
                }
                _ => false,
            }
        }
        RebuildCompare::StorePathSet | RebuildCompare::GraphIsomorphic => {
            // Both engines print one path per line; we set-compare.
            let mut s: Vec<&str> = sui.lines()
                .filter(|l| l.starts_with("/nix/store/"))
                .collect();
            let mut n: Vec<&str> = nix.lines()
                .filter(|l| l.starts_with("/nix/store/"))
                .collect();
            s.sort();
            n.sort();
            s == n
        }
        RebuildCompare::IntegerEqual => {
            let sn: Option<i64> = serde_json::from_str(sui).ok();
            let nn: Option<i64> = serde_json::from_str(nix).ok();
            matches!((sn, nn), (Some(a), Some(b)) if a == b)
        }
    }
}

/// Extract the top-level attribute names from one of cppnix's
/// `--json` outputs.  Accepts both:
///   - `{"k1": ..., "k2": ...}`  → `["k1", "k2"]`
///   - `["k1", "k2"]`            → `["k1", "k2"]`
/// Returns `None` for any other JSON shape (number, string, etc.).
fn top_level_keys(s: &str) -> Option<Vec<String>> {
    let v: serde_json::Value = serde_json::from_str(s).ok()?;
    if let Some(arr) = v.as_array() {
        return arr.iter().map(|x| x.as_str().map(String::from)).collect();
    }
    let obj = v.as_object()?;
    Some(obj.keys().cloned().collect())
}

// ── Canonical corpus, compiled in ──────────────────────────────────

pub const CANONICAL_REBUILD_PROBES_LISP: &str =
    include_str!("../specs/rebuild_probes.lisp");

/// Compile the canonical rebuild-probe corpus.
///
/// # Errors
///
/// Returns an error if the Lisp source fails to parse.
pub fn load_canonical() -> Result<Vec<RebuildProbe>, SpecError> {
    crate::loader::load_all::<RebuildProbe>(CANONICAL_REBUILD_PROBES_LISP)
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;

    #[test]
    fn canonical_rebuild_corpus_parses() {
        let probes = load_canonical().expect("canonical rebuild probes must compile");
        assert!(!probes.is_empty(), "rebuild corpus must contain at least one probe");
        for p in &probes {
            assert!(!p.name.is_empty(), "probe must have a name: {p:?}");
        }
    }

    #[test]
    fn canonical_rebuild_corpus_has_expected_stages() {
        let probes = load_canonical().unwrap();
        let stages: std::collections::HashSet<RebuildStageKind> =
            probes.iter().map(|p| p.stage.kind).collect();
        // The five baselines the operator picked + the three extra
        // categories.  If any of these is missing, the M0 corpus
        // regressed.
        for required in [
            RebuildStageKind::FlakeShowKeys,
            RebuildStageKind::FlakeCheckExit,
            RebuildStageKind::EvalToplevel,
            RebuildStageKind::DryRunClosure,
            RebuildStageKind::InputLockHash,
        ] {
            assert!(stages.contains(&required), "missing stage {required:?}");
        }
    }

    #[test]
    fn host_literal_filters() {
        let probe = RebuildProbe {
            name: "rio-only".into(),
            host_mode: HostMode::Literal,
            host_literal: Some("rio".into()),
            stage: RebuildStage {
                kind: RebuildStageKind::FlakeShowKeys,
                target: None,
                user: None,
                input: None,
            },
            compare: RebuildCompare::AttrNamesEqual,
            tags: vec![],
        };
        let ctx_rio = mk_ctx("rio", TargetOs::Linux);
        let ctx_cid = mk_ctx("cid", TargetOs::Darwin);
        assert!(probe.applies(&ctx_rio));
        assert!(!probe.applies(&ctx_cid));
    }

    #[test]
    fn target_os_filters_skip_mismatch() {
        let probe = RebuildProbe {
            name: "darwin-only".into(),
            host_mode: HostMode::Current,
            host_literal: None,
            stage: RebuildStage {
                kind: RebuildStageKind::EvalToplevel,
                target: Some(ToplevelTarget::Darwin),
                user: None,
                input: None,
            },
            compare: RebuildCompare::JsonEqual,
            tags: vec![],
        };
        assert!(probe.applies(&mk_ctx("cid", TargetOs::Darwin)));
        assert!(!probe.applies(&mk_ctx("rio", TargetOs::Linux)));
    }

    #[test]
    fn toplevel_attr_renders_correctly() {
        let darwin = ToplevelTarget::Darwin.flake_attr("cid");
        let linux = ToplevelTarget::NixOS.flake_attr("rio");
        assert_eq!(darwin, "darwinConfigurations.cid.system.build.toplevel");
        assert_eq!(linux, "nixosConfigurations.rio.config.system.build.toplevel");
    }

    #[test]
    fn sui_invocation_includes_flake_path() {
        let probe = mk_probe(RebuildStageKind::FlakeShowKeys, None);
        let ctx = mk_ctx("cid", TargetOs::Darwin);
        let cmd = probe.sui_invocation(&ctx, Path::new("/usr/local/bin/sui"));
        let argv = crate::exec::command_argv(&cmd);
        assert_eq!(argv[1], "flake");
        assert_eq!(argv[2], "show");
        assert!(argv.iter().any(|a| a.contains("/tmp/flake")));
    }

    #[test]
    fn nix_invocation_includes_experimental_features() {
        let probe = mk_probe(RebuildStageKind::FlakeShowKeys, None);
        let ctx = mk_ctx("cid", TargetOs::Darwin);
        let cmd = probe.nix_invocation(&ctx, Path::new("/usr/bin/nix"));
        let argv = crate::exec::command_argv(&cmd);
        assert!(argv.iter().any(|a| a == "--extra-experimental-features"));
    }

    fn mk_ctx(host: &str, os: TargetOs) -> ProbeContext {
        ProbeContext {
            flake_path: PathBuf::from("/tmp/flake"),
            flake_label: "flake".into(),
            host: host.into(),
            system: match os {
                TargetOs::Darwin => "aarch64-darwin".into(),
                TargetOs::Linux  => "x86_64-linux".into(),
                TargetOs::Other  => "unknown".into(),
            },
            user: "drzzln".into(),
            os,
        }
    }

    fn mk_probe(kind: RebuildStageKind, target: Option<ToplevelTarget>) -> RebuildProbe {
        RebuildProbe {
            name: "test".into(),
            host_mode: HostMode::Current,
            host_literal: None,
            stage: RebuildStage { kind, target, user: None, input: None },
            compare: RebuildCompare::JsonEqual,
            tags: vec!["test".into()],
        }
    }

    #[test]
    fn integer_equal_compare() {
        let sui = CapturedOutput {
            exit_code: Some(0), success: true,
            stdout: "42".into(), stderr: String::new(),
            duration: std::time::Duration::ZERO, timed_out: false,
        };
        let nix = sui.clone();
        let mut nix_diff = nix.clone();
        nix_diff.stdout = "43".into();
        assert!(compare_outputs(RebuildCompare::IntegerEqual, "42", "42", &sui, &nix));
        assert!(!compare_outputs(RebuildCompare::IntegerEqual, "42", "43", &sui, &nix_diff));
    }

    #[test]
    fn attr_names_equal_matches_objects_with_same_keys() {
        let sui = r#"{"nixosConfigurations":{"rio":{"type":"nixos-configuration"}}}"#;
        let nix = r#"{"nixosConfigurations":{"rio":{"type":"nixos-configuration"}}}"#;
        let dummy = CapturedOutput {
            exit_code: Some(0), success: true,
            stdout: String::new(), stderr: String::new(),
            duration: std::time::Duration::ZERO, timed_out: false,
        };
        assert!(compare_outputs(RebuildCompare::AttrNamesEqual, sui, nix, &dummy, &dummy));
    }

    #[test]
    fn attr_names_equal_diverges_on_extra_key() {
        let sui = r#"{"nixosConfigurations":{},"darwinConfigurations":{}}"#;
        let nix = r#"{"nixosConfigurations":{}}"#;
        let dummy = CapturedOutput {
            exit_code: Some(0), success: true,
            stdout: String::new(), stderr: String::new(),
            duration: std::time::Duration::ZERO, timed_out: false,
        };
        assert!(!compare_outputs(RebuildCompare::AttrNamesEqual, sui, nix, &dummy, &dummy));
    }

    #[test]
    fn attr_names_equal_accepts_legacy_array_shape() {
        let sui = r#"["nixosConfigurations"]"#;
        let nix = r#"{"nixosConfigurations":{}}"#;
        let dummy = CapturedOutput {
            exit_code: Some(0), success: true,
            stdout: String::new(), stderr: String::new(),
            duration: std::time::Duration::ZERO, timed_out: false,
        };
        assert!(compare_outputs(RebuildCompare::AttrNamesEqual, sui, nix, &dummy, &dummy));
    }

    #[test]
    fn store_path_set_compare_sorts() {
        let sui_out = "/nix/store/aaaa-x\n/nix/store/bbbb-y\n";
        let nix_out = "/nix/store/bbbb-y\n/nix/store/aaaa-x\n";
        let dummy = CapturedOutput {
            exit_code: Some(0), success: true,
            stdout: String::new(), stderr: String::new(),
            duration: std::time::Duration::ZERO, timed_out: false,
        };
        assert!(compare_outputs(RebuildCompare::StorePathSet, sui_out, nix_out, &dummy, &dummy));
    }
}