bendis 0.5.12

A patch tool for Bender to work better in HERIS project
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
use anyhow::{bail, Context, Result};
use colored::Colorize;
use std::fs;
use std::io::{BufRead, BufReader};
use std::path::Path;
use std::process::{Command, Stdio};

use super::hardening::{self, HardeningStatus};
use crate::converter::format;
use crate::utils::config::{self, BendisConfig};

#[derive(Default)]
struct ConflictCleanupResult {
    removed: usize,
    preserved: Vec<String>,
}

pub fn run(hard: bool) -> Result<()> {
    // Check for legacy structure and offer migration
    if config::check_and_migrate_if_needed()? {
        // Migration was performed or user declined
        // If migration was successful, continue with update
        // If user declined, exit
        if !config::get_bendis_dir().exists() {
            // User declined migration and no new structure exists
            bail!(
                "error: bendis_workspace directory not found\nrun `bendis init` to migrate or initialize the project"
            );
        }
    }

    println!("Updating dependencies...");

    // Load configuration
    let cfg = BendisConfig::load()?;

    let bendis_dir = config::get_bendis_dir();
    let root_dir = config::get_root_dir();

    // Check if bendis_workspace directory exists
    if !bendis_dir.exists() {
        bail!(
            "error: bendis_workspace directory not found\nrun `bendis init` first to initialize the project"
        );
    }

    // Check bendis_workspace/.gitignore if enabled in config
    let mut gitignore_warning = None;
    if cfg.gitignore_check == 1 {
        if let Err(e) = config::check_bendis_gitignore() {
            gitignore_warning = Some(e.to_string());
        }
    }

    // Step 1: Copy hw/ and target/ directories from root to bendis_workspace/
    println!("  Syncing hw/ and target/ directories to bendis_workspace/...");
    config::copy_root_dirs_to_bendis_workspace()?;

    // Restore the authoritative workspace override before Bender searches parent configs.
    restore_root_override_for_workspace_update(&bendis_dir, &root_dir)?;

    // Step 2: Run bender update in bendis_workspace directory
    println!("  Preparing cache files (it may take long)...");
    run_bender_update_in_bendis(&bendis_dir, cfg.silent_mode == 1)?;

    // Step 3: Run format converter
    println!("  Converting URLs...");
    let configs_changed = format::convert(&bendis_dir, &root_dir)?;

    // Step 4: Ensure bendis_workspace/.gitignore has required entries (hw/, target/)
    println!("  Updating bendis_workspace/.gitignore...");
    config::ensure_bendis_workspace_gitignore_entries()?;

    // Step 5: Ensure root .gitignore does not contain hw/, target/
    println!("  Updating root .gitignore...");
    config::ensure_root_gitignore_excludes_hw_target()?;

    // Step 6: Materialize the converted exact lock without resolving versions again.
    println!("  Checking for changes...");
    if configs_changed {
        println!("  Detected changes, checking out dependencies...");
    } else {
        println!("  No changes detected, checking local dependency cache...");
    }
    run_bender_checkout_in_root(&root_dir, Path::new("bender"))?;

    // Step 7: Clean up based on storage_saving_mode
    println!("  Cleaning up cache...");
    cleanup_bendis_workspace_bender_dir(&bendis_dir, cfg.storage_saving_mode == 1)?;

    // Step 8: Verify
    verify_completion(&root_dir)?;

    // Display gitignore warning if there was an issue
    if let Some(warning_msg) = gitignore_warning {
        eprintln!("\n{}", "warning:".yellow().bold());
        eprintln!("  {}", warning_msg);
        eprintln!("  Some files in bendis_workspace/ may be tracked by git unexpectedly.");
        eprintln!("  Please review bendis_workspace/.gitignore and ensure it contains the required entries.");
        eprintln!(
            "  To disable this check, set 'gitignore_check = 0' in: {}",
            "bendis config".cyan()
        );
    }

    if hard {
        println!("Preparing AegisRTL workspace...");
        let result = match hardening::run(&root_dir) {
            Ok(result) => result,
            Err(error) => {
                eprintln!("Hardening failed; local RTL dependencies were not activated");
                return Err(error);
            }
        };
        for message in hardening_completion_messages(&result) {
            println!("{message}");
        }
    }

    let cleanup = cleanup_generated_conflict_copies(&root_dir, &bendis_dir, hard)?;
    if cleanup.removed > 0 {
        println!("Removed generated conflict copies: {}", cleanup.removed);
    }
    for path in cleanup.preserved {
        eprintln!("Warning: possible workspace conflict copy was not removed: {path}");
    }

    println!("Done");

    Ok(())
}

