@yadsh/dsh-qa-integrations 0.5.0 → 0.6.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.
Files changed (191) hide show
  1. package/README.md +431 -18
  2. package/compatibility.json +1 -1
  3. package/lib/broker.js +456 -9
  4. package/lib/broker.js.map +1 -1
  5. package/lib/client/bitrix24.js +2 -1
  6. package/lib/client/bitrix24.js.map +1 -1
  7. package/lib/client/card.js +8 -1
  8. package/lib/client/card.js.map +1 -1
  9. package/lib/client/confluence.js +3 -2
  10. package/lib/client/confluence.js.map +1 -1
  11. package/lib/client/gitlab.js +40 -4
  12. package/lib/client/gitlab.js.map +1 -1
  13. package/lib/client/index.js +13 -11
  14. package/lib/client/index.js.map +1 -1
  15. package/lib/client/integrations.js +39 -2
  16. package/lib/client/integrations.js.map +1 -1
  17. package/lib/client/jira.js +3 -2
  18. package/lib/client/jira.js.map +1 -1
  19. package/lib/client/provider-card.js +138 -4
  20. package/lib/client/provider-card.js.map +1 -1
  21. package/lib/client/styles.js +8 -5
  22. package/lib/client/styles.js.map +1 -1
  23. package/lib/client/teamcity.js +31 -4
  24. package/lib/client/teamcity.js.map +1 -1
  25. package/lib/client/testit.js +65 -0
  26. package/lib/client/testit.js.map +1 -0
  27. package/lib/client/weblate.js +70 -0
  28. package/lib/client/weblate.js.map +1 -0
  29. package/lib/client.js +2600 -480
  30. package/lib/client.js.map +1 -1
  31. package/lib/coerce.js +16 -7
  32. package/lib/coerce.js.map +1 -1
  33. package/lib/config.js +12 -0
  34. package/lib/config.js.map +1 -1
  35. package/lib/errors.js.map +1 -1
  36. package/lib/index.js +274 -28
  37. package/lib/index.js.map +1 -1
  38. package/lib/providers/bitrix24/catalog.js +13 -0
  39. package/lib/providers/bitrix24/catalog.js.map +1 -1
  40. package/lib/providers/bitrix24/config.js +3 -0
  41. package/lib/providers/bitrix24/config.js.map +1 -1
  42. package/lib/providers/bitrix24/credential-help.js +24 -0
  43. package/lib/providers/bitrix24/credential-help.js.map +1 -0
  44. package/lib/providers/bitrix24/index.js +9 -0
  45. package/lib/providers/bitrix24/index.js.map +1 -1
  46. package/lib/providers/bitrix24/operations.js +60 -1
  47. package/lib/providers/bitrix24/operations.js.map +1 -1
  48. package/lib/providers/bitrix24/tools.js +95 -3
  49. package/lib/providers/bitrix24/tools.js.map +1 -1
  50. package/lib/providers/confluence/credential-help.js +29 -0
  51. package/lib/providers/confluence/credential-help.js.map +1 -0
  52. package/lib/providers/confluence/index.js +9 -0
  53. package/lib/providers/confluence/index.js.map +1 -1
  54. package/lib/providers/gitlab/catalog.js +108 -15
  55. package/lib/providers/gitlab/catalog.js.map +1 -1
  56. package/lib/providers/gitlab/config.js +11 -3
  57. package/lib/providers/gitlab/config.js.map +1 -1
  58. package/lib/providers/gitlab/credential-help.js +33 -0
  59. package/lib/providers/gitlab/credential-help.js.map +1 -0
  60. package/lib/providers/gitlab/index.js +337 -6
  61. package/lib/providers/gitlab/index.js.map +1 -1
  62. package/lib/providers/jira/credential-help.js +31 -0
  63. package/lib/providers/jira/credential-help.js.map +1 -0
  64. package/lib/providers/jira/index.js +9 -0
  65. package/lib/providers/jira/index.js.map +1 -1
  66. package/lib/providers/registry.js +4 -0
  67. package/lib/providers/registry.js.map +1 -1
  68. package/lib/providers/shared/credential-help.js +29 -0
  69. package/lib/providers/shared/credential-help.js.map +1 -0
  70. package/lib/providers/shared/service-boundary.js +44 -0
  71. package/lib/providers/shared/service-boundary.js.map +1 -0
  72. package/lib/providers/teamcity/catalog.js +56 -2
  73. package/lib/providers/teamcity/catalog.js.map +1 -1
  74. package/lib/providers/teamcity/credential-help.js +25 -0
  75. package/lib/providers/teamcity/credential-help.js.map +1 -0
  76. package/lib/providers/teamcity/index.js +254 -2
  77. package/lib/providers/teamcity/index.js.map +1 -1
  78. package/lib/providers/testit/attachments.js +131 -0
  79. package/lib/providers/testit/attachments.js.map +1 -0
  80. package/lib/providers/testit/catalog.js +225 -0
  81. package/lib/providers/testit/catalog.js.map +1 -0
  82. package/lib/providers/testit/config.js +175 -0
  83. package/lib/providers/testit/config.js.map +1 -0
  84. package/lib/providers/testit/credential-help.js +29 -0
  85. package/lib/providers/testit/credential-help.js.map +1 -0
  86. package/lib/providers/testit/index.js +184 -0
  87. package/lib/providers/testit/index.js.map +1 -0
  88. package/lib/providers/testit/operations.js +1070 -0
  89. package/lib/providers/testit/operations.js.map +1 -0
  90. package/lib/providers/testit/tools.js +717 -0
  91. package/lib/providers/testit/tools.js.map +1 -0
  92. package/lib/providers/testit/transport.js +158 -0
  93. package/lib/providers/testit/transport.js.map +1 -0
  94. package/lib/providers/weblate/catalog.js +185 -0
  95. package/lib/providers/weblate/catalog.js.map +1 -0
  96. package/lib/providers/weblate/config.js +147 -0
  97. package/lib/providers/weblate/config.js.map +1 -0
  98. package/lib/providers/weblate/credential-help.js +26 -0
  99. package/lib/providers/weblate/credential-help.js.map +1 -0
  100. package/lib/providers/weblate/index.js +181 -0
  101. package/lib/providers/weblate/index.js.map +1 -0
  102. package/lib/providers/weblate/operations.js +703 -0
  103. package/lib/providers/weblate/operations.js.map +1 -0
  104. package/lib/providers/weblate/query.js +80 -0
  105. package/lib/providers/weblate/query.js.map +1 -0
  106. package/lib/providers/weblate/tools.js +408 -0
  107. package/lib/providers/weblate/tools.js.map +1 -0
  108. package/lib/providers/weblate/transport.js +179 -0
  109. package/lib/providers/weblate/transport.js.map +1 -0
  110. package/lib/repository.js +197 -13
  111. package/lib/repository.js.map +1 -1
  112. package/lib/service-credentials/config.js +179 -0
  113. package/lib/service-credentials/config.js.map +1 -0
  114. package/lib/service-credentials/policy.js +92 -0
  115. package/lib/service-credentials/policy.js.map +1 -0
  116. package/lib/service-credentials/registry.js +142 -0
  117. package/lib/service-credentials/registry.js.map +1 -0
  118. package/lib/service-credentials/state.js +30 -0
  119. package/lib/service-credentials/state.js.map +1 -0
  120. package/lib/service-credentials/types.js +20 -0
  121. package/lib/service-credentials/types.js.map +1 -0
  122. package/lib/tools.js +27 -2
  123. package/lib/tools.js.map +1 -1
  124. package/lib/typert.host.js +1187 -39
  125. package/lib/typert.remote-client.d.ts +37 -5
  126. package/lib/typert.remote-client.js +1057 -33
  127. package/lib/types/broker.d.ts +70 -4
  128. package/lib/types/client/bitrix24.d.ts +1 -1
  129. package/lib/types/client/card.d.ts +3 -1
  130. package/lib/types/client/confluence.d.ts +2 -2
  131. package/lib/types/client/gitlab.d.ts +15 -2
  132. package/lib/types/client/index.d.ts +3 -2
  133. package/lib/types/client/integrations.d.ts +11 -2
  134. package/lib/types/client/jira.d.ts +2 -2
  135. package/lib/types/client/provider-card.d.ts +50 -8
  136. package/lib/types/client/styles.d.ts +4 -3
  137. package/lib/types/client/teamcity.d.ts +15 -2
  138. package/lib/types/client/testit.d.ts +15 -0
  139. package/lib/types/client/weblate.d.ts +15 -0
  140. package/lib/types/coerce.d.ts +2 -2
  141. package/lib/types/config.d.ts +21 -0
  142. package/lib/types/errors.d.ts +9 -1
  143. package/lib/types/index.d.ts +108 -11
  144. package/lib/types/providers/bitrix24/catalog.d.ts +1 -1
  145. package/lib/types/providers/bitrix24/config.d.ts +11 -1
  146. package/lib/types/providers/bitrix24/credential-help.d.ts +8 -0
  147. package/lib/types/providers/bitrix24/index.d.ts +5 -0
  148. package/lib/types/providers/bitrix24/tools.d.ts +4 -0
  149. package/lib/types/providers/confluence/credential-help.d.ts +9 -0
  150. package/lib/types/providers/confluence/index.d.ts +5 -0
  151. package/lib/types/providers/contract.d.ts +62 -1
  152. package/lib/types/providers/gitlab/catalog.d.ts +20 -5
  153. package/lib/types/providers/gitlab/config.d.ts +14 -3
  154. package/lib/types/providers/gitlab/credential-help.d.ts +9 -0
  155. package/lib/types/providers/gitlab/index.d.ts +51 -1
  156. package/lib/types/providers/jira/credential-help.d.ts +8 -0
  157. package/lib/types/providers/jira/index.d.ts +5 -0
  158. package/lib/types/providers/registry.d.ts +2 -0
  159. package/lib/types/providers/shared/credential-help.d.ts +17 -0
  160. package/lib/types/providers/shared/service-boundary.d.ts +25 -0
  161. package/lib/types/providers/teamcity/catalog.d.ts +18 -2
  162. package/lib/types/providers/teamcity/credential-help.d.ts +8 -0
  163. package/lib/types/providers/teamcity/index.d.ts +53 -2
  164. package/lib/types/providers/testit/attachments.d.ts +20 -0
  165. package/lib/types/providers/testit/catalog.d.ts +75 -0
  166. package/lib/types/providers/testit/config.d.ts +61 -0
  167. package/lib/types/providers/testit/credential-help.d.ts +8 -0
  168. package/lib/types/providers/testit/index.d.ts +60 -0
  169. package/lib/types/providers/testit/operations.d.ts +95 -0
  170. package/lib/types/providers/testit/tools.d.ts +15 -0
  171. package/lib/types/providers/testit/transport.d.ts +67 -0
  172. package/lib/types/providers/weblate/catalog.d.ts +43 -0
  173. package/lib/types/providers/weblate/config.d.ts +57 -0
  174. package/lib/types/providers/weblate/credential-help.d.ts +9 -0
  175. package/lib/types/providers/weblate/index.d.ts +50 -0
  176. package/lib/types/providers/weblate/operations.d.ts +77 -0
  177. package/lib/types/providers/weblate/query.d.ts +37 -0
  178. package/lib/types/providers/weblate/tools.d.ts +15 -0
  179. package/lib/types/providers/weblate/transport.d.ts +60 -0
  180. package/lib/types/repository.d.ts +38 -3
  181. package/lib/types/service-credentials/config.d.ts +73 -0
  182. package/lib/types/service-credentials/policy.d.ts +44 -0
  183. package/lib/types/service-credentials/registry.d.ts +43 -0
  184. package/lib/types/service-credentials/state.d.ts +14 -0
  185. package/lib/types/service-credentials/types.d.ts +97 -0
  186. package/lib/types/tools.d.ts +10 -1
  187. package/lib/types/types.d.ts +114 -10
  188. package/package.json +7 -7
  189. package/lib/shared/settings.js +0 -19
  190. package/lib/shared/settings.js.map +0 -1
  191. package/lib/types/shared/settings.d.ts +0 -19
