link-assistant-router 1.9.0

Link.Assistant.Router — Claude MAX OAuth proxy and token gateway for Anthropic APIs
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
#!/usr/bin/env rust-script
//! Bump version in Cargo.toml and commit changes
//! Used by the CI/CD pipeline for releases
//!
//! Supports both single-language and multi-language repository structures:
//! - Single-language: Cargo.toml and changelog.d/ in repository root
//! - Multi-language: Cargo.toml and changelog.d/ in rust/ subfolder
//!
//! Usage: rust-script scripts/version-and-commit.rs --bump-type <major|minor|patch> [--description <desc>] [--rust-root <path>]
//!
//! ```cargo
//! [dependencies]
//! regex = "1"
//! chrono = "0.4"
//! ```

use chrono::Utc;
use regex::Regex;
use std::env;
use std::fs;
use std::io::Write;
use std::path::Path;
use std::process::{exit, Command};

fn get_arg(name: &str) -> Option<String> {
    let args: Vec<String> = env::args().collect();
    let flag = format!("--{}", name);

    if let Some(idx) = args.iter().position(|a| a == &flag) {
        return args.get(idx + 1).cloned();
    }

    let env_name = name.to_uppercase().replace('-', "_");
    env::var(&env_name).ok().filter(|s| !s.is_empty())
}

fn get_rust_root() -> String {
    if let Some(root) = get_arg("rust-root") {
        eprintln!("Using explicitly configured Rust root: {}", root);
        return root;
    }

    if Path::new("./Cargo.toml").exists() {
        eprintln!("Detected single-language repository (Cargo.toml in root)");
        return ".".to_string();
    }

    if Path::new("./rust/Cargo.toml").exists() {
        eprintln!("Detected multi-language repository (Cargo.toml in rust/)");
        return "rust".to_string();
    }

    eprintln!("Error: Could not find Cargo.toml in expected locations");
    exit(1);
}

fn get_cargo_toml_path(rust_root: &str) -> String {
    if rust_root == "." {
        "./Cargo.toml".to_string()
    } else {
        format!("{}/Cargo.toml", rust_root)
    }
}

fn get_cargo_lock_path(rust_root: &str) -> String {
    if rust_root == "." {
        "./Cargo.lock".to_string()
    } else {
        format!("{}/Cargo.lock", rust_root)
    }
}

fn get_changelog_dir(rust_root: &str) -> String {
    if rust_root == "." {
        "./changelog.d".to_string()
    } else {
        format!("{}/changelog.d", rust_root)
    }
}

fn get_changelog_path(rust_root: &str) -> String {
    if rust_root == "." {
        "./CHANGELOG.md".to_string()
    } else {
        format!("{}/CHANGELOG.md", rust_root)
    }
}

fn set_output(key: &str, value: &str) {
    if let Ok(output_file) = env::var("GITHUB_OUTPUT") {
        if let Ok(mut file) = fs::OpenOptions::new()
            .create(true)
            .append(true)
            .open(&output_file)
        {
            let _ = writeln!(file, "{}={}", key, value);
        }
    }
    println!("Output: {}={}", key, value);
}

fn exec(command: &str, args: &[&str]) -> Result<String, String> {
    match Command::new(command).args(args).output() {
        Ok(output) => {
            if output.status.success() {
                Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
            } else {
                let stderr = String::from_utf8_lossy(&output.stderr);
                Err(format!("Command failed: {}", stderr))
            }
        }
        Err(e) => Err(format!("Failed to execute: {}", e)),
    }
}

fn exec_check(command: &str, args: &[&str]) -> bool {
    Command::new(command)
        .args(args)
        .output()
        .map(|o| o.status.success())
        .unwrap_or(false)
}

struct Version {
    major: u32,
    minor: u32,
    patch: u32,
}

