Class: Ace::Git::Worktree::Molecules::BootstrapExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/molecules/bootstrap_executor.rb

Overview

Molecule for executing worktree preparation bootstrap phase

Instance Method Summary collapse

Constructor Details

#initialize(project_root: Dir.pwd, worktree_path: nil, bootstrap_config: nil, no_bootstrap: false) ⇒ BootstrapExecutor

Initialize BootstrapExecutor

Parameters:

  • project_root (String) (defaults to: Dir.pwd)

    Project root path

  • worktree_path (String) (defaults to: nil)

    Target worktree path

  • bootstrap_config (Hash) (defaults to: nil)

    Resolved bootstrap policy configuration

  • no_bootstrap (Boolean) (defaults to: false)

    Whether bootstrap was explicitly skipped



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

#runHash

Execute or skip bootstrap phase

Returns:

  • (Hash)

    Phase ledger item



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.expand_path(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.message}"
    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