@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.4 → 3.9.0-ultramodern.6

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 (178) hide show
  1. package/README.md +5 -5
  2. package/dist/cjs/bff-policy/crossProjectPolicy.js +299 -0
  3. package/dist/cjs/bff-policy/index.js +62 -0
  4. package/dist/cjs/bff-policy/node.js +69 -0
  5. package/dist/cjs/bff-policy/operationContracts.js +182 -0
  6. package/dist/cjs/bff-policy/resolveCrossProjectPolicy.js +65 -0
  7. package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -8
  8. package/dist/cjs/errorResponsePlugin.js +57 -0
  9. package/dist/cjs/localisedLoaderPlugin.js +62 -0
  10. package/dist/cjs/mfCache.js +6 -0
  11. package/dist/cjs/module-federation-css/plugin.js +6 -0
  12. package/dist/cjs/serverConfig.js +18 -0
  13. package/dist/cjs/serverPlugin.js +74 -0
  14. package/dist/cjs/static-serving/plugin.js +57 -0
  15. package/dist/cjs/static-serving/responders.js +158 -0
  16. package/dist/cjs/static-serving/staticModuleFederation.js +173 -0
  17. package/dist/cjs/static-serving/staticPrecompressed.js +152 -0
  18. package/dist/cjs/telemetry/exporters.js +4 -4
  19. package/dist/cjs/telemetry/healthSetup.js +14 -14
  20. package/dist/cjs/telemetry/lifecycle.js +20 -21
  21. package/dist/cjs/telemetry/plugin.js +10 -4
  22. package/dist/cjs/telemetry/runtimeEndpoints.js +3 -2
  23. package/dist/cjs/telemetryCore.js +5 -5
  24. package/dist/esm/bff-policy/crossProjectPolicy.mjs +249 -0
  25. package/dist/esm/bff-policy/index.mjs +1 -0
  26. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -8
  27. package/dist/esm/errorResponsePlugin.mjs +19 -0
  28. package/dist/esm/localisedLoaderPlugin.mjs +24 -0
  29. package/dist/esm/mfCache.mjs +6 -0
  30. package/dist/esm/module-federation-css/plugin.mjs +6 -0
  31. package/dist/esm/serverConfig.mjs +0 -0
  32. package/dist/esm/serverPlugin.mjs +34 -0
  33. package/dist/esm/telemetry/exporters.mjs +2 -2
  34. package/dist/esm/telemetry/healthSetup.mjs +14 -14
  35. package/dist/esm/telemetry/lifecycle.mjs +21 -22
  36. package/dist/esm/telemetry/plugin.mjs +9 -3
  37. package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -2
  38. package/dist/esm/telemetryCore.mjs +1 -1
  39. package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +250 -0
  40. package/dist/esm-node/bff-policy/index.mjs +2 -0
  41. package/dist/esm-node/bff-policy/node.mjs +3 -0
  42. package/dist/esm-node/bff-policy/operationContracts.mjs +129 -0
  43. package/dist/esm-node/bff-policy/resolveCrossProjectPolicy.mjs +28 -0
  44. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -8
  45. package/dist/esm-node/errorResponsePlugin.mjs +20 -0
  46. package/dist/esm-node/localisedLoaderPlugin.mjs +25 -0
  47. package/dist/esm-node/mfCache.mjs +6 -0
  48. package/dist/esm-node/module-federation-css/plugin.mjs +6 -0
  49. package/dist/esm-node/serverConfig.mjs +1 -0
  50. package/dist/esm-node/serverPlugin.mjs +35 -0
  51. package/dist/esm-node/static-serving/plugin.mjs +18 -0
  52. package/dist/esm-node/static-serving/responders.mjs +111 -0
  53. package/dist/esm-node/static-serving/staticModuleFederation.mjs +105 -0
  54. package/dist/esm-node/static-serving/staticPrecompressed.mjs +112 -0
  55. package/dist/esm-node/telemetry/exporters.mjs +2 -2
  56. package/dist/esm-node/telemetry/healthSetup.mjs +14 -14
  57. package/dist/esm-node/telemetry/lifecycle.mjs +21 -22
  58. package/dist/esm-node/telemetry/plugin.mjs +9 -3
  59. package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -2
  60. package/dist/esm-node/telemetryCore.mjs +1 -1
  61. package/dist/types/bff-policy/crossProjectPolicy.d.ts +101 -0
  62. package/dist/types/bff-policy/index.d.ts +1 -0
  63. package/dist/types/bff-policy/node.d.ts +2 -0
  64. package/dist/types/bff-policy/operationContracts.d.ts +85 -0
  65. package/dist/types/bff-policy/resolveCrossProjectPolicy.d.ts +39 -0
  66. package/dist/types/errorResponsePlugin.d.ts +3 -0
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/types/localisedLoaderPlugin.d.ts +2 -0
  69. package/dist/types/mfCache.d.ts +2 -3
  70. package/dist/types/module-federation-css/plugin.d.ts +2 -3
  71. package/dist/types/serverConfig.d.ts +17 -0
  72. package/dist/types/serverPlugin.d.ts +5 -0
  73. package/dist/types/static-serving/plugin.d.ts +3 -0
  74. package/dist/types/static-serving/responders.d.ts +2 -0
  75. package/dist/types/static-serving/staticModuleFederation.d.ts +13 -0
  76. package/dist/types/static-serving/staticPrecompressed.d.ts +13 -0
  77. package/dist/types/telemetry/exporters.d.ts +1 -1
  78. package/dist/types/telemetry/healthSetup.d.ts +3 -3
  79. package/dist/types/telemetry/lifecycle.d.ts +4 -4
  80. package/dist/types/telemetry/plugin.d.ts +2 -1
  81. package/dist/types/telemetryCore.d.ts +1 -1
  82. package/dist/types-esm/backend-federation-security/index.d.mts +68 -0
  83. package/dist/types-esm/backend-federation-security/node.d.mts +3 -0
  84. package/dist/types-esm/bff-policy/crossProjectPolicy.d.mts +101 -0
  85. package/dist/types-esm/bff-policy/index.d.mts +1 -0
  86. package/dist/types-esm/bff-policy/node.d.mts +2 -0
  87. package/dist/types-esm/bff-policy/operationContracts.d.mts +85 -0
  88. package/dist/types-esm/bff-policy/resolveCrossProjectPolicy.d.mts +39 -0
  89. package/dist/types-esm/contract-gate-snapshot-normalization.d.mts +15 -0
  90. package/dist/types-esm/contract-gate-snapshot-store/file-store.d.mts +3 -0
  91. package/dist/types-esm/contract-gate-snapshot-store/http-store.d.mts +5 -0
  92. package/dist/types-esm/contract-gate-snapshot-store/index.d.mts +5 -0
  93. package/dist/types-esm/contract-gate-snapshot-store/resolve.d.mts +9 -0
  94. package/dist/types-esm/contract-gate-snapshot-store/types.d.mts +47 -0
  95. package/dist/types-esm/contractGateSnapshotObserver.d.mts +33 -0
  96. package/dist/types-esm/env.d.mts +40 -0
  97. package/dist/types-esm/errorResponsePlugin.d.mts +3 -0
  98. package/dist/types-esm/index.d.mts +8 -0
  99. package/dist/types-esm/localisedLoaderPlugin.d.mts +2 -0
  100. package/dist/types-esm/mfCache.d.mts +26 -0
  101. package/dist/types-esm/module-federation-css/collector.d.mts +25 -0
  102. package/dist/types-esm/module-federation-css/index.d.mts +8 -0
  103. package/dist/types-esm/module-federation-css/manifest.d.mts +28 -0
  104. package/dist/types-esm/module-federation-css/plugin.d.mts +22 -0
  105. package/dist/types-esm/module-federation-css/remote.d.mts +20 -0
  106. package/dist/types-esm/runtime-fallback-signal/index.d.mts +4 -0
  107. package/dist/types-esm/runtime-fallback-signal/model.d.mts +70 -0
  108. package/dist/types-esm/runtime-fallback-signal/resolver.d.mts +29 -0
  109. package/dist/types-esm/runtime-fallback-signal/store.d.mts +4 -0
  110. package/dist/types-esm/runtimeFallbackSignal.d.mts +1 -0
  111. package/dist/types-esm/runtimeLifecycle.d.mts +10 -0
  112. package/dist/types-esm/serverConfig.d.mts +17 -0
  113. package/dist/types-esm/serverPlugin.d.mts +5 -0
  114. package/dist/types-esm/static-serving/plugin.d.mts +3 -0
  115. package/dist/types-esm/static-serving/responders.d.mts +2 -0
  116. package/dist/types-esm/static-serving/staticModuleFederation.d.mts +13 -0
  117. package/dist/types-esm/static-serving/staticPrecompressed.d.mts +13 -0
  118. package/dist/types-esm/telemetry/envelope.d.mts +55 -0
  119. package/dist/types-esm/telemetry/exporters.d.mts +12 -0
  120. package/dist/types-esm/telemetry/healthEvaluation.d.mts +20 -0
  121. package/dist/types-esm/telemetry/healthMonitor.d.mts +88 -0
  122. package/dist/types-esm/telemetry/healthSetup.d.mts +17 -0
  123. package/dist/types-esm/telemetry/lifecycle.d.mts +18 -0
  124. package/dist/types-esm/telemetry/metrics.d.mts +3 -0
  125. package/dist/types-esm/telemetry/plugin.d.mts +13 -0
  126. package/dist/types-esm/telemetry/registry.d.mts +69 -0
  127. package/dist/types-esm/telemetry/registryTypes.d.mts +50 -0
  128. package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +35 -0
  129. package/dist/types-esm/telemetry.d.mts +1 -0
  130. package/dist/types-esm/telemetryCore.d.mts +6 -0
  131. package/package.json +158 -26
  132. package/rslib.config.mts +36 -2
  133. package/rstest.config.mts +11 -0
  134. package/src/bff-policy/crossProjectPolicy.ts +754 -0
  135. package/src/bff-policy/index.ts +1 -0
  136. package/src/bff-policy/node.ts +2 -0
  137. package/src/bff-policy/operationContracts.ts +298 -0
  138. package/src/bff-policy/resolveCrossProjectPolicy.ts +88 -0
  139. package/src/contract-gate-snapshot-store/http-store.ts +1 -11
  140. package/src/errorResponsePlugin.ts +21 -0
  141. package/src/index.ts +4 -0
  142. package/src/localisedLoaderPlugin.ts +34 -0
  143. package/src/mfCache.ts +4 -3
  144. package/src/module-federation-css/plugin.ts +4 -3
  145. package/src/serverConfig.ts +32 -0
  146. package/src/serverPlugin.ts +38 -0
  147. package/src/static-serving/plugin.ts +16 -0
  148. package/src/static-serving/responders.ts +208 -0
  149. package/src/static-serving/staticModuleFederation.ts +255 -0
  150. package/src/static-serving/staticPrecompressed.ts +193 -0
  151. package/src/telemetry/exporters.ts +1 -1
  152. package/src/telemetry/healthSetup.ts +17 -20
  153. package/src/telemetry/lifecycle.ts +27 -39
  154. package/src/telemetry/plugin.ts +6 -4
  155. package/src/telemetry/runtimeEndpoints.ts +3 -2
  156. package/src/telemetryCore.ts +1 -1
  157. package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +487 -0
  158. package/tests/bff-policy/crossProjectPolicy.test.ts +970 -0
  159. package/tests/bff-policy/operationContracts.test.ts +221 -0
  160. package/tests/bff-policy/optionalZodPeer.test.ts +30 -0
  161. package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +134 -0
  162. package/tests/contractGateSnapshotObserver.test.ts +0 -58
  163. package/tests/env.test.ts +45 -64
  164. package/tests/localisedLoader.test.ts +120 -0
  165. package/tests/mfCache.test.ts +1 -88
  166. package/tests/moduleFederationCss.test.ts +4 -48
  167. package/tests/nativeErrorResponse.test.ts +199 -0
  168. package/tests/nativeServerAssembly.test.ts +402 -0
  169. package/tests/registration.test.ts +2 -87
  170. package/tests/runtimeLifecycle.test.ts +69 -17
  171. package/tests/static-serving/ordering.test.ts +214 -0
  172. package/tests/static-serving/provider.test.ts +83 -0
  173. package/tests/static-serving/static.test.ts +400 -0
  174. package/tests/telemetry.test.ts +35 -101
  175. package/tests/telemetryHealthMonitor.test.ts +0 -2
  176. package/tests/{telemetryAutopilot.test.ts → telemetryHealthObservation.test.ts} +43 -182
  177. package/tests/telemetryLifecycle.test.ts +11 -253
  178. package/tests/telemetryRegistryQueueMatrix.test.ts +0 -1
