supercov 0.0.8 → 0.0.11

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 (117) hide show
  1. package/README.md +14 -1
  2. package/bin/native.js +87 -0
  3. package/bin/supercov.js +20 -3
  4. package/dist/agentJson.d.ts +2 -1
  5. package/dist/agentJson.d.ts.map +1 -1
  6. package/dist/agentJson.js +18 -0
  7. package/dist/agentJson.js.map +1 -1
  8. package/dist/analyze.d.ts.map +1 -1
  9. package/dist/analyze.js +9 -5
  10. package/dist/analyze.js.map +1 -1
  11. package/dist/cli.js +126 -23
  12. package/dist/cli.js.map +1 -1
  13. package/dist/directInstrumenter.d.ts.map +1 -1
  14. package/dist/directInstrumenter.js +39 -19
  15. package/dist/directInstrumenter.js.map +1 -1
  16. package/dist/engineEvidence.d.ts +9 -0
  17. package/dist/engineEvidence.d.ts.map +1 -0
  18. package/dist/engineEvidence.js +31 -0
  19. package/dist/engineEvidence.js.map +1 -0
  20. package/dist/engineInstrumenter.d.ts +16 -0
  21. package/dist/engineInstrumenter.d.ts.map +1 -0
  22. package/dist/engineInstrumenter.js +50 -0
  23. package/dist/engineInstrumenter.js.map +1 -0
  24. package/dist/engineProcess.d.ts +11 -0
  25. package/dist/engineProcess.d.ts.map +1 -0
  26. package/dist/engineProcess.js +59 -0
  27. package/dist/engineProcess.js.map +1 -0
  28. package/dist/evidenceArchive.d.ts +1 -0
  29. package/dist/evidenceArchive.d.ts.map +1 -1
  30. package/dist/evidenceArchive.js +59 -13
  31. package/dist/evidenceArchive.js.map +1 -1
  32. package/dist/instrumenter.d.ts +8 -1
  33. package/dist/instrumenter.d.ts.map +1 -1
  34. package/dist/instrumenter.js +585 -113
  35. package/dist/instrumenter.js.map +1 -1
  36. package/dist/integrity.d.ts.map +1 -1
  37. package/dist/integrity.js +20 -1
  38. package/dist/integrity.js.map +1 -1
  39. package/dist/launchSupervisor.d.ts.map +1 -1
  40. package/dist/launchSupervisor.js +3 -0
  41. package/dist/launchSupervisor.js.map +1 -1
  42. package/dist/merge.d.ts.map +1 -1
  43. package/dist/merge.js +9 -6
  44. package/dist/merge.js.map +1 -1
  45. package/dist/nodeAssert.d.ts +31 -0
  46. package/dist/nodeAssert.d.ts.map +1 -0
  47. package/dist/nodeAssert.js +30 -0
  48. package/dist/nodeAssert.js.map +1 -0
  49. package/dist/nodeAssertAdapter.d.ts +6 -0
  50. package/dist/nodeAssertAdapter.d.ts.map +1 -0
  51. package/dist/nodeAssertAdapter.js +94 -0
  52. package/dist/nodeAssertAdapter.js.map +1 -0
  53. package/dist/nodeAssertStrict.d.ts +31 -0
  54. package/dist/nodeAssertStrict.d.ts.map +1 -0
  55. package/dist/nodeAssertStrict.js +28 -0
  56. package/dist/nodeAssertStrict.js.map +1 -0
  57. package/dist/nodeAssertionInstrumenter.d.ts +8 -0
  58. package/dist/nodeAssertionInstrumenter.d.ts.map +1 -0
  59. package/dist/nodeAssertionInstrumenter.js +271 -0
  60. package/dist/nodeAssertionInstrumenter.js.map +1 -0
  61. package/dist/nodeTest.d.ts.map +1 -1
  62. package/dist/nodeTest.js +14 -5
  63. package/dist/nodeTest.js.map +1 -1
  64. package/dist/playwright.d.ts.map +1 -1
  65. package/dist/playwright.js +177 -89
  66. package/dist/playwright.js.map +1 -1
  67. package/dist/processDiagnostics.d.ts +34 -0
  68. package/dist/processDiagnostics.d.ts.map +1 -0
  69. package/dist/processDiagnostics.js +155 -0
  70. package/dist/processDiagnostics.js.map +1 -0
  71. package/dist/project.d.ts +1 -0
  72. package/dist/project.d.ts.map +1 -1
  73. package/dist/project.js +39 -4
  74. package/dist/project.js.map +1 -1
  75. package/dist/query.d.ts +11 -0
  76. package/dist/query.d.ts.map +1 -1
  77. package/dist/query.js +224 -11
  78. package/dist/query.js.map +1 -1
  79. package/dist/register.mjs +97 -4
  80. package/dist/register.mjs.map +1 -1
  81. package/dist/resolve-loader.d.mts.map +1 -1
  82. package/dist/resolve-loader.mjs +16 -2
  83. package/dist/resolve-loader.mjs.map +1 -1
  84. package/dist/runAnalysis.d.ts.map +1 -1
  85. package/dist/runAnalysis.js +3 -1
  86. package/dist/runAnalysis.js.map +1 -1
  87. package/dist/runnerEvidence.d.ts +3 -3
  88. package/dist/runnerEvidence.d.ts.map +1 -1
  89. package/dist/runnerEvidence.js +7 -4
  90. package/dist/runnerEvidence.js.map +1 -1
  91. package/dist/runtime.d.ts +77 -4
  92. package/dist/runtime.d.ts.map +1 -1
  93. package/dist/runtime.js +395 -26
  94. package/dist/runtime.js.map +1 -1
  95. package/dist/runtimeIsolation.d.ts +3 -0
  96. package/dist/runtimeIsolation.d.ts.map +1 -0
  97. package/dist/runtimeIsolation.js +9 -0
  98. package/dist/runtimeIsolation.js.map +1 -0
  99. package/dist/sourceDiscovery.d.ts.map +1 -1
  100. package/dist/sourceDiscovery.js +7 -2
  101. package/dist/sourceDiscovery.js.map +1 -1
  102. package/dist/transport.js +2 -2
  103. package/dist/transport.js.map +1 -1
  104. package/dist/vitePlugin.d.ts.map +1 -1
  105. package/dist/vitePlugin.js +21 -7
  106. package/dist/vitePlugin.js.map +1 -1
  107. package/dist/vitest.js +38 -7
  108. package/dist/vitest.js.map +1 -1
  109. package/dist/waivers.d.ts +52 -0
  110. package/dist/waivers.d.ts.map +1 -0
  111. package/dist/waivers.js +121 -0
  112. package/dist/waivers.js.map +1 -0
  113. package/dist/workspace.d.ts +36 -0
  114. package/dist/workspace.d.ts.map +1 -1
  115. package/dist/workspace.js +216 -37
  116. package/dist/workspace.js.map +1 -1
  117. package/package.json +29 -3