impl Version {
    fn parse(content: &str) -> Option<Version> {
        let re = Regex::new(r#"(?m)^version\s*=\s*"(\d+)\.(\d+)\.(\d+)""#).ok()?;
        let caps = re.captures(content)?;
        Some(Version {
            major: caps.get(1)?.as_str().parse().ok()?,
            minor: caps.get(2)?.as_str().parse().ok()?,
            patch: caps.get(3)?.as_str().parse().ok()?,
        })
    }

    fn bump(&self, bump_type: &str) -> String {
        match bump_type {
            "major" => format!("{}.0.0", self.major + 1),
            "minor" => format!("{}.{}.0", self.major, self.minor + 1),
            _ => format!("{}.{}.{}", self.major, self.minor, self.patch + 1),
        }
    }
}

fn update_cargo_toml(cargo_toml_path: &str, new_version: &str) -> Result<(), String> {
    let content = fs::read_to_string(cargo_toml_path)
        .map_err(|e| format!("Failed to read {}: {}", cargo_toml_path, e))?;

    let re = Regex::new(r#"(?m)^(version\s*=\s*")[^"]+(")"#).unwrap();
    let new_content = re.replace(&content, format!("${{1}}{}${{2}}", new_version).as_str());

    fs::write(cargo_toml_path, new_content.as_ref())
        .map_err(|e| format!("Failed to write {}: {}", cargo_toml_path, e))?;

    println!("Updated {} to version {}", cargo_toml_path, new_version);
    Ok(())
}

fn update_cargo_lock(
    cargo_lock_path: &str,
    crate_name: &str,
    new_version: &str,
) -> Result<bool, String> {
    if !Path::new(cargo_lock_path).exists() {
        println!("No Cargo.lock at {cargo_lock_path}; skipping lockfile synchronization");
        return Ok(false);
    }

    let content = fs::read_to_string(cargo_lock_path)
        .map_err(|e| format!("Failed to read {cargo_lock_path}: {e}"))?;
    let pattern = format!(
        r#"(?m)(\[\[package\]\]\s*\nname\s*=\s*"{}"\s*\nversion\s*=\s*")[^"]+(")"#,
        regex::escape(crate_name),
    );
    let package = Regex::new(&pattern)
        .map_err(|e| format!("Failed to build Cargo.lock package matcher: {e}"))?;

    if !package.is_match(&content) {
        return Err(format!(
            "Could not find [[package]] entry for `{crate_name}` in {cargo_lock_path}"
        ));
    }

    let updated = package.replace(&content, format!("${{1}}{new_version}${{2}}").as_str());
    if updated == content {
        println!("Cargo.lock already contains version {new_version}");
        return Ok(false);
    }

    fs::write(cargo_lock_path, updated.as_ref())
        .map_err(|e| format!("Failed to write {cargo_lock_path}: {e}"))?;
    println!("Updated {cargo_lock_path} to version {new_version}");
    Ok(true)
}

fn check_tag_exists(version: &str) -> bool {
    exec_check("git", &["rev-parse", &format!("v{}", version)])
}

fn strip_frontmatter(content: &str) -> String {
    let re = Regex::new(r"(?s)^---\s*\n.*?\n---\s*\n(.*)$").unwrap();
    if let Some(caps) = re.captures(content) {
        caps.get(1).unwrap().as_str().trim().to_string()
    } else {
        content.trim().to_string()
    }
}

fn collect_changelog(changelog_dir: &str, changelog_file: &str, version: &str) {
    let dir_path = Path::new(changelog_dir);
    if !dir_path.exists() {
        return;
    }

    let mut files: Vec<_> = match fs::read_dir(dir_path) {
        Ok(entries) => entries
            .filter_map(|e| e.ok())
            .map(|e| e.path())
            .filter(|p| {
                p.extension().map_or(false, |ext| ext == "md")
                    && p.file_name().map_or(false, |name| name != "README.md")
            })
            .collect(),
        Err(_) => return,
    };

    if files.is_empty() {
        return;
    }

    files.sort();

    let fragments: Vec<String> = files
        .iter()
        .filter_map(|f| fs::read_to_string(f).ok())
        .map(|c| strip_frontmatter(&c))
        .filter(|c| !c.is_empty())
        .collect();

    if fragments.is_empty() {
        return;
    }

    let date_str = Utc::now().format("%Y-%m-%d").to_string();
    let new_entry = format!(
        "\n## [{}] - {}\n\n{}\n",
        version,
        date_str,
        fragments.join("\n\n")
    );

    if Path::new(changelog_file).exists() {
        let mut content = fs::read_to_string(changelog_file).unwrap_or_default();
        let lines: Vec<&str> = content.lines().collect();
        let mut insert_index = None;

        for (i, line) in lines.iter().enumerate() {
            if line.starts_with("## [") {
                insert_index = Some(i);
                break;
            }
        }

        if let Some(idx) = insert_index {
            let mut new_lines: Vec<String> = lines[..idx].iter().map(|s| s.to_string()).collect();
            new_lines.push(new_entry.clone());
            new_lines.extend(lines[idx..].iter().map(|s| s.to_string()));
            content = new_lines.join("\n");
        } else {
            content.push_str(&new_entry);
        }

        fs::write(changelog_file, content).expect("Failed to write changelog");
    }

    // Removed once collected, or the next release collects them again. This
    // was the whole defect: only `collect-changelog.rs` deleted, and that is
    // the manual dispatch path, so the automatic release on merge to main
    // re-collected every fragment ever written. Each release therefore
    // republished the entire archive as though it were new -- 154 fragments
    // and a 145 KB section for one version by v0.120.0 (issue #337).
    for file in &files {
        if let Err(error) = fs::remove_file(file) {
            // Failing the release over a leftover file would be worse than
            // the duplication; the next release collects it again and the
            // guard below is what makes that visible.
            eprintln!(
                "warning: could not remove collected fragment {}: {error}",
                file.display()
            );
        }
    }

    println!("Collected and removed {} changelog fragment(s)", files.len());
}

fn main() {
    let bump_type = match get_arg("bump-type") {
        Some(bt) => bt,
        None => {
            eprintln!("Usage: rust-script scripts/version-and-commit.rs --bump-type <major|minor|patch> [--description <desc>] [--rust-root <path>]");
            exit(1);
        }
    };

    if !["major", "minor", "patch"].contains(&bump_type.as_str()) {
        eprintln!(
            "Invalid bump type: {}. Must be major, minor, or patch.",
            bump_type
        );
        exit(1);
    }

    let description = get_arg("description");
    let rust_root = get_rust_root();
    let cargo_toml = get_cargo_toml_path(&rust_root);
    let cargo_lock = get_cargo_lock_path(&rust_root);
    let changelog_dir = get_changelog_dir(&rust_root);
    let changelog_file = get_changelog_path(&rust_root);

    // Configure git
    let _ = exec("git", &["config", "user.name", "github-actions[bot]"]);
    let _ = exec(
        "git",
        &[
            "config",
            "user.email",
            "github-actions[bot]@users.noreply.github.com",
        ],
    );

    // Get current version
    let content = match fs::read_to_string(&cargo_toml) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("Error reading {}: {}", cargo_toml, e);
            exit(1);
        }
    };

