testit-js-commons 5.0.7 → 5.0.8-TMS-5.8

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 (68) hide show
  1. package/lib/adapters-api/dist/ApiClient.js +5 -6
  2. package/lib/adapters-api/dist/api/AttachmentsApi.js +5 -5
  3. package/lib/adapters-api/dist/api/AutoTestsApi.js +11 -11
  4. package/lib/adapters-api/dist/api/ConfigurationsApi.js +1 -1
  5. package/lib/adapters-api/dist/api/ParametersApi.js +3 -3
  6. package/lib/adapters-api/dist/api/ProjectAttributesApi.js +6 -6
  7. package/lib/adapters-api/dist/api/ProjectSectionsApi.js +1 -1
  8. package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +1 -1
  9. package/lib/adapters-api/dist/api/ProjectsApi.js +4 -4
  10. package/lib/adapters-api/dist/api/SectionsApi.js +2 -2
  11. package/lib/adapters-api/dist/api/TestResultsApi.js +3 -3
  12. package/lib/adapters-api/dist/api/TestRunsApi.js +8 -8
  13. package/lib/adapters-api/dist/api/WorkItemsApi.js +3 -3
  14. package/lib/adapters-api/dist/api/WorkflowsApi.js +1 -1
  15. package/lib/adapters-api/dist/index.js +3 -80
  16. package/lib/adapters-api/dist/model/AttachmentPutModelAutoTestStepResultsModel.js +1 -1
  17. package/lib/adapters-api/dist/model/AutoTestApiResult.js +0 -15
  18. package/lib/adapters-api/dist/model/AutoTestCreateApiModel.js +0 -15
  19. package/lib/adapters-api/dist/model/AutoTestStepResult.js +1 -1
  20. package/lib/adapters-api/dist/model/AutoTestStepResultUpdateRequest.js +1 -1
  21. package/lib/adapters-api/dist/model/AutoTestUpdateApiModel.js +4 -30
  22. package/lib/adapters-api/dist/model/CreateEmptyTestRunApiModel.js +2 -2
  23. package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +6 -56
  24. package/lib/adapters-api/dist/model/{CustomAttributeModel.js → CustomAttributeGetModel.js} +39 -89
  25. package/lib/adapters-api/dist/model/CustomAttributePutModel.js +1 -1
  26. package/lib/adapters-api/dist/model/LabelApiModel.js +15 -4
  27. package/lib/adapters-api/dist/model/ProjectsFilterModel.js +13 -13
  28. package/lib/adapters-api/dist/model/TestResultResponse.js +4 -18
  29. package/lib/adapters-api/dist/model/TestResultShortResponse.js +4 -15
  30. package/lib/adapters-api/dist/model/TestResultsFilterApiModel.js +0 -14
  31. package/lib/adapters-api/dist/model/TestRunApiResult.js +4 -45
  32. package/lib/adapters-api/dist/model/UpdateEmptyTestRunApiModel.js +1 -1
  33. package/lib/adapters-api/index.d.ts +204 -758
  34. package/lib/common/index.d.ts +0 -1
  35. package/lib/common/index.js +0 -1
  36. package/lib/common/types/common.type.d.ts +0 -6
  37. package/lib/common/utils/tms-load-test-run-debug.d.ts +0 -2
  38. package/lib/common/utils/tms-load-test-run-debug.js +0 -6
  39. package/lib/services/autotests/autotests.converter.d.ts +2 -6
  40. package/lib/services/autotests/autotests.converter.js +16 -41
  41. package/lib/services/autotests/autotests.service.js +3 -3
  42. package/lib/services/autotests/autotests.type.d.ts +0 -2
  43. package/lib/services/syncstorage/syncstorage.runner.js +5 -6
  44. package/lib/services/syncstorage/syncstorage.runner.test.js +0 -16
  45. package/lib/services/testruns/testruns.handler.d.ts +2 -2
  46. package/lib/services/testruns/testruns.handler.js +2 -12
  47. package/lib/services/testruns/testruns.service.d.ts +0 -2
  48. package/lib/services/testruns/testruns.service.js +6 -31
  49. package/lib/services/testruns/testruns.service.test.js +47 -5
  50. package/lib/strategy/base.strategy.d.ts +11 -0
  51. package/lib/strategy/base.strategy.js +72 -4
  52. package/lib/sync-storage/dist/ApiClient.js +0 -3
  53. package/package.json +1 -1
  54. package/lib/adapters-api/dist/api/CustomAttributesApi.js +0 -201
  55. package/lib/adapters-api/dist/model/CustomAttributeOptionPostApiModel.js +0 -98
  56. package/lib/adapters-api/dist/model/CustomAttributeOptionUpdateApiModel.js +0 -124
  57. package/lib/adapters-api/dist/model/CustomAttributeSearchApiModel.js +0 -137
  58. package/lib/adapters-api/dist/model/CustomAttributeSearchApiResult.js +0 -281
  59. package/lib/adapters-api/dist/model/GlobalCustomAttributePostApiModel.js +0 -141
  60. package/lib/adapters-api/dist/model/GlobalCustomAttributeUpdateApiModel.js +0 -129
  61. package/lib/adapters-api/dist/model/LayerApiModel.js +0 -102
  62. package/lib/adapters-api/dist/model/LayerApiResult.js +0 -102
  63. package/lib/adapters-api/dist/model/LayerSource.js +0 -61
  64. package/lib/adapters-api/dist/model/ProjectShortestApiResult.js +0 -138
  65. package/lib/common/test-layers.d.ts +0 -11
  66. package/lib/common/test-layers.js +0 -13
  67. package/lib/services/autotests/autotests.converter.test.d.ts +0 -1
  68. package/lib/services/autotests/autotests.converter.test.js +0 -39
