@nsshunt/stsrunnerframework 2.0.11 → 2.0.13

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/README.md CHANGED
@@ -1097,8 +1097,6 @@ stateDiagram
1097
1097
  import { IRunnerInstance, ITestRunnerTelemetryPayload, eIWMessageCommands, WorkerInstance } from './../index'
1098
1098
  import { TestCase01 } from './testCase01'
1099
1099
 
1100
- import isNode from 'detect-node'
1101
-
1102
1100
  import { parentPort } from 'worker_threads';
1103
1101
 
1104
1102
  export class WorkerTestCases extends WorkerInstance {
@@ -1186,7 +1184,6 @@ import { TestCase01 } from './testCase01'
1186
1184
 
1187
1185
  import { MessagePort } from 'worker_threads';
1188
1186
 
1189
- import isNode from 'detect-node'
1190
1187
  import { JSONObject } from '@nsshunt/stsutils';
1191
1188
 
1192
1189
  export class WorkerTestCases extends WorkerInstance {
package/dist/index.cjs CHANGED
@@ -22,8 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  enumerable: true
23
23
  }) : target, mod));
24
24
  //#endregion
25
- let detect_node = require("detect-node");
26
- detect_node = __toESM(detect_node);
27
25
  let _nsshunt_stsutils = require("@nsshunt/stsutils");
28
26
  let _nsshunt_stsobservability = require("@nsshunt/stsobservability");
29
27
  //#region src/commonTypes.ts
