workspaces 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 501f96e0f82b4dc9f30ec6682feb64329301b3ee888561e84e65941cff084ae7
4
- data.tar.gz: 4ae2d5e24099d7638b349a332daaadf89813a96e37996c4f03c41c7baf2f7636
3
+ metadata.gz: 9e8987b36ff8ba5cfd6c039c911012462661c5da01989e84843188e471c58171
4
+ data.tar.gz: 1bae9743875990e29ada15d6b26885d0881eaf84dbf8626bfef1bea779753833
5
5
  SHA512:
6
- metadata.gz: 67865a47386639bfcff1218218bcf8f055c0b563d295d355d9667e1d8410da7a4981def707bc0f219f4179215b4839a689ec36bfa8bba90738ea92d7771b8ad7
7
- data.tar.gz: 4be62e33d0f29d0c19751b61bd3b9d0dab8cf334314ce62bc5bcfe5f59569235c960b10647cf5bb7060705068db6c1489052b59a97b543c662750f66df3e6f4d
6
+ metadata.gz: 173beba79ca2237d5632e06f7abb7edbc0a46f3a17d283bfdead8e59469bb9383d1de2af97f90c8c9c51e24d2b014aa6a21c63dc83f80ac257c488121f7ae909
7
+ data.tar.gz: b98959ea514d65b64d454f928330b86959e417bbf1be83466790ea072cd350757b9daa5ff5c7724877684bc834618eeb6a6d6b20788879dcceba48ca8be32712
data/README.md CHANGED
@@ -39,6 +39,17 @@ The returned JSON includes the workspace ID, dashboard URL, and preview URL. You
39
39
  create from a pull request with `create --pr NUMBER`, or create a new branch with
40
40
  `create --new-branch NAME --from REF`. Run `help` for lifecycle and other commands.
41
41
 
42
+ ### Step timings
43
+
44
+ Per-step durations are persisted in seconds in workspace step status JSON, so they
45
+ remain available after the command exits. Timings also appear in CLI progress,
46
+ the workspace setup log, and the dashboard's step list.
47
+
48
+ A background step measures only process launch, not the server's lifetime or
49
+ readiness. The following readiness step measures its own wait separately.
50
+ Interrupted steps have no recorded duration. Step timings are not the total
51
+ workflow wall-clock time; orchestration overhead can fall outside the steps.
52
+
42
53
  ## Serve the dashboard and previews
43
54
 
44
55
  Run `serve` in a separate terminal using the **same project root and `WORKSPACES_HOME`**
@@ -4,6 +4,7 @@ require 'time'
4
4
  require_relative 'config'
5
5
  require_relative 'state_store'
6
6
  require_relative 'port_allocator'
7
+ require_relative 'child_env'
7
8
 
8
9
  module Workspaces
9
10
  class Backend
@@ -61,8 +62,10 @@ module Workspaces
61
62
 
62
63
  def spawn_command(workspace, command, env)
63
64
  File.open(Config.backend_log_path(workspace_id), 'a') do |file|
64
- Process.spawn(env, [command.first, command.first], *command.drop(1),
65
- chdir: workspace.path.to_s, in: File::NULL, out: file, err: file, pgroup: true)
65
+ child_env = ChildEnv.for_workspace(workspace_path: workspace.path, extra_env: env)
66
+ Process.spawn(child_env, [command.first, command.first], *command.drop(1),
67
+ chdir: workspace.path.to_s, in: File::NULL, out: file, err: file, pgroup: true,
68
+ unsetenv_others: true)
66
69
  end
67
70
  end
68
71
 
