diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index bae37bcb..5b4a1a4d 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -187,7 +187,19 @@ fn main() { }) } - config::Step::ResetWorkspace { workspace_id } => todo!(), + config::Step::ResetWorkspace { workspace_id } => { + let session = + Session::new(cli.config.clone()).expect("session creation"); + let wid = bough_core::WorkspaceId::parse(workspace_id) + .expect("invalid workspace id"); + let outcome = session + .run_reset_in_workspace(&wid, None) + .expect("reset workspace"); + Box::new(render::ResetWorkspace { + workspace_id: wid, + outcome, + }) + } config::Step::ApplyMutation { workspace_id, @@ -202,7 +214,20 @@ fn main() { config::Step::TestMutation { workspace_id, mutation_hash, - } => todo!(), + } => { + let session = + Session::new(cli.config.clone()).expect("session creation"); + let wid = bough_core::WorkspaceId::parse(workspace_id) + .expect("invalid workspace id"); + let outcome = session + .run_test_in_workspace(&wid, None) + .expect("test mutation"); + Box::new(render::TestMutation { + workspace_id: wid, + mutation_hash: mutation_hash.clone(), + outcome, + }) + } } } diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index e7d62141..fe311eae 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -528,6 +528,111 @@ impl Render for InitWorkspace { } } +pub struct ResetWorkspace { + pub workspace_id: bough_core::WorkspaceId, + pub outcome: bough_core::PhaseOutcome, +} + +impl Render for ResetWorkspace { + fn markdown(&self) -> String { + let stdout = String::from_utf8_lossy(self.outcome.stdout()); + let stderr = String::from_utf8_lossy(self.outcome.stderr()); + let mut out = format!( + "# Reset Workspace `{}`\n\n- Exit: {}\n- Duration: {:.2}s\n- Timed out: {}", + self.workspace_id, + self.outcome.exit_code(), + self.outcome.duration().as_secs_f64(), + self.outcome.timed_out(), + ); + if !stdout.is_empty() { + out.push_str(&format!("\n\n## stdout\n\n```\n{stdout}\n```")); + } + if !stderr.is_empty() { + out.push_str(&format!("\n\n## stderr\n\n```\n{stderr}\n```")); + } + out + } + + fn terse(&self) -> String { + format!( + "{HASH}{}{RESET} {}", + self.workspace_id, + fmt_phase_outcome_terse(&self.outcome), + ) + } + + fn verbose(&self) -> String { + format!( + "{TITLE}Reset Workspace{RESET} {HASH}{}{RESET}\n\n{}", + self.workspace_id, + fmt_phase_outcome_verbose(&self.outcome), + ) + } + + fn json(&self) -> String { + format!( + r#"{{"workspace_id":"{}","outcome":{}}}"#, + self.workspace_id, + fmt_phase_outcome_json(&self.outcome), + ) + } +} + +pub struct TestMutation { + pub workspace_id: bough_core::WorkspaceId, + pub mutation_hash: String, + pub outcome: bough_core::PhaseOutcome, +} + +impl Render for TestMutation { + fn markdown(&self) -> String { + let stdout = String::from_utf8_lossy(self.outcome.stdout()); + let stderr = String::from_utf8_lossy(self.outcome.stderr()); + let mut out = format!( + "# Test Mutation `{}` in `{}`\n\n- Exit: {}\n- Duration: {:.2}s\n- Timed out: {}", + self.mutation_hash, + self.workspace_id, + self.outcome.exit_code(), + self.outcome.duration().as_secs_f64(), + self.outcome.timed_out(), + ); + if !stdout.is_empty() { + out.push_str(&format!("\n\n## stdout\n\n```\n{stdout}\n```")); + } + if !stderr.is_empty() { + out.push_str(&format!("\n\n## stderr\n\n```\n{stderr}\n```")); + } + out + } + + fn terse(&self) -> String { + format!( + "{HASH}{}{RESET} {HASH}{}{RESET} {}", + self.workspace_id, + self.mutation_hash, + fmt_phase_outcome_terse(&self.outcome), + ) + } + + fn verbose(&self) -> String { + format!( + "{TITLE}Test Mutation{RESET} {HASH}{}{RESET} in {HASH}{}{RESET}\n\n{}", + self.mutation_hash, + self.workspace_id, + fmt_phase_outcome_verbose(&self.outcome), + ) + } + + fn json(&self) -> String { + format!( + r#"{{"workspace_id":"{}","mutation_hash":"{}","outcome":{}}}"#, + self.workspace_id, + self.mutation_hash, + fmt_phase_outcome_json(&self.outcome), + ) + } +} + impl Render for Config { fn markdown(&self) -> String { format!(