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
//! Safety tests for git cleanup behavior in CueLoop.
//!
//! Purpose:
//! - Safety tests for git cleanup behavior in CueLoop.
//!
//! Responsibilities:
//! - Provide focused implementation or regression coverage for this file's owning feature.
//!
//! Scope:
//! - Limited to this file's owning feature boundary.
//!
//!
//! Usage:
//! - Used through the crate module tree or integration test harness.
//!
//! Invariants/Assumptions:
//! - Keep behavior aligned with CueLoop's canonical CLI, machine-contract, and queue semantics.
use anyhow::{Context, Result};
use std::fs;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn revert_uncommitted_preserves_untracked_env_files() -> Result<()> {
let dir = TempDir::new()?;
let root = dir.path();
// 1. Init git repo
Command::new("git")
.current_dir(root)
.args(["init", "--quiet"])
.output()
.context("git init")?;
// 2. Commit a base file so we have a HEAD
fs::write(root.join("README.md"), "# Test")?;
Command::new("git")
.current_dir(root)
.args(["add", "."])
.status()?;
Command::new("git")
.current_dir(root)
.args(["commit", "-m", "init"])
.status()?;
// 3. Create untracked files
let env_file = root.join(".env");
let env_local = root.join(".env.local");
let garbage = root.join("garbage.txt");
fs::write(&env_file, "SECRET=123")?;
fs::write(&env_local, "SECRET=456")?;
fs::write(&garbage, "trash")?;
// 4. Run revert_uncommitted
cueloop::git::revert_uncommitted(root)?;
// 5. Verify assertions
assert!(env_file.exists(), ".env should be preserved");
assert!(env_local.exists(), ".env.local should be preserved");
assert!(!garbage.exists(), "garbage.txt should be removed");
Ok(())
}