package/dist/runtime.js CHANGED
@@ -102,10 +102,10 @@ function serverRunEvidenceDirectory(runId, root = configuredServerEvidenceRoot()
102
102
  return `${root.replace(/\/+$/, "")}/${pathComponent(runId)}`;
103
103
  }
104
104
  function serverEvidenceDirectory(scope, root = configuredServerEvidenceRoot()) {
105
- return `${serverRunEvidenceDirectory(scope.runId, root)}/${pathComponent(scope.workerId)}/${scope.testKey}/${scope.retry}`;
105
+ return `${serverRunEvidenceDirectory(scope.runId, root)}/attempts`;
106
106
  }
107
107
  function serverEvidencePath(scope, root = configuredServerEvidenceRoot()) {
108
- return `${serverEvidenceDirectory(scope, root)}/server.jsonl`;
108
+ return `${serverEvidenceDirectory(scope, root)}/${pathComponent(scope.attemptId)}.jsonl`;
109
109
  }
110
110
  function backgroundEvidenceDirectory(runId, root = configuredServerEvidenceRoot()) {
111
111
  return `${serverRunEvidenceDirectory(runId, root)}/background`;
@@ -148,8 +148,15 @@ function createState() {
148
148
  bufferedAttempts: /* @__PURE__ */ new Set(),
149
149
  serverBuffers: /* @__PURE__ */ new Map(),
150
150
  persistedServerRecords: /* @__PURE__ */ new Set(),
151
+ backgroundBuffers: /* @__PURE__ */ new Map(),
151
152
  backgroundSequence: 0,
152
- runtimeSnapshots: false
153
+ runtimeSnapshots: false,
154
+ assertionPhases: /* @__PURE__ */ new Map(),
155
+ probeV2Files: /* @__PURE__ */ new Set(),
156
+ probeV2Clock: { epoch: Number.NaN, fast: false },
157
+ probeV2ContextEpochs: /* @__PURE__ */ new Map(),
158
+ probeV2NextEpoch: 1,
159
+ probeV2HookInstalled: false
153
160
  };
154
161
  if (!isBrowser)
155
162
  return state2;
@@ -196,6 +203,83 @@ var _a6;
196
203
  var serverPhaseStorage = (_a6 = serverPhaseStorages.get(runtimeInstance)) != null ? _a6 : createServerPhaseStorage();
197
204
  if (serverPhaseStorage)
198
205
  serverPhaseStorages.set(runtimeInstance, serverPhaseStorage);
206
+ function probeV2ContextKey(context) {
207
+ var _a8, _b;
208
+ const phase = (_a8 = context.phaseId) != null ? _a8 : "unscoped";
209
+ if (!context.scope) {
210
+ const runId = typeof process !== "undefined" ? process.env["SUPERCOV_RUN_ID"] : void 0;
211
+ return `background\0${(_b = runId != null ? runId : runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__) != null ? _b : testId}\0${phase}`;
212
+ }
213
+ return `scope\0${attemptKey(context.scope)}\0${phase}`;
214
+ }
215
+ function activateProbeV2Key(key, force = false) {
216
+ let epoch = force ? void 0 : state.probeV2ContextEpochs.get(key);
217
+ if (epoch === void 0) {
218
+ state.probeV2NextEpoch += 1;
219
+ if (state.probeV2NextEpoch >= 4294967295) {
220
+ state.probeV2NextEpoch = 1;
221
+ state.probeV2ContextEpochs.clear();
222
+ for (const file of state.probeV2Files) {
223
+ file.hitEpochs.fill(0);
224
+ file.decisionObservationEpochs.fill(0);
225
+ file.decisionObservationCounts.fill(0);
226
+ file.decisionCompleteEpochs.fill(0);
227
+ for (const vectors of file.decisionEpochs) {
228
+ if (vectors instanceof Uint32Array)
229
+ vectors.fill(0);
230
+ else
231
+ vectors.clear();
232
+ }
233
+ }
234
+ }
235
+ epoch = state.probeV2NextEpoch;
236
+ state.probeV2ContextEpochs.set(key, epoch);
237
+ }
238
+ state.probeV2Clock.epoch = epoch;
239
+ return epoch;
240
+ }
241
+ function activateProbeV2Context(context) {
242
+ return activateProbeV2Key(probeV2ContextKey(context));
243
+ }
244
+ function withProbeV2Context(context, callback) {
245
+ const previous = state.probeV2Clock.epoch;
246
+ activateProbeV2Context(context);
247
+ try {
248
+ return callback();
249
+ } finally {
250
+ state.probeV2Clock.epoch = previous;
251
+ }
252
+ }
253
+ function installProbeV2AsyncHook() {
254
+ var _a8;
255
+ if (isBrowser || state.probeV2HookInstalled || typeof process === "undefined")
256
+ return;
257
+ try {
258
+ const getBuiltinModule = process.getBuiltinModule;
259
+ const createHook = (_a8 = getBuiltinModule == null ? void 0 : getBuiltinModule("node:async_hooks")) == null ? void 0 : _a8.createHook;
260
+ if (!createHook)
261
+ return;
262
+ const epochs = [];
263
+ createHook({
264
+ before() {
265
+ var _a9, _b;
266
+ epochs.push(state.probeV2Clock.epoch);
267
+ activateProbeV2Context((_b = (_a9 = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore()) != null ? _a9 : environmentRequestContext()) != null ? _b : {});
268
+ },
269
+ after() {
270
+ var _a9;
271
+ state.probeV2Clock.epoch = (_a9 = epochs.pop()) != null ? _a9 : state.probeV2Clock.epoch;
272
+ }
273
+ }).enable();
274
+ state.probeV2HookInstalled = true;
275
+ state.probeV2Clock.fast = true;
276
+ } catch (e) {
277
+ }
278
+ }
279
+ runtimeGlobal.__SUPERCOV_ACTIVATE_PROBE_CONTEXT__ = (browserTestId, browserPhaseId) => {
280
+ state.probeV2Clock.fast = true;
281
+ activateProbeV2Key(`browser\0${browserTestId}\0${browserPhaseId != null ? browserPhaseId : "unscoped"}`);
282
+ };
199
283
  function decisionSnapshot() {
200
284
  return [...state.decisions.values()].map((decision) => ({
201
285
  meta: decision.meta,
@@ -214,6 +298,8 @@ function resetCoverage(testId2) {
214
298
  state.hits.clear();
215
299
  state.events.length = 0;
216
300
  state.eventKeys.clear();
301
+ state.probeV2ContextEpochs.clear();
302
+ activateProbeV2Key(`reset\0${state.probeV2NextEpoch}`, true);
217
303
  if (testId2)
218
304
  runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ = testId2;
219
305
  if (isBrowser) {
@@ -245,24 +331,34 @@ function serverRecordKey(record) {
245
331
  function beginBufferedServerEvidence(scope) {
246
332
  if (isBrowser)
247
333
  return;
248
- state.bufferedAttempts.add(attemptKey(scope));
334
+ const key = attemptKey(scope);
335
+ state.bufferedAttempts.add(key);
336
+ if (!state.serverBuffers.has(key))
337
+ state.serverBuffers.set(key, {
338
+ scope,
339
+ directory: serverEvidenceDirectory(scope),
340
+ path: serverEvidencePath(scope),
341
+ records: /* @__PURE__ */ new Map()
342
+ });
249
343
  }
250
344
  function flushBufferedServerEvidence(scope) {
251
345
  if (isBrowser)
252
- return;
346
+ return void 0;
253
347
  const key = attemptKey(scope);
254
348
  state.bufferedAttempts.delete(key);
255
349
  const buffered = state.serverBuffers.get(key);
256
350
  if (!buffered)
257
- return;
351
+ return void 0;
258
352
  state.serverBuffers.delete(key);
259
353
  const fs = getFs();
260
354
  if (!fs || buffered.records.size === 0)
261
- return;
355
+ return void 0;
262
356
  try {
263
357
  fs.mkdirSync(buffered.directory, { recursive: true });
264
358
  fs.appendFileSync(buffered.path, [...buffered.records.values()].map((record) => JSON.stringify(record)).join("\n") + "\n");
359
+ return buffered.path;
265
360
  } catch (e) {
361
+ return void 0;
266
362
  }
267
363
  }
268
364
  function enableRuntimeSnapshotEvidence() {
@@ -271,6 +367,32 @@ function enableRuntimeSnapshotEvidence() {
271
367
  function flushAllBufferedServerEvidence() {
272
368
  for (const buffered of [...state.serverBuffers.values()])
273
369
  flushBufferedServerEvidence(buffered.scope);
370
+ for (const runId of [...state.backgroundBuffers.keys()])
371
+ flushBufferedBackgroundEvidence(runId);
372
+ }
373
+ function flushBufferedBackgroundEvidence(runId) {
374
+ var _a8;
375
+ if (isBrowser)
376
+ return void 0;
377
+ const records = state.backgroundBuffers.get(runId);
378
+ if (!records || records.size === 0)
379
+ return void 0;
380
+ const fs = getFs();
381
+ if (!fs)
382
+ return void 0;
383
+ const directory = backgroundEvidenceDirectory(runId);
384
+ const shard = (_a8 = process.env["SUPERCOV_EXECUTION_LOG_SHARD"]) != null ? _a8 : "process";
385
+ const writer = `${shard}-${process.pid}`;
386
+ const payload = [...records.values()].map((record) => JSON.stringify(record)).join("\n") + "\n";
387
+ try {
388
+ fs.mkdirSync(directory, { recursive: true });
389
+ const nextSequence = writeExclusiveBackgroundRecord(fs, runId, writer, state.backgroundSequence, payload);
390
+ state.backgroundSequence = nextSequence;
391
+ state.backgroundBuffers.delete(runId);
392
+ return backgroundEvidencePath(runId, `${writer}-${nextSequence - 1}`);
393
+ } catch (e) {
394
+ return void 0;
395
+ }
274
396
  }
275
397
  function writeExclusiveBackgroundRecord(fs, runId, writer, initialSequence, payload) {
276
398
  let sequence = initialSequence;
@@ -302,24 +424,44 @@ if (!isBrowser) {
302
424
  }
303
425
  }
304
426
  function appendServer(record) {
305
- var _a8, _b, _c;
306
- if (state.runtimeSnapshots)
427
+ var _a8, _b, _c, _d;
428
+ if (state.runtimeSnapshots) {
429
+ const timestampMs = (_a8 = record.timestampMs) != null ? _a8 : Date.now();
430
+ if (record.type === "decision") {
431
+ recordBrowserEvent(__spreadProps(__spreadValues({
432
+ type: "decision",
433
+ id: record.meta.id,
434
+ vector: record.vector,
435
+ timestampMs
436
+ }, record.phaseId ? { phaseId: record.phaseId } : {}), {
437
+ environment: "server"
438
+ }));
439
+ } else {
440
+ recordBrowserEvent(__spreadProps(__spreadValues({
441
+ type: "hit",
442
+ id: record.id,
443
+ timestampMs
444
+ }, record.phaseId ? { phaseId: record.phaseId } : {}), {
445
+ environment: "server"
446
+ }));
447
+ }
307
448
  return;
449
+ }
308
450
  const fs = getFs();
309
451
  if (!fs)
310
452
  return;
311
453
  const context = currentRequestContext();
312
454
  const scope = context.scope;
313
- const runId = (_a8 = scope == null ? void 0 : scope.runId) != null ? _a8 : typeof process !== "undefined" ? process.env["SUPERCOV_RUN_ID"] : void 0;
455
+ const runId = (_b = scope == null ? void 0 : scope.runId) != null ? _b : typeof process !== "undefined" ? process.env["SUPERCOV_RUN_ID"] : void 0;
314
456
  if (!runId)
315
457
  return;
316
458
  try {
317
- const directory = scope ? serverEvidenceDirectory(scope) : backgroundEvidenceDirectory(runId);
459
+ const directory = scope ? serverEvidenceDirectory(scope) : void 0;
318
460
  const path = scope ? serverEvidencePath(scope) : void 0;
319
461
  const serialized = __spreadValues(__spreadValues({}, record), scope ? { scope } : {});
320
462
  if (scope && state.bufferedAttempts.has(attemptKey(scope))) {
321
463
  const key = attemptKey(scope);
322
- const buffered = (_b = state.serverBuffers.get(key)) != null ? _b : {
464
+ const buffered = (_c = state.serverBuffers.get(key)) != null ? _c : {
323
465
  scope,
324
466
  directory,
325
467
  path,
@@ -332,14 +474,15 @@ function appendServer(record) {
332
474
  const deduplicationKey = scope && serialized.phaseId ? `${attemptKey(scope)}:${serverRecordKey(serialized)}` : void 0;
333
475
  if (deduplicationKey && state.persistedServerRecords.has(deduplicationKey))
334
476
  return;
335
- fs.mkdirSync(directory, { recursive: true });
336
477
  if (!path) {
337
- const shard = (_c = process.env["SUPERCOV_EXECUTION_LOG_SHARD"]) != null ? _c : "process";
338
- const writer = `${shard}-${process.pid}`;
339
- const payload = JSON.stringify(serialized) + "\n";
340
- state.backgroundSequence = writeExclusiveBackgroundRecord(fs, runId, writer, state.backgroundSequence, payload);
478
+ const buffered = (_d = state.backgroundBuffers.get(runId)) != null ? _d : /* @__PURE__ */ new Map();
479
+ buffered.set(serverRecordKey(serialized), serialized);
480
+ state.backgroundBuffers.set(runId, buffered);
481
+ if (buffered.size >= 4096)
482
+ flushBufferedBackgroundEvidence(runId);
341
483
  return;
342
484
  }
485
+ fs.mkdirSync(directory, { recursive: true });
343
486
  fs.appendFileSync(path, JSON.stringify(serialized) + "\n");
344
487
  if (deduplicationKey)
345
488
  state.persistedServerRecords.add(deduplicationKey);
@@ -353,8 +496,23 @@ function environmentRequestContext() {
353
496
  return carrier ? __spreadValues(__spreadValues({}, carrier.scope ? { scope: carrier.scope } : {}), carrier.phaseId ? { phaseId: carrier.phaseId } : {}) : void 0;
354
497
  }
355
498
  function currentRequestContext() {
356
- var _a8, _b;
357
- return (_b = (_a8 = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore()) != null ? _a8 : environmentRequestContext()) != null ? _b : {};
499
+ const stored = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore();
500
+ if (stored !== void 0) {
501
+ if (stored.scope || stored.phaseId)
502
+ return stored;
503
+ return runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__ ? { scope: runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__ } : {};
504
+ }
505
+ const environment = environmentRequestContext();
506
+ if ((environment == null ? void 0 : environment.scope) || (environment == null ? void 0 : environment.phaseId))
507
+ return environment;
508
+ return runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__ ? { scope: runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__ } : {};
509
+ }
510
+ function activateCoverageScope(scope) {
511
+ if (scope)
512
+ runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__ = scope;
513
+ else
514
+ delete runtimeGlobal.__SUPERCOV_ACTIVE_SCOPE__;
515
+ activateProbeV2Context(scope ? { scope } : {});
358
516
  }
359
517
  function coverageCarrier() {
360
518
  const context = currentRequestContext();
@@ -366,7 +524,68 @@ function withCoverageCarrier(carrier, callback) {
366
524
  const decoded = typeof carrier === "string" ? decodeCoverageCarrier(carrier) : carrier;
367
525
  if (!serverPhaseStorage || !decoded)
368
526
  return callback();
369
- return serverPhaseStorage.run(__spreadValues(__spreadValues({}, decoded.scope ? { scope: decoded.scope } : {}), decoded.phaseId ? { phaseId: decoded.phaseId } : {}), callback);
527
+ const context = __spreadValues(__spreadValues({}, decoded.scope ? { scope: decoded.scope } : {}), decoded.phaseId ? { phaseId: decoded.phaseId } : {});
528
+ return serverPhaseStorage.run(context, () => withProbeV2Context(context, callback));
529
+ }
530
+ function assertionPhaseState(scope) {
531
+ const key = attemptKey(scope);
532
+ const existing = state.assertionPhases.get(key);
533
+ if (existing)
534
+ return existing;
535
+ const created = { counter: 0, phases: [] };
536
+ state.assertionPhases.set(key, created);
537
+ return created;
538
+ }
539
+ function finishAssertionPhase(phase, error) {
540
+ phase.endedAtMs = Date.now();
541
+ phase.status = error === void 0 ? "passed" : "failed";
542
+ if (error !== void 0)
543
+ phase.error = error instanceof Error ? error.message : String(error);
544
+ }
545
+ function withNodeAssertionPhase(operation, source, callback) {
546
+ var _a8;
547
+ const context = currentRequestContext();
548
+ const scope = context.scope;
549
+ if (!scope)
550
+ return callback();
551
+ const existing = context.phaseId ? assertionPhaseState(scope).phases.find((phase2) => phase2.id === context.phaseId && phase2.kind === "assertion") : void 0;
552
+ if (existing)
553
+ return callback();
554
+ const bridged = (_a8 = runtimeGlobal.__SUPERCOV_ASSERTION_PHASE_BRIDGE__) == null ? void 0 : _a8.call(runtimeGlobal, operation, source, callback);
555
+ if (bridged == null ? void 0 : bridged.handled)
556
+ return bridged.value;
557
+ const attempt = assertionPhaseState(scope);
558
+ const phase = __spreadProps(__spreadValues({
559
+ id: `${scope.attemptId}:assertion:${++attempt.counter}`,
560
+ kind: "assertion",
561
+ operation
562
+ }, source ? { source } : {}), {
563
+ startedAtMs: Date.now()
564
+ });
565
+ attempt.phases.push(phase);
566
+ try {
567
+ const result = withCoverageCarrier({ version: 1, scope, phaseId: phase.id }, callback);
568
+ if (result && typeof result.then === "function")
569
+ return Promise.resolve(result).then((value) => {
570
+ finishAssertionPhase(phase);
571
+ return value;
572
+ }, (error) => {
573
+ finishAssertionPhase(phase, error);
574
+ throw error;
575
+ });
576
+ finishAssertionPhase(phase);
577
+ return result;
578
+ } catch (error) {
579
+ finishAssertionPhase(phase, error);
580
+ throw error;
581
+ }
582
+ }
583
+ function takeNodeAssertionPhases(scope) {
584
+ var _a8, _b;
585
+ const key = attemptKey(scope);
586
+ const phases = (_b = (_a8 = state.assertionPhases.get(key)) == null ? void 0 : _a8.phases) != null ? _b : [];
587
+ state.assertionPhases.delete(key);
588
+ return phases;
370
589
  }
371
590
  function bindCoverageContext(callback, carrier = coverageCarrier()) {
372
591
  return function boundCoverageContext(...args) {
@@ -490,7 +709,7 @@ function requestCoverageContext(value) {
490
709
  var _a8, _b;
491
710
  const headers = requestHeaders(value);
492
711
  if (!headers)
493
- return {};
712
+ return void 0;
494
713
  const rawCookie = headers.get("cookie");
495
714
  const cookies = /* @__PURE__ */ new Map();
496
715
  if (typeof rawCookie === "string") {
@@ -516,12 +735,12 @@ function withRequestPhase(handler) {
516
735
  if (!serverPhaseStorage)
517
736
  return handler;
518
737
  return function coverageRequestPhase(...args) {
519
- var _a8, _b, _c, _d, _e;
520
- const requestContext = (_a8 = args.map((argument) => requestCoverageContext(argument)).find((context2) => context2.scope || context2.phaseId)) != null ? _a8 : {};
521
- const inheritedContext = currentRequestContext();
522
- const context = __spreadValues(__spreadValues({}, ((_b = requestContext.scope) != null ? _b : inheritedContext.scope) ? { scope: (_c = requestContext.scope) != null ? _c : inheritedContext.scope } : {}), ((_d = requestContext.phaseId) != null ? _d : inheritedContext.phaseId) ? { phaseId: (_e = requestContext.phaseId) != null ? _e : inheritedContext.phaseId } : {});
738
+ var _a8, _b, _c, _d;
739
+ const requestContext = args.map((argument) => requestCoverageContext(argument)).find((context2) => context2 !== void 0);
740
+ const inheritedContext = requestContext === void 0 ? currentRequestContext() : {};
741
+ const context = __spreadValues(__spreadValues({}, ((_a8 = requestContext == null ? void 0 : requestContext.scope) != null ? _a8 : inheritedContext.scope) ? { scope: (_b = requestContext == null ? void 0 : requestContext.scope) != null ? _b : inheritedContext.scope } : {}), ((_c = requestContext == null ? void 0 : requestContext.phaseId) != null ? _c : inheritedContext.phaseId) ? { phaseId: (_d = requestContext == null ? void 0 : requestContext.phaseId) != null ? _d : inheritedContext.phaseId } : {});
523
742
  const invoke = () => Reflect.apply(handler, this, args);
524
- return context.scope || context.phaseId ? serverPhaseStorage.run(context, invoke) : invoke();
743
+ return requestContext !== void 0 || context.scope || context.phaseId ? serverPhaseStorage.run(context, () => withProbeV2Context(context, invoke)) : invoke();
525
744
  };
526
745
  }
527
746
  function eventKey(event) {
@@ -558,6 +777,109 @@ function coverageHit(id) {
558
777
  }, phaseId ? { phaseId } : {}));
559
778
  }
560
779
  }
780
+ function registerProbeV2(definition) {
781
+ var _a8, _b;
782
+ const file = {
783
+ decisions: definition.decisions,
784
+ pointIds: definition.pointIds,
785
+ clock: state.probeV2Clock,
786
+ hitEpochs: new Uint32Array(definition.pointIds.length),
787
+ decisionEpochs: definition.decisions.map((meta) => meta.conditions.length <= 6 ? new Uint32Array(2 * 3 ** meta.conditions.length) : /* @__PURE__ */ new Map()),
788
+ decisionVectorCounts: definition.decisions.map((_, index) => {
789
+ var _a9, _b2;
790
+ return (_b2 = (_a9 = definition.decisionVectorCounts) == null ? void 0 : _a9[index]) != null ? _b2 : 0;
791
+ }),
792
+ decisionObservationEpochs: new Uint32Array(definition.decisions.length),
793
+ decisionObservationCounts: new Uint16Array(definition.decisions.length),
794
+ decisionCompleteEpochs: new Uint32Array(definition.decisions.length)
795
+ };
796
+ state.probeV2Files.add(file);
797
+ if (isBrowser) {
798
+ state.probeV2Clock.fast = true;
799
+ activateProbeV2Key(`browser\0${(_a8 = runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__) != null ? _a8 : testId}\0${(_b = runtimeGlobal.__SUPERCOV_PHASE_ID__) != null ? _b : "unscoped"}`);
800
+ } else {
801
+ installProbeV2AsyncHook();
802
+ }
803
+ return file;
804
+ }
805
+ function coverageHitV2(file, index) {
806
+ const id = file.pointIds[index];
807
+ if (!id)
808
+ return;
809
+ const fallbackEpoch = !file.clock.fast;
810
+ const previousEpoch = file.clock.epoch;
811
+ if (fallbackEpoch)
812
+ activateProbeV2Context(currentRequestContext());
813
+ try {
814
+ const epoch = file.clock.epoch;
815
+ if (file.hitEpochs[index] === epoch)
816
+ return;
817
+ file.hitEpochs[index] = epoch;
818
+ coverageHit(id);
819
+ } finally {
820
+ if (fallbackEpoch)
821
+ file.clock.epoch = previousEpoch;
822
+ }
823
+ }
824
+ function decodeProbeV2Vector(conditionCount, encoded, outcome) {
825
+ if (!Number.isSafeInteger(conditionCount) || conditionCount < 0 || conditionCount > 32 || !Number.isSafeInteger(encoded) || encoded < 0)
826
+ return void 0;
827
+ const values = [];
828
+ let remaining = encoded;
829
+ for (let index = 0; index < conditionCount; index += 1) {
830
+ const digit = remaining % 3;
831
+ values.push(digit === 0 ? null : digit === 2);
832
+ remaining = Math.floor(remaining / 3);
833
+ }
834
+ return remaining === 0 ? { values, outcome } : void 0;
835
+ }
836
+ function mcdcEndV2(file, decisionIndex, encoded, value) {
837
+ var _a8, _b;
838
+ const meta = file.decisions[decisionIndex];
839
+ if (!meta || !Number.isSafeInteger(encoded) || encoded < 0)
840
+ return value;
841
+ const outcome = Boolean(value);
842
+ const vectorIndex = encoded * 2 + (outcome ? 1 : 0);
843
+ if (!Number.isSafeInteger(vectorIndex))
844
+ return value;
845
+ const fallbackEpoch = !file.clock.fast;
846
+ const previousEpoch = file.clock.epoch;
847
+ if (fallbackEpoch)
848
+ activateProbeV2Context(currentRequestContext());
849
+ try {
850
+ const epoch = file.clock.epoch;
851
+ const seen = file.decisionEpochs[decisionIndex];
852
+ if (!seen)
853
+ return value;
854
+ if (seen instanceof Uint32Array) {
855
+ if (seen[vectorIndex] === epoch)
856
+ return value;
857
+ seen[vectorIndex] = epoch;
858
+ } else {
859
+ if (seen.get(vectorIndex) === epoch)
860
+ return value;
861
+ seen.set(vectorIndex, epoch);
862
+ }
863
+ const expectedCount = (_a8 = file.decisionVectorCounts[decisionIndex]) != null ? _a8 : 0;
864
+ if (expectedCount > 0) {
865
+ if (file.decisionObservationEpochs[decisionIndex] !== epoch) {
866
+ file.decisionObservationEpochs[decisionIndex] = epoch;
867
+ file.decisionObservationCounts[decisionIndex] = 0;
868
+ }
869
+ const observedCount = ((_b = file.decisionObservationCounts[decisionIndex]) != null ? _b : 0) + 1;
870
+ file.decisionObservationCounts[decisionIndex] = observedCount;
871
+ if (observedCount >= expectedCount)
872
+ file.decisionCompleteEpochs[decisionIndex] = epoch;
873
+ }
874
+ if (!state.decisions.has(meta.id))
875
+ state.decisions.set(meta.id, { meta, vectors: /* @__PURE__ */ new Map() });
876
+ const vector = decodeProbeV2Vector(meta.conditions.length, encoded, outcome);
877
+ return vector ? mcdcEnd({ meta, values: vector.values }, value) : value;
878
+ } finally {
879
+ if (fallbackEpoch)
880
+ file.clock.epoch = previousEpoch;
881
+ }
882
+ }
561
883
  function selectionBegin(shortId, rightId) {
562
884
  return { shortId, rightId, rightEvaluated: false };
563
885
  }
@@ -570,6 +892,15 @@ function applyInferredName(value, inferredName) {
570
892
  }
571
893
  return value;
572
894
  }
895
+ var hostNamesParenthesizedAssignments = (() => {
896
+ let candidate;
897
+ candidate = function() {
898
+ };
899
+ return candidate.name === "candidate";
900
+ })();
901
+ function parenthesizedAssignmentValue(value, inferredName) {
902
+ return hostNamesParenthesizedAssignments ? applyInferredName(value, inferredName) : value;
903
+ }
573
904
  function selectionRight(frame, value, inferredName) {
574
905
  frame.rightEvaluated = true;
575
906
  return applyInferredName(value, inferredName);
@@ -582,6 +913,31 @@ function optionalSelect(shortId, continuedId, value) {
582
913
  coverageHit(value === null || value === void 0 ? shortId : continuedId);
583
914
  return value;
584
915
  }
916
+ function optionalCallBegin(shortId, continuedId) {
917
+ return { shortId, continuedId, reached: false, continued: false };
918
+ }
919
+ function optionalCallReached(frame, value) {
920
+ frame.reached = true;
921
+ return value;
922
+ }
923
+ var optionalCallEmptySpread = {
924
+ [Symbol.iterator]() {
925
+ return {
926
+ next() {
927
+ return { done: true, value: void 0 };
928
+ }
929
+ };
930
+ }
931
+ };
932
+ function optionalCallContinued(frame) {
933
+ frame.continued = true;
934
+ return optionalCallEmptySpread;
935
+ }
936
+ function optionalCallEnd(frame, value) {
937
+ if (frame.reached)
938
+ coverageHit(frame.continued ? frame.continuedId : frame.shortId);
939
+ return value;
940
+ }
585
941
  function defaultSelected(defaultId, value, inferredName) {
586
942
  var _a8;
587
943
  pendingDefaults.set(defaultId, ((_a8 = pendingDefaults.get(defaultId)) != null ? _a8 : 0) + 1);
@@ -659,16 +1015,20 @@ function mcdcEnd(frame, value) {
659
1015
  return value;
660
1016
  }
661
1017
  export {
1018
+ activateCoverageScope,
662
1019
  beginBufferedServerEvidence,
663
1020
  bindCoverageContext,
664
1021
  coverageCarrier,
665
1022
  coverageContextEnvironment,
666
1023
  coverageContextHeaders,
667
1024
  coverageHit,
1025
+ coverageHitV2,
668
1026
  coverageSnapshot,
1027
+ decodeProbeV2Vector,
669
1028
  defaultEntered,
670
1029
  defaultSelected,
671
1030
  enableRuntimeSnapshotEvidence,
1031
+ flushBufferedBackgroundEvidence,
672
1032
  flushBufferedServerEvidence,
673
1033
  loopBegin,
674
1034
  loopEnd,
@@ -676,15 +1036,24 @@ export {
676
1036
  mcdcBegin,
677
1037
  mcdcCondition,
678
1038
  mcdcEnd,
1039
+ mcdcEndV2,
1040
+ optionalCallBegin,
1041
+ optionalCallContinued,
1042
+ optionalCallEnd,
1043
+ optionalCallReached,
679
1044
  optionalSelect,
1045
+ parenthesizedAssignmentValue,
1046
+ registerProbeV2,
680
1047
  resetCoverage,
681
1048
  selectionBegin,
682
1049
  selectionEnd,
683
1050
  selectionRight,
1051
+ takeNodeAssertionPhases,
684
1052
  tryBegin,
685
1053
  tryCatch,
686
1054
  tryEnd,
687
1055
  withCoverageCarrier,
1056
+ withNodeAssertionPhase,
688
1057
  withRequestPhase,
689
1058
  writeExclusiveBackgroundRecord
690
1059
  };