testit-js-commons 5.0.9-TMS-5.8 → 5.1.0
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/lib/adapters-api/dist/ApiClient.js +6 -5
- package/lib/adapters-api/dist/api/AttachmentsApi.js +5 -5
- package/lib/adapters-api/dist/api/AutoTestsApi.js +11 -11
- package/lib/adapters-api/dist/api/ConfigurationsApi.js +1 -1
- package/lib/adapters-api/dist/api/CustomAttributesApi.js +201 -0
- package/lib/adapters-api/dist/api/ParametersApi.js +3 -3
- package/lib/adapters-api/dist/api/ProjectAttributesApi.js +6 -6
- package/lib/adapters-api/dist/api/ProjectSectionsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectsApi.js +4 -4
- package/lib/adapters-api/dist/api/SectionsApi.js +2 -2
- package/lib/adapters-api/dist/api/TestResultsApi.js +3 -3
- package/lib/adapters-api/dist/api/TestRunsApi.js +8 -8
- package/lib/adapters-api/dist/api/WorkItemsApi.js +3 -3
- package/lib/adapters-api/dist/api/WorkflowsApi.js +1 -1
- package/lib/adapters-api/dist/index.js +80 -3
- package/lib/adapters-api/dist/model/AttachmentPutModelAutoTestStepResultsModel.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestApiResult.js +15 -0
- package/lib/adapters-api/dist/model/AutoTestCreateApiModel.js +15 -0
- package/lib/adapters-api/dist/model/AutoTestStepResult.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestStepResultUpdateRequest.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestUpdateApiModel.js +30 -4
- package/lib/adapters-api/dist/model/CreateEmptyTestRunApiModel.js +2 -2
- package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +56 -6
- package/lib/adapters-api/dist/model/{CustomAttributeGetModel.js → CustomAttributeModel.js} +89 -39
- package/lib/adapters-api/dist/model/CustomAttributeOptionPostApiModel.js +98 -0
- package/lib/adapters-api/dist/model/CustomAttributeOptionUpdateApiModel.js +124 -0
- package/lib/adapters-api/dist/model/CustomAttributePutModel.js +1 -1
- package/lib/adapters-api/dist/model/CustomAttributeSearchApiModel.js +137 -0
- package/lib/adapters-api/dist/model/CustomAttributeSearchApiResult.js +281 -0
- package/lib/adapters-api/dist/model/GlobalCustomAttributePostApiModel.js +141 -0
- package/lib/adapters-api/dist/model/GlobalCustomAttributeUpdateApiModel.js +129 -0
- package/lib/adapters-api/dist/model/LabelApiModel.js +4 -15
- package/lib/adapters-api/dist/model/LayerApiModel.js +102 -0
- package/lib/adapters-api/dist/model/LayerApiResult.js +102 -0
- package/lib/adapters-api/dist/model/LayerSource.js +61 -0
- package/lib/adapters-api/dist/model/ProjectShortestApiResult.js +138 -0
- package/lib/adapters-api/dist/model/ProjectsFilterModel.js +13 -13
- package/lib/adapters-api/dist/model/TestResultResponse.js +18 -4
- package/lib/adapters-api/dist/model/TestResultShortResponse.js +15 -4
- package/lib/adapters-api/dist/model/TestResultsFilterApiModel.js +14 -0
- package/lib/adapters-api/dist/model/TestRunApiResult.js +45 -4
- package/lib/adapters-api/dist/model/UpdateEmptyTestRunApiModel.js +1 -1
- package/lib/adapters-api/index.d.ts +758 -204
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/test-layers.d.ts +11 -0
- package/lib/common/test-layers.js +13 -0
- package/lib/common/types/common.type.d.ts +6 -0
- package/lib/common/utils/index.d.ts +1 -0
- package/lib/common/utils/index.js +1 -0
- package/lib/common/utils/log-sanitize.util.d.ts +12 -0
- package/lib/common/utils/log-sanitize.util.js +112 -0
- package/lib/common/utils/log-sanitize.util.test.d.ts +1 -0
- package/lib/common/utils/log-sanitize.util.test.js +55 -0
- package/lib/common/utils/tms-load-test-run-debug.d.ts +2 -0
- package/lib/common/utils/tms-load-test-run-debug.js +6 -0
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +19 -21
- package/lib/services/attachments/attachments.service.js +2 -14
- package/lib/services/autotests/autotests.converter.d.ts +6 -2
- package/lib/services/autotests/autotests.converter.js +41 -16
- package/lib/services/autotests/autotests.converter.test.d.ts +1 -0
- package/lib/services/autotests/autotests.converter.test.js +39 -0
- package/lib/services/autotests/autotests.service.js +4 -5
- package/lib/services/autotests/autotests.type.d.ts +2 -0
- package/lib/services/syncstorage/syncstorage.runner.js +6 -5
- package/lib/services/syncstorage/syncstorage.runner.test.js +16 -0
- package/lib/services/testruns/testruns.converter.d.ts +5 -0
- package/lib/services/testruns/testruns.converter.js +18 -1
- package/lib/services/testruns/testruns.converter.test.js +24 -0
- package/lib/services/testruns/testruns.handler.d.ts +2 -2
- package/lib/services/testruns/testruns.handler.js +12 -2
- package/lib/services/testruns/testruns.service.d.ts +3 -1
- package/lib/services/testruns/testruns.service.js +33 -18
- package/lib/services/testruns/testruns.service.test.js +0 -43
- package/lib/services/testruns/testruns.type.d.ts +3 -1
- package/lib/strategy/base.strategy.d.ts +1 -0
- package/lib/strategy/base.strategy.js +35 -12
- package/lib/strategy/strategy.type.d.ts +2 -0
- package/lib/sync-storage/dist/ApiClient.js +3 -0
- package/package.json +1 -1
package/lib/common/index.d.ts
CHANGED
package/lib/common/index.js
CHANGED
|
@@ -16,5 +16,6 @@ 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);
|
|
19
20
|
__exportStar(require("./base.converter"), exports);
|
|
20
21
|
__exportStar(require("./base.service"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Recommended autotest pyramid layer names (not enforced). */
|
|
2
|
+
export declare const TestLayers: {
|
|
3
|
+
readonly E2E: "E2E";
|
|
4
|
+
readonly UI: "UI";
|
|
5
|
+
readonly API: "API";
|
|
6
|
+
readonly CONTRACT: "Contract";
|
|
7
|
+
readonly INTEGRATION: "Integration";
|
|
8
|
+
readonly COMPONENT: "Component";
|
|
9
|
+
readonly UNIT: "Unit";
|
|
10
|
+
};
|
|
11
|
+
export type TestLayerName = (typeof TestLayers)[keyof typeof TestLayers] | string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestLayers = void 0;
|
|
4
|
+
/** Recommended autotest pyramid layer names (not enforced). */
|
|
5
|
+
exports.TestLayers = {
|
|
6
|
+
E2E: "E2E",
|
|
7
|
+
UI: "UI",
|
|
8
|
+
API: "API",
|
|
9
|
+
CONTRACT: "Contract",
|
|
10
|
+
INTEGRATION: "Integration",
|
|
11
|
+
COMPONENT: "Component",
|
|
12
|
+
UNIT: "Unit",
|
|
13
|
+
};
|
|
@@ -38,9 +38,15 @@ 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
|
+
*/
|
|
41
45
|
workItemsIds?: string[];
|
|
42
46
|
links?: Link[];
|
|
43
47
|
labels?: string[];
|
|
48
|
+
/** Test pyramid layer declared in test code. */
|
|
49
|
+
layer?: string;
|
|
44
50
|
classname?: string;
|
|
45
51
|
namespace?: string;
|
|
46
52
|
properties?: {
|
|
@@ -18,3 +18,4 @@ __exportStar(require("./utils"), exports);
|
|
|
18
18
|
__exportStar(require("./html-escape.util"), exports);
|
|
19
19
|
__exportStar(require("./tms-load-test-run-debug"), exports);
|
|
20
20
|
__exportStar(require("./http-retry.util"), exports);
|
|
21
|
+
__exportStar(require("./log-sanitize.util"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Redact Authorization / PrivateToken values from a string. */
|
|
2
|
+
export declare function redactSecretsInString(value: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Deep-redact secrets from any value before logging.
|
|
5
|
+
* Keeps structure; replaces sensitive header/token fields and string matches.
|
|
6
|
+
*/
|
|
7
|
+
export declare function redactSecrets(value: unknown, depth?: number, seen?: WeakSet<object>): unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Compact, header-free error summary for logs.
|
|
10
|
+
* Prefer body / error / message — never dump req._header.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatLogError(err: unknown): Record<string, unknown> | string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactSecretsInString = redactSecretsInString;
|
|
4
|
+
exports.redactSecrets = redactSecrets;
|
|
5
|
+
exports.formatLogError = formatLogError;
|
|
6
|
+
const AUTH_HEADER_RE = /(Authorization\s*[:=]\s*)(["']?)(PrivateToken|Bearer)\s+\S+/gi;
|
|
7
|
+
const PRIVATE_TOKEN_RE = /(PrivateToken)\s+\S+/gi;
|
|
8
|
+
const SENSITIVE_KEYS = new Set([
|
|
9
|
+
"authorization",
|
|
10
|
+
"privatetoken",
|
|
11
|
+
"private_token",
|
|
12
|
+
"apitoken",
|
|
13
|
+
"api_token",
|
|
14
|
+
"token",
|
|
15
|
+
]);
|
|
16
|
+
const REDACTED = "*****";
|
|
17
|
+
/** Redact Authorization / PrivateToken values from a string. */
|
|
18
|
+
function redactSecretsInString(value) {
|
|
19
|
+
return value
|
|
20
|
+
.replace(AUTH_HEADER_RE, `$1$2$3 ${REDACTED}`)
|
|
21
|
+
.replace(PRIVATE_TOKEN_RE, `$1 ${REDACTED}`);
|
|
22
|
+
}
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Deep-redact secrets from any value before logging.
|
|
28
|
+
* Keeps structure; replaces sensitive header/token fields and string matches.
|
|
29
|
+
*/
|
|
30
|
+
function redactSecrets(value, depth = 0, seen = new WeakSet()) {
|
|
31
|
+
if (value == null || depth > 8) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === "string") {
|
|
35
|
+
return redactSecretsInString(value);
|
|
36
|
+
}
|
|
37
|
+
if (typeof value !== "object") {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (seen.has(value)) {
|
|
41
|
+
return "[Circular]";
|
|
42
|
+
}
|
|
43
|
+
seen.add(value);
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value.map((item) => redactSecrets(item, depth + 1, seen));
|
|
46
|
+
}
|
|
47
|
+
// Prefer a safe HTTP-error shape when request/response with headers is present.
|
|
48
|
+
const err = value;
|
|
49
|
+
if (err.response != null || err.req != null || typeof err.statusCode === "number") {
|
|
50
|
+
return formatLogError(value);
|
|
51
|
+
}
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const [key, nested] of Object.entries(err)) {
|
|
54
|
+
if (SENSITIVE_KEYS.has(key.toLowerCase())) {
|
|
55
|
+
out[key] = REDACTED;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Drop raw request objects that carry headers.
|
|
59
|
+
if (key === "req" || key === "request") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
out[key] = redactSecrets(nested, depth + 1, seen);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Compact, header-free error summary for logs.
|
|
68
|
+
* Prefer body / error / message — never dump req._header.
|
|
69
|
+
*/
|
|
70
|
+
function formatLogError(err) {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
72
|
+
if (err == null) {
|
|
73
|
+
return String(err);
|
|
74
|
+
}
|
|
75
|
+
if (typeof err === "string") {
|
|
76
|
+
return redactSecretsInString(err);
|
|
77
|
+
}
|
|
78
|
+
if (typeof err !== "object") {
|
|
79
|
+
return String(err);
|
|
80
|
+
}
|
|
81
|
+
const e = err;
|
|
82
|
+
const nested = (_b = (_a = (isPlainObject(e.error) ? e.error : null)) !== null && _a !== void 0 ? _a : (isPlainObject(e.cause) ? e.cause : null)) !== null && _b !== void 0 ? _b : e;
|
|
83
|
+
const response = isPlainObject(nested.response) ? nested.response : undefined;
|
|
84
|
+
const status = (_e = (_d = (_c = nested.statusCode) !== null && _c !== void 0 ? _c : nested.status) !== null && _d !== void 0 ? _d : response === null || response === void 0 ? void 0 : response.status) !== null && _e !== void 0 ? _e : response === null || response === void 0 ? void 0 : response.statusCode;
|
|
85
|
+
const body = (_g = (_f = nested.body) !== null && _f !== void 0 ? _f : response === null || response === void 0 ? void 0 : response.body) !== null && _g !== void 0 ? _g : response === null || response === void 0 ? void 0 : response.text;
|
|
86
|
+
const message = (typeof nested.message === "string" && nested.message) ||
|
|
87
|
+
(typeof e.message === "string" && e.message) ||
|
|
88
|
+
undefined;
|
|
89
|
+
const code = (_h = nested.code) !== null && _h !== void 0 ? _h : e.code;
|
|
90
|
+
const safe = {};
|
|
91
|
+
if (status != null) {
|
|
92
|
+
safe.status = status;
|
|
93
|
+
}
|
|
94
|
+
if (code != null) {
|
|
95
|
+
safe.code = code;
|
|
96
|
+
}
|
|
97
|
+
if (message) {
|
|
98
|
+
safe.message = redactSecretsInString(message);
|
|
99
|
+
}
|
|
100
|
+
if (body != null) {
|
|
101
|
+
safe.body = typeof body === "string" ? redactSecretsInString(body) : redactSecrets(body);
|
|
102
|
+
}
|
|
103
|
+
if (Object.keys(safe).length === 0) {
|
|
104
|
+
try {
|
|
105
|
+
return redactSecretsInString(JSON.stringify(err));
|
|
106
|
+
}
|
|
107
|
+
catch (_j) {
|
|
108
|
+
return redactSecretsInString(String(err));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return safe;
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const log_sanitize_util_1 = require("./log-sanitize.util");
|
|
4
|
+
describe("log-sanitize", () => {
|
|
5
|
+
const token = "AvG6M3Vnc5SDZ0t4VlY0HqTG";
|
|
6
|
+
const header = "GET /api/v2/testRuns/7526aece-b91d-479a-98e2-2ced1c2a513c HTTP/1.1\r\n" +
|
|
7
|
+
`Authorization: PrivateToken ${token}\r\n` +
|
|
8
|
+
"Accept: application/json\r\n";
|
|
9
|
+
it("redacts Authorization PrivateToken in strings", () => {
|
|
10
|
+
const out = (0, log_sanitize_util_1.redactSecretsInString)(header);
|
|
11
|
+
expect(out).not.toContain(token);
|
|
12
|
+
expect(out).toContain("PrivateToken *****");
|
|
13
|
+
});
|
|
14
|
+
it("formatLogError drops req/_header and keeps status/body", () => {
|
|
15
|
+
const err = {
|
|
16
|
+
statusCode: 404,
|
|
17
|
+
message: "Not Found",
|
|
18
|
+
body: { error: { message: "Test run not found" } },
|
|
19
|
+
response: {
|
|
20
|
+
status: 404,
|
|
21
|
+
req: { _header: header },
|
|
22
|
+
},
|
|
23
|
+
req: { _header: header },
|
|
24
|
+
};
|
|
25
|
+
const safe = (0, log_sanitize_util_1.formatLogError)(err);
|
|
26
|
+
expect(JSON.stringify(safe)).not.toContain(token);
|
|
27
|
+
expect(safe).not.toHaveProperty("req");
|
|
28
|
+
expect(safe).not.toHaveProperty("response");
|
|
29
|
+
expect(safe.status).toBe(404);
|
|
30
|
+
expect(safe.message).toBe("Not Found");
|
|
31
|
+
});
|
|
32
|
+
it("redactSecrets sanitizes nested error objects used by logger", () => {
|
|
33
|
+
const err = {
|
|
34
|
+
response: { req: { _header: header }, status: 401 },
|
|
35
|
+
statusCode: 401,
|
|
36
|
+
message: `Unauthorized PrivateToken ${token}`,
|
|
37
|
+
};
|
|
38
|
+
const out = JSON.stringify((0, log_sanitize_util_1.redactSecrets)(err));
|
|
39
|
+
expect(out).not.toContain(token);
|
|
40
|
+
expect(out).toContain("*****");
|
|
41
|
+
});
|
|
42
|
+
it("formatLogError prefers body/error without headers", () => {
|
|
43
|
+
const err = {
|
|
44
|
+
error: {
|
|
45
|
+
statusCode: 401,
|
|
46
|
+
body: { title: "Unauthorized" },
|
|
47
|
+
response: { req: { _header: header } },
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const safe = (0, log_sanitize_util_1.formatLogError)(err);
|
|
51
|
+
expect(JSON.stringify(safe)).not.toContain(token);
|
|
52
|
+
expect(safe.status).toBe(401);
|
|
53
|
+
expect(safe.body).toEqual({ title: "Unauthorized" });
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -1,2 +1,4 @@
|
|
|
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;
|
|
2
4
|
export declare function logTmsLoadTestRun(message: string, data?: Record<string, unknown>): void;
|
|
@@ -4,6 +4,7 @@ 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;
|
|
7
8
|
exports.logTmsLoadTestRun = logTmsLoadTestRun;
|
|
8
9
|
/** Trace loadTestRun / result POST with `LOG_LEVEL=debug` or `TMS_DEBUG_LOAD_TEST_RUN=1`. */
|
|
9
10
|
const logger_1 = __importDefault(require("../../logger"));
|
|
@@ -14,6 +15,11 @@ function isTmsLoadTestRunDebug() {
|
|
|
14
15
|
const v = process.env.TMS_DEBUG_LOAD_TEST_RUN;
|
|
15
16
|
return v === "1" || (v === null || v === void 0 ? void 0 : v.toLowerCase()) === "true";
|
|
16
17
|
}
|
|
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
|
+
}
|
|
17
23
|
function logTmsLoadTestRun(message, data) {
|
|
18
24
|
if (!isTmsLoadTestRunDebug()) {
|
|
19
25
|
return;
|
package/lib/logger/index.d.ts
CHANGED
package/lib/logger/index.js
CHANGED
|
@@ -1,65 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const log_sanitize_util_1 = require("../common/utils/log-sanitize.util");
|
|
3
4
|
class Logger {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.levels = {
|
|
6
7
|
error: 0,
|
|
7
8
|
warn: 1,
|
|
8
9
|
info: 2,
|
|
9
|
-
debug: 3
|
|
10
|
+
debug: 3,
|
|
10
11
|
};
|
|
11
|
-
//
|
|
12
|
-
const envLevel = (process.env.LOG_LEVEL ||
|
|
13
|
-
this.currentLevel =
|
|
14
|
-
? this.levels[envLevel]
|
|
15
|
-
: this.levels.info;
|
|
12
|
+
// Level from env or default 'warn'
|
|
13
|
+
const envLevel = (process.env.LOG_LEVEL || "warn").toLowerCase();
|
|
14
|
+
this.currentLevel =
|
|
15
|
+
this.levels[envLevel] !== undefined ? this.levels[envLevel] : this.levels.info;
|
|
16
16
|
}
|
|
17
17
|
log_(level, message, ...args) {
|
|
18
18
|
if (this.levels[level] <= this.currentLevel) {
|
|
19
19
|
const timestamp = new Date().toISOString();
|
|
20
20
|
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const safeMessage = (0, log_sanitize_util_1.redactSecretsInString)(message);
|
|
22
|
+
const safeArgs = args.map((arg) => (0, log_sanitize_util_1.redactSecrets)(arg));
|
|
23
|
+
if (level === "error") {
|
|
24
|
+
console.error(prefix, safeMessage, ...safeArgs);
|
|
23
25
|
}
|
|
24
|
-
else if (level ===
|
|
25
|
-
console.warn(prefix,
|
|
26
|
+
else if (level === "warn") {
|
|
27
|
+
console.warn(prefix, safeMessage, ...safeArgs);
|
|
26
28
|
}
|
|
27
29
|
else {
|
|
28
|
-
console.log(prefix,
|
|
30
|
+
console.log(prefix, safeMessage, ...safeArgs);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
error(message, ...args) {
|
|
33
|
-
this.log_(
|
|
35
|
+
this.log_("error", message, ...args);
|
|
34
36
|
}
|
|
35
37
|
warn(message, ...args) {
|
|
36
|
-
this.log_(
|
|
38
|
+
this.log_("warn", message, ...args);
|
|
37
39
|
}
|
|
38
40
|
info(message, ...args) {
|
|
39
|
-
this.log_(
|
|
41
|
+
this.log_("info", message, ...args);
|
|
40
42
|
}
|
|
41
43
|
log(message, ...args) {
|
|
42
|
-
this.log_(
|
|
44
|
+
this.log_("info", message, ...args);
|
|
43
45
|
}
|
|
44
46
|
debug(message, ...args) {
|
|
45
|
-
this.log_(
|
|
47
|
+
this.log_("debug", message, ...args);
|
|
46
48
|
}
|
|
47
|
-
// Проверка, включен ли уровень
|
|
48
49
|
isLevelEnabled(level) {
|
|
49
50
|
return this.levels[level] <= this.currentLevel;
|
|
50
51
|
}
|
|
51
|
-
// Получить текущий уровень логирования
|
|
52
52
|
getCurrentLevel() {
|
|
53
53
|
const level = Object.keys(this.levels).find((key) => this.levels[key] === this.currentLevel);
|
|
54
|
-
return level ||
|
|
54
|
+
return level || "info";
|
|
55
55
|
}
|
|
56
|
-
// Установить уровень логирования динамически
|
|
57
56
|
setLevel(level) {
|
|
58
57
|
if (this.levels[level] !== undefined) {
|
|
59
58
|
this.currentLevel = this.levels[level];
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
// Синглтон
|
|
64
62
|
const logger = new Logger();
|
|
65
63
|
exports.default = logger;
|
|
@@ -114,13 +114,7 @@ class AttachmentsService extends common_1.BaseService {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
|
-
logger_1.default.error("Error uploading text attachment:", error);
|
|
118
|
-
if (error.response) {
|
|
119
|
-
logger_1.default.error("Response details:", {
|
|
120
|
-
status: error.response.status,
|
|
121
|
-
text: error.response.text,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
117
|
+
logger_1.default.error("Error uploading text attachment:", (0, common_1.formatLogError)(error));
|
|
124
118
|
throw error;
|
|
125
119
|
}
|
|
126
120
|
});
|
|
@@ -150,13 +144,7 @@ class AttachmentsService extends common_1.BaseService {
|
|
|
150
144
|
attachmentIds.push(id);
|
|
151
145
|
}
|
|
152
146
|
catch (error) {
|
|
153
|
-
logger_1.default.error(`Error uploading attachment ${path}:`, error);
|
|
154
|
-
if (error.response) {
|
|
155
|
-
logger_1.default.error("Response details:", {
|
|
156
|
-
status: error.response.status,
|
|
157
|
-
text: error.response.text,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
147
|
+
logger_1.default.error(`Error uploading attachment ${path}:`, (0, common_1.formatLogError)(error));
|
|
160
148
|
throw error;
|
|
161
149
|
}
|
|
162
150
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { BaseConverter, AdapterConfig } from "../../common";
|
|
2
2
|
import { AutotestGet, AutotestPost } from "./autotests.type";
|
|
3
3
|
export interface IAutotestConverter {
|
|
4
|
-
|
|
4
|
+
toOriginAutotestCreate(autotest: AutotestPost): any;
|
|
5
|
+
toOriginAutotestUpdate(autotest: AutotestPost): any;
|
|
5
6
|
toLocalAutotest(autotest: any): AutotestGet;
|
|
6
7
|
}
|
|
7
8
|
export declare class AutotestConverter extends BaseConverter implements IAutotestConverter {
|
|
8
9
|
constructor(config: AdapterConfig);
|
|
9
|
-
|
|
10
|
+
toOriginAutotestCreate(autotest: AutotestPost): any;
|
|
11
|
+
toOriginAutotestUpdate(autotest: AutotestPost): any;
|
|
10
12
|
toLocalAutotest(autotest: any): AutotestGet;
|
|
13
|
+
private baseAutotestFields;
|
|
14
|
+
private layerToApiModel;
|
|
11
15
|
}
|
|
@@ -2,11 +2,45 @@
|
|
|
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";
|
|
5
6
|
class AutotestConverter extends common_1.BaseConverter {
|
|
6
7
|
constructor(config) {
|
|
7
8
|
super(config);
|
|
8
9
|
}
|
|
9
|
-
|
|
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) {
|
|
10
44
|
return {
|
|
11
45
|
externalId: autotest.externalId,
|
|
12
46
|
name: autotest.name,
|
|
@@ -26,21 +60,12 @@ class AutotestConverter extends common_1.BaseConverter {
|
|
|
26
60
|
shouldCreateWorkItem: this.config.automaticCreationTestCases,
|
|
27
61
|
};
|
|
28
62
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
};
|
|
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 };
|
|
44
69
|
}
|
|
45
70
|
}
|
|
46
71
|
exports.AutotestConverter = AutotestConverter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const autotests_converter_1 = require("./autotests.converter");
|
|
4
|
+
function makeConfig() {
|
|
5
|
+
return {
|
|
6
|
+
url: "http://localhost:8080",
|
|
7
|
+
privateToken: "token",
|
|
8
|
+
projectId: "11111111-1111-1111-1111-111111111111",
|
|
9
|
+
configurationId: "22222222-2222-2222-2222-222222222222",
|
|
10
|
+
testRunId: "33333333-3333-3333-3333-333333333333",
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function makeAutotest(overrides = {}) {
|
|
14
|
+
return Object.assign({ externalId: "ext-1", name: "test name" }, overrides);
|
|
15
|
+
}
|
|
16
|
+
describe("AutotestConverter layer", () => {
|
|
17
|
+
const converter = new autotests_converter_1.AutotestConverter(makeConfig());
|
|
18
|
+
it("create: includes layer when set", () => {
|
|
19
|
+
const model = converter.toOriginAutotestCreate(makeAutotest({ layer: "API" }));
|
|
20
|
+
expect(model.layer).toEqual({ name: "API", source: "Run" });
|
|
21
|
+
expect(model.resetLayer).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it("create: omits layer when not set", () => {
|
|
24
|
+
const model = converter.toOriginAutotestCreate(makeAutotest());
|
|
25
|
+
expect(model.layer).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
it("create: accepts custom layer string", () => {
|
|
28
|
+
const model = converter.toOriginAutotestCreate(makeAutotest({ layer: "my-custom-layer" }));
|
|
29
|
+
expect(model.layer).toEqual({ name: "my-custom-layer", source: "Run" });
|
|
30
|
+
});
|
|
31
|
+
it("update: always resetLayer false, layer only when set", () => {
|
|
32
|
+
const withLayer = converter.toOriginAutotestUpdate(makeAutotest({ layer: "E2E" }));
|
|
33
|
+
expect(withLayer.resetLayer).toBe(false);
|
|
34
|
+
expect(withLayer.layer).toEqual({ name: "E2E", source: "Run" });
|
|
35
|
+
const withoutLayer = converter.toOriginAutotestUpdate(makeAutotest());
|
|
36
|
+
expect(withoutLayer.resetLayer).toBe(false);
|
|
37
|
+
expect(withoutLayer.layer).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -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.
|
|
31
|
+
const autotestPost = this._converter.toOriginAutotestCreate(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.
|
|
54
|
+
const autotestPost = this._converter.toOriginAutotestUpdate(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,19 +103,18 @@ 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, 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, layer: autotest.layer, workItemIds: autotest.workItemIds, isFlaky: autotest.isFlaky, shouldCreateWorkItem: autotest.shouldCreateWorkItem }));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
linkToWorkItems(internalId, workItemIds) {
|
|
110
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
111
|
const promises = workItemIds.map((workItemId) => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
var _a, _b;
|
|
113
112
|
try {
|
|
114
113
|
yield this._client.adaptersAutoTestsIdWorkItemsPost(internalId, { workItemIdApiModel: { id: workItemId } });
|
|
115
114
|
logger_1.default.log(`Link autotest ${internalId} to workitem ${workItemId} is successfully`);
|
|
116
115
|
}
|
|
117
116
|
catch (e) {
|
|
118
|
-
logger_1.default.error(`Cannot link autotest ${internalId} to work item ${workItemId}`, (
|
|
117
|
+
logger_1.default.error(`Cannot link autotest ${internalId} to work item ${workItemId}`, (0, common_1.formatLogError)(e));
|
|
119
118
|
}
|
|
120
119
|
}));
|
|
121
120
|
yield Promise.all(promises);
|
|
@@ -25,6 +25,8 @@ 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;
|
|
28
30
|
}
|
|
29
31
|
export interface AutotestPost extends AutotestBase {
|
|
30
32
|
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.
|
|
114
|
+
if ((0, utils_1.isSyncStorageDebug)()) {
|
|
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.
|
|
129
|
+
if ((0, utils_1.isSyncStorageDebug)()) {
|
|
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.
|
|
150
|
+
if ((0, utils_1.isSyncStorageDebug)()) {
|
|
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.
|
|
164
|
+
if ((0, utils_1.isSyncStorageDebug)()) {
|
|
165
165
|
logger_1.default.debug("[syncstorage] in-progress cut publish failed", {
|
|
166
166
|
workerPid: this.workerPid,
|
|
167
167
|
autoTestExternalId: model.autoTestExternalId,
|
|
@@ -233,6 +233,7 @@ 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.
|
|
236
237
|
this.syncStorageProcess = (0, child_process_1.spawn)(executablePath, command, {
|
|
237
238
|
cwd: (0, path_1.join)(process.cwd(), "build", ".caches"),
|
|
238
239
|
stdio: "ignore",
|
|
@@ -353,7 +354,7 @@ class SyncStorageRunner {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
exports.SyncStorageRunner = SyncStorageRunner;
|
|
356
|
-
SyncStorageRunner.VERSION = "v0.3.
|
|
357
|
+
SyncStorageRunner.VERSION = "v0.3.12";
|
|
357
358
|
SyncStorageRunner.STARTUP_TIMEOUT_MS = 30000;
|
|
358
359
|
SyncStorageRunner.STARTUP_POLL_MS = 1000;
|
|
359
360
|
SyncStorageRunner.PROCESS_WARMUP_MS = 2000;
|