patchloom 0.18.0

Structured file editing library and CLI for AI agents: parser-backed JSON/YAML/TOML edits, AST-aware code operations, multi-file batching, markdown operations, and MCP server
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
//! Platform path honesty: absolute paths under `--contain`, Windows UNC, and
//! CLI error paths that embed OS paths.
//!
//! These are the minimum integration locks for Windows-native and WSL-style
//! absolute path handling. Unit tests in `containment_tests` cover PathGuard
//! library behavior; this module exercises the full CLI binary.

use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;

/// #1931 / #1451: absolute path under workspace is allowed with `--contain`.
#[test]
fn contain_allows_absolute_path_inside_workspace() {
    let dir = TempDir::new().unwrap();
    let file = dir.path().join("inside.txt");
    fs::write(&file, "hello-abs\n").unwrap();
    let abs = file
        .canonicalize()
        .unwrap_or_else(|_| file.clone())
        .to_string_lossy()
        .into_owned();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "read", &abs])
        .assert()
        .code(0)
        .stdout(predicate::str::contains("hello-abs"));
}

/// Absolute path outside the workspace must fail closed under `--contain`.
#[test]
fn contain_rejects_absolute_path_outside_workspace() {
    let dir = TempDir::new().unwrap();
    let outside_dir = TempDir::new().unwrap();
    let outside = outside_dir.path().join("secret.txt");
    fs::write(&outside, "SECRET\n").unwrap();
    let abs = outside
        .canonicalize()
        .unwrap_or_else(|_| outside.clone())
        .to_string_lossy()
        .into_owned();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "read", &abs])
        .assert()
        .failure()
        .stderr(
            predicate::str::contains("escapes")
                .or(predicate::str::contains("rejected"))
                .or(predicate::str::contains("workspace guard"))
                .or(predicate::str::contains("absolute")),
        );
}

/// `--json` missing-path error includes OS detail once (no UNC double-noise).
#[test]
fn json_missing_path_error_is_single_line_usable() {
    let dir = TempDir::new().unwrap();
    let missing = dir.path().join("nope.txt");
    let abs = missing.to_string_lossy().into_owned();

    let out = Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--json", "--cwd"])
        .arg(dir.path())
        .args(["read", &abs])
        .output()
        .expect("run patchloom");

    assert_ne!(out.status.code(), Some(0), "missing path must fail");
    let stderr = String::from_utf8_lossy(&out.stderr);
    let stdout = String::from_utf8_lossy(&out.stdout);
    let body = if stdout.contains("error") {
        stdout.as_ref()
    } else {
        stderr.as_ref()
    };
    assert!(
        body.contains("nope") || body.contains("not found") || body.contains("No such file"),
        "expected path/OS detail in JSON error, got: {body}"
    );
    // #1931 display honesty: agent envelopes must not show raw UNC.
    assert!(
        !body.contains(r"\\?\"),
        "JSON error must not embed Windows UNC prefix: {body}"
    );
    // #1929: OS detail once (when present).
    // #1929: "No such file" must not appear twice in one envelope.
    assert!(
        body.matches("No such file").count() <= 1,
        "OS detail must not double in agent JSON: {body}"
    );
}

/// Doc get absolute path under `--contain` (sole-path load + JSON).
#[test]
fn contain_doc_get_absolute_inside_workspace() {
    let dir = TempDir::new().unwrap();
    let file = dir.path().join("cfg.json");
    fs::write(&file, r#"{"port": 9}"#).unwrap();
    let abs = file
        .canonicalize()
        .unwrap_or_else(|_| file.clone())
        .to_string_lossy()
        .into_owned();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--json", "--cwd"])
        .arg(dir.path())
        .args(["--contain", "doc", "get", &abs, "port"])
        .assert()
        .code(0)
        .stdout(predicate::str::contains('9'));
}

/// Replace with absolute path under `--contain` (write path + PathGuard).
#[test]
fn contain_replace_absolute_path_apply() {
    let dir = TempDir::new().unwrap();
    let file = dir.path().join("note.txt");
    fs::write(&file, "old-token\n").unwrap();
    let abs = file
        .canonicalize()
        .unwrap_or_else(|_| file.clone())
        .to_string_lossy()
        .into_owned();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args([
            "--contain",
            "replace",
            "old-token",
            "--new",
            "new-token",
            &abs,
            "--apply",
        ])
        .assert()
        .code(0);

    let content = fs::read_to_string(&file).unwrap();
    assert!(
        content.contains("new-token"),
        "absolute-path replace under --contain must write: {content}"
    );
}

/// Forward-slash absolute paths (common from agents / WSL-style spellings).
#[test]
fn contain_allows_forward_slash_absolute_inside_workspace() {
    let dir = TempDir::new().unwrap();
    let file = dir.path().join("slash.txt");
    fs::write(&file, "slash-ok\n").unwrap();
    let abs = file.canonicalize().unwrap_or_else(|_| file.clone());
    let slashy = abs.to_string_lossy().replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "read", &slashy])
        .assert()
        .code(0)
        .stdout(predicate::str::contains("slash-ok"));
}

