返回 CodeWhale
coordination_acceptance.rs
根目录 / crates / tui / tests / integration / coordination_acceptance.rs
1 //! Process-boundary acceptance for delegated coordination (#4647).
2 //!
3 //! This target retains the real-Git fan-in proof: terminal reconciliation must
4 //! keep both candidates available instead of reducing them to source strings.
5 //! Visible focus and composer behavior is accepted in the actual terminal.
6
7 use std::path::Path;
8 use std::process::Command;
9
10 use tempfile::tempdir;
11
12 #[test]
13 fn terminal_retry_fixture_preserves_both_real_git_candidates() {
14 let repo = tempdir().expect("temp repo");
15 git(repo.path(), &["init"]);
16 git(repo.path(), &["config", "core.autocrlf", "false"]);
17 git(repo.path(), &["config", "user.name", "codewhale Tests"]);
18 git(repo.path(), &["config", "user.email", "tests@example.com"]);
19 git(repo.path(), &["config", "commit.gpgsign", "false"]);
20 git(repo.path(), &["commit", "--allow-empty", "-m", "base"]);
21 let base = git_stdout(repo.path(), &["branch", "--show-current"]);
22
23 git(repo.path(), &["switch", "-c", "candidate-a"]);
24 std::fs::create_dir_all(repo.path().join("src")).expect("src");
25 std::fs::write(repo.path().join("src/a.rs"), "pub const A: u8 = 1;\n").expect("candidate A");
26 git(repo.path(), &["add", "src/a.rs"]);
27 git(repo.path(), &["commit", "-m", "candidate A"]);
28 let candidate_a = git_stdout(repo.path(), &["rev-parse", "HEAD"]);
29
30 git(repo.path(), &["switch", &base]);
31 git(repo.path(), &["switch", "-c", "candidate-b"]);
32 std::fs::create_dir_all(repo.path().join("src")).expect("src");
33 std::fs::write(repo.path().join("src/b.rs"), "pub const B: u8 = 2;\n").expect("candidate B");
34 git(repo.path(), &["add", "src/b.rs"]);
35 git(repo.path(), &["commit", "-m", "candidate B"]);
36 let candidate_b = git_stdout(repo.path(), &["rev-parse", "HEAD"]);
37
38 assert_ne!(candidate_a, candidate_b);
39 assert_eq!(
40 git_stdout(repo.path(), &["show", "candidate-a:src/a.rs"]),
41 "pub const A: u8 = 1;"
42 );
43 assert_eq!(
44 git_stdout(repo.path(), &["show", "candidate-b:src/b.rs"]),
45 "pub const B: u8 = 2;"
46 );
47 }
48
49 fn git(repo: &Path, args: &[&str]) {
50 let output = Command::new("git")
51 .args(args)
52 .current_dir(repo)
53 .output()
54 .expect("git command");
55 assert!(
56 output.status.success(),
57 "git {args:?} failed: {}",
58 String::from_utf8_lossy(&output.stderr)
59 );
60 }
61
62 fn git_stdout(repo: &Path, args: &[&str]) -> String {
63 let output = Command::new("git")
64 .args(args)
65 .current_dir(repo)
66 .output()
67 .expect("git command");
68 assert!(
69 output.status.success(),
70 "git {args:?} failed: {}",
71 String::from_utf8_lossy(&output.stderr)
72 );
73 String::from_utf8_lossy(&output.stdout).trim().to_string()
74 }
75
75 lines RUST