Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/dev/agent_bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ def grant_work_tree!(runner_dir)

# Step 7: the runner service plist carries the service env — Umask 002 and
# AI_FLOW_AGENT_USER — applied between a service stop/start so launchd
# rereads it. The plist name comes from the `.service` record svc.sh
# wrote at install.
# rereads it. The plist location comes from the `.service` record svc.sh
# wrote at install: on macOS that record is the full plist path; on Linux
# it is the bare service name, which we resolve under launch_agents_dir.
#
# @param runner_dir [String]
# @raise [StepFailedError] when no service was installed in runner_dir
Expand All @@ -428,7 +429,7 @@ def configure_service!(runner_dir)
end

service = File.read(service_file).strip
plist = File.join(@launch_agents_dir, "#{service}.plist")
plist = service.end_with?(".plist") ? service : File.join(@launch_agents_dir, "#{service}.plist")
@out.puts ">>> Writing Umask 002 + AI_FLOW_AGENT_USER=#{@agent_user} into #{plist} ..."
step!("./svc.sh", "stop", chdir: runner_dir)
plist_set!(plist, "Umask", "integer", "2")
Expand Down
18 changes: 18 additions & 0 deletions test/dev/agent_bootstrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ def converged_identity_executor
executor.runs.last == ["./svc.sh", "start", { chdir: runner_dir }]
end

test "after_enroll! uses the .service record verbatim when it is a plist path (macOS svc.sh shape)" do
Given "a runner dir whose .service records the full plist path, as macOS svc.sh writes it"
executor = RecordedBootstrapExecutor.new
runner_dir = Dir.mktmpdir
agents_dir = Dir.mktmpdir
plist = File.join(agents_dir, "actions.runner.d3mlabs.mac.plist")
File.write(File.join(runner_dir, ".service"), "#{plist}\n")

When "converging the post-enrollment steps"
bootstrap(executor, launch_agents_dir: agents_dir).after_enroll!(runner_dir: runner_dir)

Then "PlistBuddy targets the recorded path, not a re-joined one"
executor.runs.include?(["/usr/libexec/PlistBuddy", "-c", "Set :Umask 2", plist])
executor.runs.include?(
["/usr/libexec/PlistBuddy", "-c", "Set :EnvironmentVariables:AI_FLOW_AGENT_USER ai-agent", plist],
)
end

test "after_enroll! adds plist keys when Set finds none" do
Given "PlistBuddy Set failing (fresh plist without the keys)"
executor = RecordedBootstrapExecutor.new(fail_matching: "Set :")
Expand Down
Loading