/// Library PathGuard via CLI: create under absolute dest path inside workspace.
#[test]
fn contain_create_absolute_path_apply() {
    let dir = TempDir::new().unwrap();
    let dest = dir.path().join("created.txt");
    // Use non-existing absolute path (ancestor canonicalize).
    let abs = dest.to_string_lossy().replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args([
            "--contain",
            "create",
            &abs,
            "--content",
            "created-ok\n",
            "--apply",
        ])
        .assert()
        .code(0);

    let content = fs::read_to_string(&dest).unwrap();
    assert!(
        content.contains("created-ok"),
        "absolute create under --contain must write: {content}"
    );
}

#[cfg(windows)]
mod windows_native {
    use super::*;

    /// #1931 regression at CLI: feed a path that went through std canonicalize
    /// (may be `\\?\` form). PathGuard must re-canonicalize with dunce and allow.
    #[test]
    fn contain_accepts_std_canonicalized_absolute_path() {
        let dir = TempDir::new().unwrap();
        let file = dir.path().join("unc.txt");
        fs::write(&file, "unc-ok\n").unwrap();
        let std_canon = std::fs::canonicalize(&file).expect("std canonicalize");
        let s = std_canon.to_string_lossy().into_owned();
        // On modern Windows this often starts with \\?\ — that is the bug class.
        let _maybe_unc = s.starts_with(r"\\?\");

        Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--cwd"])
            .arg(dir.path())
            .args(["--contain", "read", &s])
            .assert()
            .code(0)
            .stdout(predicate::str::contains("unc-ok"));
    }

    /// Agent JSON for containment escape must not leak UNC prefixes.
    #[test]
    fn contain_json_escape_error_has_no_unc_prefix() {
        let dir = TempDir::new().unwrap();
        let outside = TempDir::new().unwrap();
        let file = outside.path().join("x.txt");
        fs::write(&file, "x\n").unwrap();
        let abs = std::fs::canonicalize(&file)
            .unwrap_or(file)
            .to_string_lossy()
            .into_owned();

        let out = Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--json", "--cwd"])
            .arg(dir.path())
            .args(["--contain", "read", &abs])
            .output()
            .expect("run");

        assert!(!out.status.success());
        let combined = format!(
            "{}{}",
            String::from_utf8_lossy(&out.stdout),
            String::from_utf8_lossy(&out.stderr)
        );
        assert!(
            !combined.contains(r"\\?\"),
            "containment error JSON must not use UNC: {combined}"
        );
    }

    /// Drive-letter absolute path under workspace (C:\... form without UNC).
    #[test]
    fn contain_drive_letter_absolute_inside_workspace() {
        let dir = TempDir::new().unwrap();
        let file = dir.path().join("drive.txt");
        fs::write(&file, "drive-ok\n").unwrap();
        // Prefer dunce form if available via patchloom API; otherwise strip UNC.
        let abs = std::fs::canonicalize(&file).unwrap();
        let s = abs.to_string_lossy();
        let drive = s.strip_prefix(r"\\?\").unwrap_or(&s);

        Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--cwd"])
            .arg(dir.path())
            .args(["--contain", "read", drive])
            .assert()
            .code(0)
            .stdout(predicate::str::contains("drive-ok"));
    }
}

// ---------------------------------------------------------------------------
// Expansions: md / patch / tx / rename / long-path
// ---------------------------------------------------------------------------

/// Absolute path under `--contain` for md upsert-bullet (engine write path).
#[test]
fn contain_md_upsert_bullet_absolute_path() {
    let dir = TempDir::new().unwrap();
    let file = dir.path().join("doc.md");
    fs::write(&file, "# Intro\n\n").unwrap();
    let abs = file
        .canonicalize()
        .unwrap_or_else(|_| file.clone())
        .to_string_lossy()
        .replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args([
            "--contain",
            "md",
            "upsert-bullet",
            &abs,
            "--heading",
            "Intro",
            "--bullet",
            "- item",
            "--apply",
        ])
        .assert()
        .code(0);

    let content = fs::read_to_string(&file).unwrap();
    assert!(
        content.contains("- item"),
        "md absolute under --contain must write: {content}"
    );
}

/// Absolute patch *file* path under `--contain` (meta-input resolve_user_path).
#[test]
fn contain_patch_check_absolute_patch_file() {
    let dir = TempDir::new().unwrap();
    let target = dir.path().join("t.txt");
    fs::write(&target, "hello\n").unwrap();
    let patch = dir.path().join("change.diff");
    // Unified diff with relative target under --cwd.
    let body = "\
--- a/t.txt
+++ b/t.txt
@@ -1 +1 @@
-hello
+world
";
    fs::write(&patch, body).unwrap();
    let abs_patch = patch
        .canonicalize()
        .unwrap_or_else(|_| patch.clone())
        .to_string_lossy()
        .replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "patch", "check", &abs_patch])
        .assert()
        .code(2); // changes detected in check mode
}

/// Absolute plan path for `tx` under `--contain`.
#[test]
fn contain_tx_absolute_plan_path() {
    let dir = TempDir::new().unwrap();
    let target = dir.path().join("note.txt");
    fs::write(&target, "alpha\n").unwrap();
    let plan = dir.path().join("plan.json");
    fs::write(
        &plan,
        r#"{
  "version": 1,
  "operations": [
    {"op": "replace", "path": "note.txt", "old": "alpha", "new": "beta"}
  ]
}
"#,
    )
    .unwrap();
    let abs_plan = plan
        .canonicalize()
        .unwrap_or_else(|_| plan.clone())
        .to_string_lossy()
        .replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "tx", &abs_plan, "--apply"])
        .assert()
        .code(0);

    let content = fs::read_to_string(&target).unwrap();
    assert!(
        content.contains("beta"),
        "tx absolute plan under --contain must apply: {content}"
    );
}

