@hughescr/stryker-bun-runner 1.3.6 → 1.3.7

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 (3) hide show
  1. package/README.md +36 -17
  2. package/dist/index.js +75 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -292,24 +292,43 @@ of them in a clean run's logs is worth investigating before trusting the score.
292
292
  apply to them.
293
293
 
294
294
  At the default (WARN) log level, dry runs also emit a few lines tracing this
295
- handshake: `Drain-request received`, `Drain handler settled via ...`, and
296
- `Post-drain inspector snapshot`, reporting the round-trip's outcome (`ack`,
297
- `silence`, `ceiling`, or `send-rejected`), the found/start/end event-count
298
- deltas observed during the wait, and any found-id gaps. A separate DEBUG-level
295
+ handshake: `Drain-request received`, `Drain handler settled via ...`,
296
+ `Post-drain inspector snapshot`, and `Post-drain inspector close/collision
297
+ diagnostics`, reporting the round-trip's outcome (`ack`, `silence`,
298
+ `ceiling`, or `send-rejected`), the found/start/end event-count deltas
299
+ observed during the wait, any found-id gaps, the WebSocket close
300
+ code/reason/wasClean (plus how many ms after the last received frame the
301
+ close arrived), and raw-vs-unique found-event counts. A separate DEBUG-level
299
302
  line notes if the inspector socket closed while the run was still thought to
300
- be in progress — this is logged at DEBUG rather than WARN because the child
301
- closing its own socket right after receiving `'drained'` routinely wins the
302
- race against the runner's own close-expectation on a clean run, so on its own
303
- it is not evidence of anything wrong (it is folded into the completeness
304
- gate's error message as corroborating context only if that gate has already
305
- fired for another reason). Together the WARN-level lines are useful for
306
- telling apart two different failure shapes: residual loss caused by a
307
- runner-side bound being hit (a give-up
308
- outcome — `silence` or `ceiling`) versus loss happening inside Bun's own
309
- inspector agent (found-id gaps persisting even though the round-trip `ack`
310
- succeeded). One caveat: gap detection assumes Bun assigns test-discovery ids
311
- densely, which has been observed but is not a guaranteed contract, so treat
312
- gap reports as diagnostic rather than definitive.
303
+ be in progress (including the same close code/reason/wasClean detail) — this
304
+ is logged at DEBUG rather than WARN because the child closing its own socket
305
+ right after receiving `'drained'` routinely wins the race against the
306
+ runner's own close-expectation on a clean run, so on its own it is not
307
+ evidence of anything wrong (it is folded into the completeness gate's error
308
+ message as corroborating context — now including the captured close
309
+ code/reason — only if that gate has already fired for another reason).
310
+ Together the WARN-level lines are useful for telling apart two different
311
+ failure shapes: residual loss caused by a runner-side bound being hit (a
312
+ give-up outcome — `silence` or `ceiling`) versus loss happening inside Bun's
313
+ own inspector agent (found-id gaps persisting even though the round-trip
314
+ `ack` succeeded). One caveat: gap detection assumes Bun assigns
315
+ test-discovery ids densely, which has been observed but is not a guaranteed
316
+ contract — and even a dense (0-gap) id range does **not** prove
317
+ losslessness: a confirmed Bun TestReporter id-collision bug (two interleaved
318
+ `1..N` id sequences when `TestReporter.enable` lands mid-collection) keeps
319
+ ids dense while silently merging two distinct tests under one shared id.
320
+ That is exactly what the close/collision diagnostics line's
321
+ raw/unique/duplicate found counts exist to catch: a **nonzero duplicate
322
+ count is direct in-the-wild evidence of that id-collision bug**, and the
323
+ close code/reason/wasClean fields confirm or rule out a separate confirmed
324
+ Bun bug where `idleTimeout: 0` websockets are force-closed on a ~252-second
325
+ ping cycle (`ERR_WEBSOCKET_TIMEOUT`) — an abnormal close landing right on
326
+ that cadence points at the ping-cycle bug, while a clean close rules it out.
327
+ Finally, a WARN-level `Inspector request unanswered after ...` line fires if
328
+ an inspector protocol request (e.g. `TestReporter.enable`) goes unanswered
329
+ for more than 2 seconds while other frames are still arriving on the same
330
+ connection — a protocol-level stall signature distinct from the
331
+ total-silence give-up above.
313
332
 
314
333
  ### Coverage-bleed warning (dry run only)
315
334
 
