@runeditrun/rer 0.2.20 → 0.2.22

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.
Files changed (51) hide show
  1. package/cli/README.md +7 -0
  2. package/cli/demo-host.mjs +9 -8
  3. package/cli/demo-removal-provider.mjs +24 -0
  4. package/cli/deploy-command.mjs +10 -7
  5. package/cli/deploy-hook.mjs +10 -14
  6. package/cli/deploy.mjs +3 -1
  7. package/cli/export.mjs +1 -1
  8. package/cli/managed-server.mjs +5 -2
  9. package/cli/production-auth.mjs +19 -5
  10. package/global/CHANGELOG.md +7 -1
  11. package/modules/container/README.md +10 -0
  12. package/modules/container/build.mjs +10 -12
  13. package/modules/container/host.mjs +3 -1
  14. package/modules/container/ingress.mjs +15 -4
  15. package/modules/container/migration-inventory.mjs +33 -0
  16. package/modules/container/migrations.mjs +16 -2
  17. package/modules/delivery-producer/migrations.mjs +61 -0
  18. package/modules/demo/effects.mjs +4 -0
  19. package/modules/demo-host/README.md +34 -15
  20. package/modules/demo-host/capacity.mjs +1 -1
  21. package/modules/demo-host/container.mjs +73 -39
  22. package/modules/demo-host/diagnostics.mjs +1 -0
  23. package/modules/demo-host/pages.mjs +1 -1
  24. package/modules/demo-host/placement.mjs +23 -0
  25. package/modules/demo-host/plan.mjs +20 -7
  26. package/modules/demo-host/remove.mjs +9 -7
  27. package/modules/demo-host/start-script.mjs +10 -1
  28. package/modules/demo-host/startup.mjs +4 -2
  29. package/modules/demo-host/worker.mjs +18 -1
  30. package/modules/dependencies/approval.mjs +3 -2
  31. package/modules/dependencies/index.mjs +2 -2
  32. package/modules/deploy-kit/README.md +16 -2
  33. package/modules/deploy-kit/diagnostics.mjs +9 -0
  34. package/modules/deploy-kit/health-request.mjs +7 -5
  35. package/modules/deploy-kit/provider-transport.mjs +56 -0
  36. package/modules/deploy-kit/provider.mjs +22 -20
  37. package/modules/operator-auth/README.md +4 -0
  38. package/modules/operator-auth/accounts/credentials.mjs +2 -2
  39. package/modules/operator-auth/accounts/email-change.mjs +2 -2
  40. package/modules/operator-auth/accounts/provider-control.mjs +3 -3
  41. package/modules/operator-auth/accounts/store.mjs +9 -8
  42. package/modules/operator-auth/dev/cli-session.mjs +5 -4
  43. package/modules/operator-auth/dev/index.mjs +5 -5
  44. package/modules/operator-auth/dev-gate.mjs +4 -2
  45. package/modules/operator-auth/identity/email-link/index.mjs +2 -1
  46. package/modules/operator-auth/signin/index.mjs +10 -2
  47. package/onboarding/adapter.mjs +11 -3
  48. package/onboarding/operator-installer.mjs +2 -2
  49. package/onboarding/operator-migrations.mjs +48 -0
  50. package/onboarding/process-table.mjs +45 -19
  51. package/package.json +1 -1
@@ -7,6 +7,21 @@ const execute = promisify(execFile)
7
7
  // One bounded wait for any process inspection; a loaded machine can take over a
8
8
  // second to list processes, which must not abort an otherwise healthy cleanup.
9
9
  export const inspectionMs = 5000
10
+ // A snapshot taken while processes start or exit can hold a row ps has not yet
11
+ // finished, or ps itself can fail for an instant. Such a read says nothing
12
+ // about ownership; it is repeated within the same bound rather than ending a
13
+ // launch whose own processes are accounted for.
14
+ const transient = (message) => Object.assign(new Error(message), { transient: true })
15
+ const retryMs = 10
16
+ async function withinBound(timeout, attempt) {
17
+ const deadline = Date.now() + timeout
18
+ for (;;) {
19
+ try { return await attempt(Math.max(1, deadline - Date.now())) } catch (error) {
20
+ if (!error.transient || Date.now() + retryMs >= deadline) throw error
21
+ await delay(retryMs)
22
+ }
23
+ }
24
+ }
10
25
  export const validPid = (pid) => Number.isSafeInteger(pid) && pid > 0 && pid <= 0x7fffffff
11
26
 
12
27
  // Inspect numeric identity and the executable name, never private argv.
@@ -60,20 +75,23 @@ async function processGroup(pgid, signal) {
60
75
  }
61
76
  return group
62
77
  }