@@ -6,7 +6,6 @@ import {
6
6
  TelemetryRegistry,
7
7
  TelemetryStartupHealthError,
8
8
  } from '../src/telemetry';
9
- import { clamp } from '../src/telemetry/envelope';
10
9
 
11
10
  const createEnvelope = (partial: Record<string, unknown> = {}) => ({
12
11
  timestamp: Date.now(),
@@ -20,74 +19,7 @@ const createEnvelope = (partial: Record<string, unknown> = {}) => ({
20
19
  ...partial,
21
20
  });
22
21
 
23
- describe('telemetry envelope helpers', () => {
24
- test('clamps NaN input to a finite in-range value', () => {
25
- const value = clamp(Number.NaN, 0, 1);
26
-
27
- expect(Number.isFinite(value)).toBe(true);
28
- expect(value).toBeGreaterThanOrEqual(0);
29
- expect(value).toBeLessThanOrEqual(1);
30
- });
31
- });
32
-
33
22
  describe('telemetry registry', () => {
34
- test('applies redaction and emits dropped-count metric under backpressure', async () => {
35
- const batches: unknown[] = [];
36
- const registry = new TelemetryRegistry({
37
- service: 'svc',
38
- module: 'server',
39
- environment: 'test',
40
- maxBatchSize: 10,
41
- maxQueueSize: 3,
42
- flushIntervalMs: 60_000,
43
- redactionKeys: ['token'],
44
- });
45
- await registry.register({
46
- name: 'memory',
47
- async emit(batch) {
48
- batches.push(...batch);
49
- },
50
- });
51
-
52
- registry.enqueue(
53
- createEnvelope({
54
- name: 'first',
55
- attributes: { token: 's1', keep: 'ok' },
56
- }),
57
- );
58
- registry.enqueue(
59
- createEnvelope({
60
- name: 'second',
61
- }),
62
- );
63
- registry.enqueue(
64
- createEnvelope({
65
- name: 'third',
66
- }),
67
- );
68
- registry.enqueue(
69
- createEnvelope({
70
- name: 'fourth',
71
- }),
72
- );
73
-
74
- await registry.flush();
75
- await registry.shutdown();
76
-
77
- const names = batches.map(
78
- item => (item as { name?: string }).name || 'unknown',
79
- );
80
- expect(names).toContain('telemetry.queue.dropped');
81
- const withAttributes = batches.find(
82
- item => (item as { name?: string }).name === 'first',
83
- ) as
84
- | {
85
- attributes?: Record<string, unknown>;
86
- }
87
- | undefined;
88
- expect(withAttributes).toBeUndefined();
89
- });
90
-
91
23
  test('redacts configured keys recursively', async () => {
92
24
  const batches: unknown[] = [];
93
25
  const registry = new TelemetryRegistry({
@@ -188,37 +120,6 @@ describe('telemetry registry', () => {
188
120
  expect(timerEnvelope.spanId).toBe('1111222233334444');
189
121
  });
190
122
 
191
- test('emits queue depth and utilization metrics during flush', async () => {
192
- const emitted: TelemetryEnvelope[] = [];
193
- const registry = new TelemetryRegistry({
194
- service: 'svc',
195
- module: 'server',
196
- environment: 'test',
197
- maxQueueSize: 10,
198
- flushIntervalMs: 60_000,
199
- });
200
- await registry.register({
201
- name: 'memory',
202
- async emit(batch) {
203
- emitted.push(...batch);
204
- },
205
- });
206
-
207
- registry.enqueue(createEnvelope({ name: 'a' }));
208
- registry.enqueue(createEnvelope({ name: 'b' }));
209
- await registry.flush();
210
-
211
- const depthEnvelope = emitted.find(
212
- item => item.name === 'telemetry.queue.depth',
213
- );
214
- const utilizationEnvelope = emitted.find(
215
- item => item.name === 'telemetry.queue.utilization',
216
- );
217
- expect(depthEnvelope?.value).toBe(2);
218
- expect(utilizationEnvelope?.value).toBe(0.2);
219
- await registry.shutdown();
220
- });
221
-
222
123
  test('exposes queue stats and emits SLO alerts for utilization and dropped envelopes', async () => {
223
124
  const alerts: Array<{ type: string; value: number }> = [];
224
125
  const registry = new TelemetryRegistry({
@@ -370,10 +271,33 @@ describe('telemetry exporters', () => {
370
271
  ];
371
272
  expect(url).toBe('http://localhost:4318/v1/logs');
372
273
  expect(init.method).toBe('POST');
274
+ expect(new Headers(init.headers).get('content-type')).toBe(
275
+ 'application/json',
276
+ );
373
277
  const payload = JSON.parse(String(init.body)) as {
278
+ resource: {
279
+ service: string;
280
+ module: string;
281
+ environment: string;
282
+ };
283
+ emittedAt: number;
374
284
  events: unknown[];
375
285
  };
286
+ expect(payload.resource).toEqual({
287
+ service: 'svc',
288
+ module: 'server',
289
+ environment: 'test',
290
+ });
291
+ expect(payload.emittedAt).toEqual(expect.any(Number));
376
292
  expect(payload.events).toHaveLength(1);
293
+ expect(payload.events[0]).toMatchObject({
294
+ service: 'svc',
295
+ module: 'server',
296
+ environment: 'test',
297
+ signalType: 'log',
298
+ name: 'hello',
299
+ level: 'info',
300
+ });
377
301
  });
378
302
 
379
303
  test('victoria metrics exporter emits prometheus lines', async () => {
@@ -404,8 +328,18 @@ describe('telemetry exporters', () => {
404
328
  ];
405
329
  expect(url).toBe('http://localhost:8428/api/v1/import/prometheus');
406
330
  expect(init.method).toBe('POST');
331
+ expect(new Headers(init.headers).get('content-type')).toBe(
332
+ 'text/plain; version=0.0.4',
333
+ );
407
334
  const body = String(init.body);
408
- expect(body).toContain('modernjs_metric_server_handle_request');
409
- expect(body).toContain('modernjs_log_request_error');
335
+ expect(body.endsWith('\n')).toBe(true);
336
+ const lines = body.trimEnd().split('\n');
337
+ expect(lines).toHaveLength(2);
338
+ expect(lines[0]).toMatch(
339
+ /^modernjs_metric_server_handle_request\{environment="test",module="server",service="svc"\} 42 \d+$/,
340
+ );
341
+ expect(lines[1]).toMatch(
342
+ /^modernjs_log_request_error\{environment="test",level="error",module="server",service="svc"\} 10 \d+$/,
343
+ );
410
344
  });
411
345
  });
@@ -83,8 +83,6 @@ describe('telemetry health monitor', () => {
83
83
  consecutiveHealthy: 3,
84
84
  });
85
85
 
86
- expect('action' in recovered).toBe(false);
87
- expect(JSON.stringify(recovered)).not.toMatch(/promot|rollback/i);
88
86
  expect(onEvaluate).toHaveBeenCalledTimes(6);
89
87
  expect(onTransition).toHaveBeenCalledTimes(2);
90
88
  expect(onTransition).toHaveBeenNthCalledWith(1, unhealthy);
@@ -6,9 +6,11 @@ import { injectTelemetryPlugin } from '../src/telemetry';
6
6
  import { getDefaultAppContext, getDefaultConfig } from './helpers';
7
7
 
8
8
  const makeTempDir = () =>
9
- fs.mkdtempSync(path.join(os.tmpdir(), 'modern-telemetry-autopilot-'));
9
+ fs.mkdtempSync(
10
+ path.join(os.tmpdir(), 'modern-telemetry-health-observation-'),
11
+ );
10
12
 
11
- describe('telemetry autopilot runtime signal', () => {
13
+ describe('telemetry health observation runtime signal', () => {
12
14
  test('accepts runtime fallback signal and persists gate snapshot', async () => {
13
15
  const tempDir = makeTempDir();
14
16
  const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
@@ -18,10 +20,10 @@ describe('telemetry autopilot runtime signal', () => {
18
20
  config.server = {
19
21
  telemetry: {
20
22
  enabled: true,
21
- canary: {
23
+ health: {
22
24
  enabled: true,
23
- rollbackConsecutiveFailures: 1,
24
- autopilot: {
25
+ minConsecutiveFailedEvaluations: 1,
26
+ snapshotObservation: {
25
27
  enabled: true,
26
28
  gateSnapshotPath: snapshotPath,
27
29
  pollIntervalMs: 20,
@@ -102,10 +104,10 @@ describe('telemetry autopilot runtime signal', () => {
102
104
  config.server = {
103
105
  telemetry: {
104
106
  enabled: true,
105
- canary: {
107
+ health: {
106
108
  enabled: true,
107
- rollbackConsecutiveFailures: 1,
108
- autopilot: {
109
+ minConsecutiveFailedEvaluations: 1,
110
+ snapshotObservation: {
109
111
  enabled: true,
110
112
  gateSnapshotPath: snapshotPath,
111
113
  runtimeFallbackSignal: {
@@ -171,10 +173,10 @@ describe('telemetry autopilot runtime signal', () => {
171
173
  config.server = {
172
174
  telemetry: {
173
175
  enabled: true,
174
- canary: {
176
+ health: {
175
177
  enabled: true,
176
- rollbackConsecutiveFailures: 1,
177
- autopilot: {
178
+ minConsecutiveFailedEvaluations: 1,
179
+ snapshotObservation: {
178
180
  enabled: true,
179
181
  gateSnapshotPath: snapshotPath,
180
182
  runtimeFallbackSignal: {
@@ -255,10 +257,10 @@ describe('telemetry autopilot runtime signal', () => {
255
257
  config.server = {
256
258
  telemetry: {
257
259
  enabled: true,
258
- canary: {
260
+ health: {
259
261
  enabled: true,
260
- rollbackConsecutiveFailures: 1,
261
- autopilot: {
262
+ minConsecutiveFailedEvaluations: 1,
263
+ snapshotObservation: {
262
264
  enabled: true,
263
265
  gateSnapshotPath: snapshotPath,
264
266
  runtimeFallbackSignal: {
@@ -313,7 +315,7 @@ describe('telemetry autopilot runtime signal', () => {
313
315
  const payload = (await authorized.json()) as {
314
316
  ok?: boolean;
315
317
  telemetry?: { queueStats?: { capacity?: number } };
316
- canary?: { enabled?: boolean };
318
+ health?: { enabled?: boolean };
317
319
  runtimeFallbackSignal?: {
318
320
  enabled?: boolean;
319
321
  endpoint?: string;
@@ -322,7 +324,7 @@ describe('telemetry autopilot runtime signal', () => {
322
324
  };
323
325
  expect(payload.ok).toBe(true);
324
326
  expect(payload.telemetry?.queueStats?.capacity).toBeGreaterThan(0);
325
- expect(payload.canary?.enabled).toBe(true);
327
+ expect(payload.health?.enabled).toBe(true);
326
328
  expect(payload.runtimeFallbackSignal?.enabled).toBe(true);
327
329
  expect(payload.runtimeFallbackSignal?.endpoint).toBe(
328
330
  '/_modern/contract-gates/runtime-fallback',
@@ -374,10 +376,10 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
374
376
  config.server = {
375
377
  telemetry: {
376
378
  enabled: true,
377
- canary: {
379
+ health: {
378
380
  enabled: true,
379
- rollbackConsecutiveFailures: 1,
380
- autopilot: {
381
+ minConsecutiveFailedEvaluations: 1,
382
+ snapshotObservation: {
381
383
  enabled: true,
382
384
  gateSnapshotPath: defaultSnapshotPath,
383
385
  stateStore: {
@@ -442,147 +444,6 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
442
444
  }
443
445
  });
444
446
 
445
- test('autopilot path honors configured contract gate snapshot stateStore', async () => {
446
- const tempDir = makeTempDir();
447
- const defaultSnapshotPath = path.join(
448
- tempDir,
449
- '.modern/contract-gates.json',
450
- );
451
- const customSnapshotPath = path.join(tempDir, '.state-store/gates.json');
452
- const stateStoreModulePath = path.join(
453
- tempDir,
454
- 'autopilot-gate-state-store.js',
455
- );
456
- const readMarkerPath = path.join(tempDir, '.state-store/read-marker.txt');
457
- const now = Date.now();
458
-
459
- fs.mkdirSync(path.dirname(customSnapshotPath), { recursive: true });
460
- fs.writeFileSync(
461
- customSnapshotPath,
462
- JSON.stringify(
463
- {
464
- schemaVersion: 1,
465
- updatedAt: now,
466
- gates: {
467
- 'state-store-autopilot-gate': {
468
- passed: false,
469
- reason: 'from configured stateStore',
470
- updatedAt: now,
471
- },
472
- },
473
- },
474
- null,
475
- 2,
476
- ),
477
- 'utf8',
478
- );
479
- fs.writeFileSync(
480
- stateStoreModulePath,
481
- `'use strict';
482
- const fs = require('fs');
483
- const path = require('path');
484
- exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
485
- const targetPath = options && typeof options.snapshotPath === 'string'
486
- ? options.snapshotPath
487
- : gateSnapshotPath;
488
- const markerPath = options && typeof options.markerPath === 'string'
489
- ? options.markerPath
490
- : undefined;
491
- return {
492
- name: 'autopilot-test-state-store',
493
- async readSnapshot() {
494
- if (markerPath) {
495
- fs.mkdirSync(path.dirname(markerPath), { recursive: true });
496
- fs.appendFileSync(markerPath, targetPath + '\\n');
497
- }
498
- if (!fs.existsSync(targetPath)) {
499
- return undefined;
500
- }
501
- return JSON.parse(fs.readFileSync(targetPath, 'utf8'));
502
- },
503
- async writeSnapshot(snapshot) {
504
- fs.mkdirSync(path.dirname(targetPath), { recursive: true });
505
- fs.writeFileSync(targetPath, JSON.stringify(snapshot, null, 2));
506
- },
507
- };
508
- };
509
- `,
510
- 'utf8',
511
- );
512
-
513
- try {
514
- const config = getDefaultConfig();
515
- config.server = {
516
- telemetry: {
517
- enabled: true,
518
- canary: {
519
- enabled: true,
520
- rollbackConsecutiveFailures: 1,
521
- contractGates: {
522
- 'state-store-autopilot-gate': true,
523
- },
524
- autopilot: {
525
- enabled: true,
526
- gateSnapshotPath: defaultSnapshotPath,
527
- pollIntervalMs: 20,
528
- gateStaleAfterMs: 60_000,
529
- stateStore: {
530
- module: stateStoreModulePath,
531
- options: {
532
- snapshotPath: customSnapshotPath,
533
- markerPath: readMarkerPath,
534
- },
535
- },
536
- runtimeFallbackSignal: {
537
- auth: {
538
- enabled: true,
539
- expectedValue: 'state-store-status-token',
540
- },
541
- },
542
- },
543
- },
544
- },
545
- } as any;
546
-
547
- const server = createServerBase({
548
- config,
549
- pwd: tempDir,
550
- appContext: getDefaultAppContext(),
551
- });
552
-
553
- server.addPlugins([
554
- ...createDefaultPlugins({
555
- logger: false,
556
- }),
557
- injectTelemetryPlugin(),
558
- ]);
559
-
560
- await server.init();
561
-
562
- expect(fs.existsSync(readMarkerPath)).toBe(true);
563
- expect(fs.readFileSync(readMarkerPath, 'utf8')).toContain(
564
- customSnapshotPath,
565
- );
566
- expect(fs.existsSync(defaultSnapshotPath)).toBe(false);
567
-
568
- const status = await server.request(
569
- '/_modern/runtime/status',
570
- {
571
- method: 'GET',
572
- headers: new Headers({
573
- 'x-modernjs-runtime-signal-token': 'state-store-status-token',
574
- }),
575
- },
576
- {},
577
- );
578
- expect(status.status).toBe(200);
579
- const statusBody = await status.json();
580
- expect(statusBody.canary?.enabled).toBe(true);
581
- } finally {
582
- fs.rmSync(tempDir, { recursive: true, force: true });
583
- }
584
- });
585
-
586
447
  test('enforces runtime fallback trust policy before mutating gate snapshots', async () => {
587
448
  const tempDir = makeTempDir();
588
449
  const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
@@ -592,10 +453,10 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
592
453
  config.server = {
593
454
  telemetry: {
594
455
  enabled: true,
595
- canary: {
456
+ health: {
596
457
  enabled: true,
597
- rollbackConsecutiveFailures: 1,
598
- autopilot: {
458
+ minConsecutiveFailedEvaluations: 1,
459
+ snapshotObservation: {
599
460
  enabled: true,
600
461
  gateSnapshotPath: snapshotPath,
601
462
  runtimeFallbackSignal: {
@@ -726,10 +587,10 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
726
587
  config.server = {
727
588
  telemetry: {
728
589
  enabled: true,
729
- canary: {
590
+ health: {
730
591
  enabled: true,
731
- rollbackConsecutiveFailures: 1,
732
- autopilot: {
592
+ minConsecutiveFailedEvaluations: 1,
593
+ snapshotObservation: {
733
594
  enabled: true,
734
595
  gateSnapshotPath: snapshotPath,
735
596
  runtimeFallbackSignal: {
@@ -833,13 +694,13 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
833
694
  config.server = {
834
695
  telemetry: {
835
696
  enabled: true,
836
- canary: {
697
+ health: {
837
698
  enabled: true,
838
- rollbackConsecutiveFailures: 1,
839
- autopilot: {
699
+ minConsecutiveFailedEvaluations: 1,
700
+ snapshotObservation: {
840
701
  enabled: true,
841
702
  gateSnapshotPath: snapshotPath,
842
- // no runtimeFallbackSignal config: the canary kill switch must
703
+ // no runtimeFallbackSignal config: the health observation switch must
843
704
  // stay OFF by default.
844
705
  },
845
706
  },
@@ -892,9 +753,9 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
892
753
  config.server = {
893
754
  telemetry: {
894
755
  enabled: true,
895
- canary: {
756
+ health: {
896
757
  enabled: true,
897
- autopilot: {
758
+ snapshotObservation: {
898
759
  enabled: true,
899
760
  gateSnapshotPath: snapshotPath,
900
761
  runtimeFallbackSignal: {
@@ -935,10 +796,10 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
935
796
  config.server = {
936
797
  telemetry: {
937
798
  enabled: true,
938
- canary: {
799
+ health: {
939
800
  enabled: true,
940
- rollbackConsecutiveFailures: 1,
941
- autopilot: {
801
+ minConsecutiveFailedEvaluations: 1,
802
+ snapshotObservation: {
942
803
  enabled: true,
943
804
  gateSnapshotPath: snapshotPath,
944
805
  runtimeFallbackSignal: {
@@ -1012,9 +873,9 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
1012
873
  config.server = {
1013
874
  telemetry: {
1014
875
  enabled: true,
1015
- canary: {
876
+ health: {
1016
877
  enabled: true,
1017
- autopilot: {
878
+ snapshotObservation: {
1018
879
  enabled: true,
1019
880
  gateSnapshotPath: snapshotPath,
1020
881
  },
@@ -1041,9 +902,9 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
1041
902
  const payload = (await response.json()) as Record<string, unknown>;
1042
903
  expect(payload.ok).toBe(true);
1043
904
  expect(typeof payload.timestamp).toBe('number');
1044
- // No telemetry/canary/trust internals are disclosed without auth.
905
+ // No telemetry/health/trust internals are disclosed without auth.
1045
906
  expect(payload.telemetry).toBeUndefined();
1046
- expect(payload.canary).toBeUndefined();
907
+ expect(payload.health).toBeUndefined();
1047
908
  expect(payload.runtimeFallbackSignal).toBeUndefined();
1048
909
  } finally {
1049
910
  fs.rmSync(tempDir, { recursive: true, force: true });
@@ -1059,9 +920,9 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
1059
920
  config.server = {
1060
921
  telemetry: {
1061
922
  enabled: true,
1062
- canary: {
923
+ health: {
1063
924
  enabled: true,
1064
- autopilot: {
925
+ snapshotObservation: {
1065
926
  enabled: true,
1066
927
  gateSnapshotPath: snapshotPath,
1067
928
  runtimeFallbackSignal: {
@@ -1125,7 +986,7 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
1125
986
  expect(authorized.status).toBe(200);
1126
987
  const payload = (await authorized.json()) as Record<string, any>;
1127
988
  expect(payload.ok).toBe(true);
1128
- expect(payload.canary?.enabled).toBe(true);
989
+ expect(payload.health?.enabled).toBe(true);
1129
990
  expect(payload.runtimeFallbackSignal?.enabled).toBe(false);
1130
991
  } finally {
1131
992
  fs.rmSync(tempDir, { recursive: true, force: true });