|
| 1 | +//! Gated end-to-end test for the multi-persona swarm campaign. |
| 2 | +//! |
| 3 | +//! Proves the campaign actually runs: each persona executes as a real `korg |
| 4 | +//! worker` subprocess in a git worktree, completes its work, and sends a |
| 5 | +//! `TerminationReport`, so the leader records it as DONE — not the false |
| 6 | +//! `exit_code=-1` "crash" that stdout pollution used to cause for *every* |
| 7 | +//! worker. Guards the swarm-real fix (worker sends TerminationReport; all logs |
| 8 | +//! go to stderr so stdout stays a clean ACP channel). |
| 9 | +//! |
| 10 | +//! GATED: spawns the `korg` binary plus worker subprocesses in git worktrees — |
| 11 | +//! CI-hostile and slow (~60-90s). Run locally: |
| 12 | +//! cargo test --test campaign_e2e -- --ignored --nocapture |
| 13 | +
|
| 14 | +use std::process::Command; |
| 15 | + |
| 16 | +fn git(dir: &std::path::Path, args: &[&str]) { |
| 17 | + let out = Command::new("git") |
| 18 | + .args(args) |
| 19 | + .current_dir(dir) |
| 20 | + .output() |
| 21 | + .expect("git spawn failed"); |
| 22 | + assert!( |
| 23 | + out.status.success(), |
| 24 | + "git {:?} failed: {}", |
| 25 | + args, |
| 26 | + String::from_utf8_lossy(&out.stderr) |
| 27 | + ); |
| 28 | +} |
| 29 | + |
| 30 | +/// Last N lines of a log, for readable assertion failures. |
| 31 | +fn tail(s: &str) -> String { |
| 32 | + let lines: Vec<&str> = s.lines().collect(); |
| 33 | + let start = lines.len().saturating_sub(40); |
| 34 | + lines[start..].join("\n") |
| 35 | +} |
| 36 | + |
| 37 | +#[test] |
| 38 | +#[ignore = "spawns korg + worker subprocesses in git worktrees; CI-hostile/slow — run locally with --ignored"] |
| 39 | +fn campaign_workers_complete_and_attest_real_work() { |
| 40 | + // A fixture crate with the canonical add-bug (`a - b`). The deterministic |
| 41 | + // provider produces Benjamin's real fix for this task, applied + measured. |
| 42 | + let dir = std::env::temp_dir().join(format!("korg-campaign-e2e-{}", std::process::id())); |
| 43 | + let _ = std::fs::remove_dir_all(&dir); |
| 44 | + std::fs::create_dir_all(dir.join("src")).unwrap(); |
| 45 | + std::fs::write( |
| 46 | + dir.join("Cargo.toml"), |
| 47 | + "[package]\nname = \"e2e\"\nversion = \"0.1.0\"\nedition = \"2021\"\n", |
| 48 | + ) |
| 49 | + .unwrap(); |
| 50 | + std::fs::write( |
| 51 | + dir.join("src/lib.rs"), |
| 52 | + "pub fn add(a: i64, b: i64) -> i64 { a - b }\n", |
| 53 | + ) |
| 54 | + .unwrap(); |
| 55 | + git(&dir, &["init", "-q"]); |
| 56 | + git(&dir, &["add", "-A"]); |
| 57 | + git( |
| 58 | + &dir, |
| 59 | + &[ |
| 60 | + "-c", |
| 61 | + "user.email=t@t", |
| 62 | + "-c", |
| 63 | + "user.name=t", |
| 64 | + "commit", |
| 65 | + "-qm", |
| 66 | + "base", |
| 67 | + ], |
| 68 | + ); |
| 69 | + |
| 70 | + let out = Command::new(env!("CARGO_BIN_EXE_korg")) |
| 71 | + .args([ |
| 72 | + "Fix the add function in src/lib.rs so it adds", |
| 73 | + "--goal", |
| 74 | + "--provider", |
| 75 | + "deterministic", |
| 76 | + ]) |
| 77 | + .current_dir(&dir) |
| 78 | + .output() |
| 79 | + .expect("run korg campaign"); |
| 80 | + let log = String::from_utf8_lossy(&out.stderr); |
| 81 | + |
| 82 | + let _ = std::fs::remove_dir_all(&dir); |
| 83 | + |
| 84 | + // The workers must terminate SUCCESS — before the fix, stdout pollution |
| 85 | + // corrupted the ACP stream and the leader stamped every worker crashed. |
| 86 | + assert!( |
| 87 | + log.contains("exit_status=success"), |
| 88 | + "expected workers to terminate success (TerminationReport received); got:\n{}", |
| 89 | + tail(&log) |
| 90 | + ); |
| 91 | + assert!( |
| 92 | + !log.contains("worker_crashed"), |
| 93 | + "no worker should be falsely marked crashed; got:\n{}", |
| 94 | + tail(&log) |
| 95 | + ); |
| 96 | + // Benjamin (the implementer) attests exactly one REAL measured mutation — |
| 97 | + // the applied fix on the fixture — proving real per-persona work flows |
| 98 | + // through the campaign, not theater. |
| 99 | + assert!( |
| 100 | + log.contains("persona=\"Benjamin\" mutations=1"), |
| 101 | + "Benjamin should attest one real measured mutation; got:\n{}", |
| 102 | + tail(&log) |
| 103 | + ); |
| 104 | +} |
0 commit comments