codecraftai-integration-runtime 1.3.0__py3-none-any.whl

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 (48) hide show
  1. ccai/integrationruntime/__init__.py +27 -0
  2. ccai/integrationruntime/entrypoints.py +59 -0
  3. ccai/integrationruntime/initialize.py +100 -0
  4. ccai/integrationruntime/integratedtestjob.py +100 -0
  5. ccai/integrationruntime/integrationruntimedefaulttypefactory.py +51 -0
  6. ccai/integrationruntime/py.typed +0 -0
  7. ccai/integrationruntime/results/__init__.py +13 -0
  8. ccai/integrationruntime/results/concentrators/__init__.py +13 -0
  9. ccai/integrationruntime/results/concentrators/progressconcentratorservice.py +526 -0
  10. ccai/integrationruntime/results/recorders/__init__.py +22 -0
  11. ccai/integrationruntime/results/recorders/integrationjsonresultrecorder.py +126 -0
  12. ccai/integrationruntime/results/recorders/streamingresultrecorder.py +271 -0
  13. ccai/integrationruntime/results/streaming/__init__.py +25 -0
  14. ccai/integrationruntime/results/streaming/resultstreamer.py +581 -0
  15. ccai/integrationruntime/runtimeoutputcontext.py +68 -0
  16. ccai/integrationruntime/runtimerunmetadata.py +165 -0
  17. ccai/integrationruntime/templates/v2/static/images/test-report-banner-background-image.png +0 -0
  18. ccai/integrationruntime/templates/v2/static/javascript/d3.v7.js +20625 -0
  19. ccai/integrationruntime/templates/v2/static/javascript/icon-components.js +510 -0
  20. ccai/integrationruntime/templates/v2/static/javascript/mojo-components.js +1417 -0
  21. ccai/integrationruntime/templates/v2/static/javascript/prism.js +1789 -0
  22. ccai/integrationruntime/templates/v2/static/javascript/testsummary-accessibility.js +704 -0
  23. ccai/integrationruntime/templates/v2/static/javascript/testsummary-comparison.js +1287 -0
  24. ccai/integrationruntime/templates/v2/static/javascript/testsummary-components.js +3499 -0
  25. ccai/integrationruntime/templates/v2/static/javascript/testsummary-helpers.js +426 -0
  26. ccai/integrationruntime/templates/v2/static/javascript/testsummary-responsive.js +493 -0
  27. ccai/integrationruntime/templates/v2/static/javascript/testsummary.js +1128 -0
  28. ccai/integrationruntime/templates/v2/static/javascript/webcomponent-helpers.js +112 -0
  29. ccai/integrationruntime/templates/v2/static/styles/branding-theme.css +144 -0
  30. ccai/integrationruntime/templates/v2/static/styles/icon-styles.css +9 -0
  31. ccai/integrationruntime/templates/v2/static/styles/mojo-components.css +384 -0
  32. ccai/integrationruntime/templates/v2/static/styles/prism.css +143 -0
  33. ccai/integrationruntime/templates/v2/static/styles/tabs-responsive.css +186 -0
  34. ccai/integrationruntime/templates/v2/static/styles/testsummary-accessibility.css +413 -0
  35. ccai/integrationruntime/templates/v2/static/styles/testsummary-comparison.css +746 -0
  36. ccai/integrationruntime/templates/v2/static/styles/testsummary-responsive.css +679 -0
  37. ccai/integrationruntime/templates/v2/static/styles/testsummary.css +1631 -0
  38. ccai/integrationruntime/templates/v2/tabs/tab-data.html +870 -0
  39. ccai/integrationruntime/templates/v2/tabs/tab-images.html +110 -0
  40. ccai/integrationruntime/templates/v2/tabs/tab-logs.html +594 -0
  41. ccai/integrationruntime/templates/v2/tabs/tab-sounds.html +112 -0
  42. ccai/integrationruntime/templates/v2/tabs/tab-timeseries.html +368 -0
  43. ccai/integrationruntime/templates/v2/tabs/tab-videos.html +372 -0
  44. ccai/integrationruntime/templates/v2/testsummary.html +81 -0
  45. codecraftai_integration_runtime-1.3.0.dist-info/METADATA +73 -0
  46. codecraftai_integration_runtime-1.3.0.dist-info/RECORD +48 -0
  47. codecraftai_integration_runtime-1.3.0.dist-info/WHEEL +4 -0
  48. codecraftai_integration_runtime-1.3.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,426 @@
