Class: Ace::Git::Worktree::Molecules::BootstrapExecutor
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Molecules::BootstrapExecutor
- Defined in:
- lib/ace/git/worktree/molecules/bootstrap_executor.rb
Overview
Molecule for executing worktree preparation bootstrap phase
Instance Method Summary collapse
-
#initialize(project_root: Dir.pwd, worktree_path: nil, bootstrap_config: nil, no_bootstrap: false) ⇒ BootstrapExecutor
constructor
Initialize BootstrapExecutor.
-
#run ⇒ Hash
Execute or skip bootstrap phase.
Constructor Details
#initialize(project_root: Dir.pwd, worktree_path: nil, bootstrap_config: nil, no_bootstrap: false) ⇒ BootstrapExecutor
Initialize BootstrapExecutor
18 19 20 21 22 23 |
# File 'lib/ace/git/worktree/molecules/bootstrap_executor.rb', line 18 def initialize(project_root: Dir.pwd, worktree_path: nil, bootstrap_config: nil, no_bootstrap: false) @project_root = project_root @worktree_path = worktree_path || project_root @config = bootstrap_config || {} @no_bootstrap = no_bootstrap end |
Instance Method Details
#run ⇒ Hash
Execute or skip bootstrap phase
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ace/git/worktree/molecules/bootstrap_executor.rb', line 28 def run policy = @config["policy"] || "required" if @no_bootstrap return { phase: "bootstrap", policy: policy, status: "skipped", command: nil, duration: 0.0 } end command = @config["command"] if command.nil? || command.to_s.strip.empty? return { phase: "bootstrap", policy: policy, status: "not_configured", command: nil, duration: 0.0 } end working_dir = @config["working_dir"] || "." target_dir = File.(working_dir, @worktree_path) timeout_sec = (@config["timeout"] || 60).to_i env_vars = (@config["env"] || {}).transform_keys(&:to_s).transform_values(&:to_s) start_time = Time.now output = "" exit_code = 1 begin Timeout.timeout(timeout_sec) do stdout, stderr, proc_status = Open3.capture3(env_vars, command, chdir: target_dir) output = "#{stdout}\n#{stderr}".strip exit_code = proc_status.exitstatus || (proc_status.success? ? 0 : 1) end if exit_code == 0 status = "succeeded" else status = (policy == "advisory") ? "advisory_failed" : "required_failed" end rescue Timeout::Error output = "Execution timed out after #{timeout_sec}s" exit_code = 124 status = (policy == "advisory") ? "advisory_failed" : "required_failed" rescue => e output = "Execution error: #{e.}" exit_code = 1 status = (policy == "advisory") ? "advisory_failed" : "required_failed" end duration = (Time.now - start_time).round(3) { phase: "bootstrap", policy: policy, status: status, command: command, working_dir: working_dir, exit_code: exit_code, output: output, duration: duration } end |