From f95a6728644448e5b703b58ec88299190fd8d7c2 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Sat, 14 Mar 2026 23:57:39 +0000 Subject: [PATCH] refactor: extract StepUnapplyMutation into step_unapply_mutation module --- crates/bough-cli/src/main.rs | 11 +--- crates/bough-cli/src/step_unapply_mutation.rs | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 crates/bough-cli/src/step_unapply_mutation.rs diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index caab1b6b..be39dc9e 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -10,6 +10,7 @@ mod step_apply_mutation; mod step_init_workspace; mod step_reset_workspace; mod step_tend_state; +mod step_unapply_mutation; mod step_tend_workspaces; use std::sync::atomic::{AtomicBool, Ordering}; @@ -107,15 +108,7 @@ fn main() { workspace_id, mutation_hash, } => { - let session = Session::new(cli.config.clone()).expect("session creation"); - let wid = - bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); - let mut workspace = session.bind_workspace(&wid).expect("bind workspace"); - workspace.revert_mutant().expect("unapply mutation"); - Box::new(render::UnapplyMutation { - workspace_id: wid, - mutation_hash: mutation_hash.clone(), - }) + step_unapply_mutation::StepUnapplyMutation::run(cli.config.clone(), workspace_id, mutation_hash) } config::Step::TestMutation { diff --git a/crates/bough-cli/src/step_unapply_mutation.rs b/crates/bough-cli/src/step_unapply_mutation.rs new file mode 100644 index 00000000..23e224ab --- /dev/null +++ b/crates/bough-cli/src/step_unapply_mutation.rs @@ -0,0 +1,52 @@ +use bough_core::Session; + +use crate::config::Config; +use crate::render::{HASH, RESET, TITLE, Render}; + +pub struct StepUnapplyMutation { + pub workspace_id: bough_core::WorkspaceId, + pub mutation_hash: String, +} + +impl StepUnapplyMutation { + pub fn run(config: Config, workspace_id: &str, mutation_hash: &str) -> Box { + let session = Session::new(config).expect("session creation"); + let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let mut workspace = session.bind_workspace(&wid).expect("bind workspace"); + workspace.revert_mutant().expect("unapply mutation"); + Box::new(Self { + workspace_id: wid, + mutation_hash: mutation_hash.to_string(), + }) + } +} + +impl Render for StepUnapplyMutation { + fn markdown(&self) -> String { + format!( + "# Unapply Mutation\n\n- Workspace: `{}`\n- Mutation: `{}`", + self.workspace_id, self.mutation_hash, + ) + } + + fn terse(&self) -> String { + format!( + "{HASH}{}{RESET} {HASH}{}{RESET}", + self.workspace_id, self.mutation_hash, + ) + } + + fn verbose(&self) -> String { + format!( + "{TITLE}Unapply Mutation{RESET} {HASH}{}{RESET} from {HASH}{}{RESET}", + self.mutation_hash, self.workspace_id, + ) + } + + fn json(&self) -> String { + format!( + r#"{{"workspace_id":"{}","mutation_hash":"{}"}}"#, + self.workspace_id, self.mutation_hash, + ) + } +} -- knotmirror 0.0.1