/// Absolute plan path outside workspace rejected under `--contain`.
#[test]
fn contain_tx_rejects_absolute_plan_outside_workspace() {
    let dir = TempDir::new().unwrap();
    let outside = TempDir::new().unwrap();
    let plan = outside.path().join("evil.json");
    fs::write(&plan, r#"{"version":1,"operations":[]}"#).unwrap();
    let abs = plan
        .canonicalize()
        .unwrap_or_else(|_| plan.clone())
        .to_string_lossy()
        .into_owned();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "tx", &abs, "--apply"])
        .assert()
        .failure()
        .stderr(
            predicate::str::contains("escapes")
                .or(predicate::str::contains("rejected"))
                .or(predicate::str::contains("workspace guard")),
        );
}

/// Absolute rename under `--contain` (both from and to).
#[test]
fn contain_rename_absolute_paths_apply() {
    let dir = TempDir::new().unwrap();
    let src = dir.path().join("old-name.txt");
    fs::write(&src, "data\n").unwrap();
    let dst = dir.path().join("new-name.txt");
    let abs_src = src
        .canonicalize()
        .unwrap_or_else(|_| src.clone())
        .to_string_lossy()
        .replace('\\', "/");
    let abs_dst = dst.to_string_lossy().replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "rename", &abs_src, &abs_dst, "--apply"])
        .assert()
        .code(0);

    assert!(!src.exists() || !src.is_file() || fs::read_to_string(&src).is_err());
    let content = fs::read_to_string(&dst).unwrap();
    assert!(
        content.contains("data"),
        "rename absolute under --contain: {content}"
    );
}

