@hughescr/stryker-bun-runner 1.3.2 → 1.3.4

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/index.js CHANGED
@@ -2320,6 +2320,8 @@ var require_receiver = __commonJS((exports, module) => {
2320
2320
  this._binaryType = options.binaryType || BINARY_TYPES[0];
2321
2321
  this._extensions = options.extensions || {};
2322
2322
  this._isServer = !!options.isServer;
2323
+ this._maxBufferedChunks = options.maxBufferedChunks | 0;
2324
+ this._maxFragments = options.maxFragments | 0;
2323
2325
  this._maxPayload = options.maxPayload | 0;
2324
2326
  this._skipUTF8Validation = !!options.skipUTF8Validation;
2325
2327
  this[kWebSocket] = undefined;
@@ -2342,6 +2344,10 @@ var require_receiver = __commonJS((exports, module) => {
2342
2344
  _write(chunk, encoding, cb) {
2343
2345
  if (this._opcode === 8 && this._state == GET_INFO)
2344
2346
  return cb();
2347
+ if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
2348
+ cb(this.createError(RangeError, "Too many buffered chunks", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
2349
+ return;
2350
+ }
2345
2351
  this._bufferedBytes += chunk.length;
2346
2352
  this._buffers.push(chunk);
2347
2353
  this.startLoop(cb);
@@ -2545,6 +2551,11 @@ var require_receiver = __commonJS((exports, module) => {
2545
2551
  return;
2546
2552
  }
2547
2553
  if (data.length) {
2554
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
2555
+ const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
2556
+ cb(error);
2557
+ return;
2558
+ }
2548
2559
  this._messageLength = this._totalPayloadLength;
2549
2560
  this._fragments.push(data);
2550
2561
  }
@@ -2562,6 +2573,11 @@ var require_receiver = __commonJS((exports, module) => {
2562
2573
  cb(error);
2563
2574
  return;
2564
2575
  }
2576
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
2577
+ const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
2578
+ cb(error);
2579
+ return;
2580
+ }
2565
2581
  this._fragments.push(buf);
2566
2582
  }
2567
2583
  this.dataMessage(cb);
@@ -2677,6 +2693,9 @@ var require_receiver = __commonJS((exports, module) => {
2677
2693
  var require_sender = __commonJS((exports, module) => {
2678
2694
  var { Duplex } = __require("stream");
2679
2695
  var { randomFillSync } = __require("crypto");
2696
+ var {
2697
+ types: { isUint8Array }
2698
+ } = __require("util");
2680
2699
  var PerMessageDeflate = require_permessage_deflate();
2681
2700
  var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants2();
2682
2701
  var { isBlob, isValidStatusCode } = require_validation();
@@ -2796,8 +2815,10 @@ var require_sender = __commonJS((exports, module) => {
2796
2815
  buf.writeUInt16BE(code, 0);
2797
2816
  if (typeof data === "string") {
2798
2817
  buf.write(data, 2);
2799
- } else {
2818
+ } else if (isUint8Array(data)) {
2800
2819
  buf.set(data, 2);
2820
+ } else {
2821
+ throw new TypeError("Second argument must be a string or a Uint8Array");
2801
2822
  }
2802
2823
  }
2803
2824
  const options = {
@@ -3464,6 +3485,8 @@ var require_websocket = __commonJS((exports, module) => {
3464
3485
  binaryType: this.binaryType,
3465
3486
  extensions: this._extensions,
3466
3487
  isServer: this._isServer,
3488
+ maxBufferedChunks: options.maxBufferedChunks,
3489
+ maxFragments: options.maxFragments,
3467
3490
  maxPayload: options.maxPayload,
3468
3491
  skipUTF8Validation: options.skipUTF8Validation
3469
3492
  });
@@ -3706,6 +3729,8 @@ var require_websocket = __commonJS((exports, module) => {
3706
3729
  autoPong: true,
3707
3730
  closeTimeout: CLOSE_TIMEOUT,
3708
3731
  protocolVersion: protocolVersions[1],
3732
+ maxBufferedChunks: 1024 * 1024,
3733
+ maxFragments: 128 * 1024,
3709
3734
  maxPayload: 100 * 1024 * 1024,
3710
3735
  skipUTF8Validation: false,
3711
3736
  perMessageDeflate: true,
@@ -3944,6 +3969,8 @@ var require_websocket = __commonJS((exports, module) => {
3944
3969
  websocket.setSocket(socket, head, {
3945
3970
  allowSynchronousEvents: opts.allowSynchronousEvents,
3946
3971
  generateMask: opts.generateMask,
3972
+ maxBufferedChunks: opts.maxBufferedChunks,
3973
+ maxFragments: opts.maxFragments,
3947
3974
  maxPayload: opts.maxPayload,
3948
3975
  skipUTF8Validation: opts.skipUTF8Validation
3949
3976
  });
@@ -4279,6 +4306,8 @@ var require_websocket_server = __commonJS((exports, module) => {
4279
4306
  options = {
4280
4307
  allowSynchronousEvents: true,
4281
4308
  autoPong: true,
4309
+ maxBufferedChunks: 1024 * 1024,
4310
+ maxFragments: 128 * 1024,
4282
4311
  maxPayload: 100 * 1024 * 1024,
4283
4312
  skipUTF8Validation: false,
4284
4313
  perMessageDeflate: false,
@@ -4505,6 +4534,8 @@ var require_websocket_server = __commonJS((exports, module) => {
4505
4534
  socket.removeListener("error", socketOnError);
4506
4535
  ws.setSocket(socket, head, {
4507
4536
  allowSynchronousEvents: this.options.allowSynchronousEvents,
4537
+ maxBufferedChunks: this.options.maxBufferedChunks,
4538
+ maxFragments: this.options.maxFragments,
4508
4539
  maxPayload: this.options.maxPayload,
4509
4540
  skipUTF8Validation: this.options.skipUTF8Validation
4510
4541
  });
@@ -4604,6 +4635,7 @@ var Scope;
4604
4635
  Scope2["Singleton"] = "singleton";
4605
4636
  })(Scope || (Scope = {}));
4606
4637
  // src/bun-test-runner.ts
4638
+ import { createHash } from "node:crypto";
4607
4639
  import * as fsPromises2 from "node:fs/promises";
4608
4640
  import { tmpdir } from "node:os";
4609
4641
  import path4 from "node:path";
@@ -5176,6 +5208,7 @@ var Builder = class {
5176
5208
  var import_picomatch = __toESM(require_picomatch2(), 1);
5177
5209
  var isReadonlyArray = Array.isArray;
5178
5210
  var BACKSLASHES = /\\/g;
5211
+ var DRIVE_RELATIVE_PATH = /^[A-Za-z]:$/;
5179
5212
  var isWin = process.platform === "win32";
5180
5213
  var ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
5181
5214
  function getPartialMatcher(patterns, options = {}) {
@@ -5250,6 +5283,9 @@ function buildRelative(cwd, root) {
5250
5283
  return p[p.length - 1] === "/" && result !== "" ? `${result}/` : result || ".";
5251
5284
  };
5252
5285
  }
5286
+ function ensureNonDriveRelativePath(path) {
5287
+ return path.replace(DRIVE_RELATIVE_PATH, (match) => `${match}/`);
5288
+ }
5253
5289
  var splitPatternOptions = { parts: true };
5254
5290
  function splitPattern(path) {
5255
5291
  var _result$parts;
@@ -5297,7 +5333,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
5297
5333
  }
5298
5334
  const potentialRoot = posix.join(cwd, parentDir.slice(i * 3));
5299
5335
  if (potentialRoot[0] !== "." && props.root.length > potentialRoot.length) {
5300
- props.root = potentialRoot;
5336
+ props.root = ensureNonDriveRelativePath(potentialRoot);
5301
5337
  props.depthOffset = -n + i;
5302
5338
  }
5303
5339
  }
@@ -5318,7 +5354,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
5318
5354
  }
5319
5355
  props.depthOffset = newCommonPath.length;
5320
5356
  props.commonPath = newCommonPath;
5321
- props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
5357
+ props.root = ensureNonDriveRelativePath(newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd);
5322
5358
  }
5323
5359
  return result;
5324
5360
  }
@@ -5418,18 +5454,17 @@ function formatPaths(paths, mapper) {
5418
5454
  }
5419
5455
  var defaultOptions = {
5420
5456
  caseSensitiveMatch: true,
5421
- cwd: process.cwd(),
5422
5457
  debug: !!process.env.TINYGLOBBY_DEBUG,
5423
5458
  expandDirectories: true,
5424
5459
  followSymbolicLinks: true,
5425
5460
  onlyFiles: true
5426
5461
  };
5427
5462
  function getOptions(options) {
5428
- const opts = {
5429
- ...defaultOptions,
5430
- ...options
5431
- };
5432
- opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve2(opts.cwd)).replace(BACKSLASHES, "/");
5463
+ const opts = Object.assign({}, options);
5464
+ for (const key in defaultOptions)
5465
+ if (opts[key] === undefined)
5466
+ Object.assign(opts, { [key]: defaultOptions[key] });
5467
+ opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve2(opts.cwd || process.cwd())).replace(BACKSLASHES, "/");
5433
5468
  opts.ignore = ensureStringArray(opts.ignore);
5434
5469
  opts.fs && (opts.fs = {
5435
5470
  readdir: opts.fs.readdir || readdir,
@@ -5505,7 +5540,6 @@ async function cleanupPreloadScript(preloadPath) {
5505
5540
  await unlink(preloadPath);
5506
5541
  } catch {}
5507
5542
  }
5508
-
5509
5543
  // src/coverage/collector.ts
5510
5544
  import { readFile as readFile2, unlink as unlink2 } from "node:fs/promises";
5511
5545
  function arrayToCoverageData(mutantIds) {
@@ -5540,7 +5574,7 @@ function mergeCoverageData(dataList) {
5540
5574
  merged.static = [...staticSet];
5541
5575
  return merged;
5542
5576
  }
5543
- async function collectCoverage(coverageFile, logger) {
5577
+ async function readCoverageFileData(coverageFile, logger) {
5544
5578
  try {
5545
5579
  const content = await readFile2(coverageFile, "utf8");
5546
5580
  const trimmed = content.trim();
@@ -5556,6 +5590,14 @@ async function collectCoverage(coverageFile, logger) {
5556
5590
  logger?.warn("[Stryker Coverage] Failed to parse coverage line: %s", errorMsg);
5557
5591
  }
5558
5592
  }
5593
+ return dataList;
5594
+ } catch {
5595
+ return [];
5596
+ }
5597
+ }
5598
+ async function collectCoverage(coverageFile, logger) {
5599
+ try {
5600
+ const dataList = await readCoverageFileData(coverageFile, logger);
5559
5601
  if (dataList.length === 0) {
5560
5602
  return;
5561
5603
  }
@@ -5573,11 +5615,39 @@ async function collectCoverage(coverageFile, logger) {
5573
5615
  return;
5574
5616
  }
5575
5617
  }
5618
+ async function collectLateHits(coverageFile, logger) {
5619
+ const dataList = await readCoverageFileData(coverageFile, logger);
5620
+ return dataList.flatMap((data) => data.lateHits ?? []);
5621
+ }
5576
5622
  async function cleanupCoverageFile(coverageFile) {
5577
5623
  try {
5578
5624
  await unlink2(coverageFile);
5579
5625
  } catch {}
5580
5626
  }
5627
+ // src/utils/duplicate-suffix.ts
5628
+ function buildDiscoveryOrderIndex(discoveryOrderedIds) {
5629
+ const index = new Map;
5630
+ let i = 0;
5631
+ for (const id of discoveryOrderedIds) {
5632
+ index.set(id, i);
5633
+ i++;
5634
+ }
5635
+ return index;
5636
+ }
5637
+ function sortDuplicateGroupByLineThenDiscovery(group, getLine, getInspectorId, discoveryOrderIndex) {
5638
+ return group.toSorted((a, b) => {
5639
+ const lineA = getLine(a) ?? Infinity;
5640
+ const lineB = getLine(b) ?? Infinity;
5641
+ if (lineA !== lineB) {
5642
+ return lineA - lineB;
5643
+ }
5644
+ const idA = getInspectorId(a);
5645
+ const idB = getInspectorId(b);
5646
+ const discA = idA === undefined ? Infinity : discoveryOrderIndex.get(idA) ?? Infinity;
5647
+ const discB = idB === undefined ? Infinity : discoveryOrderIndex.get(idB) ?? Infinity;
5648
+ return discA - discB;
5649
+ });
5650
+ }
5581
5651
 
5582
5652
  // src/utils/test-name.ts
5583
5653
  function normalizeTestFilePath(url) {
@@ -5607,16 +5677,34 @@ function buildUniqueTestName(fullName, url) {
5607
5677
  // src/coverage/coverage-mapper.ts
5608
5678
  function mapCoverageToInspectorIds(rawCoverage, executionOrder, testHierarchy, logger) {
5609
5679
  if (!rawCoverage?.perTest || Object.keys(rawCoverage.perTest).length === 0) {
5610
- return { coverage: rawCoverage ?? undefined, inspectorIdToProjectFile: new Map };
5680
+ return {
5681
+ coverage: rawCoverage ?? undefined,
5682
+ inspectorIdToProjectFile: new Map,
5683
+ counterKeyToTestName: new Map,
5684
+ rawKeyCount: 0,
5685
+ orphanedKeyCount: 0
5686
+ };
5611
5687
  }
5612
5688
  const firstKey = Object.keys(rawCoverage.perTest)[0];
5613
5689
  if (/@@test-\d+$/.test(firstKey)) {
5614
5690
  return mapFilePrefixedCounterKeys(rawCoverage, executionOrder, testHierarchy, logger);
5615
5691
  }
5616
5692
  if (/^test-\d+$/.test(firstKey)) {
5617
- return { coverage: mapLegacyCounterKeys(rawCoverage, executionOrder, testHierarchy, logger), inspectorIdToProjectFile: new Map };
5693
+ return {
5694
+ coverage: mapLegacyCounterKeys(rawCoverage, executionOrder, testHierarchy, logger),
5695
+ inspectorIdToProjectFile: new Map,
5696
+ counterKeyToTestName: new Map,
5697
+ rawKeyCount: Object.keys(rawCoverage.perTest).length,
5698
+ orphanedKeyCount: 0
5699
+ };
5618
5700
  }
5619
- return { coverage: rawCoverage, inspectorIdToProjectFile: new Map };
5701
+ return {
5702
+ coverage: rawCoverage,
5703
+ inspectorIdToProjectFile: new Map,
5704
+ counterKeyToTestName: new Map,
5705
+ rawKeyCount: Object.keys(rawCoverage.perTest).length,
5706
+ orphanedKeyCount: 0
5707
+ };
5620
5708
  }
5621
5709
  function buildFilteredPerTest(perTestEntries, staticIds) {
5622
5710
  const newPerTest = {};
@@ -5672,7 +5760,7 @@ function resolveCounterKeys(counterIds, fileToInspectorIds, testHierarchy, logge
5672
5760
  const testName = buildProjectFileTestName(filePrefix, testInfo.fullName);
5673
5761
  return { name: testName, testInfo, inspectorId };
5674
5762
  }
5675
- logger?.warn('Coverage key %s: no inspector test found for file "%s" at position %s ' + "(file has %s tests in execution order). Skipping this test in coverage mapping.", key, filePrefix, n, fileToInspectorIds.get(filePrefix)?.length ?? 0);
5763
+ logger?.debug('Coverage key %s: no inspector test found for file "%s" at position %s ' + "(file has %s tests in execution order). Skipping this test in coverage mapping.", key, filePrefix, n, fileToInspectorIds.get(filePrefix)?.length ?? 0);
5676
5764
  return { name: `unknown-${key}`, testInfo: null, inspectorId: undefined };
5677
5765
  });
5678
5766
  }
@@ -5691,31 +5779,40 @@ function buildNameInspectorIds(resolved) {
5691
5779
  }
5692
5780
  return nameInspectorIds;
5693
5781
  }
5694
- function resolveEachTestName(baseName, inspectorId, nameInspectorIds, nameIndexes) {
5782
+ function buildDuplicateNameIndex(nameInspectorIds, testHierarchy) {
5783
+ const discoveryOrderIndex = buildDiscoveryOrderIndex(testHierarchy.keys());
5784
+ const indexByKey = new Map;
5785
+ for (const [baseName, ids] of nameInspectorIds) {
5786
+ if (ids.size <= 1) {
5787
+ continue;
5788
+ }
5789
+ const group = [...ids].filter((id) => id !== undefined);
5790
+ const sorted = sortDuplicateGroupByLineThenDiscovery(group, (id) => testHierarchy.get(id)?.line, (id) => id, discoveryOrderIndex);
5791
+ for (const [i, id] of sorted.entries()) {
5792
+ indexByKey.set(`${id}/${baseName}`, i);
5793
+ }
5794
+ }
5795
+ return indexByKey;
5796
+ }
5797
+ function resolveEachTestName(baseName, inspectorId, nameInspectorIds, duplicateNameIndex) {
5695
5798
  const distinctIds = nameInspectorIds.get(baseName);
5696
5799
  if ((distinctIds?.size ?? 1) <= 1) {
5697
5800
  return baseName;
5698
5801
  }
5699
5802
  const key_ = `${inspectorId}/${baseName}`;
5700
- const existingIndex = nameIndexes.get(key_);
5701
- if (existingIndex === undefined) {
5702
- const nextIndex = nameIndexes.get(baseName) ?? 0;
5703
- nameIndexes.set(key_, nextIndex);
5704
- nameIndexes.set(baseName, nextIndex + 1);
5705
- return `${baseName} [${nextIndex}]`;
5706
- }
5707
- return `${baseName} [${existingIndex}]`;
5803
+ const index = duplicateNameIndex.get(key_) ?? 0;
5804
+ return `${baseName} [${index}]`;
5708
5805
  }
5709
- function buildRemappedPerTest(counterIds, resolved, rawPerTest) {
5806
+ function buildRemappedPerTest(counterIds, resolved, rawPerTest, testHierarchy) {
5710
5807
  const nameInspectorIds = buildNameInspectorIds(resolved);
5808
+ const duplicateNameIndex = buildDuplicateNameIndex(nameInspectorIds, testHierarchy);
5711
5809
  const remappedPerTest = {};
5712
- const nameIndexes = new Map;
5713
5810
  for (const [i, key] of counterIds.entries()) {
5714
5811
  const { name: baseName, testInfo, inspectorId } = resolved[i];
5715
5812
  if (!testInfo) {
5716
5813
  continue;
5717
5814
  }
5718
- const finalName = resolveEachTestName(baseName, inspectorId, nameInspectorIds, nameIndexes);
5815
+ const finalName = resolveEachTestName(baseName, inspectorId, nameInspectorIds, duplicateNameIndex);
5719
5816
  const incoming = rawPerTest[key];
5720
5817
  const existing = remappedPerTest[finalName];
5721
5818
  if (existing) {
@@ -5745,6 +5842,25 @@ function warnInteriorGapIfPresent(pairs, testHierarchy, logger) {
5745
5842
  }
5746
5843
  }
5747
5844
  }
5845
+ function reportOrphanedKeys(resolved, counterIds, logger) {
5846
+ const orphanedIndexes = [];
5847
+ for (const [i, r] of resolved.entries()) {
5848
+ if (!r.testInfo) {
5849
+ orphanedIndexes.push(i);
5850
+ }
5851
+ }
5852
+ const orphanedKeyCount = orphanedIndexes.length;
5853
+ if (orphanedKeyCount > 0) {
5854
+ const orphanedFiles = new Set;
5855
+ for (const i of orphanedIndexes) {
5856
+ const key = counterIds[i];
5857
+ const sepIdx = key.indexOf("@@");
5858
+ orphanedFiles.add(sepIdx === -1 ? key : key.slice(0, sepIdx));
5859
+ }
5860
+ logger?.warn("%s of %s coverage key(s) across %s file(s) could not be paired with any inspector test " + "(orphaned — see per-key detail at debug level). This can indicate the Bun inspector " + "stream was truncated mid-run.", orphanedKeyCount, counterIds.length, orphanedFiles.size);
5861
+ }
5862
+ return orphanedKeyCount;
5863
+ }
5748
5864
  function mapFilePrefixedCounterKeys(rawCoverage, executionOrder, testHierarchy, logger) {
5749
5865
  const globallyOrderedKeys = Object.keys(rawCoverage.perTest);
5750
5866
  const pairs = pairKeysWithInspectorIds(globallyOrderedKeys, executionOrder, testHierarchy, logger);
@@ -5768,12 +5884,25 @@ function mapFilePrefixedCounterKeys(rawCoverage, executionOrder, testHierarchy,
5768
5884
  return nA - nB;
5769
5885
  });
5770
5886
  const resolved = resolveCounterKeys(counterIds, fileToInspectorIds, testHierarchy, logger);
5771
- const remappedPerTest = buildRemappedPerTest(counterIds, resolved, rawCoverage.perTest);
5887
+ const remappedPerTest = buildRemappedPerTest(counterIds, resolved, rawCoverage.perTest, testHierarchy);
5888
+ const counterKeyToTestName = new Map;
5889
+ for (const [i, key] of counterIds.entries()) {
5890
+ if (resolved[i].testInfo) {
5891
+ counterKeyToTestName.set(key, resolved[i].name);
5892
+ }
5893
+ }
5894
+ const orphanedKeyCount = reportOrphanedKeys(resolved, counterIds, logger);
5772
5895
  const coverage = stabilizeCoverage({
5773
5896
  static: rawCoverage.static,
5774
5897
  perTest: remappedPerTest
5775
5898
  });
5776
- return { coverage, inspectorIdToProjectFile };
5899
+ return {
5900
+ coverage,
5901
+ inspectorIdToProjectFile,
5902
+ counterKeyToTestName,
5903
+ rawKeyCount: counterIds.length,
5904
+ orphanedKeyCount
5905
+ };
5777
5906
  }
5778
5907
  function mapLegacyCounterKeys(rawCoverage, executionOrder, testHierarchy, logger) {
5779
5908
  const counterIds = Object.keys(rawCoverage.perTest).toSorted((a, b) => Number.parseInt(a.split("-")[1] ?? "0", 10) - Number.parseInt(b.split("-")[1] ?? "0", 10));
@@ -5820,7 +5949,6 @@ function mapLegacyCounterKeys(rawCoverage, executionOrder, testHierarchy, logger
5820
5949
  perTest: remappedPerTest
5821
5950
  });
5822
5951
  }
5823
-
5824
5952
  // node_modules/ws/wrapper.mjs
5825
5953
  var import_stream = __toESM(require_stream(), 1);
5826
5954
  var import_extension = __toESM(require_extension(), 1);
@@ -5868,6 +5996,10 @@ class InspectorClient {
5868
5996
  state;
5869
5997
  isClosing = false;
5870
5998
  WebSocketClass;
5999
+ closeExpected = false;
6000
+ wsClosed = false;
6001
+ _wasClosedUnexpectedly = false;
6002
+ closeWaiters = [];
5871
6003
  constructor(options) {
5872
6004
  this.handlers = options.handlers ?? {};
5873
6005
  this.WebSocketClass = options.WebSocketClass ?? wrapper_default;
@@ -5946,6 +6078,37 @@ class InspectorClient {
5946
6078
  }
5947
6079
  this.ws = null;
5948
6080
  }
6081
+ expectClose() {
6082
+ this.closeExpected = true;
6083
+ }
6084
+ get wasClosedUnexpectedly() {
6085
+ return this._wasClosedUnexpectedly;
6086
+ }
6087
+ async waitForClose(timeoutMs) {
6088
+ if (this.wsClosed || !this.ws) {
6089
+ return;
6090
+ }
6091
+ return new Promise((resolve3) => {
6092
+ let settled = false;
6093
+ let timer;
6094
+ const finish = () => {
6095
+ if (settled) {
6096
+ return;
6097
+ }
6098
+ settled = true;
6099
+ clearTimeout(timer);
6100
+ const idx = this.closeWaiters.indexOf(finish);
6101
+ if (idx !== -1) {
6102
+ this.closeWaiters.splice(idx, 1);
6103
+ }
6104
+ resolve3();
6105
+ };
6106
+ timer = setTimeout(() => {
6107
+ finish();
6108
+ }, timeoutMs);
6109
+ this.closeWaiters.push(finish);
6110
+ });
6111
+ }
5949
6112
  getTests() {
5950
6113
  return [...this.testHierarchy.values()];
5951
6114
  }
@@ -6050,9 +6213,16 @@ class InspectorClient {
6050
6213
  return { fullName: parts.join(" > "), bunName: parts.join(" ") };
6051
6214
  }
6052
6215
  handleClose() {
6053
- if (this.isClosing) {
6216
+ this.wsClosed = true;
6217
+ const waiters = this.closeWaiters;
6218
+ this.closeWaiters = [];
6219
+ for (const finish of waiters) {
6220
+ finish();
6221
+ }
6222
+ if (this.isClosing || this.closeExpected) {
6054
6223
  return;
6055
6224
  }
6225
+ this._wasClosedUnexpectedly = true;
6056
6226
  const error = new InspectorConnectionError("Connection closed unexpectedly");
6057
6227
  for (const pending of this.pendingRequests.values()) {
6058
6228
  clearTimeout(pending.timer);
@@ -6165,6 +6335,8 @@ function parseSummaryLines(output) {
6165
6335
  if (bailSummary) {
6166
6336
  counts.failed = Math.max(counts.failed, Number.parseInt(bailSummary[1], 10));
6167
6337
  }
6338
+ const genuinePassed = counts.passed;
6339
+ const genuineFailed = counts.failed;
6168
6340
  const ranTestsSummary = /Ran\s+(\d+)\s+tests?/.exec(output);
6169
6341
  if (ranTestsSummary) {
6170
6342
  const totalFromRan = Number.parseInt(ranTestsSummary[1], 10);
@@ -6173,7 +6345,7 @@ function parseSummaryLines(output) {
6173
6345
  counts.passed = totalFromRan;
6174
6346
  }
6175
6347
  }
6176
- return counts;
6348
+ return { ...counts, genuinePassed, genuineFailed };
6177
6349
  }
6178
6350
  function parseBunTestOutput(stdout, stderr) {
6179
6351
  const tests = [];
@@ -6219,7 +6391,10 @@ ${stderr}`;
6219
6391
  totalTests: counters.passed + counters.failed + counters.skipped,
6220
6392
  passed: counters.passed,
6221
6393
  failed: counters.failed,
6222
- skipped: counters.skipped
6394
+ skipped: counters.skipped,
6395
+ summaryPassed: summaryCounts.genuinePassed,
6396
+ summaryFailed: summaryCounts.genuineFailed,
6397
+ summarySkipped: summaryCounts.skipped
6223
6398
  };
6224
6399
  }
6225
6400
 
@@ -6301,7 +6476,7 @@ function killWithEscalation(childProcess, isClosed, gracePeriodMs) {
6301
6476
  async function runBunTests(options) {
6302
6477
  const args = ["test"];
6303
6478
  if (options.inspectWaitPort) {
6304
- args.push(`--inspect=${options.inspectWaitPort}`);
6479
+ args.push(`--inspect=127.0.0.1:${options.inspectWaitPort}`);
6305
6480
  }
6306
6481
  if (options.bunfigPath) {
6307
6482
  args.push(`--config=${options.bunfigPath}`);
@@ -6575,189 +6750,6 @@ class SyncServer {
6575
6750
  import { readFile as readFile4, unlink as unlink3, writeFile as writeFile2, mkdir as mkdir2 } from "node:fs/promises";
6576
6751
  import path2 from "node:path";
6577
6752
 
6578
- // node_modules/smol-toml/dist/error.js
6579
- /*!
6580
- * Copyright (c) Squirrel Chat et al., All rights reserved.
6581
- * SPDX-License-Identifier: BSD-3-Clause
6582
- *
6583
- * Redistribution and use in source and binary forms, with or without
6584
- * modification, are permitted provided that the following conditions are met:
6585
- *
6586
- * 1. Redistributions of source code must retain the above copyright notice, this
6587
- * list of conditions and the following disclaimer.
6588
- * 2. Redistributions in binary form must reproduce the above copyright notice,
6589
- * this list of conditions and the following disclaimer in the
6590
- * documentation and/or other materials provided with the distribution.
6591
- * 3. Neither the name of the copyright holder nor the names of its contributors
6592
- * may be used to endorse or promote products derived from this software without
6593
- * specific prior written permission.
6594
- *
6595
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
6596
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
6597
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6598
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
6599
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6600
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6601
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6602
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6603
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6604
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6605
- */
6606
- function getLineColFromPtr(string, ptr) {
6607
- let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
6608
- return [lines.length, lines.pop().length + 1];
6609
- }
6610
- function makeCodeBlock(string, line, column) {
6611
- let lines = string.split(/\r\n|\n|\r/g);
6612
- let codeblock = "";
6613
- let numberLen = (Math.log10(line + 1) | 0) + 1;
6614
- for (let i = line - 1;i <= line + 1; i++) {
6615
- let l = lines[i - 1];
6616
- if (!l)
6617
- continue;
6618
- codeblock += i.toString().padEnd(numberLen, " ");
6619
- codeblock += ": ";
6620
- codeblock += l;
6621
- codeblock += `
6622
- `;
6623
- if (i === line) {
6624
- codeblock += " ".repeat(numberLen + column + 2);
6625
- codeblock += `^
6626
- `;
6627
- }
6628
- }
6629
- return codeblock;
6630
- }
6631
-
6632
- class TomlError extends Error {
6633
- line;
6634
- column;
6635
- codeblock;
6636
- constructor(message, options) {
6637
- const [line, column] = getLineColFromPtr(options.toml, options.ptr);
6638
- const codeblock = makeCodeBlock(options.toml, line, column);
6639
- super(`Invalid TOML document: ${message}
6640
-
6641
- ${codeblock}`, options);
6642
- this.line = line;
6643
- this.column = column;
6644
- this.codeblock = codeblock;
6645
- }
6646
- }
6647
-
6648
- // node_modules/smol-toml/dist/util.js
6649
- /*!
6650
- * Copyright (c) Squirrel Chat et al., All rights reserved.
6651
- * SPDX-License-Identifier: BSD-3-Clause
6652
- *
6653
- * Redistribution and use in source and binary forms, with or without
6654
- * modification, are permitted provided that the following conditions are met:
6655
- *
6656
- * 1. Redistributions of source code must retain the above copyright notice, this
6657
- * list of conditions and the following disclaimer.
6658
- * 2. Redistributions in binary form must reproduce the above copyright notice,
6659
- * this list of conditions and the following disclaimer in the
6660
- * documentation and/or other materials provided with the distribution.
6661
- * 3. Neither the name of the copyright holder nor the names of its contributors
6662
- * may be used to endorse or promote products derived from this software without
6663
- * specific prior written permission.
6664
- *
6665
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
6666
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
6667
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6668
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
6669
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6670
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6671
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6672
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6673
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6674
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6675
- */
6676
- function isEscaped(str, ptr) {
6677
- let i = 0;
6678
- while (str[ptr - ++i] === "\\")
6679
- ;
6680
- return --i && i % 2;
6681
- }
6682
- function indexOfNewline(str, start = 0, end = str.length) {
6683
- let idx = str.indexOf(`
6684
- `, start);
6685
- if (str[idx - 1] === "\r")
6686
- idx--;
6687
- return idx <= end ? idx : -1;
6688
- }
6689
- function skipComment(str, ptr) {
6690
- for (let i = ptr;i < str.length; i++) {
6691
- let c = str[i];
6692
- if (c === `
6693
- `)
6694
- return i;
6695
- if (c === "\r" && str[i + 1] === `
6696
- `)
6697
- return i + 1;
6698
- if (c < " " && c !== "\t" || c === "") {
6699
- throw new TomlError("control characters are not allowed in comments", {
6700
- toml: str,
6701
- ptr
6702
- });
6703
- }
6704
- }
6705
- return str.length;
6706
- }
6707
- function skipVoid(str, ptr, banNewLines, banComments) {
6708
- let c;
6709
- while (true) {
6710
- while ((c = str[ptr]) === " " || c === "\t" || !banNewLines && (c === `
6711
- ` || c === "\r" && str[ptr + 1] === `
6712
- `))
6713
- ptr++;
6714
- if (banComments || c !== "#")
6715
- break;
6716
- ptr = skipComment(str, ptr);
6717
- }
6718
- return ptr;
6719
- }
6720
- function skipUntil(str, ptr, sep2, end, banNewLines = false) {
6721
- if (!end) {
6722
- ptr = indexOfNewline(str, ptr);
6723
- return ptr < 0 ? str.length : ptr;
6724
- }
6725
- for (let i = ptr;i < str.length; i++) {
6726
- let c = str[i];
6727
- if (c === "#") {
6728
- i = indexOfNewline(str, i);
6729
- } else if (c === sep2) {
6730
- return i + 1;
6731
- } else if (c === end || banNewLines && (c === `
6732
- ` || c === "\r" && str[i + 1] === `
6733
- `)) {
6734
- return i;
6735
- }
6736
- }
6737
- throw new TomlError("cannot find end of structure", {
6738
- toml: str,
6739
- ptr
6740
- });
6741
- }
6742
- function getStringEnd(str, seek) {
6743
- let first = str[seek];
6744
- let target2 = first === str[seek + 1] && str[seek + 1] === str[seek + 2] ? str.slice(seek, seek + 3) : first;
6745
- seek += target2.length - 1;
6746
- do
6747
- seek = str.indexOf(target2, ++seek);
6748
- while (seek > -1 && first !== "'" && isEscaped(str, seek));
6749
- if (seek > -1) {
6750
- seek += target2.length;
6751
- if (target2.length > 1) {
6752
- if (str[seek] === first)
6753
- seek++;
6754
- if (str[seek] === first)
6755
- seek++;
6756
- }
6757
- }
6758
- return seek;
6759
- }
6760
-
6761
6753
  // node_modules/smol-toml/dist/date.js
6762
6754
  /*!
6763
6755
  * Copyright (c) Squirrel Chat et al., All rights reserved.
@@ -6878,6 +6870,76 @@ class TomlDate extends Date {
6878
6870
  }
6879
6871
  }
6880
6872
 
6873
+ // node_modules/smol-toml/dist/error.js
6874
+ /*!
6875
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
6876
+ * SPDX-License-Identifier: BSD-3-Clause
6877
+ *
6878
+ * Redistribution and use in source and binary forms, with or without
6879
+ * modification, are permitted provided that the following conditions are met:
6880
+ *
6881
+ * 1. Redistributions of source code must retain the above copyright notice, this
6882
+ * list of conditions and the following disclaimer.
6883
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
6884
+ * this list of conditions and the following disclaimer in the
6885
+ * documentation and/or other materials provided with the distribution.
6886
+ * 3. Neither the name of the copyright holder nor the names of its contributors
6887
+ * may be used to endorse or promote products derived from this software without
6888
+ * specific prior written permission.
6889
+ *
6890
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
6891
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
6892
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6893
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
6894
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6895
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6896
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6897
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6898
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6899
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6900
+ */
6901
+ function getLineColFromPtr(string, ptr) {
6902
+ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
6903
+ return [lines.length, lines.pop().length + 1];
6904
+ }
6905
+ function makeCodeBlock(string, line, column) {
6906
+ let lines = string.split(/\r\n|\n|\r/g);
6907
+ let codeblock = "";
6908
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
6909
+ for (let i = line - 1;i <= line + 1; i++) {
6910
+ let l = lines[i - 1];
6911
+ if (!l)
6912
+ continue;
6913
+ codeblock += i.toString().padEnd(numberLen, " ");
6914
+ codeblock += ": ";
6915
+ codeblock += l;
6916
+ codeblock += `
6917
+ `;
6918
+ if (i === line) {
6919
+ codeblock += " ".repeat(numberLen + column + 2);
6920
+ codeblock += `^
6921
+ `;
6922
+ }
6923
+ }
6924
+ return codeblock;
6925
+ }
6926
+
6927
+ class TomlError extends Error {
6928
+ line;
6929
+ column;
6930
+ codeblock;
6931
+ constructor(message, options) {
6932
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
6933
+ const codeblock = makeCodeBlock(options.toml, line, column);
6934
+ super(`Invalid TOML document: ${message}
6935
+
6936
+ ${codeblock}`, options);
6937
+ this.line = line;
6938
+ this.column = column;
6939
+ this.codeblock = codeblock;
6940
+ }
6941
+ }
6942
+
6881
6943
  // node_modules/smol-toml/dist/primitive.js
6882
6944
  /*!
6883
6945
  * Copyright (c) Squirrel Chat et al., All rights reserved.
@@ -6909,95 +6971,103 @@ class TomlDate extends Date {
6909
6971
  var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
6910
6972
  var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
6911
6973
  var LEADING_ZERO = /^[+-]?0[0-9_]/;
6912
- var ESCAPE_REGEX = /^[0-9a-f]{2,8}$/i;
6913
- var ESC_MAP = {
6914
- b: "\b",
6915
- t: "\t",
6916
- n: `
6917
- `,
6918
- f: "\f",
6919
- r: "\r",
6920
- e: "\x1B",
6921
- '"': '"',
6922
- "\\": "\\"
6923
- };
6924
- function parseString(str, ptr = 0, endPtr = str.length) {
6925
- let isLiteral = str[ptr] === "'";
6926
- let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
6974
+ function parseString(str, ptr) {
6975
+ let c = str[ptr++];
6976
+ let first = c;
6977
+ let isLiteral = c === "'";
6978
+ let isMultiline = c === str[ptr] && c === str[ptr + 1];
6927
6979
  if (isMultiline) {
6928
- endPtr -= 2;
6929
- if (str[ptr += 2] === "\r")
6930
- ptr++;
6931
- if (str[ptr] === `
6980
+ if (str[ptr += 2] === `
6932
6981
  `)
6933
6982
  ptr++;
6983
+ else if (str[ptr] === "\r" && str[ptr + 1] === `
6984
+ `)
6985
+ ptr += 2;
6934
6986
  }
6935
- let tmp = 0;
6936
- let isEscape;
6937
6987
  let parsed = "";
6938
6988
  let sliceStart = ptr;
6939
- while (ptr < endPtr - 1) {
6940
- let c = str[ptr++];
6941
- if (c === `
6942
- ` || c === "\r" && str[ptr] === `
6943
- `) {
6944
- if (!isMultiline) {
6945
- throw new TomlError("newlines are not allowed in strings", {
6946
- toml: str,
6947
- ptr: ptr - 1
6948
- });
6949
- }
6989
+ let state = 0;
6990
+ for (let i = ptr;i < str.length; i++) {
6991
+ c = str[i];
6992
+ if (isMultiline && (c === `
6993
+ ` || c === "\r" && str[i + 1] === `
6994
+ `)) {
6995
+ state = state && 3;
6950
6996
  } else if (c < " " && c !== "\t" || c === "") {
6951
6997
  throw new TomlError("control characters are not allowed in strings", {
6952
6998
  toml: str,
6953
- ptr: ptr - 1
6999
+ ptr: i
6954
7000
  });
6955
- }
6956
- if (isEscape) {
6957
- isEscape = false;
7001
+ } else if ((!state || state === 3) && c === first && (!isMultiline || str[i + 1] === first && str[i + 2] === first)) {
7002
+ if (isMultiline) {
7003
+ if (str[i + 3] === first)
7004
+ i++;
7005
+ if (str[i + 3] === first)
7006
+ i++;
7007
+ }
7008
+ return [
7009
+ state ? parsed : parsed + str.slice(sliceStart, i),
7010
+ i + (isMultiline ? 3 : 1)
7011
+ ];
7012
+ } else if (!state) {
7013
+ if (!isLiteral && c === "\\") {
7014
+ parsed += str.slice(sliceStart, sliceStart = i);
7015
+ state = 1;
7016
+ }
7017
+ } else if (state === 1) {
6958
7018
  if (c === "x" || c === "u" || c === "U") {
6959
- let code = str.slice(ptr, ptr += c === "x" ? 2 : c === "u" ? 4 : 8);
6960
- if (!ESCAPE_REGEX.test(code)) {
6961
- throw new TomlError("invalid unicode escape", {
6962
- toml: str,
6963
- ptr: tmp
6964
- });
6965
- }
6966
- try {
6967
- parsed += String.fromCodePoint(parseInt(code, 16));
6968
- } catch {
6969
- throw new TomlError("invalid unicode escape", {
6970
- toml: str,
6971
- ptr: tmp
6972
- });
6973
- }
6974
- } else if (isMultiline && (c === `
6975
- ` || c === " " || c === "\t" || c === "\r")) {
6976
- ptr = skipVoid(str, ptr - 1, true);
6977
- if (str[ptr] !== `
6978
- ` && str[ptr] !== "\r") {
6979
- throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
6980
- toml: str,
6981
- ptr: tmp
6982
- });
6983
- }
6984
- ptr = skipVoid(str, ptr);
6985
- } else if (c in ESC_MAP) {
6986
- parsed += ESC_MAP[c];
7019
+ let value = 0;
7020
+ let len = c === "x" ? 2 : c === "u" ? 4 : 8;
7021
+ for (let j = 0;j < len; j++, i++) {
7022
+ let hex = str.charCodeAt(i + 1);
7023
+ let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
7024
+ if (digit < 0)
7025
+ throw new TomlError("invalid non-hex character in unicode escape", { toml: str, ptr: i + 1 });
7026
+ value = value << 4 | digit;
7027
+ }
7028
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
7029
+ throw new TomlError("invalid unicode escape", { toml: str, ptr: i });
7030
+ }
7031
+ parsed += String.fromCodePoint(value);
7032
+ sliceStart = i + 1;
7033
+ state = 0;
7034
+ } else if (c === " " || c === "\t") {
7035
+ state = 2;
6987
7036
  } else {
6988
- throw new TomlError("unrecognized escape sequence", {
7037
+ if (c === "b")
7038
+ parsed += "\b";
7039
+ else if (c === "t")
7040
+ parsed += "\t";
7041
+ else if (c === "n")
7042
+ parsed += `
7043
+ `;
7044
+ else if (c === "f")
7045
+ parsed += "\f";
7046
+ else if (c === "r")
7047
+ parsed += "\r";
7048
+ else if (c === "e")
7049
+ parsed += "\x1B";
7050
+ else if (c === '"')
7051
+ parsed += '"';
7052
+ else if (c === "\\")
7053
+ parsed += "\\";
7054
+ else
7055
+ throw new TomlError("unrecognized escape sequence", { toml: str, ptr: i });
7056
+ sliceStart = i + 1;
7057
+ state = 0;
7058
+ }
7059
+ } else if (c !== " " && c !== "\t") {
7060
+ if (state === 2) {
7061
+ throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
6989
7062
  toml: str,
6990
- ptr: tmp
7063
+ ptr: sliceStart
6991
7064
  });
6992
7065
  }
6993
- sliceStart = ptr;
6994
- } else if (!isLiteral && c === "\\") {
6995
- tmp = ptr - 1;
6996
- isEscape = true;
6997
- parsed += str.slice(sliceStart, tmp);
7066
+ state = !isLiteral && c === "\\" ? 1 : 0;
7067
+ sliceStart = i;
6998
7068
  }
6999
7069
  }
7000
- return parsed + str.slice(sliceStart, endPtr - 1);
7070
+ throw new TomlError("unfinished string", { toml: str, ptr });
7001
7071
  }
7002
7072
  function parseValue(value, toml, ptr, integersAsBigInt) {
7003
7073
  if (value === "true")
@@ -7050,6 +7120,95 @@ function parseValue(value, toml, ptr, integersAsBigInt) {
7050
7120
  return date;
7051
7121
  }
7052
7122
 
7123
+ // node_modules/smol-toml/dist/util.js
7124
+ /*!
7125
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
7126
+ * SPDX-License-Identifier: BSD-3-Clause
7127
+ *
7128
+ * Redistribution and use in source and binary forms, with or without
7129
+ * modification, are permitted provided that the following conditions are met:
7130
+ *
7131
+ * 1. Redistributions of source code must retain the above copyright notice, this
7132
+ * list of conditions and the following disclaimer.
7133
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
7134
+ * this list of conditions and the following disclaimer in the
7135
+ * documentation and/or other materials provided with the distribution.
7136
+ * 3. Neither the name of the copyright holder nor the names of its contributors
7137
+ * may be used to endorse or promote products derived from this software without
7138
+ * specific prior written permission.
7139
+ *
7140
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
7141
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7142
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7143
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
7144
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7145
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7146
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7147
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7148
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
7149
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7150
+ */
7151
+ function indexOfNewline(str, start = 0, end = str.length) {
7152
+ let idx = str.indexOf(`
7153
+ `, start);
7154
+ if (str[idx - 1] === "\r")
7155
+ idx--;
7156
+ return idx <= end ? idx : -1;
7157
+ }
7158
+ function skipComment(str, ptr) {
7159
+ for (let i = ptr;i < str.length; i++) {
7160
+ let c = str[i];
7161
+ if (c === `
7162
+ `)
7163
+ return i;
7164
+ if (c === "\r" && str[i + 1] === `
7165
+ `)
7166
+ return i + 1;
7167
+ if (c < " " && c !== "\t" || c === "") {
7168
+ throw new TomlError("control characters are not allowed in comments", {
7169
+ toml: str,
7170
+ ptr
7171
+ });
7172
+ }
7173
+ }
7174
+ return str.length;
7175
+ }
7176
+ function skipVoid(str, ptr, banNewLines, banComments) {
7177
+ let c;
7178
+ while (true) {
7179
+ while ((c = str[ptr]) === " " || c === "\t" || !banNewLines && (c === `
7180
+ ` || c === "\r" && str[ptr + 1] === `
7181
+ `))
7182
+ ptr++;
7183
+ if (banComments || c !== "#")
7184
+ break;
7185
+ ptr = skipComment(str, ptr);
7186
+ }
7187
+ return ptr;
7188
+ }
7189
+ function skipUntil(str, ptr, sep2, end, banNewLines = false) {
7190
+ if (!end) {
7191
+ ptr = indexOfNewline(str, ptr);
7192
+ return ptr < 0 ? str.length : ptr;
7193
+ }
7194
+ for (let i = ptr;i < str.length; i++) {
7195
+ let c = str[i];
7196
+ if (c === "#") {
7197
+ i = indexOfNewline(str, i);
7198
+ } else if (c === sep2) {
7199
+ return i + 1;
7200
+ } else if (c === end || banNewLines && (c === `
7201
+ ` || c === "\r" && str[i + 1] === `
7202
+ `)) {
7203
+ return i;
7204
+ }
7205
+ }
7206
+ throw new TomlError("cannot find end of structure", {
7207
+ toml: str,
7208
+ ptr
7209
+ });
7210
+ }
7211
+
7053
7212
  // node_modules/smol-toml/dist/extract.js
7054
7213
  /*!
7055
7214
  * Copyright (c) Squirrel Chat et al., All rights reserved.
@@ -7110,25 +7269,24 @@ function extractValue(str, ptr, end, depth, integersAsBigInt) {
7110
7269
  }
7111
7270
  return [value, endPtr2];
7112
7271
  }
7113
- let endPtr;
7114
7272
  if (c === '"' || c === "'") {
7115
- endPtr = getStringEnd(str, ptr);
7116
- let parsed = parseString(str, ptr, endPtr);
7273
+ let [parsed, endPtr2] = parseString(str, ptr);
7117
7274
  if (end) {
7118
- endPtr = skipVoid(str, endPtr);
7119
- if (str[endPtr] && str[endPtr] !== "," && str[endPtr] !== end && str[endPtr] !== `
7120
- ` && str[endPtr] !== "\r") {
7275
+ endPtr2 = skipVoid(str, endPtr2);
7276
+ if (str[endPtr2] && str[endPtr2] !== "," && str[endPtr2] !== end && str[endPtr2] !== `
7277
+ ` && str[endPtr2] !== "\r") {
7121
7278
  throw new TomlError("unexpected character encountered", {
7122
7279
  toml: str,
7123
- ptr: endPtr
7280
+ ptr: endPtr2
7124
7281
  });
7125
7282
  }
7126
- endPtr += +(str[endPtr] === ",");
7283
+ if (str[endPtr2] === ",")
7284
+ endPtr2++;
7127
7285
  }
7128
- return [parsed, endPtr];
7286
+ return [parsed, endPtr2];
7129
7287
  }
7130
- endPtr = skipUntil(str, ptr, ",", end);
7131
- let slice = sliceAndTrimEndOf(str, ptr, endPtr - +(str[endPtr - 1] === ","));
7288
+ let endPtr = skipUntil(str, ptr, ",", end);
7289
+ let slice = sliceAndTrimEndOf(str, ptr, endPtr - (str[endPtr - 1] === "," ? 1 : 0));
7132
7290
  if (!slice[0]) {
7133
7291
  throw new TomlError("incomplete key-value declaration: no value specified", {
7134
7292
  toml: str,
@@ -7137,7 +7295,8 @@ function extractValue(str, ptr, end, depth, integersAsBigInt) {
7137
7295
  }
7138
7296
  if (end && slice[1] > -1) {
7139
7297
  endPtr = skipVoid(str, ptr + slice[1]);
7140
- endPtr += +(str[endPtr] === ",");
7298
+ if (str[endPtr] === ",")
7299
+ endPtr++;
7141
7300
  }
7142
7301
  return [
7143
7302
  parseValue(slice[0], str, ptr, integersAsBigInt),
@@ -7194,13 +7353,7 @@ function parseKey(str, ptr, end = "=") {
7194
7353
  ptr
7195
7354
  });
7196
7355
  }
7197
- let eos = getStringEnd(str, ptr);
7198
- if (eos < 0) {
7199
- throw new TomlError("unfinished string encountered", {
7200
- toml: str,
7201
- ptr
7202
- });
7203
- }
7356
+ let [part, eos] = parseString(str, ptr);
7204
7357
  dot = str.indexOf(".", eos);
7205
7358
  let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
7206
7359
  let newLine = indexOfNewline(strEnd);
@@ -7225,7 +7378,7 @@ function parseKey(str, ptr, end = "=") {
7225
7378
  });
7226
7379
  }
7227
7380
  }
7228
- parsed.push(parseString(str, ptr, eos));
7381
+ parsed.push(part);
7229
7382
  } else {
7230
7383
  dot = str.indexOf(".", ptr);
7231
7384
  let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
@@ -7523,7 +7676,7 @@ function stringifyValue(val, type, depth, numberAsFloat) {
7523
7676
  return "inf";
7524
7677
  if (val === -Infinity)
7525
7678
  return "-inf";
7526
- if (numberAsFloat && Number.isInteger(val))
7679
+ if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
7527
7680
  return val.toFixed(1);
7528
7681
  return val.toString();
7529
7682
  }
@@ -7888,6 +8041,12 @@ function buildTestNameIndex(tests, bunNames) {
7888
8041
  return testNameIndex;
7889
8042
  }
7890
8043
  var ZERO_MATCH_TEST_PATTERN_RE = /matched 0 tests\./;
8044
+ var MAX_DRY_RUN_FAILURE_TESTS_LISTED = 20;
8045
+ var MAX_COVERAGE_BLEED_WARNINGS = 25;
8046
+ var EXECUTION_SHORTFALL_ABS_FLOOR = 10;
8047
+ var EXECUTION_SHORTFALL_RATIO_THRESHOLD = 0.05;
8048
+ var ORPHANED_KEY_ABS_FLOOR = 5;
8049
+ var INSPECTOR_DRAIN_TIMEOUT_MS = 1000;
7891
8050
 
7892
8051
  class BunTestRunner {
7893
8052
  logger;
@@ -7952,7 +8111,9 @@ class BunTestRunner {
7952
8111
  }
7953
8112
  }
7954
8113
  get registryPath() {
7955
- return path4.join(process.cwd(), ".stryker-bun-runner-registry.json");
8114
+ const key = `${process.cwd()}:${process.ppid}`;
8115
+ const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
8116
+ return path4.join(tmpdir(), "stryker-bun-runner", `registry-${hash}.json`);
7956
8117
  }
7957
8118
  get registryTmpPath() {
7958
8119
  return `${this.registryPath}.tmp`;
@@ -8061,6 +8222,13 @@ class BunTestRunner {
8061
8222
  }
8062
8223
  }
8063
8224
  }
8225
+ buildFailureMessage(testInfo, parsed) {
8226
+ const parsedTest = parsed.tests.find((t) => t.name.includes(testInfo.name));
8227
+ const baseFailureMessage = parsedTest?.failureMessage ?? testInfo.error?.message ?? "Test failed";
8228
+ const stack = testInfo.error?.stack;
8229
+ return stack && !baseFailureMessage.includes(stack) ? `${baseFailureMessage}
8230
+ ${stack}` : baseFailureMessage;
8231
+ }
8064
8232
  buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile) {
8065
8233
  if (executionOrder.length === 0) {
8066
8234
  const fallbackTests = parsed.tests.map((t) => {
@@ -8114,14 +8282,13 @@ class BunTestRunner {
8114
8282
  const elapsed = testInfo.elapsed === undefined ? timePerTest : Math.round(testInfo.elapsed / 1e6);
8115
8283
  const startPosition = testInfo.line === undefined ? undefined : { line: testInfo.line, column: 0 };
8116
8284
  if (status === "fail") {
8117
- const parsedTest = parsed.tests.find((t) => t.name.includes(testInfo.name));
8118
8285
  return {
8119
8286
  id: uniqueName,
8120
8287
  name: uniqueName,
8121
8288
  fileName,
8122
8289
  startPosition,
8123
8290
  status: TestStatus.Failed,
8124
- failureMessage: parsedTest?.failureMessage ?? testInfo.error?.message ?? "Test failed",
8291
+ failureMessage: this.buildFailureMessage(testInfo, parsed),
8125
8292
  timeSpentMs: elapsed
8126
8293
  };
8127
8294
  }
@@ -8144,28 +8311,26 @@ class BunTestRunner {
8144
8311
  timeSpentMs: elapsed
8145
8312
  };
8146
8313
  });
8314
+ const discoveryOrderIndex = buildDiscoveryOrderIndex(testHierarchy.map((t) => t.id));
8147
8315
  const nameCounts = new Map;
8148
8316
  for (const test of tests) {
8149
8317
  nameCounts.set(test.name, (nameCounts.get(test.name) ?? 0) + 1);
8150
8318
  }
8151
8319
  const nameGroups = new Map;
8152
- for (const test of tests) {
8320
+ for (const [i, test] of tests.entries()) {
8153
8321
  if ((nameCounts.get(test.name) ?? 1) > 1) {
8322
+ const entry = { test, inspectorId: executionOrder[i] };
8154
8323
  const group = nameGroups.get(test.name);
8155
8324
  if (group) {
8156
- group.push(test);
8325
+ group.push(entry);
8157
8326
  } else {
8158
- nameGroups.set(test.name, [test]);
8327
+ nameGroups.set(test.name, [entry]);
8159
8328
  }
8160
8329
  }
8161
8330
  }
8162
8331
  for (const [, group] of nameGroups) {
8163
- group.sort((a, b) => {
8164
- const lineA = "startPosition" in a && a.startPosition ? a.startPosition.line : Infinity;
8165
- const lineB = "startPosition" in b && b.startPosition ? b.startPosition.line : Infinity;
8166
- return lineA - lineB;
8167
- });
8168
- for (const [i, test] of group.entries()) {
8332
+ const sorted = sortDuplicateGroupByLineThenDiscovery(group, (e) => ("startPosition" in e.test) && e.test.startPosition ? e.test.startPosition.line : undefined, (e) => e.inspectorId, discoveryOrderIndex);
8333
+ for (const [i, { test }] of sorted.entries()) {
8169
8334
  const uniqueName = `${test.name} [${i}]`;
8170
8335
  test.id = uniqueName;
8171
8336
  test.name = uniqueName;
@@ -8246,7 +8411,11 @@ exit=%s timedOut=%s
8246
8411
  url: inspectorUrl,
8247
8412
  connectionTimeout: this.inspectorTimeout,
8248
8413
  requestTimeout: this.inspectorTimeout,
8249
- handlers: {}
8414
+ handlers: {
8415
+ onError: (error) => {
8416
+ this.logger.warn("Inspector error: %s", error.message);
8417
+ }
8418
+ }
8250
8419
  });
8251
8420
  try {
8252
8421
  await inspector.connect();
@@ -8266,24 +8435,19 @@ exit=%s timedOut=%s
8266
8435
  this.logger.debug("Signaled preload script to proceed");
8267
8436
  const result = await testProcess;
8268
8437
  const totalElapsedMs = Date.now() - startTime;
8438
+ inspector.expectClose();
8439
+ await inspector.waitForClose(INSPECTOR_DRAIN_TIMEOUT_MS);
8269
8440
  const testHierarchy = inspector.getTests();
8270
8441
  const executionOrder = inspector.getExecutionOrder();
8442
+ const wasClosedUnexpectedly = inspector.wasClosedUnexpectedly;
8271
8443
  await inspector.close();
8272
8444
  this.logger.debug("Inspector collected %d tests in hierarchy, %d in execution order", testHierarchy.length, executionOrder.length);
8273
8445
  const parsed = parseBunTestOutput(result.stdout, result.stderr);
8274
- const earlyResult = this.checkDryRunProcessResult(result, parsed);
8446
+ const earlyResult = this.checkDryRunProcessResult(result, parsed, testHierarchy);
8275
8447
  if (earlyResult) {
8276
8448
  return earlyResult;
8277
8449
  }
8278
- const { coverage: mutantCoverage, inspectorIdToProjectFile } = await this.collectAndRemapCoverage(testHierarchy, executionOrder);
8279
- const { tests, testNameIndex } = this.buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile);
8280
- tests.sort((a, b) => a.name.localeCompare(b.name));
8281
- await this.buildAndPersistTestRegistry(tests, testNameIndex);
8282
- return {
8283
- status: DryRunStatus.Complete,
8284
- tests,
8285
- mutantCoverage
8286
- };
8450
+ return await this.buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly);
8287
8451
  } finally {
8288
8452
  abortController.abort();
8289
8453
  if (this.currentAbortController === abortController) {
@@ -8292,6 +8456,22 @@ exit=%s timedOut=%s
8292
8456
  await syncServer.close();
8293
8457
  }
8294
8458
  }
8459
+ async buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly) {
8460
+ const { coverage: mutantCoverage, inspectorIdToProjectFile, rawKeyCount, orphanedKeyCount } = await this.collectAndRemapCoverage(testHierarchy, executionOrder);
8461
+ const { tests, testNameIndex } = this.buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile);
8462
+ tests.sort((a, b) => a.name.localeCompare(b.name));
8463
+ const gateResult = this.checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests);
8464
+ if (gateResult) {
8465
+ return gateResult;
8466
+ }
8467
+ await this.buildAndPersistTestRegistry(tests, testNameIndex);
8468
+ this.warnOnUnidentifiedDryRunFailure(result, parsed, tests);
8469
+ return {
8470
+ status: DryRunStatus.Complete,
8471
+ tests,
8472
+ mutantCoverage
8473
+ };
8474
+ }
8295
8475
  async buildAndPersistTestRegistry(tests, testNameIndex) {
8296
8476
  this.cachedTestNames = new Set(tests.map((t) => t.name));
8297
8477
  if (tests.length !== this.cachedTestNames.size) {
@@ -8328,6 +8508,7 @@ exit=%s timedOut=%s
8328
8508
  baseNameIndex: [...this.baseNameIndex.entries()],
8329
8509
  testNameIndex: [...testNameIndex.entries()]
8330
8510
  });
8511
+ await fsPromises2.mkdir(path4.dirname(registryPath), { recursive: true });
8331
8512
  await fsPromises2.writeFile(tmpPath, registryData, "utf8");
8332
8513
  this.lastRegistryTmpPath = tmpPath;
8333
8514
  await fsPromises2.rename(tmpPath, registryPath);
@@ -8466,32 +8647,120 @@ exit=%s timedOut=%s
8466
8647
  }
8467
8648
  return null;
8468
8649
  }
8469
- checkDryRunProcessResult(result, parsed) {
8650
+ checkDryRunProcessResult(result, parsed, testHierarchy) {
8470
8651
  if (result.timedOut) {
8471
8652
  this.logger.warn("Dry run timed out");
8472
8653
  return { status: DryRunStatus.Timeout };
8473
8654
  }
8474
8655
  if (result.exitCode !== 0 && parsed.failed === 0) {
8656
+ const failureDetails = this.formatInspectorFailureDetails(testHierarchy);
8657
+ const messageParts = [`Bun test process failed with exit code ${result.exitCode}`];
8658
+ if (failureDetails) {
8659
+ messageParts.push(failureDetails);
8660
+ }
8661
+ messageParts.push(result.stderr);
8475
8662
  return {
8476
8663
  status: DryRunStatus.Error,
8477
- errorMessage: `Bun test process failed with exit code ${result.exitCode}
8478
- ${result.stderr}`
8664
+ errorMessage: messageParts.join(`
8665
+ `)
8479
8666
  };
8480
8667
  }
8481
8668
  return null;
8482
8669
  }
8670
+ formatInspectorFailureDetails(testHierarchy) {
8671
+ const failedTests = testHierarchy.filter((t) => t.type === "test" && t.status === "fail");
8672
+ if (failedTests.length === 0) {
8673
+ return "";
8674
+ }
8675
+ const listed = failedTests.slice(0, MAX_DRY_RUN_FAILURE_TESTS_LISTED);
8676
+ const lines = listed.map((t) => {
8677
+ const message = t.error?.message ?? "no error message captured";
8678
+ let line = ` - ${t.fullName}: ${message}`;
8679
+ if (t.error?.stack) {
8680
+ const indentedStack = t.error.stack.split(`
8681
+ `).map((stackLine) => ` ${stackLine}`).join(`
8682
+ `);
8683
+ line += `
8684
+ ${indentedStack}`;
8685
+ }
8686
+ return line;
8687
+ });
8688
+ const remaining = failedTests.length - listed.length;
8689
+ if (remaining > 0) {
8690
+ lines.push(` ...and ${remaining} more`);
8691
+ }
8692
+ return `${failedTests.length} test(s) reported failed via Bun's inspector (stdout/stderr recap may be truncated or missing):
8693
+ ${lines.join(`
8694
+ `)}`;
8695
+ }
8696
+ warnOnUnidentifiedDryRunFailure(result, parsed, tests) {
8697
+ if ((result.exitCode !== 0 || parsed.failed > 0) && !tests.some((t) => t.status === TestStatus.Failed)) {
8698
+ this.logger.warn("Bun exited with code %s and its console output reported %d failed test(s), " + "but no failing test could be identified from inspector or console data. " + "An unhandled error firing between tests (e.g. a rejected fire-and-forget " + `promise) is a likely cause. Last 500 chars of stderr:
8699
+ %s`, String(result.exitCode), parsed.failed, result.stderr.slice(-500));
8700
+ }
8701
+ }
8702
+ checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests) {
8703
+ if (tests.some((t) => t.status === TestStatus.Failed)) {
8704
+ return null;
8705
+ }
8706
+ const testMap = new Map(testHierarchy.map((t) => [t.id, t]));
8707
+ const nonSkippedExecutionCount = executionOrder.filter((id) => {
8708
+ const status = testMap.get(id)?.status;
8709
+ return status !== "skip" && status !== "todo";
8710
+ }).length;
8711
+ const consoleTotal = parsed.summaryPassed + parsed.summaryFailed;
8712
+ const shortfall = consoleTotal - nonSkippedExecutionCount;
8713
+ const signalA = consoleTotal > 0 && shortfall > EXECUTION_SHORTFALL_ABS_FLOOR && shortfall / consoleTotal > EXECUTION_SHORTFALL_RATIO_THRESHOLD;
8714
+ const signalB = orphanedKeyCount > ORPHANED_KEY_ABS_FLOOR;
8715
+ if (!signalA && !signalB) {
8716
+ return null;
8717
+ }
8718
+ const reasons = [];
8719
+ if (signalA) {
8720
+ reasons.push(`console reported ${consoleTotal} test(s) (pass+fail) but the inspector's execution order ` + `contains only ${nonSkippedExecutionCount} non-skipped test(s) (shortfall ${shortfall})`);
8721
+ }
8722
+ if (signalB) {
8723
+ reasons.push(`${orphanedKeyCount} of ${rawKeyCount} coverage key(s) could not be paired with any inspector test (orphaned)`);
8724
+ }
8725
+ if (wasClosedUnexpectedly) {
8726
+ reasons.push("the inspector WebSocket closed unexpectedly before this data could be fully drained");
8727
+ }
8728
+ const errorMessage = "stryker-bun-runner: dry run data-completeness check failed — " + `${reasons.join("; ")}. This indicates the Bun inspector event stream may have been ` + "truncated mid-run; proceeding would risk silently " + "corrupted coverage attribution, so this dry run is being reported as an error instead of " + "Complete, and the test registry has NOT been persisted.";
8729
+ this.logger.error("%s", errorMessage);
8730
+ return {
8731
+ status: DryRunStatus.Error,
8732
+ errorMessage
8733
+ };
8734
+ }
8483
8735
  async collectAndRemapCoverage(testHierarchy, executionOrder) {
8484
8736
  const testMap = new Map(testHierarchy.map((t) => [t.id, t]));
8485
8737
  if (!this.coverageFilePath) {
8486
- return { coverage: undefined, inspectorIdToProjectFile: new Map };
8738
+ return { coverage: undefined, inspectorIdToProjectFile: new Map, rawKeyCount: 0, orphanedKeyCount: 0 };
8487
8739
  }
8488
- const rawCoverage = await collectCoverage(this.coverageFilePath, this.logger);
8740
+ const [rawCoverage, lateHits] = await Promise.all([
8741
+ collectCoverage(this.coverageFilePath, this.logger),
8742
+ collectLateHits(this.coverageFilePath, this.logger)
8743
+ ]);
8489
8744
  await cleanupCoverageFile(this.coverageFilePath);
8490
8745
  if (!rawCoverage) {
8491
- return { coverage: undefined, inspectorIdToProjectFile: new Map };
8746
+ return { coverage: undefined, inspectorIdToProjectFile: new Map, rawKeyCount: 0, orphanedKeyCount: 0 };
8747
+ }
8748
+ const { coverage, inspectorIdToProjectFile, counterKeyToTestName, rawKeyCount, orphanedKeyCount } = mapCoverageToInspectorIds(rawCoverage, executionOrder, testMap, this.logger);
8749
+ if (lateHits.length > 0) {
8750
+ this.emitCoverageBleedWarnings(lateHits, counterKeyToTestName);
8751
+ }
8752
+ return { coverage, inspectorIdToProjectFile, rawKeyCount, orphanedKeyCount };
8753
+ }
8754
+ emitCoverageBleedWarnings(lateHits, counterKeyToTestName) {
8755
+ const listed = lateHits.slice(0, MAX_COVERAGE_BLEED_WARNINGS);
8756
+ for (const { testId, mutantIds } of listed) {
8757
+ const testName = counterKeyToTestName.get(testId) ?? testId;
8758
+ this.logger.warn("mutant coverage was recorded between tests, after '%s' completed — likely fire-and-forget async work " + "leaking past the test boundary (or beforeAll/fixture code running between tests); attribution for %d " + "mutant(s) may be wrong (mutant IDs: %s)", testName, mutantIds.length, mutantIds.join(", "));
8759
+ }
8760
+ const remaining = lateHits.length - listed.length;
8761
+ if (remaining > 0) {
8762
+ this.logger.warn("...and %d more coverage-bleed warning(s) suppressed", remaining);
8492
8763
  }
8493
- const { coverage, inspectorIdToProjectFile } = mapCoverageToInspectorIds(rawCoverage, executionOrder, testMap, this.logger);
8494
- return { coverage, inspectorIdToProjectFile };
8495
8764
  }
8496
8765
  buildLocalTestFilterIndex(testFilter) {
8497
8766
  const localRegistry = new Set(testFilter);