    let current = match Version::parse(&content) {
        Some(v) => v,
        None => {
            eprintln!("Error: Could not parse version from {}", cargo_toml);
            exit(1);
        }
    };

    let new_version = current.bump(&bump_type);

    // Check if this version was already released
    if check_tag_exists(&new_version) {
        println!("Tag v{} already exists", new_version);
        set_output("already_released", "true");
        set_output("new_version", &new_version);
        return;
    }

    // Update version in Cargo.toml
    if let Err(e) = update_cargo_toml(&cargo_toml, &new_version) {
        eprintln!("Error: {}", e);
        exit(1);
    }

    let lock_updated = match update_cargo_lock(&cargo_lock, "link-assistant-router", &new_version) {
        Ok(updated) => updated,
        Err(e) => {
            eprintln!("Error: {e}");
            exit(1);
        }
    };

    // Collect changelog fragments
    collect_changelog(&changelog_dir, &changelog_file, &new_version);

    // Stage the manifest, synchronized lockfile, changelog, and the fragment
    // directory together.
    //
    // `changelog.d` matters as much as the rest: `collect_changelog` removes
    // the fragments it consumed, but a commit that does not stage those
    // deletions leaves them in the tree, so the next release collects them
    // again -- the very accumulation issue #337 was about. Staging the
    // directory records the removals with the release that consumed them.
    let mut release_files = vec!["add", &cargo_toml, &changelog_file, &changelog_dir];
    if lock_updated {
        release_files.push(&cargo_lock);
    }
    if let Err(e) = exec("git", &release_files) {
        eprintln!("Error staging release files: {e}");
        exit(1);
    }

    // Check if there are changes to commit
    if exec_check("git", &["diff", "--cached", "--quiet"]) {
        // No changes to commit
        println!("No changes to commit");
        set_output("version_committed", "false");
        set_output("new_version", &new_version);
        return;
    }

    // Commit changes
    let commit_msg = match &description {
        Some(desc) => format!("chore: release v{}\n\n{}", new_version, desc),
        None => format!("chore: release v{}", new_version),
    };

    if let Err(e) = exec("git", &["commit", "-m", &commit_msg]) {
        eprintln!("Error committing: {}", e);
        exit(1);
    }
    println!("Committed version {}", new_version);

