Module: RepoTender::CLI::Daemon::Helpers

Included in:
Install, Restart, Start, Status, Stop, Uninstall
Defined in:
lib/repo_tender/cli/daemon.rb

Defined Under Namespace

Classes: Resolve

Class Method Summary collapse

Class Method Details

.build_plist(resolve:, config:, paths:, label:) ⇒ Object

Build the plist XML by looking up the absolute paths the launchd runtime needs (mise, ruby, the bin script, the repo root, the mise.toml). These come from a few places:

* `mise_bin` — `which mise` (we shell out at
   install-time; the result is baked into the plist
   as an absolute path so launchd's empty PATH
   doesn't matter).
* `ruby_bin` — `mise exec -- which ruby` (the
   toolchain-resolved ruby; pinned via mise.toml).
* `bin_path` — `RbConfig.ruby` + the script path
   (we use `__dir__` of this file's caller; for the
   gem install, this is `<gem>/bin/repo-tender`).

In tests, we inject these via the ‘Resolve` object (see below) — never call out to the shell.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/repo_tender/cli/daemon.rb', line 64

def build_plist(resolve:, config:, paths:, label:)
  Launchd::Plist.call(
    label: label,
    refresh_interval: config.refresh_interval,
    log_dir: paths.log_dir,
    repo_root: resolve.repo_root,
    mise_toml: resolve.mise_toml,
    mise_bin: resolve.mise_bin,
    ruby_bin: resolve.ruby_bin,
    bin_path: resolve.bin_path
  )
end

.fail_with(cmd, msg) ⇒ Object



79
80
81
82
# File 'lib/repo_tender/cli/daemon.rb', line 79

def fail_with(cmd, msg)
  cmd.send(:err).puts msg
  RepoTender::CLI.record_outcome(Outcome.new(exit_code: 1, message: msg))
end

.format_failure(f) ⇒ Object



77
# File 'lib/repo_tender/cli/daemon.rb', line 77

def format_failure(f) = f.is_a?(Hash) ? f.inspect : f.to_s

.make_agent(uid: Process.uid, label: Launchd::Agent::DEFAULT_LABEL, runner: nil) ⇒ Object

Build a ‘Launchd::Agent` wired against the CLI’s env seam (‘CLI.env`). Tests inject a temp HOME (so `paths.launch_agents_dir` is under the temp HOME, not the real one) and a `runner:` via `Launchd::Agent.new` — the daemon commands don’t accept a runner flag, so tests must use a real ‘Agent` (whose default `runner` only fires in an ambient Async::Task) OR stub the `Launchd::Agent` class.



33
34
35
36
37
38
39
# File 'lib/repo_tender/cli/daemon.rb', line 33

def make_agent(uid: Process.uid, label: Launchd::Agent::DEFAULT_LABEL, runner: nil)
  if runner
    Launchd::Agent.new(runner: runner, uid: uid, label: label)
  else
    Launchd::Agent.new(uid: uid, label: label)
  end
end

.plist_path(paths, label) ⇒ Object

Resolve the on-disk plist path for the agent label, rooted at the env’s HOME-resolved ‘LaunchAgents/` (per slice-4 gate G3).



44
45
46
# File 'lib/repo_tender/cli/daemon.rb', line 44

def plist_path(paths, label)
  File.join(paths.launch_agents_dir, "#{label}.plist")
end