1
+
2
+ /*
3
+ Author: "Myron Walker"
4
+ Copyright: "Copyright 2024, Myron W Walker"
5
+ Version: = "2.0.0"
6
+ Email: myron.walker@gmail.com
7
+ */
8
+
9
+ /**
10
+ * @fileoverview Helper functions for the TestSummary HTML report templates.
11
+ * Provides utilities for fetching data, parsing JSON streams, time formatting,
12
+ * and other common operations used across the test summary components.
13
+ * @module testsummary-helpers
14
+ */
15
+
16
+ /**
17
+ * Standard datetime format string used for parsing timestamps.
18
+ * @constant {string}
19
+ */
20
+ const DATETIME_FORMAT = "yyyy-MM-ddTHH:mm:ss.ssssss"
21
+
22
+ /**
23
+ * Fetches raw HTTP content from a URL using XMLHttpRequest.
24
+ *
25
+ * @async
26
+ * @function fetch_http
27
+ * @param {string} url - The URL to fetch content from.
28
+ * @returns {Promise<string>} A promise that resolves with the response text on success.
29
+ * @throws {string} Rejects with the status text if the request fails.
30
+ *
31
+ * @example
32
+ * // Fetch raw content from a URL
33
+ * fetch_http('data.txt')
34
+ * .then(content => console.log(content))
35
+ * .catch(err => console.error('Failed to fetch:', err));
36
+ */
37
+ async function fetch_http(url) {
38
+ var promise = new Promise((resolve, reject) => {
39
+ var xmlhttp = new XMLHttpRequest();
40
+
41
+ xmlhttp.onreadystatechange = function () {
42
+ if (this.readyState == 4) {
43
+ if (this.status == 200) {
44
+ resolve(this.responseText);
45
+ } else {
46
+ reject(this.statusText);
47
+ }
48
+ }
49
+ };
50
+
51
+ xmlhttp.onerror = function () {
52
+ reject(this.statusText);
53
+ };
54
+
55
+ xmlhttp.open("GET", url, true);
56
+ xmlhttp.send();
57
+
58
+ });
59
+
60
+ return promise;
61
+ }
62
+
63
+ /**
64
+ * Fetches and parses JSON data from a URL using XMLHttpRequest.
65
+ * Optionally extracts response headers into a provided object.
66
+ *
67
+ * @async
68
+ * @function fetch_json
69
+ * @param {string} url - The URL to fetch JSON from.
70
+ * @param {Object|null} [headers=null] - Optional object to populate with response headers (keys uppercased).
71
+ * @returns {Promise<Object>} A promise that resolves with the parsed JSON object.
72
+ * @throws {string} Rejects with the status text if the request fails.
73
+ *
74
+ * @example
75
+ * // Fetch JSON without headers
76
+ * fetch_json('testrun_summary.json')
77
+ * .then(data => console.log(data))
78
+ * .catch(err => console.error('Failed to fetch:', err));
79
+ *
80
+ * @example
81
+ * // Fetch JSON and capture response headers
82
+ * const headers = {};
83
+ * fetch_json('testrun_summary.json', headers)
84
+ * .then(data => {
85
+ * console.log('Data:', data);
86
+ * console.log('Headers:', headers);
87
+ * });
88
+ */
89
+ async function fetch_json(url, headers=null) {
90
+ var promise = new Promise((resolve, reject) => {
91
+
92
+ var xmlhttp = new XMLHttpRequest();
93
+
94
+ xmlhttp.onreadystatechange = function () {
95
+ if (this.readyState == 4) {
96
+ if (this.status == 200) {
97
+ // If headers are provided, parse the response headers
98
+ if (headers != null) {
99
+
100
+ var respHeaderContent = this.getAllResponseHeaders();
101
+ const headerLines = respHeaderContent.split('\r\n');
102
+
103
+ // Iterate over the lines
104
+ headerLines.forEach(line => {
105
+ // Split each line into key and value
106
+ const parts = line.split(': ');
107
+ if (parts.length === 2) {
108
+ const key = parts[0];
109
+ const value = parts[1];
110
+ headers[key.toUpperCase()] = value.toUpperCase();
111
+ }
112
+ });
113
+
114
+ }
115
+
116
+ var robj = JSON.parse(this.responseText);
117
+ resolve(robj);
118
+
119
+ } else {
120
+ reject(this.statusText);
121
+ }
122
+ }
123
+ };
124
+
125
+ xmlhttp.onerror = function () {
126
+ reject(this.statusText);
127
+ };
128
+
129
+ xmlhttp.open("GET", url, true);
130
+ xmlhttp.send();
131
+
132
+ });
133
+
134
+ return promise;
135
+ }
136
+
137
+ /**
138
+ * Fetches items from a catalog.json file filtered by file extensions.
139
+ * Loads the catalog and returns only files matching the specified extensions.
140
+ *
141
+ * @async
142
+ * @function fetch_items
143
+ * @param {string[]} extensions - Array of file extensions to filter by (without dots).
144
+ * @returns {Promise<string[]>} A promise that resolves with an array of matching filenames.
145
+ * @throws {Error} Rejects if the catalog.json cannot be loaded.
146
+ *
147
+ * @example
148
+ * // Fetch all image files
149
+ * fetch_items(['png', 'jpg'])
150
+ * .then(images => console.log('Found images:', images))
151
+ * .catch(err => console.error('Failed to load catalog:', err));
152
+ */
153
+ async function fetch_items(extensions) {
154
+
155
+ var promise = new Promise((resolve, reject) => {
156
+
157
+ fetch_json("catalog.json").then((catalog) => {
158
+
159
+ var itemsFound = [];
160
+
161
+ for (var findex in catalog.files) {
162
+ var filename = catalog.files[findex];
163
+ var fext = filename.split(".").pop();
164
+
165
+ if (extensions.indexOf(fext) > -1) {
166
+ itemsFound.push(filename);
167
+ }
168
+ }
169
+
170
+ resolve(itemsFound);
171
+
172
+ }, (err) => {
173
+ reject(err);
174
+ });
175
+ });
176
+
177
+ return promise;
178
+
179
+ }
180
+
181
+ /**
182
+ * Fetches and parses a JSOS (JSON Separated Object Stream) file.
183
+ * JSOS files contain multiple JSON objects separated by the ASCII record separator (0x1e).
184
+ *
185
+ * @async
186
+ * @function fetch_json_stream
187
+ * @param {string} url - The URL to fetch the JSOS file from.
188
+ * @returns {Promise<Object[]>} A promise that resolves with an array of parsed JSON objects.
189
+ * @throws {string} Rejects with the status text if the request fails.
190
+ *
191
+ * @example
192
+ * // Load test results from a JSOS stream file
193
+ * fetch_json_stream('testrun_results_stream.jsos')
194
+ * .then(results => {
195
+ * results.forEach(result => console.log(result.name, result.result));
196
+ * })
197
+ * .catch(err => console.error('Failed to load results:', err));
198
+ */
199
+ async function fetch_json_stream(url) {
200
+ var promise = new Promise((resolve, reject) => {
201
+ var xmlhttp = new XMLHttpRequest();
202
+
203
+ xmlhttp.onreadystatechange = function () {
204
+ if (this.readyState == 4) {
205
+ if (this.status == 200) {
206
+ // =============================================================
207
+ // JSOS PARSING LOGIC - Overview
208
+ // =============================================================
209
+ // JSOS (JSON Separated Object Stream) is a streaming format
210
+ // where multiple JSON objects are concatenated in a single file,
211
+ // separated by the ASCII Record Separator character (0x1e).
212
+ //
213
+ // Format: {json1}\x1e{json2}\x1e{json3}\x1e...
214
+ //
215
+ // This format allows:
216
+ // 1. Streaming writes - append new records without rewriting
217
+ // 2. Large result sets - no need to hold entire array in memory
218
+ // 3. Incremental parsing - process records as they arrive
219
+ // =============================================================
220
+
221
+ var json_objects = [];
222
+
223
+ // =============================================================
224
+ // JSOS PARSING LOGIC - Step 1: Split by Record Separator
225
+ // =============================================================
226
+ // Split the response text using the ASCII Record Separator (0x1e).
227
+ // This produces an array of JSON string fragments.
228
+ // Note: The last element may be empty if file ends with separator.
229
+ var split_responses = this.responseText.split("\x1e");
230
+ var srlength = split_responses.length;
231
+
232
+ // =============================================================
233
+ // JSOS PARSING LOGIC - Step 2: Parse Each JSON Fragment
234
+ // =============================================================
235
+ // Process fragments from end to beginning (using pop/unshift)
236
+ // to maintain original order in the output array.
237
+ // This approach is memory-efficient for large streams.
238
+ while (srlength > 0) {
239
+ // Pop from end of split array (reverse iteration)
240
+ var ritem = split_responses.pop();
241
+
242
+ // =============================================================
243
+ // JSOS PARSING LOGIC - Step 3: Handle Empty Fragments
244
+ // =============================================================
245
+ // Skip empty strings that result from:
246
+ // - Trailing record separator at end of file
247
+ // - Consecutive separators (malformed but handled gracefully)
248
+ // - Empty file content
249
+ if (ritem.length > 0) {
250
+ // Parse the JSON string into an object
251
+ var robj = JSON.parse(ritem);
252
+ // Prepend to output array to maintain original order
253
+ // (since we're iterating backwards with pop)
254
+ json_objects.unshift(robj);
255
+ }
256
+ srlength = srlength - 1;
257
+ }
258
+
259
+ resolve(json_objects);
260
+ } else {
261
+ reject(this.statusText);
262
+ }
263
+ }
264
+ };
265
+
266
+ xmlhttp.onerror = function () {
267
+ reject(this.statusText);
268
+ };
269
+
270
+ xmlhttp.open("GET", url, true);
271
+ xmlhttp.send();
272
+
273
+ });
274
+
275
+ return promise;
276
+ }
277
+
278
+ /**
279
+ * Extracts the parent directory path from a URL or file path.
280
+ *
281
+ * @function get_parent_directory
282
+ * @param {string} refurl - The URL or file path to extract the parent directory from.
283
+ * @returns {string} The parent directory path (everything before the last '/').
284
+ *
285
+ * @example
286
+ * get_parent_directory('/path/to/file.txt'); // Returns '/path/to'
287
+ * get_parent_directory('artifacts/images/screenshot.png'); // Returns 'artifacts/images'
288
+ */
289
+ function get_parent_directory(refurl) {
290
+ return refurl.substring(0, refurl.lastIndexOf("/"));
291
+ }
292
+
293
+
294
+ /**
295
+ * Gets the output directory from a tab content URL by navigating up two directory levels.
296
+ * Used to determine the test output root directory from an artifact tab page URL.
297
+ *
298
+ * @function get_output_directory
299
+ * @param {string} tab_content_url - The URL of the tab content page.
300
+ * @returns {string} The output directory path (two levels up from the tab content).
301
+ *
302
+ * @example
303
+ * get_output_directory('/output/artifacts/images/tab.html'); // Returns '/output'
304
+ */
305
+ function get_output_directory(tab_content_url) {
306
+ var output_dir = get_parent_directory(get_parent_directory(tab_content_url));
307
+ return output_dir;
308
+ }
309
+
310
+
311
+ /**
312
+ * Calculates and formats the time difference between two timestamps.
313
+ * Returns a human-readable duration string with days, hours, minutes, and seconds.
314
+ *
315
+ * @function get_time_difference
316
+ * @param {string} start - The start timestamp in ISO format.
317
+ * @param {string} stop - The stop timestamp in ISO format.
318
+ * @returns {string} A formatted duration string (e.g., "1h30m45.1234s", "2d5h", "0.5000s").
319
+ *
320
+ * @example
321
+ * get_time_difference('2024-01-15T10:00:00', '2024-01-15T11:30:45');
322
+ * // Returns "1h30m45.0000s"
323
+ *
324
+ * @example
325
+ * get_time_difference('2024-01-15T10:00:00', '2024-01-15T10:00:00.5');
326
+ * // Returns "0.5000s"
327
+ */
328
+ function get_time_difference(start, stop) {
329
+ var startTimeStamp = Date.parse(start, DATETIME_FORMAT) / 1000;
330
+ var stopTimeStamp = Date.parse(stop, DATETIME_FORMAT) / 1000;
331
+
332
+ var elapsedTime = stopTimeStamp - startTimeStamp;
333
+
334
+ var diff = "";
335
+
336
+ if (elapsedTime > 1) {
337
+ var seconds = elapsedTime;
338
+ var minutes = null;
339
+ var hours = null;
340
+ var days = null;
341
+
342
+ if (seconds > 60) {
343
+ var minutes = Math.floor(seconds / 60);
344
+ seconds = seconds - (minutes * 60);
345
+
346
+ if (minutes > 60) {
347
+ var hours = Math.floor(minutes / 60);
348
+ minutes = minutes % 60;
349
+
350
+ if (hours > 24) {
351
+ var days = Math.floor(hours / 20);
352
+ hours = hours % 24;
353
+ diff = days.toString() + "d";
354
+ }
355
+
356
+ diff += hours.toString() + "h";
357
+ }
358
+
359
+ diff += minutes.toString() + "m";
360
+ }
361
+
362
+ diff += seconds.toFixed(4) + "s";
363
+ } else {
364
+ diff = elapsedTime.toFixed(4) + "s";
365
+ }
366
+
367
+ return diff;
368
+ }
369
+
370
+ /**
371
+ * Gets the content directory for the current tab page from the iframe's pathname.
372
+ * Used by artifact tab pages to determine their relative directory location.
373
+ *
374
+ * @function tab_get_content_directory
375
+ * @returns {string} The directory path of the current tab content.
376
+ *
377
+ * @example
378
+ * // If iframe is at /output/artifacts/images/tab.html
379
+ * tab_get_content_directory(); // Returns '/output/artifacts/images'
380
+ */
381
+ function tab_get_content_directory() {
382
+ var iframe_pathname = window.location.pathname;
383
+ var content_directory = get_parent_directory(iframe_pathname);
384
+ return content_directory;
385
+ }
386
+
387
+
388
+ /**
389
+ * Checks if a value is a plain JavaScript object (dictionary).
390
+ *
391
+ * @function isDict
392
+ * @param {*} value - The value to check.
393
+ * @returns {boolean} True if the value is a plain object, false otherwise.
394
+ *
395
+ * @example
396
+ * isDict({key: 'value'}); // Returns true
397
+ * isDict([1, 2, 3]); // Returns false
398
+ * isDict('string'); // Returns false
399
+ */
400
+ function isDict(value) {
401
+ rtnval = false;
402
+ if (value.constructor == Object) {
403
+ rtnval = true;
404
+ }
405
+ return rtnval
406
+ }
407
+
408
+ /**
409
+ * Checks if a value is a string.
410
+ *
411
+ * @function isString
412
+ * @param {*} value - The value to check.
413
+ * @returns {boolean} True if the value is a string, false otherwise.
414
+ *
415
+ * @example
416
+ * isString('hello'); // Returns true
417
+ * isString(123); // Returns false
418
+ * isString(['a', 'b']); // Returns false
419
+ */
420
+ function isString(value) {
421
+ rtnval = false;
422
+ if (value.constructor == String) {
423
+ rtnval = true;
424
+ }
425
+ return rtnval
426
+ }