package/dist/index.js CHANGED
@@ -5972,6 +5972,8 @@ function isTestReporterEndEvent(message) {
5972
5972
  }
5973
5973
 
5974
5974
  // src/inspector/inspector-client.ts
5975
+ var REQUEST_STALL_WARN_MS = 2000;
5976
+
5975
5977
  class InspectorTimeoutError extends Error {
5976
5978
  constructor(message) {
5977
5979
  super(message);
@@ -6004,6 +6006,10 @@ class InspectorClient {
6004
6006
  foundCount = 0;
6005
6007
  startCount = 0;
6006
6008
  endCount = 0;
6009
+ closeCode = undefined;
6010
+ closeReason = undefined;
6011
+ closeWasClean = undefined;
6012
+ msFromLastFrameToClose = undefined;
6007
6013
  constructor(options) {
6008
6014
  this.handlers = options.handlers ?? {};
6009
6015
  this.WebSocketClass = options.WebSocketClass ?? wrapper_default;
@@ -6038,8 +6044,8 @@ class InspectorClient {
6038
6044
  this.handleError(error);
6039
6045
  reject(error);
6040
6046
  });
6041
- ws.addEventListener("close", () => {
6042
- this.handleClose();
6047
+ ws.addEventListener("close", (event) => {
6048
+ this.handleClose(event.code, event.reason, event.wasClean);
6043
6049
  });
6044
6050
  ws.addEventListener("message", (event) => {
6045
6051
  this.handleMessage(event.data);
@@ -6054,20 +6060,40 @@ class InspectorClient {
6054
6060
  const message = { id, method, params };
6055
6061
  return new Promise((resolve3, reject) => {
6056
6062
  const effectiveTimeoutMs = timeoutMs ?? this.state.requestTimeout;
6063
+ const stallTimer = this.handlers.onRequestStall ? setTimeout(() => {
6064
+ if (this.pendingRequests.has(id)) {
6065
+ const msSinceLastFrame = this.getMsSinceLastFrame();
6066
+ if (msSinceLastFrame < REQUEST_STALL_WARN_MS) {
6067
+ this.handlers.onRequestStall({ method, id, msUnanswered: REQUEST_STALL_WARN_MS, msSinceLastFrame });
6068
+ }
6069
+ }
6070
+ }, REQUEST_STALL_WARN_MS) : undefined;
6057
6071
  const timer = setTimeout(() => {
6058
6072
  this.pendingRequests.delete(id);
6073
+ if (stallTimer) {
6074
+ clearTimeout(stallTimer);
6075
+ }
6059
6076
  reject(new InspectorTimeoutError(`Request timeout after ${effectiveTimeoutMs}ms: ${method}`));
6060
6077
  }, effectiveTimeoutMs);
6061
- this.pendingRequests.set(id, { resolve: resolve3, reject, timer });
6078
+ this.pendingRequests.set(id, { resolve: resolve3, reject, timer, stallTimer });
6062
6079
  try {
6063
6080
  this.ws.send(JSON.stringify(message));
6064
6081
  } catch (error) {
6065
6082
  this.pendingRequests.delete(id);
6066
6083
  clearTimeout(timer);
6084
+ if (stallTimer) {
6085
+ clearTimeout(stallTimer);
6086
+ }
6067
6087
  reject(error instanceof Error ? error : new Error(String(error)));
6068
6088
  }
6069
6089
  });
6070
6090
  }
6091
+ clearPendingTimers(pending) {
6092
+ clearTimeout(pending.timer);
6093
+ if (pending.stallTimer) {
6094
+ clearTimeout(pending.stallTimer);
6095
+ }
6096
+ }
6071
6097
  async close() {
6072
6098
  if (this.isClosing || !this.ws) {
6073
6099
  return;
@@ -6075,7 +6101,7 @@ class InspectorClient {
6075
6101
  this.isClosing = true;
6076
6102
  const error = new InspectorConnectionError("Connection closed");
6077
6103
  for (const pending of this.pendingRequests.values()) {
6078
- clearTimeout(pending.timer);
6104
+ this.clearPendingTimers(pending);
6079
6105
  pending.reject(error);
6080
6106
  }
6081
6107
  this.pendingRequests.clear();
@@ -6130,6 +6156,22 @@ class InspectorClient {
6130
6156
  getEventCounts() {
6131
6157
  return { found: this.foundCount, start: this.startCount, end: this.endCount };
6132
6158
  }
6159
+ getCloseInfo() {
6160
+ return {
6161
+ code: this.closeCode,
6162
+ reason: this.closeReason,
6163
+ wasClean: this.closeWasClean,
6164
+ msFromLastFrameToClose: this.msFromLastFrameToClose
6165
+ };
6166
+ }
6167
+ getFoundIdCollisionStats() {
6168
+ const uniqueFoundIdCount = this.testHierarchy.size;
6169
+ return {
6170
+ rawFoundCount: this.foundCount,
6171
+ uniqueFoundIdCount,
6172
+ duplicateFoundIdCount: this.foundCount - uniqueFoundIdCount
6173
+ };
6174
+ }
6133
6175
  getFoundIdGaps() {
6134
6176
  if (this.testHierarchy.size === 0) {
6135
6177
  return [];
@@ -6160,7 +6202,7 @@ class InspectorClient {
6160
6202
  const pending = this.pendingRequests.get(message.id);
6161
6203
  if (pending) {
6162
6204
  this.pendingRequests.delete(message.id);
6163
- clearTimeout(pending.timer);
6205
+ this.clearPendingTimers(pending);
6164
6206
  if (message.error) {
6165
6207
  pending.reject(new Error(`Inspector error: ${message.error.message}`));
6166
6208
  } else {
@@ -6250,8 +6292,12 @@ class InspectorClient {
6250
6292
  }
6251
6293
  return { fullName: parts.join(" > "), bunName: parts.join(" ") };
6252
6294
  }
6253
- handleClose() {
6295
+ handleClose(code, reason, wasClean) {
6254
6296
  this.wsClosed = true;
6297
+ this.closeCode = code;
6298
+ this.closeReason = reason;
6299
+ this.closeWasClean = wasClean;
6300
+ this.msFromLastFrameToClose = Date.now() - this.lastFrameReceivedAt;
6255
6301
  const waiters = this.closeWaiters;
6256
6302
  this.closeWaiters = [];
6257
6303
  for (const finish of waiters) {
@@ -6262,11 +6308,19 @@ class InspectorClient {
6262
6308
  }
6263
6309
  this._wasClosedUnexpectedly = true;
6264
6310
  if (this.handlers.onUnexpectedClose) {
6265
- this.handlers.onUnexpectedClose({ wsClosed: this.wsClosed, closeExpected: this.closeExpected, isClosing: this.isClosing });
6311
+ this.handlers.onUnexpectedClose({
6312
+ wsClosed: this.wsClosed,
6313
+ closeExpected: this.closeExpected,
6314
+ isClosing: this.isClosing,
6315
+ closeCode: this.closeCode,
6316
+ closeReason: this.closeReason,
6317
+ closeWasClean: this.closeWasClean,
6318
+ msFromLastFrameToClose: this.msFromLastFrameToClose
6319
+ });
6266
6320
  }
6267
6321
  const error = new InspectorConnectionError("Connection closed unexpectedly");
6268
6322
  for (const pending of this.pendingRequests.values()) {
6269
- clearTimeout(pending.timer);
6323
+ this.clearPendingTimers(pending);
6270
6324
  pending.reject(error);
6271
6325
  }
6272
6326
  this.pendingRequests.clear();
@@ -8535,7 +8589,10 @@ exit=%s timedOut=%s
8535
8589
  this.logger.warn("Inspector error: %s", error.message);
8536
8590
  },
8537
8591
  onUnexpectedClose: (context) => {
8538
- this.logger.debug("Inspector WebSocket closed while the run was still thought to be in progress (wsClosed=%s closeExpected=%s isClosing=%s) — often benign; see checkCompletenessGate", context.wsClosed, context.closeExpected, context.isClosing);
8592
+ this.logger.debug("Inspector WebSocket closed while the run was still thought to be in progress (wsClosed=%s closeExpected=%s isClosing=%s closeCode=%s closeReason=%s closeWasClean=%s msFromLastFrameToClose=%s) — often benign; see checkCompletenessGate", context.wsClosed, context.closeExpected, context.isClosing, String(context.closeCode), String(context.closeReason), String(context.closeWasClean), String(context.msFromLastFrameToClose));
8593
+ },
8594
+ onRequestStall: (info) => {
8595
+ this.logger.warn("Inspector request unanswered after %dms even though other frames are still arriving (last frame %dms ago): %s (id=%d) — possible protocol-level stall distinct from total silence", info.msUnanswered, info.msSinceLastFrame, info.method, info.id);
8539
8596
  }
8540
8597
  }
8541
8598
  });
@@ -8592,12 +8649,15 @@ exit=%s timedOut=%s
8592
8649
  this.logger.debug("Inspector collected %d tests in hierarchy, %d in execution order", testHierarchy.length, executionOrder.length);
8593
8650
  const finalGaps = inspector.getFoundIdGaps();
8594
8651
  this.logger.warn("Post-drain inspector snapshot: %d found-id gap(s) remaining%s; drain handshake %s", finalGaps.length, formatGapIdList(finalGaps), formatDrainSettleReason(drainSettleReason));
8652
+ const closeInfo = inspector.getCloseInfo();
8653
+ const collisionStats = inspector.getFoundIdCollisionStats();
8654
+ this.logger.warn("Post-drain inspector close/collision diagnostics: WS close code=%s reason=%s wasClean=%s msFromLastFrameToClose=%s; " + "found events %d raw / %d unique id(s) / %d duplicate id event(s) (nonzero duplicates = direct evidence of the Bun " + "TestReporter id-collision bug; the found-id-gap count above is density-only — it does NOT prove losslessness under collisions)", String(closeInfo.code), String(closeInfo.reason), String(closeInfo.wasClean), String(closeInfo.msFromLastFrameToClose), collisionStats.rawFoundCount, collisionStats.uniqueFoundIdCount, collisionStats.duplicateFoundIdCount);
8595
8655
  const parsed = parseBunTestOutput(result.stdout, result.stderr);
8596
8656
  const earlyResult = this.checkDryRunProcessResult(result, parsed, testHierarchy);
8597
8657
  if (earlyResult) {
8598
8658
  return earlyResult;
8599
8659
  }
8600
- return await this.buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly);
8660
+ return await this.buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly, closeInfo);
8601
8661
  } finally {
8602
8662
  abortController.abort();
8603
8663
  if (this.currentAbortController === abortController) {
@@ -8606,11 +8666,11 @@ exit=%s timedOut=%s
8606
8666
  await syncServer.close();
8607
8667
  }
8608
8668
  }
8609
- async buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly) {
8669
+ async buildGatedDryRunResult(result, parsed, testHierarchy, executionOrder, totalElapsedMs, wasClosedUnexpectedly, closeInfo) {
8610
8670
  const { coverage: mutantCoverage, inspectorIdToProjectFile, rawKeyCount, orphanedKeyCount } = await this.collectAndRemapCoverage(testHierarchy, executionOrder);
8611
8671
  const { tests, testNameIndex } = this.buildTestsFromInspector(testHierarchy, executionOrder, parsed, totalElapsedMs, inspectorIdToProjectFile);
8612
8672
  tests.sort((a, b) => a.name.localeCompare(b.name));
8613
- const gateResult = this.checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests);
8673
+ const gateResult = this.checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests, closeInfo);
8614
8674
  if (gateResult) {
8615
8675
  return gateResult;
8616
8676
  }
@@ -8849,7 +8909,7 @@ ${lines.join(`
8849
8909
  %s`, String(result.exitCode), parsed.failed, result.stderr.slice(-500));
8850
8910
  }
8851
8911
  }
8852
- checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests) {
8912
+ checkCompletenessGate(executionOrder, testHierarchy, parsed, rawKeyCount, orphanedKeyCount, wasClosedUnexpectedly, tests, closeInfo) {
8853
8913
  if (tests.some((t) => t.status === TestStatus.Failed)) {
8854
8914
  return null;
8855
8915
  }
@@ -8873,7 +8933,8 @@ ${lines.join(`
8873
8933
  reasons.push(`${orphanedKeyCount} of ${rawKeyCount} coverage key(s) could not be paired with any inspector test (orphaned)`);
8874
8934
  }
8875
8935
  if (wasClosedUnexpectedly) {
8876
- reasons.push("the inspector WebSocket closed unexpectedly before this data could be fully drained");
8936
+ const closeDetail = closeInfo.code === undefined ? "close code/reason not captured" : `close code=${closeInfo.code} reason=${JSON.stringify(closeInfo.reason ?? "")} wasClean=${String(closeInfo.wasClean)}, ${String(closeInfo.msFromLastFrameToClose)}ms after the last received frame`;
8937
+ reasons.push(`the inspector WebSocket closed unexpectedly before this data could be fully drained (${closeDetail})`);
8877
8938
  }
8878
8939
  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.";
8879
8940
  this.logger.error("%s", errorMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hughescr/stryker-bun-runner",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "Stryker test runner plugin for Bun with perTest coverage support",
5
5
  "keywords": [
6
6
  "stryker",