rollbridge 0.1.70 → 0.1.71
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.
- package/README.md +10 -63
- package/TODO.md +0 -13
- package/docs/cli.md +3 -128
- package/docs/config.md +6 -177
- package/docs/troubleshooting.md +6 -97
- package/docs/velocious.md +1 -1
- package/docs/workers.md +0 -11
- package/examples/tensorbuzz.com.js +2 -3
- package/package.json +1 -1
- package/src/cli.js +2 -68
- package/src/config.js +8 -347
- package/src/daemon.js +65 -387
- package/src/doctor.js +0 -74
- package/src/guardian-client.js +8 -67
- package/src/health.js +8 -99
- package/src/managed-process.js +16 -197
- package/src/process-guardian.js +22 -212
- package/src/process-memory.js +2 -62
- package/src/release-group.js +37 -435
- package/tensorbuzz.yml +1 -20
- package/test/completion.test.js +2 -5
- package/test/config-validation.test.js +5 -135
- package/test/guardian-client.test.js +5 -119
- package/test/health.test.js +1 -74
- package/test/managed-process.test.js +1 -260
- package/test/owner-recovery.test.js +21 -125
- package/test/owner-replacement.test.js +14 -175
- package/test/process-memory.test.js +1 -47
- package/test/release-group.test.js +2 -408
- package/test/rollbridge.test.js +72 -737
- package/test/shutdown-completion.test.js +0 -52
- package/test/support/process.js +1 -3
- package/changelog.d/20261025-guardian-re-register-dead-generation.md +0 -13
- package/changelog.d/20261026-stale-committed-generation-transition-recovery.md +0 -1
- package/changelog.d/20261104-compose-service-units.md +0 -21
- package/changelog.d/20261105-owner-mutation-lease-diagnostics.md +0 -20
- package/changelog.d/20261106-release-dependency-boot-budgets.md +0 -32
- package/changelog.d/20261109-path-filtered-builds.md +0 -11
- package/changelog.d/20261110-default-boot-budget-above-measured-startup.md +0 -26
- package/changelog.d/20261111-contention-sensitive-daemon-specs.md +0 -27
- package/changelog.d/20261113-bounded-nonblocking-retirement.md +0 -5
- package/changelog.d/20261115-bound-draining-release-groups.md +0 -62
- package/changelog.d/20261115-restore-deploy-refuses-held-generation.md +0 -27
- package/changelog.d/20261115-wedged-generation-escalation.md +0 -44
- package/changelog.d/20261116-bounded-explicit-stop-retirement.md +0 -30
- package/changelog.d/20261116-config-json-canonical-shape.md +0 -11
- package/changelog.d/20261116-drain-specs-gate-the-retirement-record.md +0 -29
- package/changelog.d/20261116-guardian-version-handoff.md +0 -37
- package/changelog.d/20261116-reclaim-dead-owner-mutation.md +0 -7
- package/changelog.d/20261117-activate-before-incumbent-retirement.md +0 -1
- package/changelog.d/20261117-activation-path-drain-deadline.md +0 -35
- package/changelog.d/20261117-stop-companion-after-retired-dependency.md +0 -7
- package/docs/compose-services.md +0 -222
- package/src/compose-unit.js +0 -725
- package/src/drain-policy.js +0 -252
- package/src/process-order.js +0 -26
- package/test/compose-config.test.js +0 -160
- package/test/compose-docker.test.js +0 -297
- package/test/compose-unit.test.js +0 -415
- package/test/drain-policy.test.js +0 -328
- package/test/fixtures/deferred-boot-app.js +0 -106
- package/test/fixtures/gated-app.js +0 -50
- package/test/tensorbuzz-config.test.js +0 -228
package/src/drain-policy.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {"progressing" | "timedOut" | "wedged" | "unproven"} DrainProgress
|
|
5
|
-
* @typedef {{cpuMs: number | undefined, heldProcessGroupPgid: number | undefined, id: string, liveChildCount: number | undefined, pid: number | undefined, retirementTimedOut: boolean}} DrainProcessObservation
|
|
6
|
-
* @typedef {{atMs: number, processes: DrainProcessObservation[]}} DrainLivenessSample
|
|
7
|
-
* @typedef {{cpuDeltaMs: number | undefined, reason: string, sampleWindowMs: number, status: DrainProgress}} DrainClassification
|
|
8
|
-
* @typedef {{releaseId: string, reason: string, status: DrainProgress}} DrainGroupReport
|
|
9
|
-
* @typedef {{allowed: boolean, draining: DrainGroupReport[], reason: string | undefined, wouldBeDrainingCount: number}} GenerationAdmission
|
|
10
|
-
* @typedef {{pgid: number, processId: string}} EscalationTarget
|
|
11
|
-
* @typedef {{decision: "escalate" | "report", killSafe: boolean, reason: string, targets: EscalationTarget[]}} EscalationDecision
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Classifies one draining release group as still draining, past its drain budget, or wedged.
|
|
16
|
-
*
|
|
17
|
-
* A group is wedged only when its drain can no longer progress. Every inconclusive reading
|
|
18
|
-
* — a live connection, a process still inside its retirement budget, an unmeasurable CPU
|
|
19
|
-
* counter, or a sample window shorter than `minSampleWindowMs` — reports `progressing` or
|
|
20
|
-
* `unproven`, never `wedged`: a legitimate multi-hour drain is valid and must not be
|
|
21
|
-
* mislabelled as a wedge.
|
|
22
|
-
*
|
|
23
|
-
* A live connection inside `drainBudgetMs` is still a legitimate drain. Past that budget the
|
|
24
|
-
* connection wait has already been given up, so the group reports `timedOut` instead of
|
|
25
|
-
* `progressing` forever — the reading that lets one held websocket outlive the activation
|
|
26
|
-
* budget and stall every later deploy. `timedOut` names the deadline; it is not an escalation
|
|
27
|
-
* and never authorises a signal.
|
|
28
|
-
* @param {object} args - Classification inputs.
|
|
29
|
-
* @param {number} args.connectionCount - Live proxy connections this generation still owns.
|
|
30
|
-
* @param {DrainLivenessSample} args.currentSample - Newest liveness observation.
|
|
31
|
-
* @param {number} args.drainBudgetMs - Configured drain budget (`proxy.drainTimeoutMs`); 0 records no budget.
|
|
32
|
-
* @param {number} args.drainElapsedMs - Time since this drain started, at classification time.
|
|
33
|
-
* @param {number} args.minSampleWindowMs - Shortest window that can prove flat CPU.
|
|
34
|
-
* @param {DrainLivenessSample | undefined} args.previousSample - Older observation, when one is in range.
|
|
35
|
-
* @returns {DrainClassification} The classification and the evidence it rests on.
|
|
36
|
-
*/
|
|
37
|
-
export function classifyDrainProgress({connectionCount, currentSample, drainBudgetMs = 0, drainElapsedMs = 0, minSampleWindowMs, previousSample}) {
|
|
38
|
-
const live = currentSample.processes.filter((process) => process.pid !== undefined || process.heldProcessGroupPgid !== undefined)
|
|
39
|
-
const stillInsideBudget = live.filter((process) => !process.retirementTimedOut)
|
|
40
|
-
|
|
41
|
-
if (connectionCount > 0) {
|
|
42
|
-
const connections = `${connectionCount} live connection${connectionCount === 1 ? "" : "s"} still owned by the generation`
|
|
43
|
-
|
|
44
|
-
if (drainBudgetMs > 0 && drainElapsedMs > drainBudgetMs) {
|
|
45
|
-
return classify("timedOut", `drain budget ${drainBudgetMs}ms exceeded by ${drainElapsedMs - drainBudgetMs}ms with ${connections}`, currentSample, previousSample)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return classify("progressing", connections, currentSample, previousSample)
|
|
49
|
-
}
|
|
50
|
-
if (stillInsideBudget.length > 0) {
|
|
51
|
-
return classify("progressing", `process ${stillInsideBudget[0].id} is still inside its retirement budget`, currentSample, previousSample)
|
|
52
|
-
}
|
|
53
|
-
if (live.length === 0) {
|
|
54
|
-
return classify("progressing", "no live process remains in the generation", currentSample, previousSample)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const liveChildCount = live.reduce((total, process) => total + (process.liveChildCount ?? 0), 0)
|
|
58
|
-
|
|
59
|
-
if (liveChildCount === 0) {
|
|
60
|
-
return classify("wedged", `${live.length} live process${live.length === 1 ? "" : "es"} past its retirement budget with no runner child remaining${heldGroupNote(live)}`, currentSample, previousSample)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!previousSample) {
|
|
64
|
-
return classify("unproven", `first liveness observation; a ${minSampleWindowMs}ms window is required before CPU flatness can be claimed`, currentSample, previousSample)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const sampleWindowMs = currentSample.atMs - previousSample.atMs
|
|
68
|
-
|
|
69
|
-
if (sampleWindowMs < minSampleWindowMs) {
|
|
70
|
-
return classify("unproven", `liveness window ${sampleWindowMs}ms is below the ${minSampleWindowMs}ms minimum`, currentSample, previousSample)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const currentCpuMs = totalCpuMs(currentSample)
|
|
74
|
-
const previousCpuMs = totalCpuMs(previousSample)
|
|
75
|
-
|
|
76
|
-
if (currentCpuMs === undefined || previousCpuMs === undefined) {
|
|
77
|
-
return classify("unproven", "process CPU is not measurable on this host", currentSample, previousSample)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const cpuDeltaMs = currentCpuMs - previousCpuMs
|
|
81
|
-
|
|
82
|
-
if (cpuDeltaMs !== 0) {
|
|
83
|
-
const change = cpuDeltaMs > 0
|
|
84
|
-
? `CPU advanced ${cpuDeltaMs}ms`
|
|
85
|
-
: `the group changed (${live.length} live process${live.length === 1 ? "" : "es"}, ${cpuDeltaMs}ms of consumed CPU left the group)`
|
|
86
|
-
|
|
87
|
-
return classify("progressing", `${change} across ${sampleWindowMs}ms`, currentSample, previousSample)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return classify("wedged", `${live.length} live process${live.length === 1 ? "" : "es"} with ${liveChildCount} runner ${liveChildCount === 1 ? "child" : "children"}, no live connection, every retirement budget expired, CPU flat across ${sampleWindowMs}ms${heldGroupNote(live)}`, currentSample, previousSample)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Decides whether a new release generation may be activated under the draining-group bound.
|
|
95
|
-
*
|
|
96
|
-
* The incumbent counts as a draining group because activating the candidate retires it: the
|
|
97
|
-
* count is what the fleet would have *after* the handoff, which is the only version of the
|
|
98
|
-
* number a pre-handoff decision can act on.
|
|
99
|
-
* @param {object} args - Admission inputs.
|
|
100
|
-
* @param {string} args.candidateReleaseId - Release the handoff would activate.
|
|
101
|
-
* @param {DrainGroupReport[]} args.draining - Every release group currently draining.
|
|
102
|
-
* @param {boolean} args.incumbentWillDrain - Whether an active generation is retired by this handoff.
|
|
103
|
-
* @param {number} args.maxConcurrentDrainingReleaseGroups - Policy bound; 0 disables the check.
|
|
104
|
-
* @returns {GenerationAdmission} Allow/deny plus the named reason and the groups behind it.
|
|
105
|
-
*/
|
|
106
|
-
export function admitGenerationRelease({candidateReleaseId, draining, incumbentWillDrain, maxConcurrentDrainingReleaseGroups}) {
|
|
107
|
-
const wouldBeDrainingCount = draining.length + (incumbentWillDrain ? 1 : 0)
|
|
108
|
-
|
|
109
|
-
if (maxConcurrentDrainingReleaseGroups === 0 || wouldBeDrainingCount <= maxConcurrentDrainingReleaseGroups) {
|
|
110
|
-
return {allowed: true, draining, reason: undefined, wouldBeDrainingCount}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const reported = draining.map((group) => `${group.releaseId} ${group.status} (${group.reason})`).join("; ")
|
|
114
|
-
const reason = `Deploy refused before activation: ${draining.length} release group${draining.length === 1 ? "" : "s"} already draining${reported ? ` (${reported})` : ""}. Activating ${candidateReleaseId} would make ${wouldBeDrainingCount}, above the releaseRetention.maxConcurrentDrainingReleaseGroups bound of ${maxConcurrentDrainingReleaseGroups}.`
|
|
115
|
-
|
|
116
|
-
return {allowed: false, draining, reason, wouldBeDrainingCount}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Decides whether a proven wedge may be terminated by the generation supervisor.
|
|
121
|
-
*
|
|
122
|
-
* A wedge claim is not a kill licence. The claim says a drain cannot progress any more; a
|
|
123
|
-
* SIGKILL is only safe when it also cannot destroy work. That needs four separate proofs: the
|
|
124
|
-
* generation is classified wedged (so it owns no live connection), every live process is
|
|
125
|
-
* already past its retirement budget, no runner child remains in any tracked process group —
|
|
126
|
-
* STOE-1077 measured 67 builds and 27.3 build-hours lost to exactly this signal reaching live
|
|
127
|
-
* lanes — and the group's CPU is proven flat across a full sample window, which rules out a
|
|
128
|
-
* group that is merely slow. Anything else reports, with the missing proof named.
|
|
129
|
-
* @param {object} args - Decision inputs.
|
|
130
|
-
* @param {DrainClassification} args.classification - The classification the wedge claim rests on.
|
|
131
|
-
* @param {DrainLivenessSample} args.currentSample - Newest liveness observation, the one the decision acts on.
|
|
132
|
-
* @param {number} args.minSampleWindowMs - Shortest window that can prove flat CPU.
|
|
133
|
-
* @returns {EscalationDecision} Escalate with named targets, or report the missing proof.
|
|
134
|
-
*/
|
|
135
|
-
export function decideWedgedEscalation({classification, currentSample, minSampleWindowMs}) {
|
|
136
|
-
if (classification.status !== "wedged") {
|
|
137
|
-
return reportEscalation(`no escalation: drain is ${classification.status} (${classification.reason})`)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const live = currentSample.processes.filter((process) => process.pid !== undefined || process.heldProcessGroupPgid !== undefined)
|
|
141
|
-
|
|
142
|
-
if (live.length === 0) {
|
|
143
|
-
return reportEscalation("no escalation: the generation holds no live process")
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const insideBudget = live.filter((process) => !process.retirementTimedOut)
|
|
147
|
-
|
|
148
|
-
if (insideBudget.length > 0) {
|
|
149
|
-
return reportEscalation(`no escalation: process ${insideBudget[0].id} has not expired its retirement budget`)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const liveChildCount = live.reduce((total, process) => total + (process.liveChildCount ?? 0), 0)
|
|
153
|
-
|
|
154
|
-
if (liveChildCount > 0) {
|
|
155
|
-
return reportEscalation(`no escalation: ${liveChildCount} runner ${liveChildCount === 1 ? "child is" : "children are"} still live in the generation; SIGKILL would abort in-flight work`)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (classification.sampleWindowMs < minSampleWindowMs) {
|
|
159
|
-
return reportEscalation(`no escalation: liveness window ${classification.sampleWindowMs}ms is below the ${minSampleWindowMs}ms minimum`)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (classification.cpuDeltaMs !== 0) {
|
|
163
|
-
const evidence = classification.cpuDeltaMs === undefined
|
|
164
|
-
? "process CPU is not measurable on this host"
|
|
165
|
-
: `${classification.cpuDeltaMs}ms of CPU moved across ${classification.sampleWindowMs}ms`
|
|
166
|
-
|
|
167
|
-
return reportEscalation(`no escalation: CPU flatness is not proven (${evidence})`)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const targets = live.flatMap((process) => {
|
|
171
|
-
const pgid = process.heldProcessGroupPgid ?? process.pid
|
|
172
|
-
|
|
173
|
-
return pgid === undefined ? [] : [{pgid, processId: process.id}]
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
if (targets.length === 0) {
|
|
177
|
-
return reportEscalation("no escalation: no process group id is addressable")
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
decision: "escalate",
|
|
182
|
-
killSafe: true,
|
|
183
|
-
reason: `escalating: ${live.length} live process${live.length === 1 ? "" : "es"} past its retirement budget, no runner child remaining, CPU flat across ${classification.sampleWindowMs}ms (${classification.reason})`,
|
|
184
|
-
targets
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @param {string} reason - The proof the escalation is missing.
|
|
190
|
-
* @returns {EscalationDecision} Report-only decision.
|
|
191
|
-
*/
|
|
192
|
-
function reportEscalation(reason) {
|
|
193
|
-
return {decision: "report", killSafe: false, reason, targets: []}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Names the process groups that outlived their tracked process.
|
|
198
|
-
*
|
|
199
|
-
* A tracked process can exit while the group it led keeps running (a shell wrapper killed by
|
|
200
|
-
* the stop signal, a runner child that outlives its parent). Those members still hold the
|
|
201
|
-
* generation's work and no rollbridge record can signal them, so a wedge claim has to say
|
|
202
|
-
* which group is holding it.
|
|
203
|
-
* @param {DrainProcessObservation[]} processes - Live observations of one generation.
|
|
204
|
-
* @returns {string} A note naming the held groups, or "" when every group is still tracked.
|
|
205
|
-
*/
|
|
206
|
-
function heldGroupNote(processes) {
|
|
207
|
-
const held = processes.filter((process) => process.heldProcessGroupPgid !== undefined)
|
|
208
|
-
|
|
209
|
-
if (held.length === 0) return ""
|
|
210
|
-
|
|
211
|
-
const named = held.map((process) => `${process.id} pgid ${process.heldProcessGroupPgid}`).join(", ")
|
|
212
|
-
|
|
213
|
-
return `; ${held.length} tracked process${held.length === 1 ? "" : "es"} already exited and left ${named} alive`
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @param {DrainProgress} status - Classification.
|
|
218
|
-
* @param {string} reason - Named evidence behind it.
|
|
219
|
-
* @param {DrainLivenessSample} currentSample - Newest observation.
|
|
220
|
-
* @param {DrainLivenessSample | undefined} previousSample - Older observation, when in range.
|
|
221
|
-
* @returns {DrainClassification} Classification payload.
|
|
222
|
-
*/
|
|
223
|
-
function classify(status, reason, currentSample, previousSample) {
|
|
224
|
-
const sampleWindowMs = previousSample ? currentSample.atMs - previousSample.atMs : 0
|
|
225
|
-
const currentCpuMs = totalCpuMs(currentSample)
|
|
226
|
-
const previousCpuMs = totalCpuMs(previousSample)
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
cpuDeltaMs: currentCpuMs === undefined || previousCpuMs === undefined ? undefined : currentCpuMs - previousCpuMs,
|
|
230
|
-
reason,
|
|
231
|
-
sampleWindowMs,
|
|
232
|
-
status
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* @param {DrainLivenessSample | undefined} sample - Observation to total.
|
|
238
|
-
* @returns {number | undefined} Summed CPU, or undefined when any live process is unmeasurable.
|
|
239
|
-
*/
|
|
240
|
-
function totalCpuMs(sample) {
|
|
241
|
-
if (!sample) return undefined
|
|
242
|
-
|
|
243
|
-
let total = 0
|
|
244
|
-
|
|
245
|
-
for (const process of sample.processes) {
|
|
246
|
-
if (process.pid === undefined && process.heldProcessGroupPgid === undefined) continue
|
|
247
|
-
if (process.cpuMs === undefined) return undefined
|
|
248
|
-
total += process.cpuMs
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return total
|
|
252
|
-
}
|
package/src/process-order.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import("./config.js").ProcessConfig} ProcessConfig
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const POLICY_START_RANK = /** @type {Record<ProcessConfig["policy"], number>} */ ({companion: 1, proxied: 2, service: 0, singleton: 3})
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Order in which Rollbridge starts processes, which is also the only order a `dependsOn`
|
|
11
|
-
* edge may point backwards in: daemon-wide persistent services are started before every
|
|
12
|
-
* release generation, then handoff services, companions, and the proxied process last.
|
|
13
|
-
* Config order is kept inside each group.
|
|
14
|
-
* @param {ProcessConfig[]} processes - Normalized processes.
|
|
15
|
-
* @param {{includePersistentServices?: boolean}} [options] - Whether to include the
|
|
16
|
-
* daemon-wide persistent services that a release group never starts itself.
|
|
17
|
-
* @returns {ProcessConfig[]} Ordered process configs.
|
|
18
|
-
*/
|
|
19
|
-
export function processStartOrder(processes, {includePersistentServices = false} = {}) {
|
|
20
|
-
const persistentServices = includePersistentServices
|
|
21
|
-
? processes.filter((processConfig) => processConfig.policy === "service" && processConfig.deployStrategy === "persistent")
|
|
22
|
-
: []
|
|
23
|
-
const generationProcesses = processes.filter((processConfig) => processConfig.policy !== "singleton" && (processConfig.policy !== "service" || processConfig.deployStrategy === "handoff"))
|
|
24
|
-
|
|
25
|
-
return [...persistentServices, ...generationProcesses.sort((left, right) => POLICY_START_RANK[left.policy] - POLICY_START_RANK[right.policy])]
|
|
26
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import path from "node:path"
|
|
4
|
-
import {describe, expect, test} from "@velocious/testing"
|
|
5
|
-
import {validateConfig} from "../src/config.js"
|
|
6
|
-
|
|
7
|
-
describe("compose-config", () => {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {Record<string, import("../src/json.js").JsonValue>} [unitOverrides] - Compose unit fields.
|
|
11
|
-
* @param {Record<string, import("../src/json.js").JsonValue>} [configOverrides] - Top-level overrides.
|
|
12
|
-
* @returns {Record<string, import("../src/json.js").JsonValue>} Raw config with one Compose unit.
|
|
13
|
-
*/
|
|
14
|
-
function buildRawConfig(unitOverrides = {}, configOverrides = {}) {
|
|
15
|
-
return {
|
|
16
|
-
application: "compose-config-test",
|
|
17
|
-
compose: [{
|
|
18
|
-
id: "gateway",
|
|
19
|
-
image: "registry.local/gateway:1.4.0",
|
|
20
|
-
projectDirectory: "/srv/gateway",
|
|
21
|
-
service: "gateway",
|
|
22
|
-
...unitOverrides
|
|
23
|
-
}],
|
|
24
|
-
control: {path: "/tmp/rollbridge-compose-config.sock"},
|
|
25
|
-
processes: [{command: "run web", id: "web", policy: "proxied", port: {from: 18000, to: 18099}}],
|
|
26
|
-
proxy: {host: "127.0.0.1", port: 8182},
|
|
27
|
-
...configOverrides
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param {{fix: string, message: string}[]} issues - Collected issues.
|
|
33
|
-
* @returns {string[]} Issue messages.
|
|
34
|
-
*/
|
|
35
|
-
function messages(issues) {
|
|
36
|
-
return issues.map((issue) => issue.message)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {import("../src/config.js").RollbridgeConfig} config - Validated config.
|
|
41
|
-
* @returns {import("../src/config.js").ComposeUnitConfig} The one Compose unit the test declared.
|
|
42
|
-
*/
|
|
43
|
-
function onlyUnit(config) {
|
|
44
|
-
const unit = config.compose?.[0]
|
|
45
|
-
|
|
46
|
-
if (unit === undefined) throw new Error("the test config declares no compose unit")
|
|
47
|
-
|
|
48
|
-
return unit
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
test("a Compose unit is normalized with drain-first defaults", () => {
|
|
52
|
-
const {config, issues} = validateConfig(buildRawConfig(), "/srv/app/rollbridge.js")
|
|
53
|
-
|
|
54
|
-
expect(issues).toEqual([])
|
|
55
|
-
|
|
56
|
-
const unit = onlyUnit(config)
|
|
57
|
-
|
|
58
|
-
expect(unit.id).toBe("gateway")
|
|
59
|
-
expect(unit.composeFile).toBe("compose.yml")
|
|
60
|
-
expect(unit.stopGracePeriodMs).toBe(10000)
|
|
61
|
-
expect(unit.recreateTimeoutMs).toBe(120000)
|
|
62
|
-
// Unset commands are absent from the normalized shape rather than present as undefined, so a unit
|
|
63
|
-
// definition that crossed the guardian's JSON transfer is still equal to a freshly loaded one.
|
|
64
|
-
expect(unit.drain).toEqual({timeoutMs: 60000})
|
|
65
|
-
expect(unit.inFlight).toEqual({intervalMs: 1000, timeoutMs: 0})
|
|
66
|
-
expect(unit.activation).toMatchObject({healthcheck: true, intervalMs: 1000, startDelayMs: 0, timeoutMs: 60000})
|
|
67
|
-
expect(unit.rollback).toEqual({enabled: true})
|
|
68
|
-
expect(config.composeStatePath).toBe(path.resolve("/srv/app", "rollbridge-compose-config-test.compose.state.json"))
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test("a Compose unit keeps its own compose file, env file, project name, and hooks", () => {
|
|
72
|
-
const {config, issues} = validateConfig(buildRawConfig({
|
|
73
|
-
activation: {intervalMs: 500, readyCommand: "probe {{service}}", readyUrl: "http://127.0.0.1:7421/ready", startDelayMs: 2000, timeoutMs: 90000},
|
|
74
|
-
composeFile: "gateway.compose.yml",
|
|
75
|
-
drain: {command: "docker compose {{composeArgs}} exec {{service}} appctl drain", timeoutMs: 30000},
|
|
76
|
-
envFile: "gateway.env",
|
|
77
|
-
inFlight: {command: "docker compose {{composeArgs}} exec {{service}} appctl in-flight", intervalMs: 2000, timeoutMs: 120000},
|
|
78
|
-
projectName: "socketduct-gateway",
|
|
79
|
-
rollback: {enabled: false},
|
|
80
|
-
stopGracePeriodMs: 45000
|
|
81
|
-
}))
|
|
82
|
-
|
|
83
|
-
expect(issues).toEqual([])
|
|
84
|
-
|
|
85
|
-
const unit = onlyUnit(config)
|
|
86
|
-
|
|
87
|
-
expect(unit.composeFile).toBe("gateway.compose.yml")
|
|
88
|
-
expect(unit.envFile).toBe("gateway.env")
|
|
89
|
-
expect(unit.projectName).toBe("socketduct-gateway")
|
|
90
|
-
expect(unit.stopGracePeriodMs).toBe(45000)
|
|
91
|
-
expect(unit.rollback.enabled).toBe(false)
|
|
92
|
-
expect(unit.drain.timeoutMs).toBe(30000)
|
|
93
|
-
expect(unit.inFlight.timeoutMs).toBe(120000)
|
|
94
|
-
expect(unit.activation.readyUrl).toBe("http://127.0.0.1:7421/ready")
|
|
95
|
-
expect(unit.activation.readyCommand).toBe("probe {{service}}")
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test("an unpinned or malformed image reference is rejected", () => {
|
|
99
|
-
const whitespace = validateConfig(buildRawConfig({image: "registry.local/gateway: 1.4.0"}))
|
|
100
|
-
const digest = validateConfig(buildRawConfig({image: "registry.local/gateway@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}))
|
|
101
|
-
const badDigest = validateConfig(buildRawConfig({image: "registry.local/gateway@sha256:nope"}))
|
|
102
|
-
|
|
103
|
-
expect(whitespace.issues.map((issue) => issue.message)).toEqual([
|
|
104
|
-
'compose[0].image "registry.local/gateway: 1.4.0" is not a valid image reference'
|
|
105
|
-
])
|
|
106
|
-
expect(digest.issues).toEqual([])
|
|
107
|
-
expect(messages(badDigest.issues)).toContain('compose[0].image "registry.local/gateway@sha256:nope" is not a valid image reference')
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
test("compose unit ids must be unique and must not collide with process ids", () => {
|
|
111
|
-
const duplicate = validateConfig({
|
|
112
|
-
...buildRawConfig(),
|
|
113
|
-
compose: [
|
|
114
|
-
{id: "gateway", image: "registry.local/gateway:1.4.0", projectDirectory: "/srv/gateway", service: "gateway"},
|
|
115
|
-
{id: "gateway", image: "registry.local/hub:1.4.0", projectDirectory: "/srv/hub", service: "hub"}
|
|
116
|
-
]
|
|
117
|
-
})
|
|
118
|
-
const collision = validateConfig(buildRawConfig({id: "web"}))
|
|
119
|
-
|
|
120
|
-
expect(messages(duplicate.issues)).toContain("Duplicate compose unit id: gateway")
|
|
121
|
-
expect(messages(collision.issues)).toContain('Compose unit id "web" collides with a process id')
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
test("a drain or in-flight command without a positive timeout is rejected", () => {
|
|
125
|
-
const drain = validateConfig(buildRawConfig({drain: {command: "appctl drain", timeoutMs: 0}}))
|
|
126
|
-
const inFlight = validateConfig(buildRawConfig({inFlight: {command: "appctl in-flight"}}))
|
|
127
|
-
|
|
128
|
-
expect(messages(drain.issues)).toContain("compose[0].drain.command requires a positive compose[0].drain.timeoutMs")
|
|
129
|
-
expect(messages(inFlight.issues)).toContain("compose[0].inFlight.command requires a positive compose[0].inFlight.timeoutMs")
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
test("a compose unit must name its service, project directory, and image", () => {
|
|
133
|
-
const {issues} = validateConfig(buildRawConfig({image: "", projectDirectory: "", service: ""}))
|
|
134
|
-
|
|
135
|
-
expect(messages(issues)).toEqual([
|
|
136
|
-
"compose[0].service is required",
|
|
137
|
-
"compose[0].projectDirectory is required",
|
|
138
|
-
"compose[0].image is required"
|
|
139
|
-
])
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
test("an empty compose list is rejected", () => {
|
|
143
|
-
const {issues} = validateConfig(buildRawConfig({}, {compose: []}))
|
|
144
|
-
|
|
145
|
-
expect(messages(issues)).toEqual(["compose must define at least one unit"])
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
test("compose must be a list of unit mappings", () => {
|
|
149
|
-
const notArray = validateConfig(buildRawConfig({}, {compose: {id: "gateway"}}))
|
|
150
|
-
const notObject = validateConfig(buildRawConfig({}, {compose: ["gateway"]}))
|
|
151
|
-
|
|
152
|
-
expect(messages(notArray.issues)).toEqual(["compose must be an array"])
|
|
153
|
-
expect(messages(notObject.issues)).toEqual([
|
|
154
|
-
"compose[0] must be an object",
|
|
155
|
-
"compose[0].service is required",
|
|
156
|
-
"compose[0].projectDirectory is required",
|
|
157
|
-
"compose[0].image is required"
|
|
158
|
-
])
|
|
159
|
-
})
|
|
160
|
-
})
|