@@ -1,5 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./utils";
3
- export * from "./test-layers";
4
3
  export * from "./base.converter";
5
4
  export * from "./base.service";
@@ -16,6 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./utils"), exports);
19
- __exportStar(require("./test-layers"), exports);
20
19
  __exportStar(require("./base.converter"), exports);
21
20
  __exportStar(require("./base.service"), exports);
@@ -38,15 +38,9 @@ export interface Metadata {
38
38
  displayName?: string;
39
39
  title?: string;
40
40
  description?: string;
41
- workItemId?: string;
42
- /**
43
- * @deprecated Use workItemId with a single globalId instead.
44
- */
45
41
  workItemsIds?: string[];
46
42
  links?: Link[];
47
43
  labels?: string[];
48
- /** Test pyramid layer declared in test code. */
49
- layer?: string;
50
44
  classname?: string;
51
45
  namespace?: string;
52
46
  properties?: {
@@ -1,4 +1,2 @@
1
1
  export declare function isTmsLoadTestRunDebug(): boolean;
2
- /** Trace sync-storage adapter calls only when `TMS_DEBUG_SYNC_STORAGE=1` (not plain LOG_LEVEL=debug). */
3
- export declare function isSyncStorageDebug(): boolean;
4
2
  export declare function logTmsLoadTestRun(message: string, data?: Record<string, unknown>): void;
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isTmsLoadTestRunDebug = isTmsLoadTestRunDebug;
7
- exports.isSyncStorageDebug = isSyncStorageDebug;
8
7
  exports.logTmsLoadTestRun = logTmsLoadTestRun;
9
8
  /** Trace loadTestRun / result POST with `LOG_LEVEL=debug` or `TMS_DEBUG_LOAD_TEST_RUN=1`. */
10
9
  const logger_1 = __importDefault(require("../../logger"));
@@ -15,11 +14,6 @@ function isTmsLoadTestRunDebug() {
15
14
  const v = process.env.TMS_DEBUG_LOAD_TEST_RUN;
16
15
  return v === "1" || (v === null || v === void 0 ? void 0 : v.toLowerCase()) === "true";
17
16
  }
18
- /** Trace sync-storage adapter calls only when `TMS_DEBUG_SYNC_STORAGE=1` (not plain LOG_LEVEL=debug). */
19
- function isSyncStorageDebug() {
20
- const v = process.env.TMS_DEBUG_SYNC_STORAGE;
21
- return v === "1" || (v === null || v === void 0 ? void 0 : v.toLowerCase()) === "true";
22
- }
23
17
  function logTmsLoadTestRun(message, data) {
24
18
  if (!isTmsLoadTestRunDebug()) {
25
19
  return;
@@ -1,15 +1,11 @@
1
1
  import { BaseConverter, AdapterConfig } from "../../common";
2
2
  import { AutotestGet, AutotestPost } from "./autotests.type";
3
3
  export interface IAutotestConverter {
4
- toOriginAutotestCreate(autotest: AutotestPost): any;
5
- toOriginAutotestUpdate(autotest: AutotestPost): any;
4
+ toOriginAutotest(autotest: AutotestPost): any;
6
5
  toLocalAutotest(autotest: any): AutotestGet;
7
6
  }
8
7
  export declare class AutotestConverter extends BaseConverter implements IAutotestConverter {
9
8
  constructor(config: AdapterConfig);
10
- toOriginAutotestCreate(autotest: AutotestPost): any;
11
- toOriginAutotestUpdate(autotest: AutotestPost): any;
9
+ toOriginAutotest(autotest: AutotestPost): any;
12
10
  toLocalAutotest(autotest: any): AutotestGet;
13
- private baseAutotestFields;
14
- private layerToApiModel;
15
11
  }
@@ -2,45 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AutotestConverter = void 0;
4
4
  const common_1 = require("../../common");
5
- const LAYER_SOURCE_RUN = "Run";
6
5
  class AutotestConverter extends common_1.BaseConverter {
7
6
  constructor(config) {
8
7
  super(config);
9
8
  }
10
- toOriginAutotestCreate(autotest) {
11
- const model = this.baseAutotestFields(autotest);
12
- const layer = this.layerToApiModel(autotest.layer);
13
- if (layer) {
14
- model.layer = layer;
15
- }
16
- return model;
17
- }
18
- toOriginAutotestUpdate(autotest) {
19
- const model = Object.assign(Object.assign({}, this.baseAutotestFields(autotest)), { resetLayer: false });
20
- const layer = this.layerToApiModel(autotest.layer);
21
- if (layer) {
22
- model.layer = layer;
23
- }
24
- return model;
25
- }
26
- toLocalAutotest(autotest) {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
28
- return {
29
- id: autotest.id,
30
- name: (_a = autotest.name) !== null && _a !== void 0 ? _a : undefined,
31
- externalId: (_b = autotest.externalId) !== null && _b !== void 0 ? _b : undefined,
32
- links: (_c = autotest.links) === null || _c === void 0 ? void 0 : _c.map((link) => this.toLocalLink(link)),
33
- namespace: (_d = autotest.namespace) !== null && _d !== void 0 ? _d : undefined,
34
- classname: (_e = autotest.classname) !== null && _e !== void 0 ? _e : undefined,
35
- steps: (_f = autotest.steps) === null || _f === void 0 ? void 0 : _f.map((step) => this.toLocalShortStep(step)),
36
- setup: (_g = autotest.setup) === null || _g === void 0 ? void 0 : _g.map((step) => this.toLocalShortStep(step)),
37
- teardown: (_h = autotest.teardown) === null || _h === void 0 ? void 0 : _h.map((step) => this.toLocalShortStep(step)),
38
- labels: (_j = autotest.labels) !== null && _j !== void 0 ? _j : undefined,
39
- tags: (_k = autotest.tags) !== null && _k !== void 0 ? _k : undefined,
40
- layer: (_m = (_l = autotest.layer) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : undefined,
41
- };
42
- }
43
- baseAutotestFields(autotest) {
9
+ toOriginAutotest(autotest) {
44
10
  return {
45
11
  externalId: autotest.externalId,
46
12
  name: autotest.name,
@@ -60,12 +26,21 @@ class AutotestConverter extends common_1.BaseConverter {
60
26
  shouldCreateWorkItem: this.config.automaticCreationTestCases,
61
27
  };
62
28
  }
63
- layerToApiModel(layer) {
64
- const name = layer === null || layer === void 0 ? void 0 : layer.trim();
65
- if (!name) {
66
- return undefined;
67
- }
68
- return { name, source: LAYER_SOURCE_RUN };
29
+ toLocalAutotest(autotest) {
30
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
31
+ return {
32
+ id: autotest.id,
33
+ name: (_a = autotest.name) !== null && _a !== void 0 ? _a : undefined,
34
+ externalId: (_b = autotest.externalId) !== null && _b !== void 0 ? _b : undefined,
35
+ links: (_c = autotest.links) === null || _c === void 0 ? void 0 : _c.map((link) => this.toLocalLink(link)),
36
+ namespace: (_d = autotest.namespace) !== null && _d !== void 0 ? _d : undefined,
37
+ classname: (_e = autotest.classname) !== null && _e !== void 0 ? _e : undefined,
38
+ steps: (_f = autotest.steps) === null || _f === void 0 ? void 0 : _f.map((step) => this.toLocalShortStep(step)),
39
+ setup: (_g = autotest.setup) === null || _g === void 0 ? void 0 : _g.map((step) => this.toLocalShortStep(step)),
40
+ teardown: (_h = autotest.teardown) === null || _h === void 0 ? void 0 : _h.map((step) => this.toLocalShortStep(step)),
41
+ labels: (_j = autotest.labels) !== null && _j !== void 0 ? _j : undefined,
42
+ tags: (_k = autotest.tags) !== null && _k !== void 0 ? _k : undefined,
43
+ };
69
44
  }
70
45
  }
71
46
  exports.AutotestConverter = AutotestConverter;
@@ -28,7 +28,7 @@ class AutotestsService extends common_1.BaseService {
28
28
  }
29
29
  createAutotest(autotest) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- const autotestPost = this._converter.toOriginAutotestCreate(autotest);
31
+ const autotestPost = this._converter.toOriginAutotest(autotest);
32
32
  (0, common_1.escapeHtmlInObject)(autotestPost);
33
33
  logger_1.default.debug("[autotests] createAutoTest", { externalId: autotest.externalId, name: autotest.name });
34
34
  try {
@@ -51,7 +51,7 @@ class AutotestsService extends common_1.BaseService {
51
51
  }
52
52
  updateAutotest(autotest) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- const autotestPost = this._converter.toOriginAutotestUpdate(autotest);
54
+ const autotestPost = this._converter.toOriginAutotest(autotest);
55
55
  (0, common_1.escapeHtmlInObject)(autotestPost);
56
56
  logger_1.default.debug("[autotests] updateAutoTest", { externalId: autotest.externalId, name: autotest.name });
57
57
  yield (0, common_1.withHttpRetry)(() => this._client
@@ -103,7 +103,7 @@ class AutotestsService extends common_1.BaseService {
103
103
  updateAutotestFromFailed(originAutotest, autotest) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  var _a, _b, _c, _d;
106
- yield this.updateAutotest(Object.assign(Object.assign({}, originAutotest), { externalId: (_a = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.externalId) !== null && _a !== void 0 ? _a : autotest.externalId, name: (_b = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.name) !== null && _b !== void 0 ? _b : autotest.name, links: autotest.links, externalKey: autotest.externalKey, steps: autotest.steps, setup: autotest.setup, teardown: autotest.teardown, title: autotest.title, description: autotest.description, namespace: (_c = autotest.namespace) !== null && _c !== void 0 ? _c : originAutotest.namespace, classname: (_d = autotest.classname) !== null && _d !== void 0 ? _d : originAutotest.classname, labels: autotest.labels, tags: autotest.tags, layer: autotest.layer, workItemIds: autotest.workItemIds, isFlaky: autotest.isFlaky, shouldCreateWorkItem: autotest.shouldCreateWorkItem }));
106
+ yield this.updateAutotest(Object.assign(Object.assign({}, originAutotest), { externalId: (_a = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.externalId) !== null && _a !== void 0 ? _a : autotest.externalId, name: (_b = originAutotest === null || originAutotest === void 0 ? void 0 : originAutotest.name) !== null && _b !== void 0 ? _b : autotest.name, links: autotest.links, externalKey: autotest.externalKey, steps: autotest.steps, setup: autotest.setup, teardown: autotest.teardown, title: autotest.title, description: autotest.description, namespace: (_c = autotest.namespace) !== null && _c !== void 0 ? _c : originAutotest.namespace, classname: (_d = autotest.classname) !== null && _d !== void 0 ? _d : originAutotest.classname, labels: autotest.labels, tags: autotest.tags, workItemIds: autotest.workItemIds, isFlaky: autotest.isFlaky, shouldCreateWorkItem: autotest.shouldCreateWorkItem }));
107
107
  });
108
108
  }
109
109
  linkToWorkItems(internalId, workItemIds) {
@@ -25,8 +25,6 @@ interface AutotestBase {
25
25
  labels?: Array<Label>;
26
26
  tags?: Array<string>;
27
27
  externalKey?: string;
28
- /** Test pyramid layer name from test code annotation (source Run is set by converter). */
29
- layer?: string;
30
28
  }
31
29
  export interface AutotestPost extends AutotestBase {
32
30
  externalId: string;
@@ -111,7 +111,7 @@ class SyncStorageRunner {
111
111
  sendInProgressTestResult(model) {
112
112
  return __awaiter(this, void 0, void 0, function* () {
113
113
  if (!this.running || !this.isMaster || this.alreadyInProgress || this.inProgressPublishing) {
114
- if ((0, utils_1.isSyncStorageDebug)()) {
114
+ if ((0, utils_1.isTmsLoadTestRunDebug)()) {
115
115
  logger_1.default.debug("[syncstorage] skip in-progress cut publish", {
116
116
  reason: {
117
117
  notRunning: !this.running,
@@ -126,7 +126,7 @@ class SyncStorageRunner {
126
126
  }
127
127
  if (!model.projectId || !model.autoTestExternalId || !model.statusCode || !model.statusType) {
128
128
  logger_1.default.warn("Sync storage in-progress payload is incomplete; skipping publish.");
129
- if ((0, utils_1.isSyncStorageDebug)()) {
129
+ if ((0, utils_1.isTmsLoadTestRunDebug)()) {
130
130
  logger_1.default.debug("[syncstorage] incomplete in-progress cut payload", {
131
131
  hasProjectId: Boolean(model.projectId),
132
132
  hasAutoTestExternalId: Boolean(model.autoTestExternalId),
@@ -147,7 +147,7 @@ class SyncStorageRunner {
147
147
  });
148
148
  yield this.withRetry(() => __awaiter(this, void 0, void 0, function* () { return this.testResultsApi.inProgressTestResultPost(this.testRunId, request); }), SyncStorageRunner.RETRY_COUNT);
149
149
  this.alreadyInProgress = true;
150
- if ((0, utils_1.isSyncStorageDebug)()) {
150
+ if ((0, utils_1.isTmsLoadTestRunDebug)()) {
151
151
  logger_1.default.debug("[syncstorage] alreadyInProgress set", {
152
152
  workerPid: this.workerPid,
153
153
  autoTestExternalId: model.autoTestExternalId,
@@ -161,7 +161,7 @@ class SyncStorageRunner {
161
161
  }
162
162
  catch (error) {
163
163
  logger_1.default.warn(`Sync storage in-progress publish failed: ${error}`);
164
- if ((0, utils_1.isSyncStorageDebug)()) {
164
+ if ((0, utils_1.isTmsLoadTestRunDebug)()) {
165
165
  logger_1.default.debug("[syncstorage] in-progress cut publish failed", {
166
166
  workerPid: this.workerPid,
167
167
  autoTestExternalId: model.autoTestExternalId,
@@ -233,7 +233,6 @@ class SyncStorageRunner {
233
233
  "--baseURL", this.baseUrl,
234
234
  "--privateToken", this.config.privateToken,
235
235
  ];
236
- // Do not inherit stdout/stderr: sync-storage binary logs stay silent unless TMS_DEBUG_SYNC_STORAGE=1 adapter traces.
237
236
  this.syncStorageProcess = (0, child_process_1.spawn)(executablePath, command, {
238
237
  cwd: (0, path_1.join)(process.cwd(), "build", ".caches"),
239
238
  stdio: "ignore",
@@ -354,7 +353,7 @@ class SyncStorageRunner {
354
353
  }
355
354
  }
356
355
  exports.SyncStorageRunner = SyncStorageRunner;
357
- SyncStorageRunner.VERSION = "v0.3.10";
356
+ SyncStorageRunner.VERSION = "v0.3.10-tms-5.8";
358
357
  SyncStorageRunner.STARTUP_TIMEOUT_MS = 30000;
359
358
  SyncStorageRunner.STARTUP_POLL_MS = 1000;
360
359
  SyncStorageRunner.PROCESS_WARMUP_MS = 2000;
@@ -10,9 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const syncstorage_runner_1 = require("./syncstorage.runner");
13
- const child_process_1 = require("child_process");
14
- jest.mock("child_process", () => (Object.assign(Object.assign({}, jest.requireActual("child_process")), { spawn: jest.fn(() => ({})) })));
15
- const spawnMock = child_process_1.spawn;
16
13
  function makeConfig() {
17
14
  return {
18
15
  url: "http://localhost:8080",
@@ -25,19 +22,6 @@ function makeConfig() {
25
22
  };
26
23
  }
27
24
  describe("SyncStorageRunner", () => {
28
- beforeEach(() => {
29
- spawnMock.mockClear();
30
- delete process.env.TMS_DEBUG_SYNC_STORAGE;
31
- });
32
- it("should spawn local process with stdio ignored", () => __awaiter(void 0, void 0, void 0, function* () {
33
- const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
34
- const internal = runner;
35
- internal.prepareExecutable = jest.fn().mockResolvedValue("/bin/syncstorage");
36
- internal.waitForStartup = jest.fn().mockResolvedValue(true);
37
- internal.delay = jest.fn().mockResolvedValue(undefined);
38
- yield internal.startLocalProcess();
39
- expect(spawnMock).toHaveBeenCalledWith("/bin/syncstorage", expect.arrayContaining(["--testRunId", "run-1"]), expect.objectContaining({ stdio: "ignore" }));
40
- }));
41
25
  it("should mark runner as active and resolve master status after start", () => __awaiter(void 0, void 0, void 0, function* () {
42
26
  const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
43
27
  const internal = runner;
@@ -1,4 +1,4 @@
1
1
  export declare class TestRunErrorHandler {
2
- static handleErrorStartTestRun(err: unknown, message?: string): void;
3
- static handleErrorCompletedTestRun(err: unknown, message?: string): void;
2
+ static handleErrorStartTestRun(err: any, message?: string): void;
3
+ static handleErrorCompletedTestRun(err: any, message?: string): void;
4
4
  }
@@ -4,23 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TestRunErrorHandler = void 0;
7
- const utils_1 = require("../../common/utils");
8
7
  const logger_1 = __importDefault(require("../../logger"));
9
- function logTestRunHttpError(action, err, message = "") {
10
- var _a;
11
- const e = (0, utils_1.unwrapHttpError)(err);
12
- const status = e ? (0, utils_1.getHttpStatus)(e) : undefined;
13
- const code = e ? (0, utils_1.getNetworkErrorCode)(e) : undefined;
14
- const body = (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : e === null || e === void 0 ? void 0 : e.body;
15
- const detail = message || (err instanceof Error ? err.message : String(err));
16
- logger_1.default.error(`Failed ${action}. Message: ${detail}. status=${status !== null && status !== void 0 ? status : "n/a"} code=${code !== null && code !== void 0 ? code : "n/a"}`, body !== null && body !== void 0 ? body : err);
17
- }
18
8
  class TestRunErrorHandler {
19
9
  static handleErrorStartTestRun(err, message = "") {
20
- logTestRunHttpError("start test run in system", err, message);
10
+ logger_1.default.error(`HttpError ${err.statusCode}. Failed start test run in system. Message: ${message}. Error body:\n`, err.body);
21
11
  }
22
12
  static handleErrorCompletedTestRun(err, message = "") {
23
- logTestRunHttpError("complete test run in system", err, message);
13
+ logger_1.default.error(`HttpError ${err.statusCode}. Failed completed test run in system. Message: ${message}. Error body:\n`, err.body);
24
14
  }
25
15
  }
26
16
  exports.TestRunErrorHandler = TestRunErrorHandler;
@@ -6,8 +6,6 @@ export declare class TestRunsService extends BaseService implements ITestRunsSer
6
6
  protected _client: any;
7
7
  protected _converter: ITestRunConverter;
8
8
  private readonly _testResults;
9
- /** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
10
- private readonly finalizedExternalIds;
11
9
  /** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
12
10
  private readonly testResultIdsByExternalId;
13
11
  constructor(config: AdapterConfig);
@@ -25,8 +25,6 @@ class TestRunsService extends common_1.BaseService {
25
25
  constructor(config) {
26
26
  super(config);
27
27
  this.config = config;
28
- /** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
29
- this.finalizedExternalIds = new Set();
30
28
  /** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
31
29
  this.testResultIdsByExternalId = new Map();
32
30
  this._client = new AdaptersApi.TestRunsApi(AdaptersApi.ApiClient.instance);
@@ -74,9 +72,10 @@ class TestRunsService extends common_1.BaseService {
74
72
  getTestRun(testRunId) {
75
73
  return __awaiter(this, void 0, void 0, function* () {
76
74
  return yield (0, utils_1.withHttpRetry)(() => __awaiter(this, void 0, void 0, function* () {
77
- const response = yield this._client.adaptersTestRunsIdGet(testRunId);
78
- // @ts-ignore
79
- const data = (response === null || response === void 0 ? void 0 : response.body) || response;
75
+ // Temporary: adapters GET omits/empties links, attachments, description, launchSource (TMS 5.8).
76
+ // Read via public API v2; PUT stays on adapters.
77
+ const apiClient = AdaptersApi.ApiClient.instance;
78
+ const { data } = yield apiClient.callApi("/api/v2/testRuns/{id}", "GET", { id: testRunId }, {}, {}, {}, null, ["PrivateToken"], [], ["application/json"], Object, null);
80
79
  return this._converter.toLocalTestRun(data);
81
80
  }), { label: `getTestRun:${testRunId}` });
82
81
  });
@@ -120,24 +119,8 @@ class TestRunsService extends common_1.BaseService {
120
119
  return __awaiter(this, void 0, void 0, function* () {
121
120
  try {
122
121
  const testRun = yield this.getTestRun(testRunId);
123
- if (testRun.stateName !== "NotStarted") {
124
- return;
125
- }
126
- try {
127
- yield (0, utils_1.withHttpRetry)(() => this._client.adaptersTestRunsIdStartPost(testRunId), {
128
- label: `startTestRun:${testRunId}`,
129
- });
130
- }
131
- catch (err) {
132
- const refreshed = yield this.getTestRun(testRunId);
133
- if (refreshed.stateName !== "NotStarted") {
134
- logger_1.default.debug("[testruns] startTestRun skipped: run already started", {
135
- testRunId,
136
- stateName: refreshed.stateName,
137
- });
138
- return;
139
- }
140
- throw err;
122
+ if (testRun.stateName === "NotStarted") {
123
+ yield this._client.adaptersTestRunsIdStartPost(testRunId);
141
124
  }
142
125
  }
143
126
  catch (err) {
@@ -180,13 +163,6 @@ class TestRunsService extends common_1.BaseService {
180
163
  var _a, _b;
181
164
  for (const result of results) {
182
165
  const externalId = result.autoTestExternalId;
183
- if (this.finalizedExternalIds.has(externalId)) {
184
- (0, utils_1.logTmsLoadTestRun)("Bulk import: skip sendTestResults (already finalized)", {
185
- testRunId,
186
- autoTestExternalId: externalId,
187
- });
188
- continue;
189
- }
190
166
  const autotestResult = this._converter.toOriginAutotestResult(result);
191
167
  (0, utils_1.escapeHtmlInObject)(autotestResult);
192
168
  (0, utils_1.logTmsLoadTestRun)("POST setAutoTestResults (final)", {
@@ -198,7 +174,6 @@ class TestRunsService extends common_1.BaseService {
198
174
  });
199
175
  yield this.sendAutotestResultWithRetry(testRunId, autotestResult)
200
176
  .then(() => {
201
- this.finalizedExternalIds.add(externalId);
202
177
  (0, utils_1.logTmsLoadTestRun)("Finalized test result via sendTestResults", {
203
178
  testRunId,
204
179
  autoTestExternalId: externalId,
@@ -17,11 +17,18 @@ jest.mock("../../adapters-api/dist/index", () => ({
17
17
  authentications: {
18
18
  PrivateToken: { apiKeyPrefix: "", apiKey: "" },
19
19
  },
20
+ callApi: jest.fn(),
20
21
  },
21
22
  },
22
23
  TestRunsApi: jest.fn().mockImplementation(() => ({
23
24
  adaptersTestRunsIdTestResultsPost: jest.fn().mockResolvedValue(["result-id-1"]),
24
25
  })),
26
+ TestRunState: {
27
+ NotStarted: "NotStarted",
28
+ InProgress: "InProgress",
29
+ Stopped: "Stopped",
30
+ Completed: "Completed",
31
+ },
25
32
  }));
26
33
  jest.mock("../testresults/testresults.service", () => ({
27
34
  TestResultsService: jest.fn().mockImplementation(() => ({
@@ -29,6 +36,9 @@ jest.mock("../testresults/testresults.service", () => ({
29
36
  updateTestResult: jest.fn().mockResolvedValue(undefined),
30
37
  })),
31
38
  }));
39
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
40
+ const AdaptersApi = require("../../adapters-api/dist/index");
41
+ const callApi = AdaptersApi.ApiClient.instance.callApi;
32
42
  function makeConfig() {
33
43
  return {
34
44
  url: "http://localhost:8080",
@@ -41,6 +51,39 @@ function makeConfig() {
41
51
  function makeResult(overrides = {}) {
42
52
  return Object.assign({ autoTestExternalId: "ext-1", outcome: "Passed", stepResults: [{ title: "step-1" }] }, overrides);
43
53
  }
54
+ describe("TestRunsService.getTestRun", () => {
55
+ beforeEach(() => {
56
+ callApi.mockReset();
57
+ });
58
+ it("reads metadata via public API v2 (links/attachments/description/launchSource)", () => __awaiter(void 0, void 0, void 0, function* () {
59
+ callApi.mockResolvedValue({
60
+ data: {
61
+ id: "run-1",
62
+ name: "run",
63
+ description: "213123123",
64
+ launchSource: "Test IT",
65
+ stateName: "Completed",
66
+ status: { code: "PASSED", type: "Succeeded" },
67
+ testResults: [{ id: "ignored" }],
68
+ attachments: [{ id: "att-1" }],
69
+ links: [{ url: "https://example.com/1", title: "one", hasInfo: true }],
70
+ tags: ["a"],
71
+ },
72
+ });
73
+ const service = new testruns_service_1.TestRunsService(makeConfig());
74
+ const run = yield service.getTestRun("run-1");
75
+ expect(callApi).toHaveBeenCalledWith("/api/v2/testRuns/{id}", "GET", { id: "run-1" }, expect.any(Object), expect.any(Object), expect.any(Object), null, ["PrivateToken"], expect.any(Array), expect.any(Array), Object, null);
76
+ expect(run.description).toBe("213123123");
77
+ expect(run.launchSource).toBe("Test IT");
78
+ expect(run.stateName).toBe("Completed");
79
+ expect(run.links).toEqual([
80
+ expect.objectContaining({ url: "https://example.com/1", title: "one" }),
81
+ ]);
82
+ expect(run.attachments).toEqual([{ id: "att-1" }]);
83
+ expect(run.tags).toEqual(["a"]);
84
+ expect(run).not.toHaveProperty("testResults");
85
+ }));
86
+ });
44
87
  describe("TestRunsService.loadAutotests", () => {
45
88
  it("always POST final result even when in-progress id exists in cache", () => __awaiter(void 0, void 0, void 0, function* () {
46
89
  const service = new testruns_service_1.TestRunsService(makeConfig());
@@ -49,14 +92,13 @@ describe("TestRunsService.loadAutotests", () => {
49
92
  yield service.loadAutotests("run-1", [makeResult()]);
50
93
  expect(internal._client.adaptersTestRunsIdTestResultsPost).toHaveBeenCalledTimes(1);
51
94
  expect(internal._testResults.updateTestResult).not.toHaveBeenCalled();
52
- expect(internal.finalizedExternalIds.has("ext-1")).toBe(true);
53
95
  }));
54
- it("skips duplicate POST for already finalized externalId", () => __awaiter(void 0, void 0, void 0, function* () {
96
+ it("allows repeated POST for the same externalId (retry attempts)", () => __awaiter(void 0, void 0, void 0, function* () {
55
97
  const service = new testruns_service_1.TestRunsService(makeConfig());
56
98
  const internal = service;
57
- internal.finalizedExternalIds.add("ext-1");
58
- yield service.loadAutotests("run-1", [makeResult()]);
59
- expect(internal._client.adaptersTestRunsIdTestResultsPost).not.toHaveBeenCalled();
99
+ yield service.loadAutotests("run-1", [makeResult({ outcome: "Failed" })]);
100
+ yield service.loadAutotests("run-1", [makeResult({ outcome: "Passed" })]);
101
+ expect(internal._client.adaptersTestRunsIdTestResultsPost).toHaveBeenCalledTimes(2);
60
102
  }));
61
103
  });
62
104
  describe("TestRunsService.updateSetupTeardown", () => {
@@ -8,11 +8,22 @@ export declare class BaseStrategy implements IStrategy {
8
8
  client: IClient;
9
9
  testRunId: Promise<TestRunId>;
10
10
  private syncStorageRunner?;
11
+ /** externalId whose first attempt was posted as InProgress; finals deferred until teardown. */
12
+ private deferredExternalId?;
13
+ /** All attempts (including retries) for deferredExternalId, in order. */
14
+ private readonly deferredResults;
11
15
  protected constructor(config: AdapterConfig);
12
16
  setup(): Promise<void>;
13
17
  teardown(): Promise<void>;
18
+ private flushDeferredResults;
14
19
  loadAutotest(autotest: AutotestPost, status: string): Promise<void>;
15
20
  private updateTestLinkToWorkItems;
21
+ /**
22
+ * Split batch: attempts for the deferred InProgress autotest go to the queue;
23
+ * everything else is posted as final immediately.
24
+ */
25
+ private partitionByDeferred;
26
+ private enqueueDeferred;
16
27
  loadTestRun(autotests: AutotestResult[]): Promise<void>;
17
28
  updateSetupTeardown(autotests: AutotestResult[]): Promise<void>;
18
29
  private tryStartSyncStorage;
@@ -21,6 +21,8 @@ const logger_1 = __importDefault(require("../logger"));
21
21
  class BaseStrategy {
22
22
  constructor(config) {
23
23
  this.config = config;
24
+ /** All attempts (including retries) for deferredExternalId, in order. */
25
+ this.deferredResults = [];
24
26
  this.client = new client_1.Client(config);
25
27
  this.testRunId = Promise.resolve(config.testRunId);
26
28
  }
@@ -38,6 +40,7 @@ class BaseStrategy {
38
40
  return __awaiter(this, void 0, void 0, function* () {
39
41
  var _a, _b;
40
42
  const testRunId = yield this.testRunId;
43
+ yield this.flushDeferredResults(testRunId);
41
44
  yield ((_a = this.syncStorageRunner) === null || _a === void 0 ? void 0 : _a.setWorkerStatus("completed"));
42
45
  yield ((_b = this.syncStorageRunner) === null || _b === void 0 ? void 0 : _b.completeProcessing());
43
46
  // With active sync-storage, run completion is finalized by sync-storage itself.
@@ -49,6 +52,27 @@ class BaseStrategy {
49
52
  //await this.client.testRuns.completeTestRun(testRunId);
50
53
  });
51
54
  }
55
+ flushDeferredResults(testRunId) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (this.deferredResults.length === 0) {
58
+ return;
59
+ }
60
+ const results = this.deferredResults.splice(0, this.deferredResults.length);
61
+ (0, utils_1.logTmsLoadTestRun)("flush deferred finals", {
62
+ testRunId,
63
+ autoTestExternalId: this.deferredExternalId,
64
+ count: results.length,
65
+ });
66
+ yield this.client.testRuns.loadAutotests(testRunId, results).catch((err) => {
67
+ var _a;
68
+ logger_1.default.error("[strategy] FAILED to flush deferred results", {
69
+ autoTestExternalId: this.deferredExternalId,
70
+ error: (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err,
71
+ });
72
+ });
73
+ this.deferredExternalId = undefined;
74
+ });
75
+ }
52
76
  loadAutotest(autotest, status) {
53
77
  return __awaiter(this, void 0, void 0, function* () {
54
78
  var _a, _b, _c, _d, _e, _f;
@@ -93,6 +117,37 @@ class BaseStrategy {
93
117
  });
94
118
  });
95
119
  }
120
+ /**
121
+ * Split batch: attempts for the deferred InProgress autotest go to the queue;
122
+ * everything else is posted as final immediately.
123
+ */
124
+ partitionByDeferred(autotests) {
125
+ if (!this.deferredExternalId) {
126
+ return { deferred: [], immediate: autotests };
127
+ }
128
+ const deferred = [];
129
+ const immediate = [];
130
+ for (const result of autotests) {
131
+ if (result.autoTestExternalId === this.deferredExternalId) {
132
+ deferred.push(result);
133
+ }
134
+ else {
135
+ immediate.push(result);
136
+ }
137
+ }
138
+ return { deferred, immediate };
139
+ }
140
+ enqueueDeferred(results) {
141
+ if (results.length === 0) {
142
+ return;
143
+ }
144
+ this.deferredResults.push(...results);
145
+ (0, utils_1.logTmsLoadTestRun)("enqueue deferred attempts", {
146
+ autoTestExternalId: this.deferredExternalId,
147
+ added: results.length,
148
+ queued: this.deferredResults.length,
149
+ });
150
+ }
96
151
  loadTestRun(autotests) {
97
152
  return __awaiter(this, void 0, void 0, function* () {
98
153
  var _a, _b, _c, _d, _e, _f, _g;
@@ -102,11 +157,21 @@ class BaseStrategy {
102
157
  testRunId,
103
158
  batchSize: autotests.length,
104
159
  firstExternalId: firstResult === null || firstResult === void 0 ? void 0 : firstResult.autoTestExternalId,
160
+ deferredExternalId: this.deferredExternalId,
105
161
  syncRunnerActive: Boolean((_b = (_a = this.syncStorageRunner) === null || _a === void 0 ? void 0 : _a.isActive) === null || _b === void 0 ? void 0 : _b.call(_a)),
106
162
  isMaster: Boolean((_d = (_c = this.syncStorageRunner) === null || _c === void 0 ? void 0 : _c.isMasterWorker) === null || _d === void 0 ? void 0 : _d.call(_c)),
107
163
  });
164
+ // Already holding an InProgress slot: buffer retries of that autotest, post the rest.
165
+ if (this.deferredExternalId) {
166
+ const { deferred, immediate } = this.partitionByDeferred(autotests);
167
+ this.enqueueDeferred(deferred);
168
+ if (immediate.length > 0) {
169
+ yield this.client.testRuns.loadAutotests(testRunId, immediate);
170
+ }
171
+ return;
172
+ }
108
173
  // InProgress is only for the first result (the one used for sync storage cut).
109
- // Its final payload is deferred until teardown, so TMS does not immediately flip to final status.
174
+ // Its final payload (and retries of the same externalId) are deferred until teardown.
110
175
  if (firstResult) {
111
176
  const isMasterWorker = Boolean((_f = (_e = this.syncStorageRunner) === null || _e === void 0 ? void 0 : _e.isMasterWorker) === null || _f === void 0 ? void 0 : _f.call(_e));
112
177
  const published = yield ((_g = this.syncStorageRunner) === null || _g === void 0 ? void 0 : _g.sendInProgressTestResult((0, syncstorage_1.toTestResultCutModel)(firstResult, this.config.projectId)));
@@ -145,10 +210,13 @@ class BaseStrategy {
145
210
  });
146
211
  throw err;
147
212
  }
148
- // For published sync-storage InProgress, finalization of the first result is handled by sync-storage.
213
+ this.deferredExternalId = firstResult.autoTestExternalId;
214
+ this.enqueueDeferred([firstResult]);
149
215
  const rest = autotests.slice(1);
150
- if (rest.length > 0) {
151
- yield this.client.testRuns.loadAutotests(testRunId, rest);
216
+ const { deferred, immediate } = this.partitionByDeferred(rest);
217
+ this.enqueueDeferred(deferred);
218
+ if (immediate.length > 0) {
219
+ yield this.client.testRuns.loadAutotests(testRunId, immediate);
152
220
  }
153
221
  return;
154
222
  }
@@ -289,9 +289,6 @@ class ApiClient {
289
289
  applyAuthToRequest(request, authNames) {
290
290
  authNames.forEach(authName => {
291
291
  var auth = this.authentications[authName];
292
- if (!auth) {
293
- return;
294
- }
295
292
  switch (auth.type) {
296
293
  case 'basic':
297
294
  if (auth.username || auth.password) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "5.0.7",
3
+ "version": "5.0.8-TMS-5.8",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",