fn hardening_completion_messages(result: &hardening::HardeningResult) -> Vec<String> {
    match result.status {
        HardeningStatus::Completed => vec![
            format!(
                "Hardening completed. Changed RTL files: {}",
                result.changed_files.len()
            ),
            "Hardened RTL dependencies activated".to_string(),
        ],
        HardeningStatus::Skipped => vec![
            "Hardening skipped: aegisrtl/scripts/harden.sh was not found".to_string(),
            "Local RTL dependencies activated without hardening".to_string(),
        ],
    }
}

fn restore_root_override_for_workspace_update(bendis_dir: &Path, root_dir: &Path) -> Result<()> {
    let source = bendis_dir.join(".bender.yml");
    if !source.is_file() {
        bail!("error: bendis_workspace/.bender.yml not found");
    }
    fs::copy(&source, root_dir.join(".bender.yml"))
        .context("Failed to restore root .bender.yml from bendis_workspace")?;
    Ok(())
}

fn run_bender_update_in_bendis(bendis_dir: &Path, silent: bool) -> Result<()> {
    let mut cmd = Command::new("bender");
    cmd.args(&["-d", "./bendis_workspace", "update"]);

    // Always capture output for error logging
    cmd.stdout(Stdio::piped());
    cmd.stderr(Stdio::piped());

    let mut child = cmd
        .spawn()
        .context("Failed to run bender. Is bender installed and in PATH?")?;

    // Capture stdout and stderr
    let stdout = child.stdout.take().unwrap();
    let stderr = child.stderr.take().unwrap();

    let mut stdout_reader = BufReader::new(stdout);
    let mut stderr_reader = BufReader::new(stderr);

    let mut log_buffer = Vec::new();
    let mut line = String::new();

    // Read stdout
    while stdout_reader.read_line(&mut line).unwrap_or(0) > 0 {
        if !silent {
            print!("{}", line);
        }
        log_buffer.push(line.clone());
        line.clear();
    }

    // Read stderr
    while stderr_reader.read_line(&mut line).unwrap_or(0) > 0 {
        if !silent {
            eprint!("{}", line);
        }
        log_buffer.push(line.clone());
        line.clear();
    }

    let status = child.wait().context("Failed to wait for bender process")?;

    if !status.success() {
        // Always display full log on error, regardless of silent mode
        eprintln!(
            "\n{}",
            "Error: bender update failed in bendis_workspace/".red()
        );
        eprintln!("\nCommand output:");
        for log_line in &log_buffer {
            eprint!("{}", log_line);
        }

        // Check for specific fetch/version error pattern
        let has_fetch_error = log_buffer.iter().any(|line| {
            line.contains("Fetching Dependency")
                && line.contains("cannot satisfy requirement")
                && line.contains("may need fetch")
        });

        if has_fetch_error {
            eprintln!("\n{}", "Possible solution:".yellow());
            eprintln!(
                "  1. Delete {} directory",
                "bendis_workspace/.bender/".cyan()
            );
            eprintln!("  2. Check your internet connection");
            eprintln!("  3. Run {} again", "bendis update".cyan());
        }

        bail!("error: bender update in bendis_workspace/ failed");
    }

    // Check if Bender.lock was created
    let lock_file = bendis_dir.join("Bender.lock");
    if !lock_file.exists() {
        bail!("error: failed to generate bendis_workspace/Bender.lock");
    }

    Ok(())
}

fn run_bender_checkout_in_root(root_dir: &Path, bender: &Path) -> Result<()> {
    let local = Command::new(bender)
        .args(["--local", "--git-submodules", "false", "checkout"])
        .current_dir(root_dir)
        .output()
        .context("Failed to run bender. Is bender installed and in PATH?")?;
    if local.status.success() && checkouts_have_complete_submodules(root_dir)? {
        return Ok(());
    }

    println!("  Local checkout could not be completed; retrying with remote access");
    let remote = Command::new(bender)
        .arg("checkout")
        .current_dir(root_dir)
        .output()
        .context("Failed to retry bender checkout with remote access")?;
    if !remote.status.success() {
        eprint!("{}", String::from_utf8_lossy(&remote.stdout));
        eprint!("{}", String::from_utf8_lossy(&remote.stderr));
        bail!("bender checkout failed in root directory");
    }
    if !checkouts_have_complete_submodules(root_dir)? {
        bail!("bender checkout did not produce complete dependency submodules");
    }
    Ok(())
}