    // Create tag
    let tag_msg = match &description {
        Some(desc) => format!("Release v{}\n\n{}", new_version, desc),
        None => format!("Release v{}", new_version),
    };

    if let Err(e) = exec(
        "git",
        &["tag", "-a", &format!("v{}", new_version), "-m", &tag_msg],
    ) {
        eprintln!("Error creating tag: {}", e);
        exit(1);
    }
    println!("Created tag v{}", new_version);

    // Push changes and tag
    if let Err(e) = exec("git", &["push"]) {
        eprintln!("Error pushing: {}", e);
        exit(1);
    }

    if let Err(e) = exec("git", &["push", "--tags"]) {
        eprintln!("Error pushing tags: {}", e);
        exit(1);
    }
    println!("Pushed changes and tags");

    set_output("version_committed", "true");
    set_output("new_version", &new_version);
}

#[cfg(test)]
mod tests {
    use super::{collect_changelog, update_cargo_lock};
    use std::fs;
    use std::path::PathBuf;
    use std::time::{SystemTime, UNIX_EPOCH};

    fn temp_lock(name: &str) -> PathBuf {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .expect("clock should be after the Unix epoch")
            .as_nanos();
        std::env::temp_dir().join(format!("router-{name}-{nonce}.lock"))
    }

    #[test]
    fn lock_update_changes_only_the_named_package() {
        let lock = temp_lock("update");
        fs::write(
            &lock,
            r#"[[package]]
name = "link-assistant-router-helper"
version = "9.9.9"

[[package]]
name = "link-assistant-router"
version = "0.28.0"

[[package]]
name = "dependency"
version = "1.2.3"
"#,
        )
        .expect("fixture should be writable");

        assert!(update_cargo_lock(
            lock.to_str().expect("temporary path should be UTF-8"),
            "link-assistant-router",
            "0.29.0",
        )
        .expect("lock update should succeed"));

        let updated = fs::read_to_string(&lock).expect("updated fixture should be readable");
        assert!(updated.contains("name = \"link-assistant-router\"\nversion = \"0.29.0\""));
        assert!(updated.contains("name = \"link-assistant-router-helper\"\nversion = \"9.9.9\""));
        assert!(updated.contains("name = \"dependency\"\nversion = \"1.2.3\""));
        fs::remove_file(lock).expect("temporary fixture should be removable");
    }

    #[test]
    fn lock_update_is_idempotent() {
        let lock = temp_lock("idempotent");
        let content = "[[package]]\nname = \"link-assistant-router\"\nversion = \"0.29.0\"\n";
        fs::write(&lock, content).expect("fixture should be writable");

        assert!(!update_cargo_lock(
            lock.to_str().expect("temporary path should be UTF-8"),
            "link-assistant-router",
            "0.29.0",
        )
        .expect("idempotent update should succeed"));
        assert_eq!(
            fs::read_to_string(&lock).expect("fixture should be readable"),
            content
        );
        fs::remove_file(lock).expect("temporary fixture should be removable");
    }

    #[test]
    fn lock_update_rejects_a_missing_package_entry() {
        let lock = temp_lock("missing");
        fs::write(
            &lock,
            "[[package]]\nname = \"dependency\"\nversion = \"1.2.3\"\n",
        )
        .expect("fixture should be writable");

        let error = update_cargo_lock(
            lock.to_str().expect("temporary path should be UTF-8"),
            "link-assistant-router",
            "0.29.0",
        )
        .expect_err("a missing root package must fail closed");
        assert!(error.contains("Could not find [[package]] entry"));
        fs::remove_file(lock).expect("temporary fixture should be removable");
    }

    /// A collected fragment is removed, so the next release does not collect
    /// it again.
    ///
    /// Only `collect-changelog.rs` deleted, and that is the manual dispatch
    /// path; the automatic release on merge ran this script, which collected
    /// and never removed. Every release therefore republished every fragment
    /// ever written -- 154 of them, and a 145 KB section for one version, by
    /// v0.120.0 (issue #337).
    #[test]
    fn collected_fragments_are_removed() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .expect("clock")
            .as_nanos();
        let root = std::env::temp_dir().join(format!("changelog-collect-{nonce}"));
        let fragments = root.join("changelog.d");
        fs::create_dir_all(&fragments).expect("create the fragment directory");
        let changelog = root.join("CHANGELOG.md");
        fs::write(&changelog, "# Changelog\n\n## [0.1.0] - 2020-01-01\n\nold\n")
            .expect("seed the changelog");
        fs::write(
            fragments.join("20260101_000000_first.md"),
            "---\nbump: minor\n---\n\n### Added\n- a first thing\n",
        )
        .expect("write a fragment");
        // README.md is documentation, not a fragment, and must survive.
        fs::write(fragments.join("README.md"), "how to write a fragment\n")
            .expect("write the readme");