@@ -0,0 +1,1070 @@
1
+ import { optionalBoolean, optionalInteger, optionalText, requiredText, } from "../../coerce.js";
2
+ import { IntegrationError } from "../../errors.js";
3
+ /**
4
+ * Request building and response shaping for the Test IT Open API v2.
5
+ *
6
+ * Every operation answers with a normalized object instead of Test IT's own
7
+ * DTO, and every list answers with the same `{ items, pagination }` envelope, so
8
+ * the model learns one shape rather than a dozen. Text a user typed into Test IT
9
+ * — descriptions, steps, comments, traces, names of configurations — is
10
+ * untrusted external content and reaches the model under `untrustedContent` or
11
+ * as a bounded block, never as a bare string that could read as an instruction.
12
+ */
13
+ /**
14
+ * Hard caps per collection, from the provider specification. They bound what one
15
+ * answer may carry; Test IT documents no ceiling of its own for `Take`.
16
+ */
17
+ export const TESTIT_LIMITS = Object.freeze({
18
+ projects: 100,
19
+ sections: 100,
20
+ workItems: 100,
21
+ history: 100,
22
+ comments: 100,
23
+ testPlans: 100,
24
+ testRuns: 50,
25
+ testResults: 100,
26
+ attachments: 100,
27
+ autoTests: 100,
28
+ configurations: 100,
29
+ });
30
+ /**
31
+ * Values Test IT accepts for the fields this provider exposes. The vocabulary is
32
+ * closed on purpose: an enum the model cannot spell is a 400 from upstream, and
33
+ * a 400 costs an answer where a refused argument costs one line.
34
+ */
35
+ export const WORK_ITEM_STATES = Object.freeze([
36
+ "NeedsWork",
37
+ "NotReady",
38
+ "Ready",
39
+ ]);
40
+ export const WORK_ITEM_PRIORITIES = Object.freeze([
41
+ "Lowest",
42
+ "Low",
43
+ "Medium",
44
+ "High",
45
+ "Highest",
46
+ ]);
47
+ export const WORK_ITEM_ENTITY_TYPES = Object.freeze([
48
+ "TestCases",
49
+ "CheckLists",
50
+ "SharedSteps",
51
+ ]);
52
+ export const TEST_RUN_STATES = Object.freeze([
53
+ "NotStarted",
54
+ "InProgress",
55
+ "Stopped",
56
+ "Completed",
57
+ ]);
58
+ export const RESULT_OUTCOMES = Object.freeze([
59
+ "InProgress",
60
+ "Passed",
61
+ "Failed",
62
+ "Skipped",
63
+ "Blocked",
64
+ ]);
65
+ /** An absurd `limit` is clamped, not refused, so the cap still answers. */
66
+ const MAX_ASKED_LIMIT = 100_000;
67
+ const MAX_OFFSET = 1_000_000;
68
+ /** Test IT ids are UUIDs; the shape is what keeps them inside a path segment. */
69
+ const ENTITY_ID = /^[A-Za-z0-9-]{1,64}$/u;
70
+ const DETAILS_CHARS = 1_000;
71
+ const TEXT_CHARS = 2_000;
72
+ const CONFIG_TEXT_CHARS = 200;
73
+ function invalid(field) {
74
+ throw new IntegrationError("InvalidRequest", `${field} is invalid`);
75
+ }
76
+ /** One Test IT identifier: a project, work item, run, result or attachment id. */
77
+ function entityId(value, field) {
78
+ const normalized = requiredText(value, field, 1, 64);
79
+ if (!ENTITY_ID.test(normalized))
80
+ invalid(field);
81
+ return normalized;
82
+ }
83
+ function optionalEntityId(value, field) {
84
+ return value === undefined ? undefined : entityId(value, field);
85
+ }
86
+ function oneOf(value, allowed, field, maxLength) {
87
+ const normalized = optionalText(value, field, 1, maxLength);
88
+ if (normalized === undefined)
89
+ return undefined;
90
+ if (!allowed.includes(normalized))
91
+ invalid(field);
92
+ return normalized;
93
+ }
94
+ /**
95
+ * A timestamp or a plain date. Test IT serves its own ISO-8601 strings back, so
96
+ * the value is passed through once it parses: the provider refuses a value it
97
+ * cannot read rather than forwarding something upstream would 400 on.
98
+ */
99
+ function optionalMoment(value, field) {
100
+ if (value === undefined)
101
+ return undefined;
102
+ const normalized = requiredText(value, field, 8, 40);
103
+ if (Number.isNaN(Date.parse(normalized)))
104
+ invalid(field);
105
+ return normalized;
106
+ }
107
+ /** The `states` filter of a run search, as the four flags upstream wants. */
108
+ function runStateFlags(value) {
109
+ if (value === undefined)
110
+ return TEST_RUN_STATES;
111
+ if (!Array.isArray(value) ||
112
+ value.length === 0 ||
113
+ value.length > TEST_RUN_STATES.length) {
114
+ invalid("states");
115
+ }
116
+ return value.map((item) => {
117
+ const state = oneOf(item, TEST_RUN_STATES, "states", 16);
118
+ if (state === undefined)
119
+ invalid("states");
120
+ return state;
121
+ });
122
+ }
123
+ /**
124
+ * Rows one call may ask for: the caller's wish is clamped to the deployment cap
125
+ * rather than refused, because a model that asks for "the last 500 test cases"
126
+ * still gets a useful answer instead of an error.
127
+ */
128
+ export function listLimit(requested, cap, flags) {
129
+ if (requested === undefined) {
130
+ return Math.min(flags.defaultResults, cap, flags.maxResults);
131
+ }
132
+ const asked = optionalInteger(requested, "limit", 1, MAX_ASKED_LIMIT);
133
+ return Math.min(asked ?? cap, cap, flags.maxResults);
134
+ }
135
+ /** Rows to skip; `offset` is the model's only pagination cursor here. */
136
+ export function listOffset(requested) {
137
+ return optionalInteger(requested, "offset", 0, MAX_OFFSET) ?? 0;
138
+ }
139
+ /* ------------------------------------------------------------------ */
140
+ /* Request building */
141
+ /* ------------------------------------------------------------------ */
142
+ export const TESTIT_HANDLERS = Object.freeze({
143
+ // The connection probe is the documented first validation call: an authorized
144
+ // answer to the project list proves the address and the token at once. `Take`
145
+ // is pinned to one row because the answer is measured, not read.
146
+ "connection.get": () => ({ path: "/projects", query: { Take: "1" } }),
147
+ "projects.list": (input, context) => ({
148
+ path: "/projects",
149
+ query: {
150
+ Skip: String(listOffset(input["offset"])),
151
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.projects, context.flags)),
152
+ },
153
+ }),
154
+ "projects.get": (input) => ({
155
+ path: `/projects/${entityId(input["projectId"], "projectId")}`,
156
+ query: {},
157
+ }),
158
+ "sections.list": (input, context) => ({
159
+ path: `/projects/${entityId(input["projectId"], "projectId")}/sections`,
160
+ query: {
161
+ Skip: String(listOffset(input["offset"])),
162
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.sections, context.flags)),
163
+ },
164
+ }),
165
+ "workItems.list": (input, context) => ({
166
+ path: `/projects/${entityId(input["projectId"], "projectId")}/workItems`,
167
+ query: {
168
+ Skip: String(listOffset(input["offset"])),
169
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.workItems, context.flags)),
170
+ },
171
+ }),
172
+ "workItems.get": (input) => ({
173
+ path: `/workItems/${entityId(input["workItemId"], "workItemId")}`,
174
+ query: {},
175
+ }),
176
+ "workItems.history": (input, context) => ({
177
+ path: `/workItems/${entityId(input["workItemId"], "workItemId")}/history`,
178
+ query: {
179
+ Skip: String(listOffset(input["offset"])),
180
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.history, context.flags)),
181
+ },
182
+ }),
183
+ "workItems.comments": (input) => ({
184
+ path: `/workItems/${entityId(input["workItemId"], "workItemId")}/comments`,
185
+ query: {},
186
+ }),
187
+ "workItems.testResults": (input, context) => ({
188
+ path: `/workItems/${entityId(input["workItemId"], "workItemId")}/testResults/history`,
189
+ query: {
190
+ Skip: String(listOffset(input["offset"])),
191
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.testResults, context.flags)),
192
+ },
193
+ }),
194
+ "testPlans.list": (input) => ({
195
+ path: `/projects/${entityId(input["projectId"], "projectId")}/testPlans`,
196
+ query: {},
197
+ }),
198
+ "testPlans.get": (input) => ({
199
+ path: `/testPlans/${entityId(input["testPlanId"], "testPlanId")}`,
200
+ query: {},
201
+ }),
202
+ "testPlans.summary": (input) => ({
203
+ path: `/testPlans/${entityId(input["testPlanId"], "testPlanId")}/summaries`,
204
+ query: {},
205
+ }),
206
+ "testRuns.list": (input, context) => {
207
+ const states = runStateFlags(input["states"]);
208
+ const testPlanId = optionalEntityId(input["testPlanId"], "testPlanId");
209
+ return {
210
+ path: `/projects/${entityId(input["projectId"], "projectId")}/testRuns`,
211
+ query: {
212
+ // The four state flags are required by this endpoint; the provider
213
+ // always sends all four, so "no filter" is four explicit `true`s.
214
+ notStarted: states.includes("NotStarted") ? "true" : "false",
215
+ inProgress: states.includes("InProgress") ? "true" : "false",
216
+ stopped: states.includes("Stopped") ? "true" : "false",
217
+ completed: states.includes("Completed") ? "true" : "false",
218
+ createdDateFrom: optionalMoment(input["createdFrom"], "createdFrom"),
219
+ createdDateTo: optionalMoment(input["createdTo"], "createdTo"),
220
+ ...(testPlanId === undefined ? {} : { testPlanId }),
221
+ Skip: String(listOffset(input["offset"])),
222
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.testRuns, context.flags)),
223
+ },
224
+ };
225
+ },
226
+ "testRuns.get": (input) => ({
227
+ path: `/testRuns/${entityId(input["testRunId"], "testRunId")}`,
228
+ query: {},
229
+ }),
230
+ "testRuns.results": (input) => ({
231
+ path: `/testRuns/${entityId(input["testRunId"], "testRunId")}/testPoints/results`,
232
+ query: {},
233
+ }),
234
+ "testResults.get": (input) => ({
235
+ path: `/testResults/${entityId(input["testResultId"], "testResultId")}`,
236
+ query: {},
237
+ }),
238
+ "testResults.attachments": (input) => ({
239
+ path: `/testResults/${entityId(input["testResultId"], "testResultId")}/attachments`,
240
+ query: {},
241
+ }),
242
+ "attachments.metadata": (input) => ({
243
+ path: `/attachments/${entityId(input["attachmentId"], "attachmentId")}/metadata`,
244
+ query: {},
245
+ }),
246
+ // The provider reads this one as bytes, not as JSON; the handler only builds
247
+ // the address, so the id is validated here exactly like everywhere else.
248
+ "attachments.text": (input) => ({
249
+ path: `/attachments/${entityId(input["attachmentId"], "attachmentId")}`,
250
+ query: {},
251
+ }),
252
+ "autoTests.list": (input, context) => {
253
+ const projectId = optionalEntityId(input["projectId"], "projectId");
254
+ return {
255
+ path: "/autoTests",
256
+ query: {
257
+ ...(projectId === undefined ? {} : { projectId }),
258
+ namespace: optionalText(input["namespace"], "namespace", 1, 255),
259
+ className: optionalText(input["className"], "className", 1, 512),
260
+ externalId: optionalText(input["externalId"], "externalId", 1, 512),
261
+ flaky: optionalBoolean(input["flaky"], "flaky")?.toString(),
262
+ includeSteps: optionalBoolean(input["includeSteps"], "includeSteps")?.toString(),
263
+ Skip: String(listOffset(input["offset"])),
264
+ Take: String(listLimit(input["limit"], TESTIT_LIMITS.autoTests, context.flags)),
265
+ },
266
+ };
267
+ },
268
+ "autoTests.get": (input) => ({
269
+ path: `/autoTests/${entityId(input["autoTestId"], "autoTestId")}`,
270
+ query: {},
271
+ }),
272
+ "configurations.list": (input) => ({
273
+ path: `/projects/${entityId(input["projectId"], "projectId")}/configurations`,
274
+ query: {},
275
+ }),
276
+ });
277
+ /* ------------------------------------------------------------------ */
278
+ /* Response shaping */
279
+ /* ------------------------------------------------------------------ */
280
+ function recordOf(value) {
281
+ return typeof value === "object" && value !== null && !Array.isArray(value)
282
+ ? value
283
+ : {};
284
+ }
285
+ function arrayOf(value) {
286
+ return Array.isArray(value) ? value : [];
287
+ }
288
+ function stringOf(source, key) {
289
+ const value = source[key];
290
+ return typeof value === "string" && value !== "" ? value : undefined;
291
+ }
292
+ function numberOf(source, key) {
293
+ const value = source[key];
294
+ return typeof value === "number" && Number.isFinite(value)
295
+ ? value
296
+ : undefined;
297
+ }
298
+ function booleanOf(source, key) {
299
+ const value = source[key];
300
+ return typeof value === "boolean" ? value : undefined;
301
+ }
302
+ /** Drop unset keys so a projection never answers with `undefined` holes. */
303
+ function compact(source) {
304
+ return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined));
305
+ }
306
+ /** External text a projection collected; omitted entirely when there is none. */
307
+ function contentOf(entries) {
308
+ const block = compact(entries);
309
+ return Object.keys(block).length === 0 ? undefined : block;
310
+ }
311
+ function itemsOf(value) {
312
+ if (Array.isArray(value))
313
+ return value;
314
+ // A single-resource answer that upstream wrapped in an array (the plan
315
+ // summaries endpoint answers a collection) still reads as one item.
316
+ return typeof value === "object" && value !== null ? [value] : [];
317
+ }
318
+ /** One bounded string field: an unbounded answer would drown the tool result. */
319
+ export function bounded(value, max) {
320
+ if (value === undefined)
321
+ return undefined;
322
+ const trimmed = value.trim();
323
+ return trimmed.length <= max ? trimmed : `${trimmed.slice(0, max)}…`;
324
+ }
325
+ /**
326
+ * One block of external text. Test IT content is written by people and by
327
+ * test tooling, so it is handed over as data with its size and a truncation
328
+ * marker, never as a string the model could read as an instruction.
329
+ */
330
+ export function contentBlock(text, limit) {
331
+ if (text === undefined)
332
+ return undefined;
333
+ const totalChars = text.length;
334
+ return {
335
+ format: "plain",
336
+ text: totalChars <= limit ? text : text.slice(0, limit),
337
+ totalChars,
338
+ truncated: totalChars > limit,
339
+ };
340
+ }
341
+ /** A bounded MIME-agnostic value out of a `{String: String}` or `{String: Object}` map. */
342
+ function valueText(value, limit) {
343
+ if (value === undefined || value === null)
344
+ return undefined;
345
+ const raw = typeof value === "string"
346
+ ? value
347
+ : typeof value === "number" || typeof value === "boolean"
348
+ ? String(value)
349
+ : JSON.stringify(value);
350
+ return bounded(raw, limit);
351
+ }
352
+ function mapObject(value, limit) {
353
+ const source = recordOf(value);
354
+ const entries = Object.entries(source)
355
+ .map(([key, item]) => {
356
+ const text = valueText(item, limit);
357
+ return text === undefined ? undefined : [key, text];
358
+ })
359
+ .filter((entry) => entry !== undefined);
360
+ return entries.length === 0 ? undefined : Object.fromEntries(entries);
361
+ }
362
+ function compactList(value) {
363
+ const items = arrayOf(value)
364
+ .map((item) => compact(recordOf(item)))
365
+ .filter((item) => Object.keys(item).length > 0);
366
+ return items.length === 0 ? undefined : items;
367
+ }
368
+ /** The upstream status reference a run, test point or result carries. */
369
+ function statusOf(value) {
370
+ const source = recordOf(value);
371
+ const status = compact({
372
+ name: stringOf(source, "name"),
373
+ code: stringOf(source, "code"),
374
+ type: stringOf(source, "type"),
375
+ isSystem: booleanOf(source, "isSystem"),
376
+ });
377
+ return Object.keys(status).length === 0 ? undefined : status;
378
+ }
379
+ function attachmentSummary(value) {
380
+ const source = recordOf(value);
381
+ return compact({
382
+ id: stringOf(source, "id"),
383
+ name: bounded(stringOf(source, "name"), 255),
384
+ type: stringOf(source, "type"),
385
+ size: numberOf(source, "size"),
386
+ createdDate: stringOf(source, "createdDate"),
387
+ createdById: stringOf(source, "createdById"),
388
+ });
389
+ }
390
+ function attachmentsOf(value) {
391
+ const items = arrayOf(value).map(attachmentSummary);
392
+ return items.length === 0 ? undefined : items;
393
+ }
394
+ function linkSummary(value) {
395
+ const source = recordOf(value);
396
+ return compact({
397
+ id: stringOf(source, "id"),
398
+ title: bounded(stringOf(source, "title"), 255),
399
+ url: bounded(stringOf(source, "url"), 2_048),
400
+ type: stringOf(source, "type"),
401
+ });
402
+ }
403
+ function linksOf(value) {
404
+ const items = arrayOf(value).map(linkSummary);
405
+ return items.length === 0 ? undefined : items;
406
+ }
407
+ function tagNames(value) {
408
+ const items = arrayOf(value)
409
+ .map((item) => typeof item === "string" ? item : stringOf(recordOf(item), "name"))
410
+ .filter((item) => item !== undefined && item !== "");
411
+ return items.length === 0 ? undefined : items;
412
+ }
413
+ function iterationSummary(value) {
414
+ const source = recordOf(value);
415
+ const parameters = arrayOf(source["parameters"])
416
+ .map((item) => {
417
+ const parameter = recordOf(item);
418
+ return compact({
419
+ name: stringOf(parameter, "name"),
420
+ value: bounded(stringOf(parameter, "value"), CONFIG_TEXT_CHARS),
421
+ });
422
+ })
423
+ .filter((item) => Object.keys(item).length > 0);
424
+ return compact({
425
+ id: stringOf(source, "id"),
426
+ parameters: parameters.length === 0 ? undefined : parameters,
427
+ });
428
+ }
429
+ function iterationsOf(value) {
430
+ const items = arrayOf(value).map(iterationSummary);
431
+ return items.length === 0 ? undefined : items;
432
+ }
433
+ /**
434
+ * One work item step. Action, expected result and test data are the text a QA
435
+ * engineer wrote, so each is its own bounded block and none of them is spliced
436
+ * into an instruction-shaped string.
437
+ */
438
+ function stepSummary(value) {
439
+ const source = recordOf(value);
440
+ const shared = recordOf(source["workItem"]);
441
+ return compact({
442
+ id: stringOf(source, "id"),
443
+ action: contentBlock(stringOf(source, "action"), TEXT_CHARS),
444
+ expected: contentBlock(stringOf(source, "expected"), TEXT_CHARS),
445
+ testData: contentBlock(stringOf(source, "testData"), TEXT_CHARS),
446
+ comments: contentBlock(stringOf(source, "comments"), TEXT_CHARS),
447
+ sharedStepId: stringOf(shared, "id"),
448
+ sharedStepName: bounded(stringOf(shared, "name"), 255),
449
+ });
450
+ }
451
+ function stepsOf(value) {
452
+ const items = arrayOf(value).map(stepSummary);
453
+ return items.length === 0 ? undefined : items;
454
+ }
455
+ function attributeSummary(value) {
456
+ const source = recordOf(value);
457
+ return compact({
458
+ id: stringOf(source, "id"),
459
+ name: bounded(stringOf(source, "name"), 255),
460
+ type: stringOf(source, "type"),
461
+ isRequired: booleanOf(source, "isRequired"),
462
+ isEnabled: booleanOf(source, "isEnabled"),
463
+ options: arrayOf(source["options"])
464
+ .map((item) => {
465
+ const option = recordOf(item);
466
+ return bounded(stringOf(option, "value"), CONFIG_TEXT_CHARS);
467
+ })
468
+ .filter((item) => item !== undefined),
469
+ });
470
+ }
471
+ /* ------------------------------------------------------------------ */
472
+ /* List envelopes */
473
+ /* ------------------------------------------------------------------ */
474
+ /**
475
+ * A page of a collection Test IT pages itself. The count comes from the
476
+ * `Pagination-Total-Items` header: the body is a bare array and the search
477
+ * endpoints that would report a total are POST-only, so without the header the
478
+ * model is told only whether the page looked full.
479
+ */
480
+ export function paged(items, page, limit, offset) {
481
+ const returned = items.length;
482
+ const total = page?.total;
483
+ const hasMore = total === undefined
484
+ ? returned >= limit && returned > 0
485
+ : offset + returned < total;
486
+ return {
487
+ items,
488
+ pagination: compact({
489
+ offset,
490
+ limit,
491
+ returned,
492
+ total,
493
+ hasMore,
494
+ }),
495
+ };
496
+ }
497
+ /**
498
+ * A collection Test IT answers whole. The provider slices it to the limit and
499
+ * says `truncated`, so the model can narrow the request instead of believing a
500
+ * cut list is the complete one.
501
+ */
502
+ export function capped(items, limit) {
503
+ return {
504
+ items: items.slice(0, limit),
505
+ truncated: items.length > limit,
506
+ pagination: { limit, returned: Math.min(items.length, limit) },
507
+ };
508
+ }
509
+ /* ------------------------------------------------------------------ */
510
+ /* Projections */
511
+ /* ------------------------------------------------------------------ */
512
+ function projectSummary(value) {
513
+ const source = recordOf(value);
514
+ return compact({
515
+ id: stringOf(source, "id"),
516
+ globalId: numberOf(source, "globalId"),
517
+ name: bounded(stringOf(source, "name"), 255),
518
+ description: contentBlock(stringOf(source, "description"), DETAILS_CHARS),
519
+ type: stringOf(source, "type"),
520
+ isFavorite: booleanOf(source, "isFavorite"),
521
+ isDeleted: booleanOf(source, "isDeleted"),
522
+ testCasesCount: numberOf(source, "testCasesCount"),
523
+ checkListsCount: numberOf(source, "checkListsCount"),
524
+ sharedStepsCount: numberOf(source, "sharedStepsCount"),
525
+ autoTestsCount: numberOf(source, "autoTestsCount"),
526
+ createdDate: stringOf(source, "createdDate"),
527
+ modifiedDate: stringOf(source, "modifiedDate"),
528
+ createdById: stringOf(source, "createdById"),
529
+ modifiedById: stringOf(source, "modifiedById"),
530
+ });
531
+ }
532
+ function sectionSummary(value) {
533
+ const source = recordOf(value);
534
+ return compact({
535
+ id: stringOf(source, "id"),
536
+ projectId: stringOf(source, "projectId"),
537
+ parentId: stringOf(source, "parentId"),
538
+ name: bounded(stringOf(source, "name"), 255),
539
+ isDeleted: booleanOf(source, "isDeleted"),
540
+ createdDate: stringOf(source, "createdDate"),
541
+ modifiedDate: stringOf(source, "modifiedDate"),
542
+ createdById: stringOf(source, "createdById"),
543
+ modifiedById: stringOf(source, "modifiedById"),
544
+ });
545
+ }
546
+ function workItemSummary(value) {
547
+ const source = recordOf(value);
548
+ return compact({
549
+ id: stringOf(source, "id"),
550
+ globalId: numberOf(source, "globalId"),
551
+ versionId: stringOf(source, "versionId"),
552
+ versionNumber: numberOf(source, "versionNumber"),
553
+ name: bounded(stringOf(source, "name"), 255),
554
+ entityTypeName: stringOf(source, "entityTypeName"),
555
+ projectId: stringOf(source, "projectId"),
556
+ sectionId: stringOf(source, "sectionId"),
557
+ sectionName: bounded(stringOf(source, "sectionName"), 255),
558
+ state: stringOf(source, "state"),
559
+ priority: stringOf(source, "priority"),
560
+ sourceType: stringOf(source, "sourceType"),
561
+ isAutomated: booleanOf(source, "isAutomated"),
562
+ isDeleted: booleanOf(source, "isDeleted"),
563
+ durationMs: numberOf(source, "duration"),
564
+ medianDurationMs: numberOf(source, "medianDuration"),
565
+ tagNames: tagNames(source["tagNames"]),
566
+ createdDate: stringOf(source, "createdDate"),
567
+ modifiedDate: stringOf(source, "modifiedDate"),
568
+ createdById: stringOf(source, "createdById"),
569
+ modifiedById: stringOf(source, "modifiedById"),
570
+ });
571
+ }
572
+ function workItemDetail(value) {
573
+ const source = recordOf(value);
574
+ const attributes = mapObject(source["attributes"], CONFIG_TEXT_CHARS);
575
+ const parameters = arrayOf(source["parameters"])
576
+ .map((item) => {
577
+ const parameter = recordOf(item);
578
+ return compact({
579
+ id: stringOf(parameter, "id"),
580
+ name: stringOf(parameter, "name"),
581
+ });
582
+ })
583
+ .filter((item) => Object.keys(item).length > 0);
584
+ return compact({
585
+ ...workItemSummary(source),
586
+ untrustedContent: contentOf({
587
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
588
+ }),
589
+ attributes,
590
+ parameters: parameters.length === 0 ? undefined : parameters,
591
+ tags: tagNames(source["tags"]),
592
+ steps: stepsOf(source["steps"]),
593
+ preconditionSteps: stepsOf(source["preconditionSteps"]),
594
+ postconditionSteps: stepsOf(source["postconditionSteps"]),
595
+ sectionPreconditionSteps: stepsOf(source["sectionPreconditionSteps"]),
596
+ sectionPostconditionSteps: stepsOf(source["sectionPostconditionSteps"]),
597
+ iterations: iterationsOf(source["iterations"]),
598
+ autoTests: compactList(source["autoTests"]),
599
+ attachments: attachmentsOf(source["attachments"]),
600
+ links: linksOf(source["links"]),
601
+ externalIssues: arrayOf(source["externalIssues"])
602
+ .map((item) => {
603
+ const issue = recordOf(item);
604
+ return compact({
605
+ id: stringOf(issue, "id"),
606
+ externalId: stringOf(issue, "externalId"),
607
+ url: bounded(stringOf(issue, "url"), 2_048),
608
+ });
609
+ })
610
+ .filter((item) => Object.keys(item).length > 0),
611
+ });
612
+ }
613
+ /** One entry of the change log: which field moved, from where to where. */
614
+ function changedFields(value) {
615
+ return Object.entries(recordOf(value))
616
+ .map(([field, item]) => {
617
+ const change = recordOf(item);
618
+ const from = valueText(change["oldValue"], CONFIG_TEXT_CHARS);
619
+ const to = valueText(change["newValue"], CONFIG_TEXT_CHARS);
620
+ if (from === undefined && to === undefined)
621
+ return undefined;
622
+ return compact({ field, from, to });
623
+ })
624
+ .filter((item) => item !== undefined);
625
+ }
626
+ function historyEntry(value) {
627
+ const source = recordOf(value);
628
+ const fields = changedFields(source["workItemChangedFields"]);
629
+ return compact({
630
+ id: stringOf(source, "id"),
631
+ workItemId: stringOf(source, "workItemId"),
632
+ oldVersionId: stringOf(source, "oldVersionId"),
633
+ newVersionId: stringOf(source, "newVersionId"),
634
+ fields: fields.length === 0 ? undefined : fields,
635
+ createdById: stringOf(source, "createdById"),
636
+ createdDate: stringOf(source, "createdDate"),
637
+ });
638
+ }
639
+ function commentEntry(value) {
640
+ const source = recordOf(value);
641
+ return compact({
642
+ id: stringOf(source, "id"),
643
+ untrustedContent: contentOf({
644
+ text: contentBlock(stringOf(source, "text"), TEXT_CHARS),
645
+ }),
646
+ createdById: stringOf(source, "createdById"),
647
+ createdDate: stringOf(source, "createdDate"),
648
+ modifiedById: stringOf(source, "modifiedById"),
649
+ modifiedDate: stringOf(source, "modifiedDate"),
650
+ });
651
+ }
652
+ function testPlanEntry(value) {
653
+ const source = recordOf(value);
654
+ return compact({
655
+ id: stringOf(source, "id"),
656
+ globalId: numberOf(source, "globalId"),
657
+ name: bounded(stringOf(source, "name"), 255),
658
+ projectId: stringOf(source, "projectId"),
659
+ status: stringOf(source, "status"),
660
+ productName: bounded(stringOf(source, "productName"), 255),
661
+ build: bounded(stringOf(source, "build"), 255),
662
+ startDate: stringOf(source, "startDate"),
663
+ endDate: stringOf(source, "endDate"),
664
+ startedOn: stringOf(source, "startedOn"),
665
+ completedOn: stringOf(source, "completedOn"),
666
+ lockedDate: stringOf(source, "lockedDate"),
667
+ lockedById: stringOf(source, "lockedById"),
668
+ hasAutomaticDurationTimer: booleanOf(source, "hasAutomaticDurationTimer"),
669
+ isDeleted: booleanOf(source, "isDeleted"),
670
+ tags: tagNames(source["tags"]),
671
+ createdDate: stringOf(source, "createdDate"),
672
+ modifiedDate: stringOf(source, "modifiedDate"),
673
+ createdById: stringOf(source, "createdById"),
674
+ modifiedById: stringOf(source, "modifiedById"),
675
+ untrustedContent: contentOf({
676
+ description: contentBlock(stringOf(source, "description"), DETAILS_CHARS),
677
+ }),
678
+ });
679
+ }
680
+ function testPlanSummaryOf(value) {
681
+ const source = recordOf(value);
682
+ return compact({
683
+ totalTestPointsCount: numberOf(source, "totalTestPointsCount"),
684
+ manualTestPointsCount: numberOf(source, "manualTestPointsCount"),
685
+ automatedTestPointsCount: numberOf(source, "automatedTestPointsCount"),
686
+ completedTestPointsCount: numberOf(source, "completedTestPointsCount"),
687
+ defectsCount: numberOf(source, "defectsCount"),
688
+ plannedTestPointsDurationMs: numberOf(source, "plannedTestPointsDuration"),
689
+ spentTestPointsDurationMs: numberOf(source, "spentTestPointsDuration"),
690
+ });
691
+ }
692
+ function testRunSummary(value) {
693
+ const source = recordOf(value);
694
+ return compact({
695
+ id: stringOf(source, "id"),
696
+ name: bounded(stringOf(source, "name"), 255),
697
+ projectId: stringOf(source, "projectId"),
698
+ testPlanId: stringOf(source, "testPlanId"),
699
+ stateName: stringOf(source, "stateName"),
700
+ status: statusOf(source["status"]),
701
+ launchSource: stringOf(source, "launchSource"),
702
+ runCount: numberOf(source, "runCount"),
703
+ startedOn: stringOf(source, "startedOn"),
704
+ completedOn: stringOf(source, "completedOn"),
705
+ createdDate: stringOf(source, "createdDate"),
706
+ modifiedDate: stringOf(source, "modifiedDate"),
707
+ createdById: stringOf(source, "createdById"),
708
+ createdByUserName: stringOf(source, "createdByUserName"),
709
+ tags: tagNames(source["tags"]),
710
+ // A run list is a list of runs, not of their results: the results of one run
711
+ // are a tool of their own, and folding them in here would answer one
712
+ // question with the whole project's history.
713
+ testResults: undefined,
714
+ });
715
+ }
716
+ function testRunDetail(value) {
717
+ const source = recordOf(value);
718
+ return compact({
719
+ ...testRunSummary(source),
720
+ untrustedContent: contentOf({
721
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
722
+ }),
723
+ customParameters: mapObject(source["customParameters"], CONFIG_TEXT_CHARS),
724
+ attachments: attachmentsOf(source["attachments"]),
725
+ links: linksOf(source["links"]),
726
+ });
727
+ }
728
+ function testResultHistoryEntry(value) {
729
+ const source = recordOf(value);
730
+ return compact({
731
+ id: stringOf(source, "id"),
732
+ testRunId: stringOf(source, "testRunId"),
733
+ testRunName: bounded(stringOf(source, "testRunName"), 255),
734
+ testPlanId: stringOf(source, "testPlanId"),
735
+ testPlanName: bounded(stringOf(source, "testPlanName"), 255),
736
+ configurationName: bounded(stringOf(source, "configurationName"), 255),
737
+ isAutomated: booleanOf(source, "isAutomated"),
738
+ outcome: stringOf(source, "outcome"),
739
+ status: statusOf(source["status"]),
740
+ launchSource: stringOf(source, "launchSource"),
741
+ workItemVersionNumber: numberOf(source, "workItemVersionNumber"),
742
+ startedOn: stringOf(source, "startedOn"),
743
+ completedOn: stringOf(source, "completedOn"),
744
+ durationMs: numberOf(source, "duration"),
745
+ createdDate: stringOf(source, "createdDate"),
746
+ createdById: stringOf(source, "createdById"),
747
+ untrustedContent: contentOf({
748
+ comment: contentBlock(stringOf(source, "comment"), TEXT_CHARS),
749
+ }),
750
+ attachments: attachmentsOf(source["attachments"]),
751
+ });
752
+ }
753
+ function configurationShort(value) {
754
+ const source = recordOf(value);
755
+ return compact({
756
+ id: stringOf(source, "id"),
757
+ name: bounded(stringOf(source, "name"), 255),
758
+ });
759
+ }
760
+ /** A short test result as it appears inside a test point. */
761
+ function testResultShort(value) {
762
+ const source = recordOf(value);
763
+ return compact({
764
+ id: stringOf(source, "id"),
765
+ outcome: stringOf(source, "outcome"),
766
+ status: statusOf(source["status"]),
767
+ untrustedContent: contentOf({
768
+ comment: contentBlock(stringOf(source, "comment"), TEXT_CHARS),
769
+ message: contentBlock(stringOf(source, "message"), TEXT_CHARS),
770
+ }),
771
+ autoTestId: stringOf(source, "autoTestId"),
772
+ configurationId: stringOf(source, "configurationId"),
773
+ configuration: configurationShort(source["configuration"]),
774
+ startedOn: stringOf(source, "startedOn"),
775
+ completedOn: stringOf(source, "completedOn"),
776
+ durationMs: numberOf(source, "durationInMs"),
777
+ attachments: attachmentsOf(source["attachments"]),
778
+ });
779
+ }
780
+ function testPointResult(value) {
781
+ const source = recordOf(value);
782
+ const results = arrayOf(source["testResults"]).map(testResultShort);
783
+ return compact({
784
+ testPointId: stringOf(source, "testPointId"),
785
+ workItemGlobalId: numberOf(source, "workItemGlobalId"),
786
+ workItemName: bounded(stringOf(source, "workItemName"), 255),
787
+ configurationName: bounded(stringOf(source, "configurationName"), 255),
788
+ aggregatedOutcome: stringOf(source, "aggregatedOutcome"),
789
+ aggregatedStatus: statusOf(source["aggregatedStatus"]),
790
+ testResults: results.length === 0 ? undefined : results,
791
+ });
792
+ }
793
+ function testResultDetail(value) {
794
+ const source = recordOf(value);
795
+ const stepResults = arrayOf(source["stepResults"]).map((item) => {
796
+ const step = recordOf(item);
797
+ return compact({
798
+ stepId: stringOf(step, "stepId"),
799
+ outcome: stringOf(step, "outcome"),
800
+ });
801
+ });
802
+ return compact({
803
+ id: stringOf(source, "id"),
804
+ testRunId: stringOf(source, "testRunId"),
805
+ testPointId: stringOf(source, "testPointId"),
806
+ configurationId: stringOf(source, "configurationId"),
807
+ workItemVersionId: stringOf(source, "workItemVersionId"),
808
+ workItemVersionNumber: numberOf(source, "workItemVersionNumber"),
809
+ autoTestId: stringOf(source, "autoTestId"),
810
+ autoTest: compact({
811
+ id: stringOf(recordOf(source["autoTest"]), "id"),
812
+ name: bounded(stringOf(recordOf(source["autoTest"]), "name"), 255),
813
+ namespace: stringOf(recordOf(source["autoTest"]), "namespace"),
814
+ classname: stringOf(recordOf(source["autoTest"]), "classname"),
815
+ }),
816
+ outcome: stringOf(source, "outcome"),
817
+ status: statusOf(source["status"]),
818
+ failureType: stringOf(source, "failureType"),
819
+ failureClassIds: arrayOf(source["failureClassIds"]).filter((item) => typeof item === "string"),
820
+ durationMs: numberOf(source, "durationInMs"),
821
+ startedOn: stringOf(source, "startedOn"),
822
+ completedOn: stringOf(source, "completedOn"),
823
+ runByUserId: stringOf(source, "runByUserId"),
824
+ stoppedByUserId: stringOf(source, "stoppedByUserId"),
825
+ createdDate: stringOf(source, "createdDate"),
826
+ modifiedDate: stringOf(source, "modifiedDate"),
827
+ createdById: stringOf(source, "createdById"),
828
+ modifiedById: stringOf(source, "modifiedById"),
829
+ parameters: mapObject(source["parameters"], CONFIG_TEXT_CHARS),
830
+ properties: mapObject(source["properties"], CONFIG_TEXT_CHARS),
831
+ stepResults: stepResults.length === 0 ? undefined : stepResults,
832
+ untrustedContent: contentOf({
833
+ comment: contentBlock(stringOf(source, "comment"), TEXT_CHARS),
834
+ message: contentBlock(stringOf(source, "message"), TEXT_CHARS),
835
+ traces: contentBlock(stringOf(source, "traces"), TEXT_CHARS),
836
+ }),
837
+ attachments: attachmentsOf(source["attachments"]),
838
+ links: linksOf(source["links"]),
839
+ });
840
+ }
841
+ function autoTestSummary(value) {
842
+ const source = recordOf(value);
843
+ return compact({
844
+ id: stringOf(source, "id"),
845
+ globalId: numberOf(source, "globalId"),
846
+ projectId: stringOf(source, "projectId"),
847
+ name: bounded(stringOf(source, "name"), 255),
848
+ externalId: bounded(stringOf(source, "externalId"), 512),
849
+ externalKey: bounded(stringOf(source, "externalKey"), 512),
850
+ namespace: bounded(stringOf(source, "namespace"), 512),
851
+ classname: bounded(stringOf(source, "classname"), 512),
852
+ title: bounded(stringOf(source, "title"), 512),
853
+ isFlaky: booleanOf(source, "isFlaky"),
854
+ isDeleted: booleanOf(source, "isDeleted"),
855
+ mustBeApproved: booleanOf(source, "mustBeApproved"),
856
+ stabilityPercentage: numberOf(source, "stabilityPercentage"),
857
+ lastTestRunId: stringOf(source, "lastTestRunId"),
858
+ lastTestRunName: bounded(stringOf(source, "lastTestRunName"), 255),
859
+ lastTestResultId: stringOf(source, "lastTestResultId"),
860
+ lastTestResultOutcome: stringOf(source, "lastTestResultOutcome"),
861
+ lastTestResultConfiguration: configurationShort(source["lastTestResultConfiguration"]),
862
+ labels: tagNames(source["labels"]),
863
+ tags: tagNames(source["tags"]),
864
+ createdDate: stringOf(source, "createdDate"),
865
+ modifiedDate: stringOf(source, "modifiedDate"),
866
+ createdById: stringOf(source, "createdById"),
867
+ modifiedById: stringOf(source, "modifiedById"),
868
+ });
869
+ }
870
+ /** One automatic-test step, nested the way Test IT nests them. */
871
+ function autoTestStep(value) {
872
+ const source = recordOf(value);
873
+ const nested = arrayOf(source["steps"]).map(autoTestStep);
874
+ return compact({
875
+ title: bounded(stringOf(source, "title"), 512),
876
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
877
+ steps: nested.length === 0 ? undefined : nested,
878
+ });
879
+ }
880
+ function autoTestDetail(value) {
881
+ const source = recordOf(value);
882
+ return compact({
883
+ ...autoTestSummary(source),
884
+ untrustedContent: contentOf({
885
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
886
+ }),
887
+ steps: arrayOf(source["steps"]).map(autoTestStep),
888
+ setup: arrayOf(source["setup"]).map(autoTestStep),
889
+ teardown: arrayOf(source["teardown"]).map(autoTestStep),
890
+ links: linksOf(source["links"]),
891
+ });
892
+ }
893
+ function configurationSummary(value) {
894
+ const source = recordOf(value);
895
+ return compact({
896
+ id: stringOf(source, "id"),
897
+ globalId: numberOf(source, "globalId"),
898
+ projectId: stringOf(source, "projectId"),
899
+ name: bounded(stringOf(source, "name"), 255),
900
+ isDefault: booleanOf(source, "isDefault"),
901
+ isDeleted: booleanOf(source, "isDeleted"),
902
+ parameters: mapObject(source["parameters"], CONFIG_TEXT_CHARS),
903
+ createdDate: stringOf(source, "createdDate"),
904
+ modifiedDate: stringOf(source, "modifiedDate"),
905
+ createdById: stringOf(source, "createdById"),
906
+ modifiedById: stringOf(source, "modifiedById"),
907
+ untrustedContent: contentOf({
908
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
909
+ }),
910
+ });
911
+ }
912
+ /** Text of the requested query, lowercased once per projection. */
913
+ function needle(input) {
914
+ return String(input["query"] ?? "")
915
+ .trim()
916
+ .toLowerCase();
917
+ }
918
+ function matches(value, query) {
919
+ return value !== undefined && value.toLowerCase().includes(query);
920
+ }
921
+ /** A page of items is narrowed the same way whichever collection it holds. */
922
+ function filterItems(items, input, fields) {
923
+ const query = needle(input);
924
+ const includeDeleted = input["includeDeleted"] === true;
925
+ return items
926
+ .filter((item) => includeDeleted || item["isDeleted"] !== true)
927
+ .filter((item) => query === "" ||
928
+ fields.some((field) => matches(item[field], query)));
929
+ }
930
+ /**
931
+ * Response shaping per operation. A projection never invents a field upstream
932
+ * did not send: Test IT tolerates version skew by adding properties, so a
933
+ * missing key is dropped rather than defaulted into a claim.
934
+ */
935
+ export const TESTIT_PROJECTIONS = Object.freeze({
936
+ "connection.get": (data, context) => {
937
+ const items = itemsOf(data);
938
+ const total = context.page?.total;
939
+ return compact({
940
+ apiGeneration: "v2",
941
+ instance: context.instanceLabel,
942
+ baseUrl: context.baseUrl,
943
+ // Test IT API v2 exposes no endpoint for the token owner, so this answer
944
+ // reports what the probe proved — the instance answers and the token may
945
+ // read projects — and claims no identity.
946
+ tokenOwner: undefined,
947
+ canReadProjects: total === undefined ? items.length > 0 : true,
948
+ projectsVisible: total ?? items.length,
949
+ });
950
+ },
951
+ "projects.list": (data, context) => {
952
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.projects, context.flags);
953
+ const offset = listOffset(context.input["offset"]);
954
+ const items = filterItems(itemsOf(data).map(projectSummary), context.input, ["name", "id"]);
955
+ return paged(items, context.page, limit, offset);
956
+ },
957
+ "projects.get": (data) => {
958
+ const source = recordOf(data);
959
+ return compact({
960
+ ...projectSummary(data),
961
+ untrustedContent: contentOf({
962
+ description: contentBlock(stringOf(source, "description"), TEXT_CHARS),
963
+ }),
964
+ workflowId: stringOf(source, "workflowId"),
965
+ attributesScheme: arrayOf(source["attributesScheme"])
966
+ .map(attributeSummary)
967
+ .filter((item) => Object.keys(item).length > 0),
968
+ });
969
+ },
970
+ "sections.list": (data, context) => {
971
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.sections, context.flags);
972
+ const offset = listOffset(context.input["offset"]);
973
+ return paged(filterItems(itemsOf(data).map(sectionSummary), context.input, [
974
+ "name",
975
+ "id",
976
+ ]), context.page, limit, offset);
977
+ },
978
+ "workItems.list": (data, context) => {
979
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.workItems, context.flags);
980
+ const offset = listOffset(context.input["offset"]);
981
+ const entityType = oneOf(context.input["entityType"], WORK_ITEM_ENTITY_TYPES, "entityType", 32);
982
+ const state = oneOf(context.input["state"], WORK_ITEM_STATES, "state", 32);
983
+ const priority = oneOf(context.input["priority"], WORK_ITEM_PRIORITIES, "priority", 16);
984
+ const tag = optionalText(context.input["tag"], "tag", 1, 128);
985
+ const items = filterItems(itemsOf(data).map(workItemSummary), context.input, ["name", "id"])
986
+ .filter((item) => entityType === undefined || item["entityTypeName"] === entityType)
987
+ .filter((item) => state === undefined || item["state"] === state)
988
+ .filter((item) => priority === undefined || item["priority"] === priority)
989
+ .filter((item) => {
990
+ if (tag === undefined)
991
+ return true;
992
+ const names = item["tagNames"];
993
+ return Array.isArray(names) && names.includes(tag);
994
+ });
995
+ return paged(items, context.page, limit, offset);
996
+ },
997
+ "workItems.get": (data) => workItemDetail(data),
998
+ "workItems.history": (data, context) => {
999
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.history, context.flags);
1000
+ const offset = listOffset(context.input["offset"]);
1001
+ return paged(itemsOf(data).map(historyEntry), context.page, limit, offset);
1002
+ },
1003
+ "workItems.comments": (data, context) => {
1004
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.comments, context.flags);
1005
+ return capped(itemsOf(data).map(commentEntry), limit);
1006
+ },
1007
+ "workItems.testResults": (data, context) => {
1008
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.testResults, context.flags);
1009
+ const offset = listOffset(context.input["offset"]);
1010
+ const outcome = oneOf(context.input["outcome"], RESULT_OUTCOMES, "outcome", 16);
1011
+ const items = itemsOf(data)
1012
+ .map(testResultHistoryEntry)
1013
+ .filter((item) => outcome === undefined || item["outcome"] === outcome);
1014
+ return paged(items, context.page, limit, offset);
1015
+ },
1016
+ "testPlans.list": (data, context) => {
1017
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.testPlans, context.flags);
1018
+ return capped(filterItems(itemsOf(data).map(testPlanEntry), context.input, [
1019
+ "name",
1020
+ "id",
1021
+ ]), limit);
1022
+ },
1023
+ "testPlans.get": (data) => {
1024
+ const source = recordOf(data);
1025
+ return compact({
1026
+ ...testPlanEntry(data),
1027
+ attributes: mapObject(source["attributes"], CONFIG_TEXT_CHARS),
1028
+ });
1029
+ },
1030
+ "testPlans.summary": (data, context) => {
1031
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.testPlans, context.flags);
1032
+ return capped(itemsOf(data).map(testPlanSummaryOf), limit);
1033
+ },
1034
+ "testRuns.list": (data, context) => {
1035
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.testRuns, context.flags);
1036
+ const offset = listOffset(context.input["offset"]);
1037
+ const items = filterItems(itemsOf(data).map(testRunSummary), context.input, ["name", "id"]);
1038
+ return paged(items, context.page, limit, offset);
1039
+ },
1040
+ "testRuns.get": (data) => testRunDetail(data),
1041
+ "testRuns.results": (data, context) => {
1042
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.testResults, context.flags);
1043
+ const outcome = oneOf(context.input["outcome"], RESULT_OUTCOMES, "outcome", 16);
1044
+ const items = itemsOf(data)
1045
+ .map(testPointResult)
1046
+ .filter((item) => outcome === undefined || item["aggregatedOutcome"] === outcome);
1047
+ return capped(items, limit);
1048
+ },
1049
+ "testResults.get": (data) => testResultDetail(data),
1050
+ "testResults.attachments": (data, context) => {
1051
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.attachments, context.flags);
1052
+ return capped(itemsOf(data).map(attachmentSummary), limit);
1053
+ },
1054
+ "attachments.metadata": (data) => attachmentSummary(data),
1055
+ "autoTests.list": (data, context) => {
1056
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.autoTests, context.flags);
1057
+ const offset = listOffset(context.input["offset"]);
1058
+ const items = filterItems(itemsOf(data).map(autoTestSummary), context.input, ["name", "externalId", "classname", "namespace", "id"]);
1059
+ return paged(items, context.page, limit, offset);
1060
+ },
1061
+ "autoTests.get": (data) => autoTestDetail(data),
1062
+ "configurations.list": (data, context) => {
1063
+ const limit = listLimit(context.input["limit"], TESTIT_LIMITS.configurations, context.flags);
1064
+ return capped(filterItems(itemsOf(data).map(configurationSummary), context.input, [
1065
+ "name",
1066
+ "id",
1067
+ ]), limit);
1068
+ },
1069
+ });
1070
+ //# sourceMappingURL=operations.js.map