Module: Nexo::Sandboxes

Defined in:
lib/nexo/sandboxes.rb,
lib/nexo/sandboxes/local.rb,
lib/nexo/sandboxes/remote.rb,
lib/nexo/sandboxes/virtual.rb,
lib/nexo/sandboxes/container.rb

Overview

Namespace for the concrete sandbox tiers plus the single resolver shared by Agent and Workflow so the two can't drift (Spec 15). Reproduces the Agent's prior resolution exactly; the host cwd: applies only to :local (a Sandboxes::Container keeps its own /workspace default — the host dir enters a container only through a binds: entry).

Defined Under Namespace

Classes: Container, Local, Remote, Virtual

Class Method Summary collapse

Class Method Details

.resolve(value, cwd: Dir.pwd) ⇒ Object

Resolves a sandbox declaration (symbol / Hash / pre-built instance) into a concrete Sandbox. cwd: is the host working directory used only by :local; container tiers ignore it. Raises ConfigurationError for an unknown value, and image: stays required for containers (the Sandboxes::Container constructor raises when it is absent).



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nexo/sandboxes.rb', line 17

def resolve(value, cwd: Dir.pwd)
  return value if value.is_a?(Nexo::Sandbox)

  case value
  when :virtual then Virtual.new
  when :local then Local.new(cwd: cwd)
  when :docker, :apple then Container.new(runtime: value) # image: required -> raises if absent
  when Hash then resolve_hash(value, cwd)
  else raise Nexo::ConfigurationError, "unknown sandbox: #{value.inspect}"
  end
end

.resolve_hash(opts, cwd) ⇒ Object

Resolves the { type:, **opts } Hash form. +:docker+/+:apple+ pass every other key straight through to Sandboxes::Container (so an explicit Hash cwd: or the /workspace default wins — never the host cwd); :local honors an explicit Hash cwd:, otherwise falls back to the host cwd.



33
34
35
36
37
38
39
40
41
# File 'lib/nexo/sandboxes.rb', line 33

def resolve_hash(opts, cwd)
  type = opts.fetch(:type)
  rest = opts.except(:type)
  case type
  when :docker, :apple then Container.new(runtime: type, **rest)
  when :local then Local.new(cwd: rest.fetch(:cwd, cwd))
  else raise Nexo::ConfigurationError, "unknown sandbox type: #{type.inspect}"
  end
end