fn checkouts_have_complete_submodules(root_dir: &Path) -> Result<bool> {
    let checkouts = root_dir.join(".bender/git/checkouts");
    if !checkouts.is_dir() {
        return Ok(true);
    }
    for entry in fs::read_dir(&checkouts)
        .with_context(|| format!("Failed to read {}", checkouts.display()))?
    {
        let path = entry?.path();
        if !path.is_dir() || !path.join(".git").exists() {
            continue;
        }
        let submodules = Command::new("git")
            .args(["submodule", "status", "--recursive"])
            .current_dir(&path)
            .output()
            .with_context(|| format!("Failed to inspect submodules in {}", path.display()))?;
        if !submodules.status.success()
            || submodules
                .stdout
                .split(|byte| *byte == b'\n')
                .filter(|line| !line.is_empty())
                .any(|line| line.first() != Some(&b' '))
        {
            return Ok(false);
        }
    }
    Ok(true)
}

fn cleanup_bendis_workspace_bender_dir(bendis_dir: &Path, full_cleanup: bool) -> Result<()> {
    if full_cleanup {
        // storage_saving_mode = 1: delete entire bendis_workspace/.bender/
        let bender_dir = bendis_dir.join(".bender");
        if bender_dir.exists() {
            fs::remove_dir_all(&bender_dir)
                .context("Failed to remove bendis_workspace/.bender/")?;
        }
    } else {
        // storage_saving_mode = 0: don't delete anything (keep cache)
        // Do nothing
    }

    Ok(())
}

fn verify_completion(root_dir: &Path) -> Result<()> {
    let mut missing = Vec::new();

    // Check required files
    if !root_dir.join("Bender.yml").exists() {
        missing.push("Bender.yml");
    }
    if !root_dir.join(".bender.yml").exists() {
        missing.push(".bender.yml");
    }
    if !root_dir.join("Bender.lock").exists() {
        missing.push("Bender.lock");
    }
    if !root_dir.join(".bender").exists() {
        missing.push(".bender/");
    }

    if !missing.is_empty() {
        bail!(
            "error: verification failed, missing: {}",
            missing.join(", ")
        );
    }

    Ok(())
}

fn cleanup_generated_conflict_copies(
    root_dir: &Path,
    bendis_dir: &Path,
    hard: bool,
) -> Result<ConflictCleanupResult> {
    let mut result = ConflictCleanupResult::default();
    for canonical in ["Bender.yml", ".bender.yml", "Bender.lock"] {
        result.removed += remove_numbered_file_copies(root_dir, canonical)?;
    }
    result.removed += remove_numbered_file_copies(bendis_dir, "Bender.lock")?;
    for canonical in ["Bender.yml", ".bender.yml"] {
        for path in numbered_file_copies(bendis_dir, canonical)? {
            let directory = bendis_dir
                .file_name()
                .and_then(|name| name.to_str())
                .unwrap_or("bendis_workspace");
            let file_name = path.file_name().and_then(|name| name.to_str()).unwrap();
            result.preserved.push(format!("{directory}/{file_name}"));
        }
    }
    if hard {
        let root = root_dir
            .canonicalize()
            .with_context(|| format!("Failed to resolve {}", root_dir.display()))?;
        let aegis = root
            .parent()
            .context("project root has no parent directory")?
            .join("aegisrtl");
        for canonical in ["Bender.yml", ".bender.yml", "Bender.lock"] {
            result.removed += remove_numbered_file_copies(&aegis, canonical)?;
        }
    }
    result.preserved.sort();
    Ok(result)
}

fn remove_numbered_file_copies(directory: &Path, canonical: &str) -> Result<usize> {
    let copies = numbered_file_copies(directory, canonical)?;
    for path in &copies {
        fs::remove_file(path)?;
    }
    Ok(copies.len())
}

