@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.6 → 3.5.0-ultramodern.75
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/contract-gate-snapshot-normalization.js +122 -0
- package/dist/cjs/contract-gate-snapshot-store/file-store.js +102 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +133 -0
- package/dist/cjs/contract-gate-snapshot-store/index.js +58 -0
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +124 -0
- package/dist/cjs/contract-gate-snapshot-store/types.js +44 -0
- package/dist/cjs/contractGateAutopilot.js +22 -70
- package/dist/cjs/index.js +6 -25
- package/dist/cjs/mfCache.js +2 -2
- package/dist/cjs/module-federation-css/collector.js +79 -0
- package/dist/cjs/module-federation-css/index.js +55 -0
- package/dist/cjs/module-federation-css/manifest.js +129 -0
- package/dist/cjs/module-federation-css/plugin.js +71 -0
- package/dist/cjs/module-federation-css/remote.js +133 -0
- package/dist/cjs/runtime-fallback-signal/index.js +93 -0
- package/dist/cjs/runtime-fallback-signal/model.js +157 -0
- package/dist/cjs/runtime-fallback-signal/resolver.js +163 -0
- package/dist/cjs/runtime-fallback-signal/store.js +83 -0
- package/dist/cjs/runtimeFallbackSignal.js +32 -281
- package/dist/cjs/telemetry/canary.js +180 -0
- package/dist/cjs/telemetry/canaryEvaluation.js +79 -0
- package/dist/cjs/telemetry/canarySetup.js +107 -0
- package/dist/cjs/telemetry/envelope.js +223 -0
- package/dist/cjs/telemetry/exporters.js +148 -0
- package/dist/cjs/telemetry/lifecycle.js +98 -0
- package/dist/cjs/telemetry/metrics.js +115 -0
- package/dist/cjs/telemetry/plugin.js +185 -0
- package/dist/cjs/telemetry/registry.js +296 -0
- package/dist/cjs/telemetry/registryTypes.js +46 -0
- package/dist/cjs/telemetry/runtimeEndpoints.js +135 -0
- package/dist/cjs/telemetry.js +32 -343
- package/dist/cjs/telemetryCore.js +14 -767
- package/dist/esm/contract-gate-snapshot-normalization.mjs +81 -0
- package/dist/esm/contract-gate-snapshot-store/file-store.mjs +51 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +92 -0
- package/dist/esm/contract-gate-snapshot-store/index.mjs +4 -0
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +70 -0
- package/dist/esm/contract-gate-snapshot-store/types.mjs +3 -0
- package/dist/esm/contractGateAutopilot.mjs +21 -69
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/mfCache.mjs +2 -2
- package/dist/esm/module-federation-css/collector.mjs +38 -0
- package/dist/esm/module-federation-css/index.mjs +4 -0
- package/dist/esm/module-federation-css/manifest.mjs +69 -0
- package/dist/esm/module-federation-css/plugin.mjs +33 -0
- package/dist/esm/module-federation-css/remote.mjs +92 -0
- package/dist/esm/runtime-fallback-signal/index.mjs +3 -0
- package/dist/esm/runtime-fallback-signal/model.mjs +73 -0
- package/dist/esm/runtime-fallback-signal/resolver.mjs +107 -0
- package/dist/esm/runtime-fallback-signal/store.mjs +39 -0
- package/dist/esm/runtimeFallbackSignal.mjs +1 -222
- package/dist/esm/telemetry/canary.mjs +142 -0
- package/dist/esm/telemetry/canaryEvaluation.mjs +41 -0
- package/dist/esm/telemetry/canarySetup.mjs +69 -0
- package/dist/esm/telemetry/envelope.mjs +164 -0
- package/dist/esm/telemetry/exporters.mjs +104 -0
- package/dist/esm/telemetry/lifecycle.mjs +60 -0
- package/dist/esm/telemetry/metrics.mjs +77 -0
- package/dist/esm/telemetry/plugin.mjs +87 -0
- package/dist/esm/telemetry/registry.mjs +258 -0
- package/dist/esm/telemetry/registryTypes.mjs +8 -0
- package/dist/esm/telemetry/runtimeEndpoints.mjs +94 -0
- package/dist/esm/telemetry.mjs +1 -275
- package/dist/esm/telemetryCore.mjs +6 -759
- package/dist/esm-node/contract-gate-snapshot-normalization.mjs +82 -0
- package/dist/esm-node/contract-gate-snapshot-store/file-store.mjs +52 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +93 -0
- package/dist/esm-node/contract-gate-snapshot-store/index.mjs +5 -0
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +71 -0
- package/dist/esm-node/contract-gate-snapshot-store/types.mjs +4 -0
- package/dist/esm-node/contractGateAutopilot.mjs +21 -69
- package/dist/esm-node/index.mjs +1 -2
- package/dist/esm-node/mfCache.mjs +2 -2
- package/dist/esm-node/module-federation-css/collector.mjs +39 -0
- package/dist/esm-node/module-federation-css/index.mjs +5 -0
- package/dist/esm-node/module-federation-css/manifest.mjs +70 -0
- package/dist/esm-node/module-federation-css/plugin.mjs +34 -0
- package/dist/esm-node/module-federation-css/remote.mjs +93 -0
- package/dist/esm-node/runtime-fallback-signal/index.mjs +4 -0
- package/dist/esm-node/runtime-fallback-signal/model.mjs +74 -0
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +108 -0
- package/dist/esm-node/runtime-fallback-signal/store.mjs +40 -0
- package/dist/esm-node/runtimeFallbackSignal.mjs +1 -222
- package/dist/esm-node/telemetry/canary.mjs +143 -0
- package/dist/esm-node/telemetry/canaryEvaluation.mjs +42 -0
- package/dist/esm-node/telemetry/canarySetup.mjs +70 -0
- package/dist/esm-node/telemetry/envelope.mjs +165 -0
- package/dist/esm-node/telemetry/exporters.mjs +105 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +61 -0
- package/dist/esm-node/telemetry/metrics.mjs +78 -0
- package/dist/esm-node/telemetry/plugin.mjs +88 -0
- package/dist/esm-node/telemetry/registry.mjs +259 -0
- package/dist/esm-node/telemetry/registryTypes.mjs +9 -0
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +95 -0
- package/dist/esm-node/telemetry.mjs +1 -275
- package/dist/esm-node/telemetryCore.mjs +6 -759
- package/dist/types/contract-gate-snapshot-normalization.d.ts +15 -0
- package/dist/types/contract-gate-snapshot-store/file-store.d.ts +3 -0
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +5 -0
- package/dist/types/contract-gate-snapshot-store/index.d.ts +5 -0
- package/dist/types/contract-gate-snapshot-store/resolve.d.ts +9 -0
- package/dist/types/{contractGateSnapshotStore.d.ts → contract-gate-snapshot-store/types.d.ts} +1 -11
- package/dist/types/contractGateAutopilot.d.ts +3 -6
- package/dist/types/index.d.ts +1 -2
- package/dist/types/module-federation-css/collector.d.ts +25 -0
- package/dist/types/module-federation-css/index.d.ts +8 -0
- package/dist/types/module-federation-css/manifest.d.ts +28 -0
- package/dist/types/module-federation-css/plugin.d.ts +23 -0
- package/dist/types/module-federation-css/remote.d.ts +20 -0
- package/dist/types/runtime-fallback-signal/index.d.ts +4 -0
- package/dist/types/runtime-fallback-signal/model.d.ts +70 -0
- package/dist/types/runtime-fallback-signal/resolver.d.ts +29 -0
- package/dist/types/runtime-fallback-signal/store.d.ts +4 -0
- package/dist/types/runtimeFallbackSignal.d.ts +1 -94
- package/dist/types/telemetry/canary.d.ts +85 -0
- package/dist/types/telemetry/canaryEvaluation.d.ts +20 -0
- package/dist/types/telemetry/canarySetup.d.ts +17 -0
- package/dist/types/telemetry/envelope.d.ts +55 -0
- package/dist/types/telemetry/exporters.d.ts +12 -0
- package/dist/types/telemetry/lifecycle.d.ts +18 -0
- package/dist/types/telemetry/metrics.d.ts +3 -0
- package/dist/types/telemetry/plugin.d.ts +12 -0
- package/dist/types/telemetry/registry.d.ts +69 -0
- package/dist/types/telemetry/registryTypes.d.ts +50 -0
- package/dist/types/telemetry/runtimeEndpoints.d.ts +35 -0
- package/dist/types/telemetry.d.ts +1 -12
- package/dist/types/telemetryCore.d.ts +6 -257
- package/package.json +11 -13
- package/src/contract-gate-snapshot-normalization.ts +155 -0
- package/src/contract-gate-snapshot-store/file-store.ts +83 -0
- package/src/contract-gate-snapshot-store/http-store.ts +159 -0
- package/src/contract-gate-snapshot-store/index.ts +20 -0
- package/src/contract-gate-snapshot-store/resolve.ts +179 -0
- package/src/contract-gate-snapshot-store/types.ts +64 -0
- package/src/contractGateAutopilot.ts +39 -131
- package/src/index.ts +1 -17
- package/src/mfCache.ts +3 -1
- package/src/module-federation-css/collector.ts +82 -0
- package/src/module-federation-css/index.ts +14 -0
- package/src/module-federation-css/manifest.ts +163 -0
- package/src/module-federation-css/plugin.ts +86 -0
- package/src/module-federation-css/remote.ts +165 -0
- package/src/runtime-fallback-signal/index.ts +34 -0
- package/src/runtime-fallback-signal/model.ts +230 -0
- package/src/runtime-fallback-signal/resolver.ts +304 -0
- package/src/runtime-fallback-signal/store.ts +78 -0
- package/src/runtimeFallbackSignal.ts +1 -584
- package/src/telemetry/canary.ts +291 -0
- package/src/telemetry/canaryEvaluation.ts +83 -0
- package/src/telemetry/canarySetup.ts +160 -0
- package/src/telemetry/envelope.ts +277 -0
- package/src/telemetry/exporters.ts +165 -0
- package/src/telemetry/lifecycle.ts +138 -0
- package/src/telemetry/metrics.ts +141 -0
- package/src/telemetry/plugin.ts +197 -0
- package/src/telemetry/registry.ts +424 -0
- package/src/telemetry/registryTypes.ts +63 -0
- package/src/telemetry/runtimeEndpoints.ts +172 -0
- package/src/telemetry.ts +1 -554
- package/src/telemetryCore.ts +34 -1332
- package/tests/contractGateAutopilot.test.ts +205 -0
- package/tests/contractGateSnapshotStore.test.ts +54 -1
- package/tests/helpers.ts +1 -0
- package/tests/moduleFederationCss.test.ts +1 -1
- package/tests/registration.test.ts +1 -1
- package/tests/telemetry.test.ts +51 -0
- package/tests/telemetryAutopilot.test.ts +141 -0
- package/tests/telemetryCanaryOrchestrator.test.ts +225 -0
- package/tests/telemetryLifecycle.test.ts +253 -2
- package/tests/telemetryRegistryQueueMatrix.test.ts +227 -0
- package/dist/cjs/contractGateSnapshotStore.js +0 -253
- package/dist/cjs/moduleFederationCss.js +0 -285
- package/dist/esm/contractGateSnapshotStore.mjs +0 -190
- package/dist/esm/moduleFederationCss.mjs +0 -225
- package/dist/esm-node/contractGateSnapshotStore.mjs +0 -192
- package/dist/esm-node/moduleFederationCss.mjs +0 -226
- package/dist/types/moduleFederationCss.d.ts +0 -87
- package/src/contractGateSnapshotStore.ts +0 -420
- package/src/moduleFederationCss.ts +0 -473
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import type { GateSnapshot } from '../src/contract-gate-snapshot-store';
|
|
4
5
|
import { ContractGateAutopilot } from '../src/contractGateAutopilot';
|
|
5
6
|
import {
|
|
6
7
|
TelemetryCanaryOrchestrator,
|
|
@@ -149,6 +150,210 @@ describe('contract gate autopilot', () => {
|
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
|
|
153
|
+
test('marks unchanged gate snapshots stale after the stale window elapses', async () => {
|
|
154
|
+
const dir = makeTempDir();
|
|
155
|
+
const snapshotPath = path.join(dir, 'contract-gates.json');
|
|
156
|
+
const originalDateNow = Date.now;
|
|
157
|
+
let now = 1_000_000;
|
|
158
|
+
Date.now = () => now;
|
|
159
|
+
|
|
160
|
+
const registry = new TelemetryRegistry({
|
|
161
|
+
service: 'svc',
|
|
162
|
+
module: 'server',
|
|
163
|
+
environment: 'test',
|
|
164
|
+
flushIntervalMs: 60_000,
|
|
165
|
+
});
|
|
166
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
167
|
+
registry,
|
|
168
|
+
rollbackConsecutiveFailures: 1,
|
|
169
|
+
});
|
|
170
|
+
fs.writeFileSync(
|
|
171
|
+
snapshotPath,
|
|
172
|
+
JSON.stringify(
|
|
173
|
+
{
|
|
174
|
+
schemaVersion: 1,
|
|
175
|
+
updatedAt: now,
|
|
176
|
+
gates: {
|
|
177
|
+
'module-onboarding-certification-gates': {
|
|
178
|
+
passed: true,
|
|
179
|
+
updatedAt: now,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
null,
|
|
184
|
+
2,
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const autopilot = new ContractGateAutopilot({
|
|
189
|
+
orchestrator,
|
|
190
|
+
gateSnapshotPath: snapshotPath,
|
|
191
|
+
gateStaleAfterMs: 1_000,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
await autopilot.syncOnce();
|
|
196
|
+
expect(orchestrator.evaluate().failures).toHaveLength(0);
|
|
197
|
+
|
|
198
|
+
now += 1_001;
|
|
199
|
+
await autopilot.syncOnce();
|
|
200
|
+
|
|
201
|
+
const decision = orchestrator.evaluate();
|
|
202
|
+
expect(decision.action).toBe('rollback');
|
|
203
|
+
expect(
|
|
204
|
+
decision.failures.some(
|
|
205
|
+
item =>
|
|
206
|
+
item.reason === 'contract_gate_failed' &&
|
|
207
|
+
item.gate === 'module-onboarding-certification-gates',
|
|
208
|
+
),
|
|
209
|
+
).toBe(true);
|
|
210
|
+
} finally {
|
|
211
|
+
Date.now = originalDateNow;
|
|
212
|
+
autopilot.stop();
|
|
213
|
+
await registry.shutdown();
|
|
214
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('ignores older snapshot reads that resolve after newer syncs', async () => {
|
|
219
|
+
const registry = new TelemetryRegistry({
|
|
220
|
+
service: 'svc',
|
|
221
|
+
module: 'server',
|
|
222
|
+
environment: 'test',
|
|
223
|
+
flushIntervalMs: 60_000,
|
|
224
|
+
});
|
|
225
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
226
|
+
registry,
|
|
227
|
+
rollbackConsecutiveFailures: 1,
|
|
228
|
+
});
|
|
229
|
+
const snapshotResolvers: Array<
|
|
230
|
+
(snapshot: GateSnapshot | undefined) => void
|
|
231
|
+
> = [];
|
|
232
|
+
const autopilot = new ContractGateAutopilot({
|
|
233
|
+
orchestrator,
|
|
234
|
+
gateSnapshotStore: {
|
|
235
|
+
name: 'deferred',
|
|
236
|
+
readSnapshot: () =>
|
|
237
|
+
new Promise<GateSnapshot | undefined>(resolve => {
|
|
238
|
+
snapshotResolvers.push(resolve);
|
|
239
|
+
}),
|
|
240
|
+
writeSnapshot: async () => {},
|
|
241
|
+
},
|
|
242
|
+
gateStaleAfterMs: 0,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
const olderSync = autopilot.syncOnce();
|
|
247
|
+
const newerSync = autopilot.syncOnce();
|
|
248
|
+
expect(snapshotResolvers).toHaveLength(2);
|
|
249
|
+
|
|
250
|
+
snapshotResolvers[1]?.({
|
|
251
|
+
schemaVersion: 1,
|
|
252
|
+
updatedAt: 2_000,
|
|
253
|
+
gates: {
|
|
254
|
+
'module-onboarding-certification-gates': {
|
|
255
|
+
passed: true,
|
|
256
|
+
updatedAt: 2_000,
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
await newerSync;
|
|
261
|
+
expect(orchestrator.evaluate().failures).toHaveLength(0);
|
|
262
|
+
|
|
263
|
+
snapshotResolvers[0]?.({
|
|
264
|
+
schemaVersion: 1,
|
|
265
|
+
updatedAt: 1_000,
|
|
266
|
+
gates: {
|
|
267
|
+
'module-onboarding-certification-gates': {
|
|
268
|
+
passed: false,
|
|
269
|
+
reason: 'older snapshot resolved late',
|
|
270
|
+
updatedAt: 1_000,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
await olderSync;
|
|
275
|
+
|
|
276
|
+
expect(orchestrator.evaluate().failures).toHaveLength(0);
|
|
277
|
+
} finally {
|
|
278
|
+
autopilot.stop();
|
|
279
|
+
await registry.shutdown();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('clears previously applied gate failures when snapshots omit them', async () => {
|
|
284
|
+
const dir = makeTempDir();
|
|
285
|
+
const snapshotPath = path.join(dir, 'contract-gates.json');
|
|
286
|
+
|
|
287
|
+
const registry = new TelemetryRegistry({
|
|
288
|
+
service: 'svc',
|
|
289
|
+
module: 'server',
|
|
290
|
+
environment: 'test',
|
|
291
|
+
flushIntervalMs: 60_000,
|
|
292
|
+
});
|
|
293
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
294
|
+
registry,
|
|
295
|
+
rollbackConsecutiveFailures: 1,
|
|
296
|
+
});
|
|
297
|
+
const autopilot = new ContractGateAutopilot({
|
|
298
|
+
orchestrator,
|
|
299
|
+
gateSnapshotPath: snapshotPath,
|
|
300
|
+
gateStaleAfterMs: 60_000,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
const now = Date.now();
|
|
305
|
+
fs.writeFileSync(
|
|
306
|
+
snapshotPath,
|
|
307
|
+
JSON.stringify(
|
|
308
|
+
{
|
|
309
|
+
schemaVersion: 1,
|
|
310
|
+
updatedAt: now,
|
|
311
|
+
gates: {
|
|
312
|
+
'runtime-mf-fallback-health': {
|
|
313
|
+
passed: false,
|
|
314
|
+
reason: 'runtime_fallback:remote_load_failed',
|
|
315
|
+
updatedAt: now,
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
null,
|
|
320
|
+
2,
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
await autopilot.syncOnce();
|
|
325
|
+
expect(
|
|
326
|
+
orchestrator
|
|
327
|
+
.evaluate()
|
|
328
|
+
.failures.some(
|
|
329
|
+
item =>
|
|
330
|
+
item.reason === 'contract_gate_failed' &&
|
|
331
|
+
item.gate === 'runtime-mf-fallback-health',
|
|
332
|
+
),
|
|
333
|
+
).toBe(true);
|
|
334
|
+
|
|
335
|
+
fs.writeFileSync(
|
|
336
|
+
snapshotPath,
|
|
337
|
+
JSON.stringify(
|
|
338
|
+
{
|
|
339
|
+
schemaVersion: 1,
|
|
340
|
+
updatedAt: Date.now(),
|
|
341
|
+
gates: {},
|
|
342
|
+
},
|
|
343
|
+
null,
|
|
344
|
+
2,
|
|
345
|
+
),
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
await autopilot.syncOnce();
|
|
349
|
+
expect(orchestrator.evaluate().failures).toHaveLength(0);
|
|
350
|
+
} finally {
|
|
351
|
+
autopilot.stop();
|
|
352
|
+
await registry.shutdown();
|
|
353
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
152
357
|
test('auto-recovers runtime fallback gates after expiry window', async () => {
|
|
153
358
|
const dir = makeTempDir();
|
|
154
359
|
const snapshotPath = path.join(dir, 'contract-gates.json');
|
|
@@ -3,9 +3,10 @@ import { createServer } from 'http';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import {
|
|
6
|
+
createFileContractGateSnapshotStore,
|
|
6
7
|
type GateSnapshot,
|
|
7
8
|
resolveContractGateSnapshotStore,
|
|
8
|
-
} from '../src/
|
|
9
|
+
} from '../src/contract-gate-snapshot-store';
|
|
9
10
|
|
|
10
11
|
const makeTempAppDir = () =>
|
|
11
12
|
fs.mkdtempSync(path.join(os.tmpdir(), 'modern-gate-store-app-'));
|
|
@@ -26,6 +27,58 @@ exports.createContractGateSnapshotStore = ({ gateSnapshotPath }) => {
|
|
|
26
27
|
`;
|
|
27
28
|
|
|
28
29
|
describe('contract gate snapshot store', () => {
|
|
30
|
+
test('preserves previous file snapshot when write fails mid-write', async () => {
|
|
31
|
+
const appDirectory = makeTempAppDir();
|
|
32
|
+
try {
|
|
33
|
+
const snapshotPath = path.join(
|
|
34
|
+
appDirectory,
|
|
35
|
+
'.modern/contract-gates.json',
|
|
36
|
+
);
|
|
37
|
+
const store = createFileContractGateSnapshotStore(snapshotPath);
|
|
38
|
+
const initialSnapshot: GateSnapshot = {
|
|
39
|
+
schemaVersion: 1,
|
|
40
|
+
updatedAt: 1,
|
|
41
|
+
gates: {
|
|
42
|
+
'runtime-mf-fallback-health': { passed: true },
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
await store.writeSnapshot(initialSnapshot);
|
|
47
|
+
|
|
48
|
+
const realWriteFile = fs.promises.writeFile.bind(fs.promises);
|
|
49
|
+
let sabotagedWrite = false;
|
|
50
|
+
const writeSpy = rs
|
|
51
|
+
.spyOn(fs.promises, 'writeFile')
|
|
52
|
+
.mockImplementation(async (file, _data, options) => {
|
|
53
|
+
if (!sabotagedWrite) {
|
|
54
|
+
sabotagedWrite = true;
|
|
55
|
+
await realWriteFile(file, '{broken', options);
|
|
56
|
+
throw new Error('simulated write interruption');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return realWriteFile(file, _data, options);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await expect(
|
|
64
|
+
store.writeSnapshot({
|
|
65
|
+
schemaVersion: 1,
|
|
66
|
+
updatedAt: 2,
|
|
67
|
+
gates: {
|
|
68
|
+
'runtime-mf-fallback-health': { passed: false },
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
).rejects.toThrow('simulated write interruption');
|
|
72
|
+
} finally {
|
|
73
|
+
writeSpy.mockRestore();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await expect(store.readSnapshot()).resolves.toEqual(initialSnapshot);
|
|
77
|
+
} finally {
|
|
78
|
+
fs.rmSync(appDirectory, { recursive: true, force: true });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
29
82
|
test('supports built-in http stateStore adapter', async () => {
|
|
30
83
|
let snapshot: GateSnapshot | undefined;
|
|
31
84
|
|
package/tests/helpers.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import os from 'os';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import { injectModuleFederationCssPlugin } from '../src/
|
|
9
|
+
import { injectModuleFederationCssPlugin } from '../src/module-federation-css';
|
|
10
10
|
import { getDefaultAppContext, getDefaultConfig } from './helpers';
|
|
11
11
|
|
|
12
12
|
describe('plugin registration', () => {
|
package/tests/telemetry.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
TelemetryRegistry,
|
|
7
7
|
TelemetryStartupHealthError,
|
|
8
8
|
} from '../src/telemetry';
|
|
9
|
+
import { clamp } from '../src/telemetry/envelope';
|
|
9
10
|
|
|
10
11
|
const createEnvelope = (partial: Record<string, unknown> = {}) => ({
|
|
11
12
|
timestamp: Date.now(),
|
|
@@ -19,6 +20,16 @@ const createEnvelope = (partial: Record<string, unknown> = {}) => ({
|
|
|
19
20
|
...partial,
|
|
20
21
|
});
|
|
21
22
|
|
|
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
|
+
|
|
22
33
|
describe('telemetry registry', () => {
|
|
23
34
|
test('applies redaction and emits dropped-count metric under backpressure', async () => {
|
|
24
35
|
const batches: unknown[] = [];
|
|
@@ -241,6 +252,46 @@ describe('telemetry registry', () => {
|
|
|
241
252
|
await registry.shutdown();
|
|
242
253
|
});
|
|
243
254
|
|
|
255
|
+
test('drop SLO alerts use pending drop pressure instead of lifetime drops', async () => {
|
|
256
|
+
const dropAlerts: Array<{ value: number; totalDropped: number }> = [];
|
|
257
|
+
const registry = new TelemetryRegistry({
|
|
258
|
+
service: 'svc',
|
|
259
|
+
module: 'server',
|
|
260
|
+
environment: 'test',
|
|
261
|
+
maxQueueSize: 1,
|
|
262
|
+
flushIntervalMs: 60_000,
|
|
263
|
+
slo: {
|
|
264
|
+
queueDroppedWarnThreshold: 2,
|
|
265
|
+
alertCooldownMs: 0,
|
|
266
|
+
onAlert(alert) {
|
|
267
|
+
if (alert.type === 'queue.drop') {
|
|
268
|
+
dropAlerts.push({
|
|
269
|
+
value: alert.value,
|
|
270
|
+
totalDropped: alert.totalDropped,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
registry.enqueue(createEnvelope({ name: 'first' }));
|
|
278
|
+
registry.enqueue(createEnvelope({ name: 'second' }));
|
|
279
|
+
expect(registry.getQueueStats().pendingDropped).toBe(1);
|
|
280
|
+
expect(dropAlerts).toEqual([]);
|
|
281
|
+
|
|
282
|
+
await registry.flush();
|
|
283
|
+
expect(registry.getQueueStats().pendingDropped).toBe(0);
|
|
284
|
+
expect(registry.getQueueStats().totalDropped).toBe(1);
|
|
285
|
+
|
|
286
|
+
registry.enqueue(createEnvelope({ name: 'third' }));
|
|
287
|
+
registry.enqueue(createEnvelope({ name: 'fourth' }));
|
|
288
|
+
|
|
289
|
+
expect(registry.getQueueStats().pendingDropped).toBe(1);
|
|
290
|
+
expect(registry.getQueueStats().totalDropped).toBe(2);
|
|
291
|
+
expect(dropAlerts).toEqual([]);
|
|
292
|
+
await registry.shutdown();
|
|
293
|
+
});
|
|
294
|
+
|
|
244
295
|
test('startup health check fails loud by default when exporter is unhealthy', async () => {
|
|
245
296
|
const registry = new TelemetryRegistry({
|
|
246
297
|
service: 'svc',
|
|
@@ -442,6 +442,147 @@ 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
|
+
|
|
445
586
|
test('enforces runtime fallback trust policy before mutating gate snapshots', async () => {
|
|
446
587
|
const tempDir = makeTempDir();
|
|
447
588
|
const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
|