@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.33 → 3.5.0-ultramodern.35

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/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.33",
20
+ "version": "3.5.0-ultramodern.35",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -44,16 +44,16 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@swc/helpers": "^0.5.23",
47
- "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.33",
48
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.33",
49
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.33",
50
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.33"
47
+ "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.35",
48
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.35",
49
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.35",
50
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.35"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@rslib/core": "0.23.1",
54
54
  "@types/node": "^26.0.1",
55
55
  "@typescript/native-preview": "7.0.0-dev.20260628.1",
56
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.33",
56
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.35",
57
57
  "@scripts/rstest-config": "2.66.0"
58
58
  },
59
59
  "sideEffects": false,
@@ -137,4 +137,229 @@ describe('telemetry canary orchestrator', () => {
137
137
 
138
138
  await registry.shutdown();
139
139
  });
140
+
141
+ test('stays canary below the healthy threshold and promotes after consecutive healthy evaluations', async () => {
142
+ const registry = new TelemetryRegistry({
143
+ service: 'svc',
144
+ module: 'server',
145
+ environment: 'test',
146
+ flushIntervalMs: 60_000,
147
+ });
148
+ const onEvaluate = rs.fn();
149
+ const onPromote = rs.fn();
150
+ const onRollback = rs.fn();
151
+ const orchestrator = new TelemetryCanaryOrchestrator({
152
+ registry,
153
+ minConsecutiveHealthyEvaluations: 3,
154
+ onEvaluate,
155
+ onPromote,
156
+ onRollback,
157
+ });
158
+
159
+ const first = orchestrator.evaluate();
160
+ expect(first.action).toBe('hold');
161
+ expect(first.state).toBe('canary');
162
+ expect(first.consecutiveHealthy).toBe(1);
163
+
164
+ const second = orchestrator.evaluate();
165
+ expect(second.action).toBe('hold');
166
+ expect(second.state).toBe('canary');
167
+ expect(second.consecutiveHealthy).toBe(2);
168
+ expect(onPromote).not.toHaveBeenCalled();
169
+
170
+ const third = orchestrator.evaluate();
171
+ expect(third.action).toBe('promote');
172
+ expect(third.state).toBe('promoted');
173
+ expect(third.consecutiveHealthy).toBe(3);
174
+
175
+ expect(onEvaluate).toHaveBeenCalledTimes(3);
176
+ expect(onEvaluate).toHaveBeenNthCalledWith(1, first);
177
+ expect(onEvaluate).toHaveBeenNthCalledWith(2, second);
178
+ expect(onEvaluate).toHaveBeenNthCalledWith(3, third);
179
+ expect(onPromote).toHaveBeenCalledTimes(1);
180
+ expect(onPromote).toHaveBeenCalledWith(third);
181
+ expect(onRollback).not.toHaveBeenCalled();
182
+
183
+ await registry.shutdown();
184
+ });
185
+
186
+ test('rolls back after consecutive failures and stays rolled back until reset', async () => {
187
+ const registry = new TelemetryRegistry({
188
+ service: 'svc',
189
+ module: 'server',
190
+ environment: 'test',
191
+ flushIntervalMs: 60_000,
192
+ });
193
+ const onEvaluate = rs.fn();
194
+ const onPromote = rs.fn();
195
+ const onRollback = rs.fn();
196
+ const orchestrator = new TelemetryCanaryOrchestrator({
197
+ registry,
198
+ minConsecutiveHealthyEvaluations: 1,
199
+ rollbackConsecutiveFailures: 2,
200
+ requiredContractGates: ['contracts'],
201
+ onEvaluate,
202
+ onPromote,
203
+ onRollback,
204
+ });
205
+
206
+ orchestrator.setContractGate('contracts', false, 'schema drift');
207
+
208
+ const firstFailure = orchestrator.evaluate();
209
+ expect(firstFailure.action).toBe('hold');
210
+ expect(firstFailure.state).toBe('canary');
211
+ expect(firstFailure.consecutiveFailures).toBe(1);
212
+ expect(onRollback).not.toHaveBeenCalled();
213
+
214
+ const secondFailure = orchestrator.evaluate();
215
+ expect(secondFailure.action).toBe('rollback');
216
+ expect(secondFailure.state).toBe('rolled_back');
217
+ expect(secondFailure.consecutiveFailures).toBe(2);
218
+ expect(onRollback).toHaveBeenCalledTimes(1);
219
+ expect(onRollback).toHaveBeenCalledWith(secondFailure);
220
+
221
+ orchestrator.setContractGate('contracts', true);
222
+ const healthyWhileRolledBack = orchestrator.evaluate();
223
+ expect(healthyWhileRolledBack.action).toBe('hold');
224
+ expect(healthyWhileRolledBack.state).toBe('rolled_back');
225
+ expect(healthyWhileRolledBack.consecutiveHealthy).toBe(1);
226
+ expect(onPromote).not.toHaveBeenCalled();
227
+ expect(onRollback).toHaveBeenCalledTimes(1);
228
+
229
+ orchestrator.resetToCanary();
230
+ expect(orchestrator.getStatusSnapshot().state).toBe('canary');
231
+
232
+ const promotedAfterReset = orchestrator.evaluate();
233
+ expect(promotedAfterReset.action).toBe('promote');
234
+ expect(promotedAfterReset.state).toBe('promoted');
235
+ expect(onEvaluate).toHaveBeenCalledTimes(4);
236
+ expect(onPromote).toHaveBeenCalledTimes(1);
237
+ expect(onPromote).toHaveBeenCalledWith(promotedAfterReset);
238
+
239
+ await registry.shutdown();
240
+ });
241
+
242
+ test('blocks promotion until required contract gates pass', async () => {
243
+ const registry = new TelemetryRegistry({
244
+ service: 'svc',
245
+ module: 'server',
246
+ environment: 'test',
247
+ flushIntervalMs: 60_000,
248
+ });
249
+ const onPromote = rs.fn();
250
+ const orchestrator = new TelemetryCanaryOrchestrator({
251
+ registry,
252
+ minConsecutiveHealthyEvaluations: 1,
253
+ rollbackConsecutiveFailures: 10,
254
+ requiredContractGates: ['contracts', 'runtime'],
255
+ onPromote,
256
+ });
257
+
258
+ orchestrator.setContractGate('contracts', true);
259
+ const missingGateDecision = orchestrator.evaluate();
260
+ expect(missingGateDecision.action).toBe('hold');
261
+ expect(missingGateDecision.state).toBe('canary');
262
+ expect(missingGateDecision.consecutiveHealthy).toBe(0);
263
+ expect(missingGateDecision.failures).toEqual(
264
+ expect.arrayContaining([
265
+ expect.objectContaining({
266
+ reason: 'contract_gate_missing',
267
+ gate: 'runtime',
268
+ }),
269
+ ]),
270
+ );
271
+ expect(onPromote).not.toHaveBeenCalled();
272
+
273
+ orchestrator.setContractGate('runtime', false, 'runtime contract failed');
274
+ const failedGateDecision = orchestrator.evaluate();
275
+ expect(failedGateDecision.action).toBe('hold');
276
+ expect(failedGateDecision.state).toBe('canary');
277
+ expect(failedGateDecision.failures).toEqual(
278
+ expect.arrayContaining([
279
+ expect.objectContaining({
280
+ reason: 'contract_gate_failed',
281
+ gate: 'runtime',
282
+ }),
283
+ ]),
284
+ );
285
+ expect(onPromote).not.toHaveBeenCalled();
286
+
287
+ orchestrator.setContractGate('runtime', true);
288
+ const passingGateDecision = orchestrator.evaluate();
289
+ expect(passingGateDecision.action).toBe('promote');
290
+ expect(passingGateDecision.state).toBe('promoted');
291
+ expect(passingGateDecision.failures).toHaveLength(0);
292
+ expect(onPromote).toHaveBeenCalledTimes(1);
293
+ expect(onPromote).toHaveBeenCalledWith(passingGateDecision);
294
+
295
+ await registry.shutdown();
296
+ });
297
+
298
+ test('observer hook failures do not escape or block later hooks', async () => {
299
+ const promotingRegistry = new TelemetryRegistry({
300
+ service: 'svc',
301
+ module: 'server',
302
+ environment: 'test',
303
+ flushIntervalMs: 60_000,
304
+ });
305
+ const onPromoteEvaluate = rs.fn(() => {
306
+ throw new Error('evaluate promote failed');
307
+ });
308
+ const onPromote = rs.fn(() => {
309
+ throw new Error('promote failed');
310
+ });
311
+ const promotingOrchestrator = new TelemetryCanaryOrchestrator({
312
+ registry: promotingRegistry,
313
+ minConsecutiveHealthyEvaluations: 1,
314
+ onEvaluate: onPromoteEvaluate,
315
+ onPromote,
316
+ });
317
+ let promotedDecision:
318
+ | ReturnType<TelemetryCanaryOrchestrator['evaluate']>
319
+ | undefined;
320
+
321
+ expect(() => {
322
+ promotedDecision = promotingOrchestrator.evaluate();
323
+ }).not.toThrow();
324
+
325
+ expect(promotedDecision?.action).toBe('promote');
326
+ expect(promotedDecision?.state).toBe('promoted');
327
+ expect(onPromoteEvaluate).toHaveBeenCalledTimes(1);
328
+ expect(onPromote).toHaveBeenCalledTimes(1);
329
+
330
+ const rollbackRegistry = new TelemetryRegistry({
331
+ service: 'svc',
332
+ module: 'server',
333
+ environment: 'test',
334
+ flushIntervalMs: 60_000,
335
+ });
336
+ const onRollbackEvaluate = rs.fn(() => {
337
+ throw new Error('evaluate rollback failed');
338
+ });
339
+ const onRollback = rs.fn(() => {
340
+ throw new Error('rollback failed');
341
+ });
342
+ const rollbackOrchestrator = new TelemetryCanaryOrchestrator({
343
+ registry: rollbackRegistry,
344
+ rollbackConsecutiveFailures: 1,
345
+ requiredContractGates: ['contracts'],
346
+ onEvaluate: onRollbackEvaluate,
347
+ onRollback,
348
+ });
349
+ let rollbackDecision:
350
+ | ReturnType<TelemetryCanaryOrchestrator['evaluate']>
351
+ | undefined;
352
+
353
+ expect(() => {
354
+ rollbackDecision = rollbackOrchestrator.evaluate();
355
+ }).not.toThrow();
356
+
357
+ expect(rollbackDecision?.action).toBe('rollback');
358
+ expect(rollbackDecision?.state).toBe('rolled_back');
359
+ expect(onRollbackEvaluate).toHaveBeenCalledTimes(1);
360
+ expect(onRollback).toHaveBeenCalledTimes(1);
361
+
362
+ await promotingRegistry.shutdown();
363
+ await rollbackRegistry.shutdown();
364
+ });
140
365
  });