fn numbered_file_copies(directory: &Path, canonical: &str) -> Result<Vec<std::path::PathBuf>> {
    if !directory.join(canonical).is_file() {
        return Ok(Vec::new());
    }

    let (stem, extension) = canonical
        .rsplit_once('.')
        .context("generated file name has no extension")?;
    let mut copies = Vec::new();
    for entry in fs::read_dir(directory)
        .with_context(|| format!("Failed to scan {}", directory.display()))?
    {
        let entry = entry?;
        let file_name = entry.file_name();
        let Some(file_name) = file_name.to_str() else {
            continue;
        };
        let Some(number) = file_name
            .strip_prefix(stem)
            .and_then(|suffix| suffix.strip_prefix(' '))
            .and_then(|suffix| suffix.strip_suffix(&format!(".{extension}")))
        else {
            continue;
        };
        let metadata = fs::symlink_metadata(entry.path())?;
        let mut digits = number.bytes();
        if digits
            .next()
            .is_some_and(|byte| byte.is_ascii_digit() && byte != b'0')
            && digits.all(|byte| byte.is_ascii_digit())
            && metadata.file_type().is_file()
        {
            copies.push(entry.path());
        }
    }
    copies.sort();
    Ok(copies)
}

#[cfg(test)]
mod tests {
    use super::{
        cleanup_generated_conflict_copies, hardening_completion_messages,
        restore_root_override_for_workspace_update, run_bender_checkout_in_root,
    };
    use crate::commands::hardening::{HardeningResult, HardeningStatus};
    use std::fs;
    use std::path::PathBuf;
    use std::time::{SystemTime, UNIX_EPOCH};

    #[test]
    fn successful_update_removes_numbered_root_override_copy() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root: PathBuf = std::env::temp_dir().join(format!("bendis-conflict-{nonce}"));
        let workspace = root.join("bendis_workspace");
        fs::create_dir_all(&workspace).unwrap();
        fs::write(root.join(".bender.yml"), "overrides: {}\n").unwrap();
        fs::write(root.join(".bender 2.yml"), "stale\n").unwrap();

        let result = cleanup_generated_conflict_copies(&root, &workspace, false).unwrap();

