@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.4 → 3.9.0-ultramodern.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.
- package/dist/cjs/bff-policy/crossProjectPolicy.js +309 -0
- package/dist/cjs/bff-policy/index.js +62 -0
- package/dist/cjs/bff-policy/node.js +69 -0
- package/dist/cjs/bff-policy/operationContracts.js +182 -0
- package/dist/cjs/bff-policy/resolveCrossProjectPolicy.js +65 -0
- package/dist/cjs/errorResponsePlugin.js +57 -0
- package/dist/cjs/localisedLoaderPlugin.js +62 -0
- package/dist/cjs/mfCache.js +6 -0
- package/dist/cjs/module-federation-css/plugin.js +6 -0
- package/dist/cjs/serverConfig.js +18 -0
- package/dist/cjs/serverPlugin.js +74 -0
- package/dist/cjs/static-serving/plugin.js +57 -0
- package/dist/cjs/static-serving/responders.js +158 -0
- package/dist/cjs/static-serving/staticModuleFederation.js +173 -0
- package/dist/cjs/static-serving/staticPrecompressed.js +152 -0
- package/dist/cjs/telemetry/canaryCompatibility.js +73 -0
- package/dist/cjs/telemetry/healthSetup.js +4 -0
- package/dist/cjs/telemetry/lifecycle.js +15 -16
- package/dist/cjs/telemetry/plugin.js +10 -3
- package/dist/cjs/telemetry/runtimeEndpoints.js +10 -3
- package/dist/esm/bff-policy/crossProjectPolicy.mjs +259 -0
- package/dist/esm/bff-policy/index.mjs +1 -0
- package/dist/esm/errorResponsePlugin.mjs +19 -0
- package/dist/esm/localisedLoaderPlugin.mjs +24 -0
- package/dist/esm/mfCache.mjs +6 -0
- package/dist/esm/module-federation-css/plugin.mjs +6 -0
- package/dist/esm/serverConfig.mjs +0 -0
- package/dist/esm/serverPlugin.mjs +34 -0
- package/dist/esm/telemetry/canaryCompatibility.mjs +35 -0
- package/dist/esm/telemetry/healthSetup.mjs +4 -0
- package/dist/esm/telemetry/lifecycle.mjs +15 -16
- package/dist/esm/telemetry/plugin.mjs +9 -2
- package/dist/esm/telemetry/runtimeEndpoints.mjs +10 -3
- package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +260 -0
- package/dist/esm-node/bff-policy/index.mjs +2 -0
- package/dist/esm-node/bff-policy/node.mjs +3 -0
- package/dist/esm-node/bff-policy/operationContracts.mjs +129 -0
- package/dist/esm-node/bff-policy/resolveCrossProjectPolicy.mjs +28 -0
- package/dist/esm-node/errorResponsePlugin.mjs +20 -0
- package/dist/esm-node/localisedLoaderPlugin.mjs +25 -0
- package/dist/esm-node/mfCache.mjs +6 -0
- package/dist/esm-node/module-federation-css/plugin.mjs +6 -0
- package/dist/esm-node/serverConfig.mjs +1 -0
- package/dist/esm-node/serverPlugin.mjs +35 -0
- package/dist/esm-node/static-serving/plugin.mjs +18 -0
- package/dist/esm-node/static-serving/responders.mjs +111 -0
- package/dist/esm-node/static-serving/staticModuleFederation.mjs +105 -0
- package/dist/esm-node/static-serving/staticPrecompressed.mjs +112 -0
- package/dist/esm-node/telemetry/canaryCompatibility.mjs +36 -0
- package/dist/esm-node/telemetry/healthSetup.mjs +4 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +15 -16
- package/dist/esm-node/telemetry/plugin.mjs +9 -2
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +10 -3
- package/dist/types/bff-policy/crossProjectPolicy.d.ts +110 -0
- package/dist/types/bff-policy/index.d.ts +1 -0
- package/dist/types/bff-policy/node.d.ts +2 -0
- package/dist/types/bff-policy/operationContracts.d.ts +85 -0
- package/dist/types/bff-policy/resolveCrossProjectPolicy.d.ts +39 -0
- package/dist/types/errorResponsePlugin.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/localisedLoaderPlugin.d.ts +2 -0
- package/dist/types/mfCache.d.ts +2 -3
- package/dist/types/module-federation-css/plugin.d.ts +2 -3
- package/dist/types/serverConfig.d.ts +17 -0
- package/dist/types/serverPlugin.d.ts +5 -0
- package/dist/types/static-serving/plugin.d.ts +3 -0
- package/dist/types/static-serving/responders.d.ts +2 -0
- package/dist/types/static-serving/staticModuleFederation.d.ts +13 -0
- package/dist/types/static-serving/staticPrecompressed.d.ts +13 -0
- package/dist/types/telemetry/canaryCompatibility.d.ts +19 -0
- package/dist/types/telemetry/healthSetup.d.ts +3 -1
- package/dist/types/telemetry/lifecycle.d.ts +2 -2
- package/dist/types/telemetry/plugin.d.ts +2 -1
- package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -1
- package/dist/types-esm/backend-federation-security/index.d.mts +68 -0
- package/dist/types-esm/backend-federation-security/node.d.mts +3 -0
- package/dist/types-esm/bff-policy/crossProjectPolicy.d.mts +110 -0
- package/dist/types-esm/bff-policy/index.d.mts +1 -0
- package/dist/types-esm/bff-policy/node.d.mts +2 -0
- package/dist/types-esm/bff-policy/operationContracts.d.mts +85 -0
- package/dist/types-esm/bff-policy/resolveCrossProjectPolicy.d.mts +39 -0
- package/dist/types-esm/contract-gate-snapshot-normalization.d.mts +15 -0
- package/dist/types-esm/contract-gate-snapshot-store/file-store.d.mts +3 -0
- package/dist/types-esm/contract-gate-snapshot-store/http-store.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/index.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/resolve.d.mts +9 -0
- package/dist/types-esm/contract-gate-snapshot-store/types.d.mts +47 -0
- package/dist/types-esm/contractGateSnapshotObserver.d.mts +33 -0
- package/dist/types-esm/env.d.mts +40 -0
- package/dist/types-esm/errorResponsePlugin.d.mts +3 -0
- package/dist/types-esm/index.d.mts +8 -0
- package/dist/types-esm/localisedLoaderPlugin.d.mts +2 -0
- package/dist/types-esm/mfCache.d.mts +26 -0
- package/dist/types-esm/module-federation-css/collector.d.mts +25 -0
- package/dist/types-esm/module-federation-css/index.d.mts +8 -0
- package/dist/types-esm/module-federation-css/manifest.d.mts +28 -0
- package/dist/types-esm/module-federation-css/plugin.d.mts +22 -0
- package/dist/types-esm/module-federation-css/remote.d.mts +20 -0
- package/dist/types-esm/runtime-fallback-signal/index.d.mts +4 -0
- package/dist/types-esm/runtime-fallback-signal/model.d.mts +70 -0
- package/dist/types-esm/runtime-fallback-signal/resolver.d.mts +29 -0
- package/dist/types-esm/runtime-fallback-signal/store.d.mts +4 -0
- package/dist/types-esm/runtimeFallbackSignal.d.mts +1 -0
- package/dist/types-esm/runtimeLifecycle.d.mts +10 -0
- package/dist/types-esm/serverConfig.d.mts +17 -0
- package/dist/types-esm/serverPlugin.d.mts +5 -0
- package/dist/types-esm/static-serving/plugin.d.mts +3 -0
- package/dist/types-esm/static-serving/responders.d.mts +2 -0
- package/dist/types-esm/static-serving/staticModuleFederation.d.mts +13 -0
- package/dist/types-esm/static-serving/staticPrecompressed.d.mts +13 -0
- package/dist/types-esm/telemetry/canaryCompatibility.d.mts +19 -0
- package/dist/types-esm/telemetry/envelope.d.mts +55 -0
- package/dist/types-esm/telemetry/exporters.d.mts +12 -0
- package/dist/types-esm/telemetry/healthEvaluation.d.mts +20 -0
- package/dist/types-esm/telemetry/healthMonitor.d.mts +88 -0
- package/dist/types-esm/telemetry/healthSetup.d.mts +19 -0
- package/dist/types-esm/telemetry/lifecycle.d.mts +18 -0
- package/dist/types-esm/telemetry/metrics.d.mts +3 -0
- package/dist/types-esm/telemetry/plugin.d.mts +13 -0
- package/dist/types-esm/telemetry/registry.d.mts +69 -0
- package/dist/types-esm/telemetry/registryTypes.d.mts +50 -0
- package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +37 -0
- package/dist/types-esm/telemetry.d.mts +1 -0
- package/dist/types-esm/telemetryCore.d.mts +6 -0
- package/package.json +158 -26
- package/rslib.config.mts +36 -2
- package/rstest.config.mts +11 -0
- package/src/bff-policy/crossProjectPolicy.ts +781 -0
- package/src/bff-policy/index.ts +1 -0
- package/src/bff-policy/node.ts +2 -0
- package/src/bff-policy/operationContracts.ts +298 -0
- package/src/bff-policy/resolveCrossProjectPolicy.ts +88 -0
- package/src/errorResponsePlugin.ts +21 -0
- package/src/index.ts +4 -0
- package/src/localisedLoaderPlugin.ts +34 -0
- package/src/mfCache.ts +4 -3
- package/src/module-federation-css/plugin.ts +4 -3
- package/src/serverConfig.ts +32 -0
- package/src/serverPlugin.ts +38 -0
- package/src/static-serving/plugin.ts +16 -0
- package/src/static-serving/responders.ts +208 -0
- package/src/static-serving/staticModuleFederation.ts +255 -0
- package/src/static-serving/staticPrecompressed.ts +193 -0
- package/src/telemetry/canaryCompatibility.ts +55 -0
- package/src/telemetry/healthSetup.ts +9 -1
- package/src/telemetry/lifecycle.ts +20 -32
- package/src/telemetry/plugin.ts +6 -2
- package/src/telemetry/runtimeEndpoints.ts +13 -2
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +487 -0
- package/tests/bff-policy/crossProjectPolicy.test.ts +1004 -0
- package/tests/bff-policy/operationContracts.test.ts +221 -0
- package/tests/bff-policy/optionalZodPeer.test.ts +30 -0
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +134 -0
- package/tests/contractGateSnapshotObserver.test.ts +0 -58
- package/tests/env.test.ts +45 -64
- package/tests/localisedLoader.test.ts +120 -0
- package/tests/mfCache.test.ts +1 -88
- package/tests/moduleFederationCss.test.ts +4 -48
- package/tests/nativeErrorResponse.test.ts +199 -0
- package/tests/nativeServerAssembly.test.ts +402 -0
- package/tests/registration.test.ts +1 -86
- package/tests/runtimeLifecycle.test.ts +69 -17
- package/tests/static-serving/ordering.test.ts +214 -0
- package/tests/static-serving/provider.test.ts +83 -0
- package/tests/static-serving/static.test.ts +400 -0
- package/tests/telemetry.test.ts +35 -101
- package/tests/telemetryAutopilot.test.ts +5 -146
- package/tests/telemetryCanaryCompatibility.test.ts +152 -0
- package/tests/telemetryHealthMonitor.test.ts +0 -2
- package/tests/telemetryLifecycle.test.ts +11 -253
- package/tests/telemetryRegistryQueueMatrix.test.ts +0 -1
package/tests/telemetry.test.ts
CHANGED
|
@@ -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
|
|
409
|
-
|
|
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
|
});
|
|
@@ -313,7 +313,7 @@ describe('telemetry autopilot runtime signal', () => {
|
|
|
313
313
|
const payload = (await authorized.json()) as {
|
|
314
314
|
ok?: boolean;
|
|
315
315
|
telemetry?: { queueStats?: { capacity?: number } };
|
|
316
|
-
|
|
316
|
+
health?: { enabled?: boolean };
|
|
317
317
|
runtimeFallbackSignal?: {
|
|
318
318
|
enabled?: boolean;
|
|
319
319
|
endpoint?: string;
|
|
@@ -322,7 +322,7 @@ describe('telemetry autopilot runtime signal', () => {
|
|
|
322
322
|
};
|
|
323
323
|
expect(payload.ok).toBe(true);
|
|
324
324
|
expect(payload.telemetry?.queueStats?.capacity).toBeGreaterThan(0);
|
|
325
|
-
expect(payload.
|
|
325
|
+
expect(payload.health?.enabled).toBe(true);
|
|
326
326
|
expect(payload.runtimeFallbackSignal?.enabled).toBe(true);
|
|
327
327
|
expect(payload.runtimeFallbackSignal?.endpoint).toBe(
|
|
328
328
|
'/_modern/contract-gates/runtime-fallback',
|
|
@@ -442,147 +442,6 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
|
|
|
442
442
|
}
|
|
443
443
|
});
|
|
444
444
|
|
|
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
445
|
test('enforces runtime fallback trust policy before mutating gate snapshots', async () => {
|
|
587
446
|
const tempDir = makeTempDir();
|
|
588
447
|
const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
|
|
@@ -1041,9 +900,9 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
|
|
|
1041
900
|
const payload = (await response.json()) as Record<string, unknown>;
|
|
1042
901
|
expect(payload.ok).toBe(true);
|
|
1043
902
|
expect(typeof payload.timestamp).toBe('number');
|
|
1044
|
-
// No telemetry/
|
|
903
|
+
// No telemetry/health/trust internals are disclosed without auth.
|
|
1045
904
|
expect(payload.telemetry).toBeUndefined();
|
|
1046
|
-
expect(payload.
|
|
905
|
+
expect(payload.health).toBeUndefined();
|
|
1047
906
|
expect(payload.runtimeFallbackSignal).toBeUndefined();
|
|
1048
907
|
} finally {
|
|
1049
908
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
@@ -1125,7 +984,7 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath, options }) => {
|
|
|
1125
984
|
expect(authorized.status).toBe(200);
|
|
1126
985
|
const payload = (await authorized.json()) as Record<string, any>;
|
|
1127
986
|
expect(payload.ok).toBe(true);
|
|
1128
|
-
expect(payload.
|
|
987
|
+
expect(payload.health?.enabled).toBe(true);
|
|
1129
988
|
expect(payload.runtimeFallbackSignal?.enabled).toBe(false);
|
|
1130
989
|
} finally {
|
|
1131
990
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { setupTelemetryHealthMonitoring } from '../src/telemetry/healthSetup';
|
|
2
|
+
import { TelemetryRegistry } from '../src/telemetryCore';
|
|
3
|
+
|
|
4
|
+
const createMonitoring = (initiallyHealthy = true) => {
|
|
5
|
+
const registry = new TelemetryRegistry({
|
|
6
|
+
service: 'svc',
|
|
7
|
+
module: 'server',
|
|
8
|
+
environment: 'test',
|
|
9
|
+
flushIntervalMs: 60_000,
|
|
10
|
+
});
|
|
11
|
+
const monitoring = setupTelemetryHealthMonitoring({
|
|
12
|
+
registry,
|
|
13
|
+
appDirectory: process.cwd(),
|
|
14
|
+
legacyHealthConfig: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
minConsecutiveHealthyEvaluations: 2,
|
|
17
|
+
rollbackConsecutiveFailures: 2,
|
|
18
|
+
contractGates: { contracts: initiallyHealthy },
|
|
19
|
+
autopilot: { enabled: false },
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (!monitoring.healthMonitor || !monitoring.canaryCompatibility) {
|
|
23
|
+
throw new Error('Expected enabled telemetry health monitoring');
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
registry,
|
|
27
|
+
monitor: monitoring.healthMonitor,
|
|
28
|
+
compatibility: monitoring.canaryCompatibility,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('telemetry canary reporting compatibility', () => {
|
|
33
|
+
test('preserves legacy decisions while native health recovers', async () => {
|
|
34
|
+
const { registry, monitor, compatibility } = createMonitoring();
|
|
35
|
+
const enqueueMetric = rs.spyOn(registry, 'enqueueMetric');
|
|
36
|
+
const snapshot = () =>
|
|
37
|
+
compatibility.getStatusSnapshot(monitor.getStatusSnapshot());
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
expect(snapshot().state).toBe('canary');
|
|
41
|
+
monitor.evaluate();
|
|
42
|
+
expect(snapshot().state).toBe('canary');
|
|
43
|
+
monitor.evaluate();
|
|
44
|
+
monitor.evaluate();
|
|
45
|
+
expect(snapshot()).toEqual({
|
|
46
|
+
...monitor.getStatusSnapshot(),
|
|
47
|
+
timestamp: expect.any(Number),
|
|
48
|
+
state: 'promoted',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
monitor.setContractGate('contracts', false, 'schema drift');
|
|
52
|
+
monitor.evaluate();
|
|
53
|
+
expect(snapshot().state).toBe('promoted');
|
|
54
|
+
monitor.evaluate();
|
|
55
|
+
expect(snapshot()).toMatchObject({
|
|
56
|
+
state: 'rolled_back',
|
|
57
|
+
consecutiveFailures: 2,
|
|
58
|
+
failurePreview: [{ reason: 'contract_gate_failed', gate: 'contracts' }],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
monitor.setContractGate('contracts', true);
|
|
62
|
+
monitor.evaluate();
|
|
63
|
+
monitor.evaluate();
|
|
64
|
+
expect(monitor.getStatusSnapshot().state).toBe('healthy');
|
|
65
|
+
expect(snapshot()).toMatchObject({
|
|
66
|
+
state: 'rolled_back',
|
|
67
|
+
consecutiveHealthy: 2,
|
|
68
|
+
failurePreview: [],
|
|
69
|
+
});
|
|
70
|
+
monitor.setContractGate('contracts', false);
|
|
71
|
+
monitor.evaluate();
|
|
72
|
+
monitor.evaluate();
|
|
73
|
+
expect(snapshot().state).toBe('rolled_back');
|
|
74
|
+
|
|
75
|
+
const metrics = enqueueMetric.mock.calls.map(([metric]) => metric);
|
|
76
|
+
expect(
|
|
77
|
+
metrics.filter(metric => metric.name.startsWith('telemetry.canary.')),
|
|
78
|
+
).toEqual([
|
|
79
|
+
{
|
|
80
|
+
name: 'telemetry.canary.promote',
|
|
81
|
+
value: 1,
|
|
82
|
+
unit: 'count',
|
|
83
|
+
tags: { action: 'promote', state: 'promoted', failures: '0' },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'telemetry.canary.rollback',
|
|
87
|
+
value: 1,
|
|
88
|
+
unit: 'count',
|
|
89
|
+
tags: { action: 'rollback', state: 'rolled_back', failures: '1' },
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
expect(
|
|
93
|
+
metrics
|
|
94
|
+
.filter(metric => metric.name === 'telemetry.health.transition')
|
|
95
|
+
.map(metric => metric.tags?.transition),
|
|
96
|
+
).toEqual([
|
|
97
|
+
'became_healthy',
|
|
98
|
+
'became_unhealthy',
|
|
99
|
+
'became_healthy',
|
|
100
|
+
'became_unhealthy',
|
|
101
|
+
]);
|
|
102
|
+
} finally {
|
|
103
|
+
await registry.shutdown();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('does not promote after an initial rollback', async () => {
|
|
108
|
+
const { registry, monitor, compatibility } = createMonitoring(false);
|
|
109
|
+
const enqueueMetric = rs.spyOn(registry, 'enqueueMetric');
|
|
110
|
+
try {
|
|
111
|
+
monitor.evaluate();
|
|
112
|
+
monitor.evaluate();
|
|
113
|
+
monitor.setContractGate('contracts', true);
|
|
114
|
+
monitor.evaluate();
|
|
115
|
+
monitor.evaluate();
|
|
116
|
+
expect(monitor.getStatusSnapshot().state).toBe('healthy');
|
|
117
|
+
expect(
|
|
118
|
+
compatibility.getStatusSnapshot(monitor.getStatusSnapshot()).state,
|
|
119
|
+
).toBe('rolled_back');
|
|
120
|
+
expect(
|
|
121
|
+
enqueueMetric.mock.calls
|
|
122
|
+
.filter(([metric]) => metric.name.startsWith('telemetry.canary.'))
|
|
123
|
+
.map(([metric]) => metric.name),
|
|
124
|
+
).toEqual(['telemetry.canary.rollback']);
|
|
125
|
+
} finally {
|
|
126
|
+
await registry.shutdown();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('isolates metric failures and retains the legacy decision', async () => {
|
|
131
|
+
const { registry, monitor, compatibility } = createMonitoring();
|
|
132
|
+
const enqueueMetric = rs
|
|
133
|
+
.spyOn(registry, 'enqueueMetric')
|
|
134
|
+
.mockImplementation(() => {
|
|
135
|
+
throw new Error('metric unavailable');
|
|
136
|
+
});
|
|
137
|
+
try {
|
|
138
|
+
expect(() => {
|
|
139
|
+
monitor.evaluate();
|
|
140
|
+
monitor.evaluate();
|
|
141
|
+
}).not.toThrow();
|
|
142
|
+
expect(monitor.getStatusSnapshot().state).toBe('healthy');
|
|
143
|
+
expect(
|
|
144
|
+
compatibility.getStatusSnapshot(monitor.getStatusSnapshot()).state,
|
|
145
|
+
).toBe('promoted');
|
|
146
|
+
expect(enqueueMetric).toHaveBeenCalledTimes(2);
|
|
147
|
+
} finally {
|
|
148
|
+
enqueueMetric.mockRestore();
|
|
149
|
+
await registry.shutdown();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -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);
|