/// Case-only rename under `--contain` with absolute paths (Windows/macOS).
#[test]
fn contain_rename_case_only_absolute_paths() {
    let dir = TempDir::new().unwrap();
    let lower = dir.path().join("readme.md");
    fs::write(&lower, "hello\n").unwrap();
    let abs_from = lower
        .canonicalize()
        .unwrap_or_else(|_| lower.clone())
        .to_string_lossy()
        .replace('\\', "/");
    // Same directory, different case of basename.
    let mut abs_to = abs_from.clone();
    if let Some(i) = abs_to.rfind("readme.md") {
        abs_to.replace_range(i..i + "readme.md".len(), "README.md");
    } else if let Some(i) = abs_to.rfind("README.md") {
        abs_to.replace_range(i..i + "README.md".len(), "readme.md");
    }

    let out = Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "rename", &abs_from, &abs_to, "--apply"])
        .output()
        .unwrap();
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr={}",
        String::from_utf8_lossy(&out.stderr)
    );

    let entries: Vec<String> = fs::read_dir(dir.path())
        .unwrap()
        .filter_map(|e| e.ok())
        .map(|e| e.file_name().to_string_lossy().into_owned())
        .filter(|n| n.eq_ignore_ascii_case("readme.md"))
        .collect();
    assert_eq!(
        entries.len(),
        1,
        "expected one readme.md entry: {entries:?}"
    );
}

/// Deep relative escape under `--contain` still fails closed.
#[test]
fn contain_rejects_deep_relative_escape() {
    let dir = TempDir::new().unwrap();
    fs::create_dir_all(dir.path().join("a/b/c")).unwrap();
    fs::write(dir.path().join("a/b/c/x.txt"), "in\n").unwrap();

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "read", "a/b/c/../../../../../../etc/passwd"])
        .assert()
        .failure()
        .stderr(
            predicate::str::contains("escapes")
                .or(predicate::str::contains("rejected"))
                .or(predicate::str::contains("workspace guard")),
        );
}

