fix(missions): give each phase its own task and its own capture base
ci / gates (push) Failing after 5s
ci / rust (push) Skipped
ci / frontend (push) Skipped
ci / e2e (push) Skipped
ci / publish (push) Skipped

The first push run against a scratch repo (mission 019fc42b) delivered
two branches correctly but exposed two bugs behind them.

Per-phase instructions were inert. `phase_task_text` took only
(kind, title, description), so `mission_phases.config.task` was accepted
by the API, stored, and read by nothing. Every phase of a mission
received byte-identical text differing only by the kind directive —
so both coding phases did the whole mission instead of their slice,
producing the same two files. The task now reaches the agent as a
trailing THIS PHASE'S TASK block, scoped against the shared brief.

The capture base never advanced. `.git/clawmates-base` is written once
at clone time, so phase two diffed against the original clone point and
reported the union of both phases' files as its own. It now moves to
each phase's committed head after the patch is on disk; the pushed
branch stays cumulative because it is built from HEAD.

Both regression tests were confirmed to fail with their fix disabled.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
Omar Sobh
2026-08-02 13:39:40 -07:00
co-authored by Claude Opus 5
parent e2871c4361
commit 8bad869248
4 changed files with 163 additions and 4 deletions
+70
View File
@@ -270,6 +270,22 @@ async fn seed_mission_phase(pool: &sqlx::PgPool, mission: Uuid) -> (Uuid, Uuid)
(ws, phase)
}
/// Add a second phase to a mission `seed_mission_phase` already created.
async fn seed_extra_phase(pool: &sqlx::PgPool, mission: Uuid, order_idx: i32) -> Uuid {
let phase = Uuid::now_v7();
sqlx::query(
"INSERT INTO mission_phases (id, mission_id, kind, order_idx, status, config)
VALUES ($1,$2,'coding',$3,'completed','{}'::jsonb)",
)
.bind(phase)
.bind(mission)
.bind(order_idx)
.execute(pool)
.await
.unwrap();
phase
}
/// The production failure this pairs with. Mission 019fc372's agent created
/// the file it was asked for and *committed* it — `rust_sdlc` has a committer
/// role, so that is the intended path — leaving a clean working tree. Capture
@@ -585,3 +601,57 @@ async fn an_unreachable_remote_does_not_lose_the_work() {
.unwrap();
assert!(String::from_utf8_lossy(&show.stdout).contains("fn kept()"));
}
/// A later phase must report its own work, not its predecessor's.
///
/// The capture base is recorded once at clone time. Left there, phase 2 diffs
/// against the original clone point and claims phase 1's commits as its own —
/// which is exactly what mission `019fc42b` produced: two coding phases, two
/// artifacts, and the second one reporting the union of both.
#[tokio::test]
async fn a_later_phase_reports_only_its_own_work() {
let pool = cm_testkit::test_pool().await;
let tmp = tempfile::tempdir().unwrap();
let mission = Uuid::now_v7();
let repo = seed_repo(tmp.path(), mission);
let (_, phase_one) = seed_mission_phase(&pool, mission).await;
let phase_two = seed_extra_phase(&pool, mission, 1).await;
std::fs::write(repo.join("ALPHA.md"), "ALPHA-DELIVERED\n").unwrap();
let first = capture(&pool, tmp.path(), mission, phase_one)
.await
.unwrap()
.unwrap();
assert_eq!(first.files_changed, 1, "phase one wrote one file");
std::fs::write(repo.join("BETA.md"), "BETA-DELIVERED\n").unwrap();
let second = capture(&pool, tmp.path(), mission, phase_two)
.await
.unwrap()
.unwrap();
assert_eq!(
second.files_changed, 1,
"phase two must report only BETA.md, not ALPHA.md as well"
);
let patch = std::fs::read_to_string(&second.patch_path).unwrap();
assert!(patch.contains("BETA-DELIVERED"), "phase two's own work");
assert!(
!patch.contains("ALPHA-DELIVERED"),
"phase one's work must not reappear in phase two's patch"
);
// The branch, unlike the patch, stays cumulative: it is built from HEAD,
// so it still carries phase one's commit underneath phase two's.
let branch = second.committed.expect("phase two committed").branch;
let files = Command::new("git")
.arg("-C")
.arg(&repo)
.args(["ls-tree", "--name-only", "-r", &branch])
.output()
.unwrap();
let listed = String::from_utf8_lossy(&files.stdout);
assert!(listed.contains("ALPHA.md"), "branch is cumulative: {listed}");
assert!(listed.contains("BETA.md"), "branch is cumulative: {listed}");
}