        assert_eq!(result.removed, 1);
        assert!(root.join(".bender.yml").is_file());
        assert!(!root.join(".bender 2.yml").exists());
        fs::remove_dir_all(root).unwrap();
    }

    #[test]
    fn cleanup_removes_workspace_lock_copy_but_preserves_workspace_config_copy() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root: PathBuf = std::env::temp_dir().join(format!("bendis-conflict-{nonce}"));
        let workspace = root.join("bendis_workspace");
        fs::create_dir_all(&workspace).unwrap();
        fs::write(workspace.join("Bender.lock"), "packages: {}\n").unwrap();
        fs::write(workspace.join("Bender 2.lock"), "stale\n").unwrap();
        fs::write(workspace.join("Bender.yml"), "dependencies: {}\n").unwrap();
        fs::write(workspace.join("Bender 2.yml"), "possible user changes\n").unwrap();

        let result = cleanup_generated_conflict_copies(&root, &workspace, false).unwrap();

        assert_eq!(result.removed, 1);
        assert_eq!(result.preserved, vec!["bendis_workspace/Bender 2.yml"]);
        assert!(!workspace.join("Bender 2.lock").exists());
        assert!(workspace.join("Bender 2.yml").is_file());
        fs::remove_dir_all(root).unwrap();
    }

    #[test]
    fn hard_cleanup_removes_numbered_aegis_generated_file_copy() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let base: PathBuf = std::env::temp_dir().join(format!("bendis-conflict-{nonce}"));
        let root = base.join("heris-soc");
        let workspace = root.join("bendis_workspace");
        let aegis = base.join("aegisrtl");
        fs::create_dir_all(&workspace).unwrap();
        fs::create_dir_all(&aegis).unwrap();
        fs::write(aegis.join("Bender.lock"), "packages: {}\n").unwrap();
        fs::write(aegis.join("Bender 3.lock"), "stale\n").unwrap();

        let normal = cleanup_generated_conflict_copies(&root, &workspace, false).unwrap();
        assert_eq!(normal.removed, 0);
        assert!(aegis.join("Bender 3.lock").is_file());

        let hard = cleanup_generated_conflict_copies(&root, &workspace, true).unwrap();
        assert_eq!(hard.removed, 1);
        assert!(!aegis.join("Bender 3.lock").exists());
        fs::remove_dir_all(base).unwrap();
    }

    #[cfg(unix)]
    #[test]
    fn cleanup_ignores_non_conflict_names_directories_and_symlinks() {
        use std::os::unix::fs::symlink;

        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root: PathBuf = std::env::temp_dir().join(format!("bendis-conflict-{nonce}"));
        let workspace = root.join("bendis_workspace");
        fs::create_dir_all(root.join("Bender 4.yml")).unwrap();
        fs::create_dir_all(&workspace).unwrap();
        fs::write(root.join("Bender.yml"), "dependencies: {}\n").unwrap();
        fs::write(root.join("Bender 02.yml"), "keep\n").unwrap();
        fs::write(root.join("Bender copy.yml"), "keep\n").unwrap();
        symlink(root.join("Bender.yml"), root.join("Bender 5.yml")).unwrap();

        let result = cleanup_generated_conflict_copies(&root, &workspace, false).unwrap();

        assert_eq!(result.removed, 0);
        assert!(root.join("Bender 02.yml").is_file());
        assert!(root.join("Bender copy.yml").is_file());
        assert!(root.join("Bender 4.yml").is_dir());
        assert!(fs::symlink_metadata(root.join("Bender 5.yml"))
            .unwrap()
            .file_type()
            .is_symlink());
        fs::remove_dir_all(root).unwrap();
    }

    #[test]
    fn workspace_update_restores_root_override_before_running_bender() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root: PathBuf = std::env::temp_dir().join(format!("bendis-restore-{nonce}"));
        let workspace = root.join("bendis_workspace");
        fs::create_dir_all(&workspace).unwrap();
        fs::write(
            root.join(".bender.yml"),
            "overrides:\n  core: { path: '../aegisrtl/core' }\n",
        )
        .unwrap();
        fs::write(
            workspace.join(".bender.yml"),
            "overrides:\n  core: { git: 'ssh://ihep/core.git', rev: abc }\n",
        )
        .unwrap();

        restore_root_override_for_workspace_update(&workspace, &root).unwrap();

        assert_eq!(
            fs::read_to_string(root.join(".bender.yml")).unwrap(),
            fs::read_to_string(workspace.join(".bender.yml")).unwrap()
        );
        fs::remove_dir_all(root).unwrap();
    }

    #[cfg(unix)]
    #[test]
    fn root_checkout_uses_local_cache_without_removing_it() {
        use std::os::unix::fs::PermissionsExt;

        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("bendis-root-checkout-{nonce}"));
        let bin = root.join("fake-bender");
        let log = root.join("calls.log");
        fs::create_dir_all(root.join(".bender/git/db/core")).unwrap();
        fs::write(root.join(".bender/git/db/core/marker"), "keep\n").unwrap();
        fs::write(
            &bin,
            format!("#!/bin/sh\nprintf '%s\\n' \"$*\" >> '{}'\n", log.display()),
        )
        .unwrap();
        let mut permissions = fs::metadata(&bin).unwrap().permissions();
        permissions.set_mode(0o755);
        fs::set_permissions(&bin, permissions).unwrap();

        run_bender_checkout_in_root(&root, &bin).unwrap();

        assert_eq!(
            fs::read_to_string(&log).unwrap(),
            "--local --git-submodules false checkout\n"
        );
        assert!(root.join(".bender/git/db/core/marker").is_file());
        fs::remove_dir_all(root).unwrap();
    }

    #[cfg(unix)]
    #[test]
    fn root_checkout_retries_once_with_remote_access() {
        use std::os::unix::fs::PermissionsExt;

        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let root = std::env::temp_dir().join(format!("bendis-root-retry-{nonce}"));
        let bin = root.join("fake-bender");
        let log = root.join("calls.log");
        fs::create_dir_all(&root).unwrap();
        fs::write(
            &bin,
            format!(
                "#!/bin/sh\nprintf '%s\\n' \"$*\" >> '{}'\n[ \"$1\" != \"--local\" ]\n",
                log.display()
            ),
        )
        .unwrap();
        let mut permissions = fs::metadata(&bin).unwrap().permissions();
        permissions.set_mode(0o755);
        fs::set_permissions(&bin, permissions).unwrap();

        run_bender_checkout_in_root(&root, &bin).unwrap();

        assert_eq!(
            fs::read_to_string(&log).unwrap(),
            "--local --git-submodules false checkout\ncheckout\n"
        );
        fs::remove_dir_all(root).unwrap();
    }

    #[test]
    fn skipped_hardening_reports_unmodified_local_rtl_activation() {
        let result = HardeningResult {
            status: HardeningStatus::Skipped,
            changed_files: Vec::new(),
        };

        assert_eq!(
            hardening_completion_messages(&result),
            vec![
                "Hardening skipped: aegisrtl/scripts/harden.sh was not found".to_string(),
                "Local RTL dependencies activated without hardening".to_string(),
            ]
        );
    }
}