/// Batch ops file as absolute path under `--contain`.
#[test]
fn contain_batch_absolute_ops_file() {
    let dir = TempDir::new().unwrap();
    let target = dir.path().join("b.txt");
    fs::write(&target, "old\n").unwrap();
    let ops = dir.path().join("ops.txt");
    // batch replace: PATH OLD NEW
    fs::write(&ops, "replace b.txt old new\n").unwrap();
    let abs_ops = ops
        .canonicalize()
        .unwrap_or_else(|_| ops.clone())
        .to_string_lossy()
        .replace('\\', "/");

    Command::cargo_bin("patchloom")
        .unwrap()
        .args(["--cwd"])
        .arg(dir.path())
        .args(["--contain", "batch", &abs_ops, "--apply"])
        .assert()
        .code(0);

    let content = fs::read_to_string(&target).unwrap();
    assert!(
        content.contains("new"),
        "batch absolute ops under --contain: {content}"
    );
}

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

    /// Case-only rename with std-canonicalize (UNC) absolute paths under contain.
    #[test]
    fn contain_rename_case_only_std_canonicalized_paths() {
        let dir = TempDir::new().unwrap();
        let lower = dir.path().join("notes.txt");
        fs::write(&lower, "body\n").unwrap();
        let from = std::fs::canonicalize(&lower).unwrap();
        let from_s = from.to_string_lossy().into_owned();
        let to_s = from_s.replace("notes.txt", "NOTES.txt");

        let out = Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--cwd"])
            .arg(dir.path())
            .args(["--contain", "rename", &from_s, &to_s, "--apply"])
            .output()
            .unwrap();
        assert_eq!(
            out.status.code(),
            Some(0),
            "stderr={} stdout={}",
            String::from_utf8_lossy(&out.stderr),
            String::from_utf8_lossy(&out.stdout)
        );
        let names: Vec<_> = fs::read_dir(dir.path())
            .unwrap()
            .filter_map(|e| e.ok())
            .map(|e| e.file_name().to_string_lossy().into_owned())
            .filter(|n| n.eq_ignore_ascii_case("notes.txt"))
            .collect();
        assert_eq!(names.len(), 1, "{names:?}");
    }

    /// Long path under workspace: either succeeds with simplified path, or
    /// fails closed with a clear error (never panics / never silent wrong write).
    #[test]
    fn long_path_under_workspace_is_honest() {
        let dir = TempDir::new().unwrap();
        // Build a nested directory name that exceeds classic MAX_PATH (260)
        // when fully joined, using a single long component where possible.
        let mut long = dir.path().to_path_buf();
        // ~40 * 8 = 320 chars of nesting under temp (often > 260 total).
        for i in 0..40 {
            long.push(format!("seg{i:02}xx"));
        }
        // Creating deep trees may require \\?\ on Windows.
        let create = std::process::Command::new("cmd")
            .args(["/C", "mkdir", &format!("\\\\?\\{}", long.display())])
            .output();
        if create.map(|o| !o.status.success()).unwrap_or(true) {
            // Fallback: try std create_dir_all (works if long-path registry is on).
            if fs::create_dir_all(&long).is_err() {
                // Environment cannot create long paths; skip without failing CI.
                return;
            }
        }
        let file = long.join("leaf.txt");
        let write_path = PathBuf::from(format!("\\\\?\\{}", file.display()));
        if fs::write(&write_path, "long-ok\n").is_err() {
            let _ = fs::write(&file, "long-ok\n");
        }
        if !file.exists() && !write_path.exists() {
            return;
        }

        let abs = std::fs::canonicalize(&file)
            .or_else(|_| std::fs::canonicalize(&write_path))
            .unwrap_or(file.clone());
        let s = abs.to_string_lossy().into_owned();

        let out = Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--json", "--cwd"])
            .arg(dir.path())
            .args(["--contain", "read", &s])
            .output()
            .unwrap();

        let combined = format!(
            "{}{}",
            String::from_utf8_lossy(&out.stdout),
            String::from_utf8_lossy(&out.stderr)
        );
        if out.status.success() {
            assert!(
                combined.contains("long-ok"),
                "long path read success must return content: {combined}"
            );
        } else {
            // Fail closed: structured failure, no panic, path mentioned.
            assert!(
                combined.contains("error")
                    || combined.contains("failed")
                    || combined.contains("path")
                    || combined.contains("escapes"),
                "long path failure must be actionable: {combined}"
            );
        }
    }

    /// Outside long path under --contain rejects (fail closed).
    #[test]
    fn contain_rejects_outside_long_absolute_path() {
        let dir = TempDir::new().unwrap();
        let outside = TempDir::new().unwrap();
        let mut long = outside.path().to_path_buf();
        for i in 0..20 {
            long.push(format!("out{i:02}"));
        }
        let _ = fs::create_dir_all(&long);
        let file = long.join("x.txt");
        if fs::write(&file, "x\n").is_err() {
            return;
        }
        let abs = std::fs::canonicalize(&file).unwrap_or(file);
        let s = abs.to_string_lossy().into_owned();

        Command::cargo_bin("patchloom")
            .unwrap()
            .args(["--cwd"])
            .arg(dir.path())
            .args(["--contain", "read", &s])
            .assert()
            .failure()
            .stderr(
                predicate::str::contains("escapes")
                    .or(predicate::str::contains("rejected"))
                    .or(predicate::str::contains("workspace guard")),
            );
    }
}