@@ -0,0 +1,38 @@
1
+ module Workspaces
2
+ module ChildEnv
3
+ module_function
4
+
5
+ def for_workspace(workspace_path:, extra_env: {}, parent_env: ENV.to_h)
6
+ env = parent_env.to_h.transform_keys(&:to_s).dup
7
+ if defined?(::Bundler)
8
+ clean = Bundler.unbundled_env
9
+ %w(PATH GEM_HOME GEM_PATH MANPATH RUBYOPT RUBYLIB RB_USER_INSTALL).each do |name|
10
+ clean.key?(name) ? env[name] = clean[name] : env.delete(name)
11
+ end
12
+ end
13
+ env.delete_if { |key, _| bundler_key?(key) }
14
+
15
+ gemfile = File.join(workspace_path.to_s, 'Gemfile')
16
+ env['BUNDLE_GEMFILE'] = gemfile
17
+ env['BUNDLE_LOCKFILE'] = File.join(workspace_path.to_s, 'Gemfile.lock')
18
+
19
+ extra_env.to_h.each do |name, value|
20
+ key = name.to_s
21
+ next if bundler_key?(key)
22
+
23
+ if value.nil?
24
+ env.delete(key)
25
+ else
26
+ env[key] = value
27
+ end
28
+ end
29
+
30
+ env
31
+ end
32
+
33
+ def bundler_key?(key)
34
+ %w(BUNDLE_GEMFILE BUNDLE_LOCKFILE BUNDLER_SETUP BUNDLER_VERSION).include?(key) ||
35
+ key.start_with?('BUNDLER_ORIG_')
36
+ end
37
+ end
38
+ end
@@ -6,6 +6,7 @@ require_relative 'registry'
6
6
  require_relative 'coordinator'
7
7
  require_relative 'front_door'
8
8
  require_relative 'tls'
9
+ require_relative 'child_env'
9
10
 
10
11
  module Workspaces
11
12
  class Cli
@@ -149,7 +150,9 @@ module Workspaces
149
150
  end
150
151
 
151
152
  registry.with_lock(id) do |workspace|
152
- pid = Process.spawn([argv.first, argv.first], *argv.drop(1), chdir: workspace.path.to_s)
153
+ child_env = ChildEnv.for_workspace(workspace_path: workspace.path)
154
+ pid = Process.spawn(child_env, [argv.first, argv.first], *argv.drop(1),
155
+ chdir: workspace.path.to_s, unsetenv_others: true)
153
156
  _, status = Process.wait2(pid)
154
157
  status.exitstatus || (128 + status.termsig)
155
158
  end
@@ -1,5 +1,6 @@
1
1
  require 'open3'
2
2
  require 'timeout'
3
+ require_relative 'child_env'
3
4
 
4
5
  module Workspaces
5
6
  class CommandRunner
@@ -12,7 +13,9 @@ module Workspaces
12
13
 
13
14
  def run!(command, env:, timeout:)
14
15
  executable = [command.first, command.first]
15
- Open3.popen2e(env, executable, *command.drop(1), chdir: @path.to_s, pgroup: true) do |input, output, child|
16
+ child_env = ChildEnv.for_workspace(workspace_path: @path, extra_env: env)
17
+ Open3.popen2e(child_env, executable, *command.drop(1), chdir: @path.to_s, pgroup: true,
18
+ unsetenv_others: true) do |input, output, child|
16
19
  input.close
17
20
  output.set_encoding(Encoding::UTF_8, invalid: :replace, undef: :replace)
18
21
  run_child(output, child, timeout)
@@ -134,7 +134,7 @@ module Workspaces
134
134
  def publish_starting(id, restart)
135
135
  recipe = Recipe.new
136
136
  steps = recipe.for_operation(restart: restart).map do |step|