63
- const { stdout } = await execute('/bin/ps', [
64
- '-ax', '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=',
65
- ], { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, signal, killSignal: 'SIGKILL', maxBuffer: 8 * 1024 * 1024 })
78
+ let stdout
79
+ try {
80
+ ({ stdout } = await execute('/bin/ps', [
81
+ '-ax', '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=',
82
+ ], { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, signal, killSignal: 'SIGKILL', maxBuffer: 8 * 1024 * 1024 }))
83
+ } catch (error) { if (signal.aborted) throw error; throw transient('Could not read process identities.') }
66
84
  const group = []
67
85
  for (const line of stdout.split('\n').filter((line) => line.trim())) {
68
86
  const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.{24})\s*$/)
69
- if (!match) throw new Error('Could not read process identities.')
87
+ if (!match) throw transient('Could not read process identities.')
70
88
  const [, id, parent, groupId, uid, state, birth] = match
71
89
  const pid = Number(id)
72
90
  const ppid = Number(parent)
73
91
  if (pgid === undefined && (pid === 0 || Number(groupId) === 0)) continue
74
92
  if (pgid !== undefined && Number(groupId) !== pgid) continue
75
93
  if (!validPid(pid) || !validPid(Number(groupId)) || !Number.isSafeInteger(ppid) || ppid < 0 || !Number.isFinite(Date.parse(birth))) {
76
- throw new Error('Invalid process identity.')
94
+ throw transient('Invalid process identity.')
77
95
  }
78
96
  group.push({ pid, ppid, pgid: Number(groupId), uid: Number(uid), state, birth })
79
97
  }
@@ -86,30 +104,38 @@ async function processGroup(pgid, signal) {
86
104
  export async function readProcessIdentity(pid, timeout = inspectionMs) {
87
105
  if (!validPid(pid) || !(timeout > 0)) throw new Error('Invalid process identity deadline.')
88
106
  if (process.platform === 'linux') return linuxProcess(pid, undefined, AbortSignal.timeout(timeout))
107
+ return withinBound(timeout, (remaining) => psIdentity(pid, remaining))
108
+ }
109
+
110
+ async function psIdentity(pid, timeout) {
89
111
  let stdout
90
112
  try {
91
113
  ({ stdout } = await execute('/bin/ps', ['-p', String(pid), '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=', '-o', 'comm='],
92
114
  { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, timeout, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024 }))
93
- } catch (error) { if (error.code === 1 && !error.stdout?.trim()) return; throw new Error('Could not inspect process identity.') }
115
+ } catch (error) { if (error.code === 1 && !error.stdout?.trim()) return; throw transient('Could not inspect process identity.') }
94
116
  const match = stdout.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.{24})\s+(.+?)\s*$/)
95
- if (!match) throw new Error('Invalid process identity.')
117
+ if (!match) throw transient('Invalid process identity.')
96
118
  const [, id, parent, groupId, uid, state, birth, command] = match
97
- if (Number(id) !== pid || !validPid(Number(groupId)) || !Number.isFinite(Date.parse(birth + ' UTC'))) throw new Error('Invalid process identity.')
119
+ if (Number(id) !== pid || !validPid(Number(groupId)) || !Number.isFinite(Date.parse(birth + ' UTC'))) throw transient('Invalid process identity.')
98
120
  return { pid, ppid: Number(parent), pgid: Number(groupId), uid: Number(uid), state, birth, command }
99
121
  }
100
122
 
101
- export async function readProcessTable(timeout = inspectionMs, pgid) {
123
+ // `read` is the process edge: it returns the table or throws; tests supply a
124
+ // failing one.
125
+ export async function readProcessTable(timeout = inspectionMs, pgid, read = processGroup) {
102
126
  if (!(timeout > 0)) throw new Error('Process inspection deadline expired.')
103
- const controller = new AbortController()
104
- let timer
105
- try {
106
- return await Promise.race([processGroup(pgid, controller.signal), new Promise((_, reject) => {
107
- timer = setTimeout(() => {
108
- controller.abort()
109
- reject(new Error('Process inspection deadline expired.'))
110
- }, timeout)
111
- })])
112
- } finally { clearTimeout(timer) }
127
+ return withinBound(timeout, async (remaining) => {
128
+ const controller = new AbortController()
129
+ let timer
130
+ try {
131
+ return await Promise.race([read(pgid, controller.signal), new Promise((_, reject) => {
132
+ timer = setTimeout(() => {
133
+ controller.abort()
134
+ reject(new Error('Process inspection deadline expired.'))
135
+ }, remaining)
136
+ })])
137
+ } finally { clearTimeout(timer) }
138
+ })
113
139
  }
114
140
 
115
141
  export const sameBirth = (left, right) => validPid(left?.pid) && left.pid === right?.pid && left.birth === right?.birth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",