@@ -574,7 +572,7 @@ var AbstractRunnerExecutionWorker = class {
574
572
  this.#debug(chalk.grey(`WorkerInstance:#processLoopExecutor(): Removing runners from collection: [${removeList}]`));
575
573
  for (let i = 0; i < removeList.length; i++) {
576
574
  this.#runners[removeList[i]].archived = true;
577
- if (this.#archiveDeleteTimeout !== 0) if (detect_node.default) setTimeout(() => delete this.#runners[removeList[i]], this.#archiveDeleteTimeout * 1e3).unref();
575
+ if (this.#archiveDeleteTimeout !== 0) if (_nsshunt_stsutils.isNode) setTimeout(() => delete this.#runners[removeList[i]], this.#archiveDeleteTimeout * 1e3).unref();
578
576
  else setTimeout(() => delete this.#runners[removeList[i]], this.#archiveDeleteTimeout * 1e3);
579
577
  }
580
578
  const message = `WorkerInstance:#processLoopExecutor(): Remaining Runner Count: [${Object.keys(this.#runners).length}]`;
@@ -647,7 +645,7 @@ var AbstractRunnerExecutionWorker = class {
647
645
  #SetMessagePort = (workerMessagePort) => {
648
646
  try {
649
647
  this.#collectorCollectorPort = workerMessagePort.port;
650
- if (detect_node.default) this.#collectorCollectorPort.on("message", (data) => {
648
+ if (_nsshunt_stsutils.isNode) this.#collectorCollectorPort.on("message", (data) => {
651
649
  this.#silly(`collectorCollectorPort on('message'): ${JSON.stringify(data)}`);
652
650
  });
653
651
  else this.#collectorCollectorPort.addEventListener("message", (data) => {
@@ -1484,6 +1482,32 @@ var AbstractRunnerExecutionWorker = class {
1484
1482
  };
1485
1483
  //#endregion
1486
1484
  //#region src/messageBroker.ts
1485
+ /**
1486
+ * STSMessageBroker
1487
+ * ----------------
1488
+ * Central message broker for worker <-> manager communications.
1489
+ *
1490
+ * Responsibilities:
1491
+ * - Create and manage callback-correlated request/response message flows
1492
+ * - Route inbound port messages as either:
1493
+ * - solicited responses (request/response messages with `messageId`)
1494
+ * - unsolicited push/event messages (telemetry, state changes, etc.)
1495
+ * - Initialise message ports between the manager and the worker
1496
+ * - Provide helper methods for sending worker-level and runner-level commands
1497
+ * - Manage response timeouts for outstanding requests
1498
+ *
1499
+ * High-level design:
1500
+ * - Every solicited request gets a generated `messageId`
1501
+ * - The broker stores a pending promise resolver keyed by `messageId`
1502
+ * - When a matching inbound response arrives, the broker resolves that promise
1503
+ * - If no response arrives before the configured timeout, the request is rejected
1504
+ *
1505
+ * Notes:
1506
+ * - This broker supports both Node and browser worker environments
1507
+ * - Environment-specific message port listener wiring is handled internally
1508
+ * - The broker itself does not interpret business meaning of unsolicited messages;
1509
+ * those are delegated to a caller-supplied callback
1510
+ */
1487
1511
  var import_lodash_merge = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
1488
1512
  /**
1489
1513
  * Lodash (Custom Build) <https://lodash.com/>
@@ -3126,7 +3150,7 @@ var STSMessageBroker = class {
3126
3150
  * @param cb Callback used to handle unsolicited inbound messages.
3127
3151
  */
3128
3152
  SetupMessagePortListener = (stsWorkerEx, cb) => {
3129
- if (detect_node.default) stsWorkerEx.messagePort.on("message", (data) => {
3153
+ if (_nsshunt_stsutils.isNode) stsWorkerEx.messagePort.on("message", (data) => {
3130
3154
  this._processInboundMessage(data, cb);
3131
3155
  });
3132
3156
  else stsWorkerEx.messagePort.addEventListener("message", (data) => {
@@ -3357,7 +3381,7 @@ var STSMessageBroker = class {
3357
3381
  */
3358
3382
  GetPorts = () => {
3359
3383
  const { port1, port2 } = new MessageChannel();
3360
- if (!detect_node.default) port1.start();
3384
+ if (!_nsshunt_stsutils.isNode) port1.start();
3361
3385
  return {
3362
3386
  port1,
3363
3387
  port2
@@ -3981,7 +4005,7 @@ var ArchiveManager = class {
3981
4005
  }
3982
4006
  delete this.archiveDelTimeout[delTimeoutId];
3983
4007
  }, this.archiveDeleteTimeout * 1e3);
3984
- if (detect_node.default) delTimeout.unref();
4008
+ if (_nsshunt_stsutils.isNode) delTimeout.unref();
3985
4009
  this.archiveDelTimeout[delTimeoutId] = {
3986
4010
  workerId: workerEx.id,
3987
4011
  runnerId: removeList[i].runnerId,
@@ -4002,15 +4026,15 @@ var ArchiveManager = class {
4002
4026
  * Schedule the next archive scan.
4003
4027
  */
4004
4028
  this.timeout = setTimeout(() => this.ProcessLoopExecutor(), 1e3);
4005
- if (detect_node.default) this.timeout.unref();
4029
+ if (_nsshunt_stsutils.isNode) this.timeout.unref();
4006
4030
  }, 100);
4007
- if (detect_node.default) startTimeout.unref();
4031
+ if (_nsshunt_stsutils.isNode) startTimeout.unref();
4008
4032
  } else {
4009
4033
  /**
4010
4034
  * No archive candidates found; just schedule the next scan.
4011
4035
  */
4012
4036
  this.timeout = setTimeout(() => this.ProcessLoopExecutor(), 1e3);
4013
- if (detect_node.default) this.timeout.unref();
4037
+ if (_nsshunt_stsutils.isNode) this.timeout.unref();
4014
4038
  }
4015
4039
  } catch (error) {
4016
4040
  this.options.logger.error(`_processLoopExecutor(): Error: [${error}]`);
@@ -4065,7 +4089,7 @@ var ArchiveManager = class {
4065
4089
  */
4066
4090
  Terminate = () => {
4067
4091
  this.options.logger.debug(`ArchiveManager:Terminate()`);
4068
- this.options.logger.debug(`Runtime context: isNode = [${detect_node.default}]`);
4092
+ this.options.logger.debug(`Runtime context: isNode = [${_nsshunt_stsutils.isNode}]`);
4069
4093
  if (this.timeout) {
4070
4094
  this.options.logger.debug(`ArchiveManager:Terminate() - this.timeout cleared ...`);
4071
4095
  clearTimeout(this.timeout);
@@ -4641,7 +4665,7 @@ var WorkerInstanceManager = class {
4641
4665
  * @param stsWorkerEx Manager-side worker instance whose underlying actual worker should be monitored.
4642
4666
  */
4643
4667
  SetupWorkerSystemEvents = (stsWorkerEx) => {
4644
- if (detect_node.default) {
4668
+ if (_nsshunt_stsutils.isNode) {
4645
4669
  /**
4646
4670
  * Node.js worker thread exit event.
4647
4671
  *