137
- { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending' }
137
+ { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending', 'duration_seconds' => nil }
138
138
  end
139
139
  update(id, 'status' => 'preparing', 'message' => restart ? 'Restarting application' : 'Preparing workspace',
140
140
  'steps' => steps,
@@ -54,11 +54,25 @@
54
54
  label.textContent = step.label;
55
55
  const outcome = document.createElement('span');
56
56
  outcome.className = 'step-outcome';
57
- outcome.textContent = step.state;
57
+ outcome.textContent = stepOutcome(step);
58
58
  item.append(bullet, label, outcome);
59
59
  return item;
60
60
  }
61
61
 
62
+ function stepOutcome(step) {
63
+ const state = step.state;
64
+ const rawDuration = step.duration_seconds;
65
+ if (typeof rawDuration !== 'number') return state;
66
+ const duration = rawDuration;
67
+ if (
68
+ (state === 'complete' || state === 'failed') &&
69
+ Number.isFinite(duration) &&
70
+ duration >= 0
71
+ )
72
+ return state + ' · ' + duration.toFixed(3) + 's';
73
+ return state;
74
+ }
75
+
62
76
  function updateLog(data) {
63
77
  if (data.log_source !== selectedLog) return;
64
78
  const log = node('log');
@@ -11,7 +11,7 @@
11
11
  <p id="message"><%= field('message') %></p>
12
12
  <ol class="stepper" id="progress" aria-label="Setup progress">
13
13
  <% @presentation['steps'].each do |step| %>
14
- <li class="step" data-step-state="<%= step['state'] %>" <%= 'aria-current="step"' if step['state'] == 'active' %>><span class="step-bullet" aria-hidden="true"></span><span><%= escape(step['label']) %></span><span class="step-outcome"><%= step['state'] %></span></li>
14
+ <li class="step" data-step-state="<%= step['state'] %>" <%= 'aria-current="step"' if step['state'] == 'active' %>><span class="step-bullet" aria-hidden="true"></span><span><%= escape(step['label']) %></span><span class="step-outcome"><%= escape(step_outcome(step)) %></span></li>
15
15
  <% end %>
16
16
  </ol>
17
17
  <section class="error-panel setup-error" id="error-panel" role="alert" <%= 'hidden' unless @presentation['error'] %>>
@@ -128,5 +128,15 @@ module Workspaces
128
128
  "<form method=\"post\" action=\"/workspaces/#{@id}/#{action.fetch('key')}\">" \
129
129
  "<button class=\"button #{style}\">#{escape(action.fetch('label'))}</button></form>"
130
130
  end
131
+
132
+ def step_outcome(step)
133
+ state = step['state'].to_s
134
+ return state unless %w(complete failed).include?(state)
135
+
136
+ duration = step['duration_seconds']
137
+ return state unless duration.is_a?(Numeric) && duration.finite? && duration >= 0
138
+
139
+ "#{state} · #{format('%.3f', duration)}s"
140
+ end
131
141
  end
132
142
  end
@@ -1,3 +1,3 @@
1
1
  module Workspaces
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -33,7 +33,7 @@ module Workspaces
33
33
 
34
34
  def publish_steps(steps)
35
35
  @state.set(@workspace.id, 'steps' => steps.map do |step|
36
- { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending' }
36
+ { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending', 'duration_seconds' => nil }
37
37
  end)
38
38
  end
39
39
 
@@ -48,6 +48,7 @@ module Workspaces
48
48
  end
49
49
 
50
50
  def execute(step, recipe, context, runner, overrides)
51
+ started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
51
52
  progress(step, 'active')
52
53
  @log.puts "==> #{step.fetch('name')}"
53
54
  command = recipe.command(step, context)
@@ -59,16 +60,24 @@ module Workspaces
59
60
  @backend.ensure_alive! if @server_started
60
61
  end
61
62
  @server_started = true if step['background']
62
- progress(step, 'complete')
63
63
  rescue StandardError
64
- progress(step, 'failed')
64
+ finish_step(step, 'failed', started_at)
65
65
  raise
66
+ else
67
+ finish_step(step, 'complete', started_at)
66
68
  end
67
69
 
68
- def progress(step, status)
70
+ def finish_step(step, status, started_at)
71
+ duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at).round(3)
72
+ progress(step, status, duration_seconds: duration)
73
+ @log.puts format('==> %s %s (%.3fs)', step.fetch('name'), status, duration)
74
+ end
75
+
76
+ def progress(step, status, duration_seconds: nil)
69
77
  @state.transaction do |data|
70
78
  entry = data.fetch(@workspace.id)
71
- entry['steps'].find { |item| item['key'] == step['id'] }['state'] = status
79
+ entry['steps'].find { |item| item['key'] == step['id'] }
80
+ .merge!('state' => status, 'duration_seconds' => duration_seconds)
72
81
  entry['message'] = step['name']
73
82
  entry['current_step'] = step['id']
74
83
  entry['updated_at'] = Time.now.utc.iso8601
data/lib/workspaces.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'workspaces/config'
2
2
  require_relative 'workspaces/state_store'
3
3
  require_relative 'workspaces/port_allocator'
4
+ require_relative 'workspaces/child_env'
4
5
  require_relative 'workspaces/backend'
5
6
  require_relative 'workspaces/cli'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workspaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Workspaces contributors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-01 00:00:00.000000000 Z
11
+ date: 2026-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -71,6 +71,7 @@ files:
71
71
  - exe/workspaces
72
72
  - lib/workspaces.rb
73
73
  - lib/workspaces/backend.rb
74
+ - lib/workspaces/child_env.rb
74
75
  - lib/workspaces/cli.rb
75
76
  - lib/workspaces/command_runner.rb
76
77
  - lib/workspaces/config.rb