        collect_changelog(
            fragments.to_str().expect("path"),
            changelog.to_str().expect("path"),
            "0.2.0",
        );

        let collected = fs::read_to_string(&changelog).expect("read the changelog");
        assert!(
            collected.contains("a first thing"),
            "the fragment must reach the changelog: {collected}"
        );
        assert!(
            !fragments.join("20260101_000000_first.md").exists(),
            "a collected fragment must not be collected again by the next release"
        );
        assert!(
            fragments.join("README.md").exists(),
            "the directory's documentation is not a fragment"
        );

        // And a second release over the same directory adds nothing.
        collect_changelog(
            fragments.to_str().expect("path"),
            changelog.to_str().expect("path"),
            "0.3.0",
        );
        let after = fs::read_to_string(&changelog).expect("read the changelog");
        assert_eq!(
            after.matches("a first thing").count(),
            1,
            "an entry belongs to one release, not every release after it: {after}"
        );

        fs::remove_dir_all(&root).expect("clean up");
    }

    /// The release commit records the fragment removals.
    ///
    /// `collect_changelog` deletes the fragments it consumed, but a commit
    /// that does not stage those deletions leaves them in the tree, so the
    /// next release collects them again -- the accumulation issue #337 was
    /// about, reintroduced one layer down. The unit tests could not see it
    /// because staging is a property of the commit, not of the collector, so
    /// this drives a real repository.
    #[test]
    fn a_release_commit_stages_the_fragments_it_consumed() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .expect("clock")
            .as_nanos();
        let root = std::env::temp_dir().join(format!("release-staging-{nonce}"));
        let fragments = root.join("changelog.d");
        fs::create_dir_all(&fragments).expect("create the fragment directory");
        fs::write(
            fragments.join("20260101_000000_first.md"),
            "---\nbump: minor\n---\n\n### Added\n- a first thing\n",
        )
        .expect("write a fragment");
        fs::write(fragments.join("README.md"), "how to write a fragment\n")
            .expect("write the readme");
        fs::write(
            root.join("CHANGELOG.md"),
            "# Changelog\n\n<!-- changelog-insert-here -->\n\n## [0.1.0] - 2020-01-01\n- start\n",
        )
        .expect("seed the changelog");
        fs::write(
            root.join("Cargo.toml"),
            "[package]\nname = \"sim\"\nversion = \"0.1.0\"\n",
        )
        .expect("seed the manifest");

        let git = |arguments: &[&str]| {
            std::process::Command::new("git")
                .args(arguments)
                .current_dir(&root)
                .output()
                .expect("run git")
        };
        git(&["init", "-q"]);
        git(&["config", "user.email", "test@example.com"]);
        git(&["config", "user.name", "test"]);
        git(&["add", "-A"]);
        git(&["commit", "-qm", "initial"]);

        // This file's own path: `CARGO_MANIFEST_DIR` points at rust-script's
        // cache rather than the repository when it runs a script.
        let script = std::path::Path::new(file!())
            .canonicalize()
            .expect("this script's path");
        let released = std::process::Command::new("rust-script")
            .args([
                script.to_str().expect("a printable path"),
                "--bump-type",
                "minor",
            ])
            .current_dir(&root)
            .output()
            .expect("run the release script");
        assert!(
            String::from_utf8_lossy(&released.stdout).contains("Committed version"),
            "the release must commit: {}",
            String::from_utf8_lossy(&released.stderr)
        );

        let tracked = git(&["ls-tree", "HEAD", "--name-only", "changelog.d/"]);
        let tracked = String::from_utf8_lossy(&tracked.stdout);
        assert!(
            !tracked.contains("20260101_000000_first.md"),
            "a collected fragment must not survive in the committed tree: {tracked}"
        );
        assert!(
            tracked.contains("README.md"),
            "the directory's documentation is not a fragment: {tracked}"
        );

        fs::remove_dir_all(&root).expect("clean up");
    }
}