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,1287 @@
1
+ /*
2
+ Author: "Myron Walker"
3
+ Copyright: "Copyright 2025, Code Craft AI LLC"
4
+ Version: = "2.0.0"
5
+ Email: myron.walker@gmail.com
6
+ */
7
+
8
+ /**
9
+ * @fileoverview Result comparison components for comparing test results between test runs.
10
+ * Provides functionality to load results from different test runs, compare them,
11
+ * highlight differences, and show trend analysis.
12
+ * @module testsummary-comparison
13
+ */
14
+
15
+ /**
16
+ * Flag indicating whether comparison components have been registered.
17
+ * @type {boolean}
18
+ * @private
19
+ */
20
+ let comparisonComponentsRegistered = false;
21
+
22
+ /**
23
+ * Component for comparing test results between different test runs.
24
+ * Allows users to load a baseline result set and compare it with the current results.
25
+ * Highlights new failures, fixes, and unchanged tests.
26
+ *
27
+ * @class TestSummaryResultComparison
28
+ * @extends HTMLElement
29
+ *
30
+ * @example
31
+ * const comparison = document.getElementById('testsummary-comparison');
32
+ * comparison.syncData(currentResults, baselineResults);
33
+ */
34
+ class TestSummaryResultComparison extends HTMLElement {
35
+
36
+ static tagname = 'testsummary-comparison'
37
+
38
+ static template = `
39
+ <div class="ts-comparison-card">
40
+ <div class="ts-section-header">
41
+ <h2 class="zero-margins-and-padding">Result Comparison</h2>
42
+ </div>
43
+ <div class="ts-comparison-toolbar">
44
+ <div class="ts-comparison-load-section">
45
+ <label for="id-baseline-url" class="ts-comparison-label">Baseline URL:</label>
46
+ <input type="text" id="id-baseline-url" class="ts-comparison-input"
47
+ placeholder="Enter path to baseline testrun_summary.json..."
48
+ title="Enter the URL or path to the baseline test run results">
49
+ <button id="id-load-baseline" class="ts-comparison-btn" title="Load baseline results for comparison">
50
+ Load Baseline
51
+ </button>
52
+ <button id="id-clear-comparison" class="ts-comparison-btn ts-comparison-btn-secondary" title="Clear comparison">
53
+ Clear
54
+ </button>
55
+ </div>
56
+ <div class="ts-comparison-status" id="id-comparison-status">
57
+ No baseline loaded
58
+ </div>
59
+ </div>
60
+ <div class="ts-comparison-summary" id="id-comparison-summary" style="display: none;">
61
+ <div class="ts-comparison-summary-item ts-comparison-new-failures">
62
+ <span class="ts-comparison-summary-label">New Failures:</span>
63
+ <span class="ts-comparison-summary-value" id="id-new-failures-count">0</span>
64
+ </div>
65
+ <div class="ts-comparison-summary-item ts-comparison-fixes">
66
+ <span class="ts-comparison-summary-label">Fixes:</span>
67
+ <span class="ts-comparison-summary-value" id="id-fixes-count">0</span>
68
+ </div>
69
+ <div class="ts-comparison-summary-item ts-comparison-new-tests">
70
+ <span class="ts-comparison-summary-label">New Tests:</span>
71
+ <span class="ts-comparison-summary-value" id="id-new-tests-count">0</span>
72
+ </div>
73
+ <div class="ts-comparison-summary-item ts-comparison-removed-tests">
74
+ <span class="ts-comparison-summary-label">Removed Tests:</span>
75
+ <span class="ts-comparison-summary-value" id="id-removed-tests-count">0</span>
76
+ </div>
77
+ <div class="ts-comparison-summary-item ts-comparison-unchanged">
78
+ <span class="ts-comparison-summary-label">Unchanged:</span>
79
+ <span class="ts-comparison-summary-value" id="id-unchanged-count">0</span>
80
+ </div>
81
+ </div>
82
+ <div class="ts-comparison-filter-bar" id="id-comparison-filter-bar" style="display: none;">
83
+ <button id="id-filter-all-changes" class="ts-comparison-filter-btn ts-comparison-filter-btn-active" data-filter="ALL">
84
+ All Changes
85
+ </button>
86
+ <button id="id-filter-new-failures" class="ts-comparison-filter-btn ts-comparison-filter-btn-fail" data-filter="NEW_FAILURE">
87
+ New Failures
88
+ </button>
89
+ <button id="id-filter-fixes" class="ts-comparison-filter-btn ts-comparison-filter-btn-pass" data-filter="FIX">
90
+ Fixes
91
+ </button>
92
+ <button id="id-filter-new-tests" class="ts-comparison-filter-btn ts-comparison-filter-btn-new" data-filter="NEW_TEST">
93
+ New Tests
94
+ </button>
95
+ <button id="id-filter-removed" class="ts-comparison-filter-btn ts-comparison-filter-btn-removed" data-filter="REMOVED">
96
+ Removed
97
+ </button>
98
+ </div>
99
+ <div class="ts-section-detail">
100
+ <div id="id-comparison-content" class="ts-comparison-content">
101
+ <div class="ts-comparison-placeholder">
102
+ Load a baseline to compare test results between runs.
103
+ </div>
104
+ </div>
105
+ </div>
106
+ </div>
107
+ `
108
+
109
+ constructor() {
110
+ super();
111
+
112
+ const shadowRoot = this.attachShadow({mode: 'open'});
113
+ shadowRoot.innerHTML = this.getTemplate();
114
+
115
+ addGlobalStylesToShadowRoot(shadowRoot);
116
+
117
+ // State
118
+ this._currentResults = null;
119
+ this._baselineResults = null;
120
+ this._comparisonData = null;
121
+ this._activeFilter = 'ALL';
122
+
123
+ // Set up event listeners
124
+ this._setupEventListeners();
125
+ }
126
+
127
+ /**
128
+ * Gets the HTML template for this component.
129
+ * @returns {string} The HTML template string.
130
+ */
131
+ getTemplate() {
132
+ return TestSummaryResultComparison.template;
133
+ }
134
+
135
+ /**
136
+ * Sets up event listeners for the comparison component.
137
+ * @private
138
+ */
139
+ _setupEventListeners() {
140
+ var self = this;
141
+
142
+ // Load baseline button
143
+ var loadBtn = this.shadowRoot.querySelector("#id-load-baseline");
144
+ loadBtn.addEventListener("click", function() {
145
+ self._loadBaseline();
146
+ });
147
+
148
+ // Clear comparison button
149
+ var clearBtn = this.shadowRoot.querySelector("#id-clear-comparison");
150
+ clearBtn.addEventListener("click", function() {
151
+ self._clearComparison();
152
+ });
153
+
154
+ // URL input - allow Enter key to load
155
+ var urlInput = this.shadowRoot.querySelector("#id-baseline-url");
156
+ urlInput.addEventListener("keypress", function(event) {
157
+ if (event.key === "Enter") {
158
+ self._loadBaseline();
159
+ }
160
+ });
161
+
162
+ // Filter buttons
163
+ var filterButtons = this.shadowRoot.querySelectorAll(".ts-comparison-filter-btn");
164
+ filterButtons.forEach(function(btn) {
165
+ btn.addEventListener("click", function(event) {
166
+ var filterValue = event.currentTarget.getAttribute("data-filter");
167
+ self._setActiveFilter(filterValue);
168
+ self._renderComparison();
169
+ });
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Loads baseline results from the specified URL.
175
+ * @private
176
+ */
177
+ async _loadBaseline() {
178
+ var urlInput = this.shadowRoot.querySelector("#id-baseline-url");
179
+ var baselineUrl = urlInput.value.trim();
180
+
181
+ if (!baselineUrl) {
182
+ this._updateStatus("Please enter a baseline URL", "error");
183
+ return;
184
+ }
185
+
186
+ this._updateStatus("Loading baseline...", "loading");
187
+
188
+ try {
189
+ // Load baseline summary
190
+ var baselineSummaryUrl = baselineUrl;
191
+ if (!baselineUrl.endsWith("testrun_summary.json")) {
192
+ baselineSummaryUrl = baselineUrl.replace(/\/?$/, "/testrun_summary.json");
193
+ }
194
+
195
+ var baselineSummary = await fetch_json(baselineSummaryUrl);
196
+ if (!baselineSummary) {
197
+ this._updateStatus("Failed to load baseline summary", "error");
198
+ return;
199
+ }
200
+
201
+ // Load baseline results stream
202
+ var baselineResultsUrl = baselineSummaryUrl.replace("testrun_summary.json", "testrun_results_stream.jsos");
203
+ var baselineResults = await fetch_json_stream(baselineResultsUrl);
204
+
205
+ if (!baselineResults || baselineResults.length === 0) {
206
+ this._updateStatus("Failed to load baseline results", "error");
207
+ return;
208
+ }
209
+
210
+ // Process baseline results into a comparable format
211
+ this._baselineResults = this._processResultsForComparison(baselineResults);
212
+
213
+ // Perform comparison
214
+ this._performComparison();
215
+
216
+ this._updateStatus("Baseline loaded: " + baselineSummary.start, "success");
217
+
218
+ } catch (error) {
219
+ console.error("Error loading baseline:", error);
220
+ this._updateStatus("Error loading baseline: " + error.message, "error");
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Processes raw results into a format suitable for comparison.
226
+ * Creates a map of test names to their results.
227
+ * @param {Array} results - Raw results array from JSOS stream.
228
+ * @returns {Object} Map of test names to result objects.
229
+ * @private
230
+ */
231
+ _processResultsForComparison(results) {
232
+ var processedResults = {};
233
+
234
+ for (var i = 0; i < results.length; i++) {
235
+ var result = results[i];
236
+
237
+ // Only process TEST records with final results (have stop time)
238
+ if (result.rtype === "TEST" && result.stop && result.stop.length > 0) {
239
+ var testName = result.name;
240
+
241
+ // Add moniker suffix if present
242
+ if (result.monikers && result.monikers.length > 0) {
243
+ var monikerSuffix = result.monikers.map(function(m) { return "[" + m + "]"; }).join("");
244
+ testName = testName + ":" + monikerSuffix;
245
+ }
246
+
247
+ processedResults[testName] = {
248
+ name: testName,
249
+ result: result.result,
250
+ start: result.start,
251
+ stop: result.stop,
252
+ detail: result.detail || {},
253
+ status: this._getTestStatus(result)
254
+ };
255
+ }
256
+ }
257
+
258
+ return processedResults;
259
+ }
260
+
261
+ /**
262
+ * Gets the status of a test based on its detail object.
263
+ * @param {Object} test - The test item.
264
+ * @returns {string} The test status: 'PASSED', 'FAILED', 'ERRORED', or 'SKIPPED'.
265
+ * @private
266
+ */
267
+ _getTestStatus(test) {
268
+ if (test.detail) {
269
+ if (test.detail.errors && test.detail.errors.length > 0) {
270
+ return 'ERRORED';
271
+ }
272
+ if (test.detail.failures && test.detail.failures.length > 0) {
273
+ return 'FAILED';
274
+ }
275
+ if (test.detail.skipped) {
276
+ return 'SKIPPED';
277
+ }
278
+ if (test.detail.passed) {
279
+ return 'PASSED';
280
+ }
281
+ }
282
+ return test.result || 'UNKNOWN';
283
+ }
284
+
285
+ /**
286
+ * Performs comparison between current and baseline results.
287
+ * @private
288
+ */
289
+ _performComparison() {
290
+ if (!this._currentResults || !this._baselineResults) {
291
+ return;
292
+ }
293
+
294
+ var comparison = {
295
+ newFailures: [],
296
+ fixes: [],
297
+ newTests: [],
298
+ removedTests: [],
299
+ unchanged: [],
300
+ statusChanges: []
301
+ };
302
+
303
+ var currentTestNames = Object.keys(this._currentResults);
304
+ var baselineTestNames = Object.keys(this._baselineResults);
305
+
306
+ // Find new tests and compare existing tests
307
+ for (var i = 0; i < currentTestNames.length; i++) {
308
+ var testName = currentTestNames[i];
309
+ var currentTest = this._currentResults[testName];
310
+
311
+ if (!this._baselineResults.hasOwnProperty(testName)) {
312
+ // New test
313
+ comparison.newTests.push({
314
+ name: testName,
315
+ current: currentTest,
316
+ baseline: null,
317
+ changeType: 'NEW_TEST'
318
+ });
319
+ } else {
320
+ // Existing test - compare status
321
+ var baselineTest = this._baselineResults[testName];
322
+ var currentStatus = currentTest.status;
323
+ var baselineStatus = baselineTest.status;
324
+
325
+ if (currentStatus !== baselineStatus) {
326
+ var changeItem = {
327
+ name: testName,
328
+ current: currentTest,
329
+ baseline: baselineTest,
330
+ currentStatus: currentStatus,
331
+ baselineStatus: baselineStatus
332
+ };
333
+
334
+ // Categorize the change
335
+ if (this._isFailure(currentStatus) && !this._isFailure(baselineStatus)) {
336
+ changeItem.changeType = 'NEW_FAILURE';
337
+ comparison.newFailures.push(changeItem);
338
+ } else if (!this._isFailure(currentStatus) && this._isFailure(baselineStatus)) {
339
+ changeItem.changeType = 'FIX';
340
+ comparison.fixes.push(changeItem);
341
+ } else {
342
+ changeItem.changeType = 'STATUS_CHANGE';
343
+ comparison.statusChanges.push(changeItem);
344
+ }
345
+ } else {
346
+ comparison.unchanged.push({
347
+ name: testName,
348
+ current: currentTest,
349
+ baseline: baselineTest,
350
+ changeType: 'UNCHANGED'
351
+ });
352
+ }
353
+ }
354
+ }
355
+
356
+ // Find removed tests
357
+ for (var j = 0; j < baselineTestNames.length; j++) {
358
+ var baselineTestName = baselineTestNames[j];
359
+ if (!this._currentResults.hasOwnProperty(baselineTestName)) {
360
+ comparison.removedTests.push({
361
+ name: baselineTestName,
362
+ current: null,
363
+ baseline: this._baselineResults[baselineTestName],
364
+ changeType: 'REMOVED'
365
+ });
366
+ }
367
+ }
368
+
369
+ this._comparisonData = comparison;
370
+ this._updateComparisonSummary();
371
+ this._renderComparison();
372
+ }
373
+
374
+ /**
375
+ * Checks if a status represents a failure (FAILED or ERRORED).
376
+ * @param {string} status - The test status.
377
+ * @returns {boolean} True if the status is a failure.
378
+ * @private
379
+ */
380
+ _isFailure(status) {
381
+ return status === 'FAILED' || status === 'ERRORED';
382
+ }
383
+
384
+ /**
385
+ * Updates the comparison summary display.
386
+ * @private
387
+ */
388
+ _updateComparisonSummary() {
389
+ if (!this._comparisonData) {
390
+ return;
391
+ }
392
+
393
+ var summaryEl = this.shadowRoot.querySelector("#id-comparison-summary");
394
+ summaryEl.style.display = "flex";
395
+
396
+ var filterBar = this.shadowRoot.querySelector("#id-comparison-filter-bar");
397
+ filterBar.style.display = "flex";
398
+
399
+ this.shadowRoot.querySelector("#id-new-failures-count").innerHTML = this._comparisonData.newFailures.length;
400
+ this.shadowRoot.querySelector("#id-fixes-count").innerHTML = this._comparisonData.fixes.length;
401
+ this.shadowRoot.querySelector("#id-new-tests-count").innerHTML = this._comparisonData.newTests.length;
402
+ this.shadowRoot.querySelector("#id-removed-tests-count").innerHTML = this._comparisonData.removedTests.length;
403
+ this.shadowRoot.querySelector("#id-unchanged-count").innerHTML = this._comparisonData.unchanged.length;
404
+ }
405
+
406
+ /**
407
+ * Renders the comparison results based on the active filter.
408
+ * @private
409
+ */
410
+ _renderComparison() {
411
+ var contentEl = this.shadowRoot.querySelector("#id-comparison-content");
412
+ contentEl.innerHTML = "";
413
+
414
+ if (!this._comparisonData) {
415
+ contentEl.innerHTML = '<div class="ts-comparison-placeholder">Load a baseline to compare test results between runs.</div>';
416
+ return;
417
+ }
418
+
419
+ var itemsToRender = this._getFilteredComparisonItems();
420
+
421
+ if (itemsToRender.length === 0) {
422
+ contentEl.innerHTML = '<div class="ts-comparison-placeholder">No changes match the selected filter.</div>';
423
+ return;
424
+ }
425
+
426
+ // Group items by change type for better organization
427
+ var groupedItems = this._groupComparisonItems(itemsToRender);
428
+
429
+ for (var groupName in groupedItems) {
430
+ if (groupedItems.hasOwnProperty(groupName) && groupedItems[groupName].length > 0) {
431
+ var groupEl = this._createComparisonGroup(groupName, groupedItems[groupName]);
432
+ contentEl.appendChild(groupEl);
433
+ }
434
+ }
435
+ }
436
+
437
+ /**
438
+ * Gets comparison items filtered by the active filter.
439
+ * @returns {Array} Filtered comparison items.
440
+ * @private
441
+ */
442
+ _getFilteredComparisonItems() {
443
+ if (!this._comparisonData) {
444
+ return [];
445
+ }
446
+
447
+ var items = [];
448
+
449
+ switch (this._activeFilter) {
450
+ case 'NEW_FAILURE':
451
+ items = this._comparisonData.newFailures;
452
+ break;
453
+ case 'FIX':
454
+ items = this._comparisonData.fixes;
455
+ break;
456
+ case 'NEW_TEST':
457
+ items = this._comparisonData.newTests;
458
+ break;
459
+ case 'REMOVED':
460
+ items = this._comparisonData.removedTests;
461
+ break;
462
+ case 'ALL':
463
+ default:
464
+ items = items.concat(
465
+ this._comparisonData.newFailures,
466
+ this._comparisonData.fixes,
467
+ this._comparisonData.newTests,
468
+ this._comparisonData.removedTests,
469
+ this._comparisonData.statusChanges
470
+ );
471
+ break;
472
+ }
473
+
474
+ return items;
475
+ }
476
+
477
+ /**
478
+ * Groups comparison items by their change type.
479
+ * @param {Array} items - Comparison items to group.
480
+ * @returns {Object} Items grouped by change type.
481
+ * @private
482
+ */
483
+ _groupComparisonItems(items) {
484
+ var groups = {
485
+ 'NEW_FAILURE': [],
486
+ 'FIX': [],
487
+ 'NEW_TEST': [],
488
+ 'REMOVED': [],
489
+ 'STATUS_CHANGE': []
490
+ };
491
+
492
+ for (var i = 0; i < items.length; i++) {
493
+ var item = items[i];
494
+ if (groups.hasOwnProperty(item.changeType)) {
495
+ groups[item.changeType].push(item);
496
+ }
497
+ }
498
+
499
+ return groups;
500
+ }
501
+
502
+ /**
503
+ * Creates a comparison group element.
504
+ * @param {string} groupName - The name of the group.
505
+ * @param {Array} items - Items in the group.
506
+ * @returns {HTMLElement} The group element.
507
+ * @private
508
+ */
509
+ _createComparisonGroup(groupName, items) {
510
+ var groupEl = document.createElement("div");
511
+ groupEl.classList.add("ts-comparison-group");
512
+
513
+ var headerEl = document.createElement("div");
514
+ headerEl.classList.add("ts-comparison-group-header");
515
+ headerEl.classList.add("ts-comparison-group-" + groupName.toLowerCase().replace(/_/g, "-"));
516
+ headerEl.innerHTML = this._getGroupDisplayName(groupName) + " (" + items.length + ")";
517
+ groupEl.appendChild(headerEl);
518
+
519
+ var itemsContainer = document.createElement("div");
520
+ itemsContainer.classList.add("ts-comparison-group-items");
521
+
522
+ for (var i = 0; i < items.length; i++) {
523
+ var itemEl = this._createComparisonItem(items[i]);
524
+ itemsContainer.appendChild(itemEl);
525
+ }
526
+
527
+ groupEl.appendChild(itemsContainer);
528
+ return groupEl;
529
+ }
530
+
531
+ /**
532
+ * Gets the display name for a group.
533
+ * @param {string} groupName - The internal group name.
534
+ * @returns {string} The display name.
535
+ * @private
536
+ */
537
+ _getGroupDisplayName(groupName) {
538
+ var displayNames = {
539
+ 'NEW_FAILURE': '🔴 New Failures',
540
+ 'FIX': '🟢 Fixes',
541
+ 'NEW_TEST': '🆕 New Tests',
542
+ 'REMOVED': '🗑️ Removed Tests',
543
+ 'STATUS_CHANGE': '🔄 Status Changes'
544
+ };
545
+ return displayNames[groupName] || groupName;
546
+ }
547
+
548
+ /**
549
+ * Creates a comparison item element.
550
+ * @param {Object} item - The comparison item.
551
+ * @returns {HTMLElement} The item element.
552
+ * @private
553
+ */
554
+ _createComparisonItem(item) {
555
+ var itemEl = document.createElement("div");
556
+ itemEl.classList.add("ts-comparison-item");
557
+ itemEl.classList.add("ts-comparison-item-" + item.changeType.toLowerCase().replace(/_/g, "-"));
558
+
559
+ var nameEl = document.createElement("div");
560
+ nameEl.classList.add("ts-comparison-item-name");
561
+ nameEl.innerHTML = this._escapeHTML(item.name);
562
+ itemEl.appendChild(nameEl);
563
+
564
+ var statusEl = document.createElement("div");
565
+ statusEl.classList.add("ts-comparison-item-status");
566
+
567
+ if (item.baseline && item.current) {
568
+ statusEl.innerHTML = '<span class="ts-comparison-status-baseline">' + item.baselineStatus + '</span>' +
569
+ '<span class="ts-comparison-status-arrow">→</span>' +
570
+ '<span class="ts-comparison-status-current">' + item.currentStatus + '</span>';
571
+ } else if (item.current) {
572
+ statusEl.innerHTML = '<span class="ts-comparison-status-current">' + item.current.status + '</span>';
573
+ } else if (item.baseline) {
574
+ statusEl.innerHTML = '<span class="ts-comparison-status-baseline">' + item.baseline.status + '</span>';
575
+ }
576
+
577
+ itemEl.appendChild(statusEl);
578
+
579
+ return itemEl;
580
+ }
581
+
582
+ /**
583
+ * Sets the active filter and updates button styling.
584
+ * @param {string} filterValue - The filter value.
585
+ * @private
586
+ */
587
+ _setActiveFilter(filterValue) {
588
+ this._activeFilter = filterValue;
589
+
590
+ var filterButtons = this.shadowRoot.querySelectorAll(".ts-comparison-filter-btn");
591
+ filterButtons.forEach(function(btn) {
592
+ var btnFilter = btn.getAttribute("data-filter");
593
+ if (btnFilter === filterValue) {
594
+ btn.classList.add("ts-comparison-filter-btn-active");
595
+ } else {
596
+ btn.classList.remove("ts-comparison-filter-btn-active");
597
+ }
598
+ });
599
+ }
600
+
601
+ /**
602
+ * Updates the status display.
603
+ * @param {string} message - The status message.
604
+ * @param {string} type - The status type: 'loading', 'success', 'error'.
605
+ * @private
606
+ */
607
+ _updateStatus(message, type) {
608
+ var statusEl = this.shadowRoot.querySelector("#id-comparison-status");
609
+ statusEl.innerHTML = message;
610
+ statusEl.className = "ts-comparison-status ts-comparison-status-" + type;
611
+ }
612
+
613
+ /**
614
+ * Clears the comparison data and resets the UI.
615
+ * @private
616
+ */
617
+ _clearComparison() {
618
+ this._baselineResults = null;
619
+ this._comparisonData = null;
620
+ this._activeFilter = 'ALL';
621
+
622
+ var urlInput = this.shadowRoot.querySelector("#id-baseline-url");
623
+ urlInput.value = "";
624
+
625
+ var summaryEl = this.shadowRoot.querySelector("#id-comparison-summary");
626
+ summaryEl.style.display = "none";
627
+
628
+ var filterBar = this.shadowRoot.querySelector("#id-comparison-filter-bar");
629
+ filterBar.style.display = "none";
630
+
631
+ var contentEl = this.shadowRoot.querySelector("#id-comparison-content");
632
+ contentEl.innerHTML = '<div class="ts-comparison-placeholder">Load a baseline to compare test results between runs.</div>';
633
+
634
+ this._updateStatus("No baseline loaded", "");
635
+
636
+ // Reset filter button states
637
+ var filterButtons = this.shadowRoot.querySelectorAll(".ts-comparison-filter-btn");
638
+ filterButtons.forEach(function(btn) {
639
+ var btnFilter = btn.getAttribute("data-filter");
640
+ if (btnFilter === "ALL") {
641
+ btn.classList.add("ts-comparison-filter-btn-active");
642
+ } else {
643
+ btn.classList.remove("ts-comparison-filter-btn-active");
644
+ }
645
+ });
646
+ }
647
+
648
+ /**
649
+ * Escapes HTML special characters.
650
+ * @param {string} str - The string to escape.
651
+ * @returns {string} The escaped string.
652
+ * @private
653
+ */
654
+ _escapeHTML(str) {
655
+ if (str === null || str === undefined) {
656
+ return "";
657
+ }
658
+ return String(str)
659
+ .replace(/&/g, "&amp;")
660
+ .replace(/</g, "&lt;")
661
+ .replace(/>/g, "&gt;")
662
+ .replace(/"/g, "&quot;")
663
+ .replace(/'/g, "&#039;");
664
+ }
665
+
666
+ /**
667
+ * Synchronizes the component with current results data.
668
+ * @param {Object} currentResults - The current test results (processed format).
669
+ */
670
+ syncData(currentResults) {
671
+ this._currentResults = currentResults;
672
+
673
+ // If baseline is already loaded, re-perform comparison
674
+ if (this._baselineResults) {
675
+ this._performComparison();
676
+ }
677
+ }
678
+
679
+ /**
680
+ * Sets the current results from raw results array.
681
+ * @param {Object} resultsDetail - Results detail object keyed by package name.
682
+ */
683
+ setCurrentResultsFromDetail(resultsDetail) {
684
+ // Convert from package-grouped format to flat comparison format
685
+ var processedResults = {};
686
+
687
+ for (var pkgName in resultsDetail) {
688
+ if (resultsDetail.hasOwnProperty(pkgName)) {
689
+ var tests = resultsDetail[pkgName];
690
+ for (var i = 0; i < tests.length; i++) {
691
+ var test = tests[i];
692
+ var fullName = pkgName + "#" + test.name;
693
+ processedResults[fullName] = {
694
+ name: fullName,
695
+ result: test.result,
696
+ start: test.start,
697
+ stop: test.stop,
698
+ detail: test.detail || {},
699
+ status: this._getTestStatus(test)
700
+ };
701
+ }
702
+ }
703
+ }
704
+
705
+ this._currentResults = processedResults;
706
+
707
+ // If baseline is already loaded, re-perform comparison
708
+ if (this._baselineResults) {
709
+ this._performComparison();
710
+ }
711
+ }
712
+ }
713
+
714
+
715
+ /**
716
+ * Component for displaying trend analysis across multiple test runs.
717
+ * Shows pass rate trends, failure patterns, and test stability metrics.
718
+ *
719
+ * @class TestSummaryTrendAnalysis
720
+ * @extends HTMLElement
721
+ */
722
+ class TestSummaryTrendAnalysis extends HTMLElement {
723
+
724
+ static tagname = 'testsummary-trend-analysis'
725
+
726
+ static template = `
727
+ <div class="ts-trend-card">
728
+ <div class="ts-section-header">
729
+ <h2 class="zero-margins-and-padding">Trend Analysis</h2>
730
+ </div>
731
+ <div class="ts-trend-toolbar">
732
+ <div class="ts-trend-load-section">
733
+ <label class="ts-trend-label">Historical Runs:</label>
734
+ <input type="text" id="id-trend-urls" class="ts-trend-input"
735
+ placeholder="Enter comma-separated paths to historical test runs..."
736
+ title="Enter comma-separated URLs to historical test run directories">
737
+ <button id="id-load-trends" class="ts-trend-btn" title="Load historical data for trend analysis">
738
+ Analyze Trends
739
+ </button>
740
+ <button id="id-clear-trends" class="ts-trend-btn ts-trend-btn-secondary" title="Clear trend data">
741
+ Clear
742
+ </button>
743
+ </div>
744
+ <div class="ts-trend-status" id="id-trend-status">
745
+ No historical data loaded
746
+ </div>
747
+ </div>
748
+ <div class="ts-section-detail">
749
+ <div id="id-trend-content" class="ts-trend-content">
750
+ <div class="ts-trend-placeholder">
751
+ Load historical test runs to analyze trends over time.
752
+ </div>
753
+ </div>
754
+ </div>
755
+ </div>
756
+ `
757
+
758
+ constructor() {
759
+ super();
760
+
761
+ const shadowRoot = this.attachShadow({mode: 'open'});
762
+ shadowRoot.innerHTML = this.getTemplate();
763
+
764
+ addGlobalStylesToShadowRoot(shadowRoot);
765
+
766
+ // State
767
+ this._currentResults = null;
768
+ this._historicalRuns = [];
769
+ this._trendData = null;
770
+
771
+ // Set up event listeners
772
+ this._setupEventListeners();
773
+ }
774
+
775
+ /**
776
+ * Gets the HTML template for this component.
777
+ * @returns {string} The HTML template string.
778
+ */
779
+ getTemplate() {
780
+ return TestSummaryTrendAnalysis.template;
781
+ }
782
+
783
+ /**
784
+ * Sets up event listeners for the trend analysis component.
785
+ * @private
786
+ */
787
+ _setupEventListeners() {
788
+ var self = this;
789
+
790
+ // Load trends button
791
+ var loadBtn = this.shadowRoot.querySelector("#id-load-trends");
792
+ loadBtn.addEventListener("click", function() {
793
+ self._loadTrends();
794
+ });
795
+
796
+ // Clear trends button
797
+ var clearBtn = this.shadowRoot.querySelector("#id-clear-trends");
798
+ clearBtn.addEventListener("click", function() {
799
+ self._clearTrends();
800
+ });
801
+
802
+ // URL input - allow Enter key to load
803
+ var urlInput = this.shadowRoot.querySelector("#id-trend-urls");
804
+ urlInput.addEventListener("keypress", function(event) {
805
+ if (event.key === "Enter") {
806
+ self._loadTrends();
807
+ }
808
+ });
809
+ }
810
+
811
+ /**
812
+ * Loads historical test runs for trend analysis.
813
+ * @private
814
+ */
815
+ async _loadTrends() {
816
+ var urlInput = this.shadowRoot.querySelector("#id-trend-urls");
817
+ var urlsText = urlInput.value.trim();
818
+
819
+ if (!urlsText) {
820
+ this._updateStatus("Please enter historical run URLs", "error");
821
+ return;
822
+ }
823
+
824
+ var urls = urlsText.split(",").map(function(url) { return url.trim(); }).filter(function(url) { return url.length > 0; });
825
+
826
+ if (urls.length === 0) {
827
+ this._updateStatus("Please enter valid URLs", "error");
828
+ return;
829
+ }
830
+
831
+ this._updateStatus("Loading historical data...", "loading");
832
+ this._historicalRuns = [];
833
+
834
+ var loadedCount = 0;
835
+ var failedCount = 0;
836
+
837
+ for (var i = 0; i < urls.length; i++) {
838
+ try {
839
+ var runData = await this._loadRunData(urls[i]);
840
+ if (runData) {
841
+ this._historicalRuns.push(runData);
842
+ loadedCount++;
843
+ } else {
844
+ failedCount++;
845
+ }
846
+ } catch (error) {
847
+ console.error("Error loading run:", urls[i], error);
848
+ failedCount++;
849
+ }
850
+ }
851
+
852
+ if (loadedCount === 0) {
853
+ this._updateStatus("Failed to load any historical runs", "error");
854
+ return;
855
+ }
856
+
857
+ // Sort by date
858
+ this._historicalRuns.sort(function(a, b) {
859
+ return new Date(a.summary.start) - new Date(b.summary.start);
860
+ });
861
+
862
+ // Perform trend analysis
863
+ this._analyzeTrends();
864
+
865
+ var statusMsg = "Loaded " + loadedCount + " runs";
866
+ if (failedCount > 0) {
867
+ statusMsg += " (" + failedCount + " failed)";
868
+ }
869
+ this._updateStatus(statusMsg, "success");
870
+ }
871
+
872
+ /**
873
+ * Loads data for a single test run.
874
+ * @param {string} url - The URL to the test run directory.
875
+ * @returns {Object|null} The run data or null if failed.
876
+ * @private
877
+ */
878
+ async _loadRunData(url) {
879
+ var summaryUrl = url;
880
+ if (!url.endsWith("testrun_summary.json")) {
881
+ summaryUrl = url.replace(/\/?$/, "/testrun_summary.json");
882
+ }
883
+
884
+ var summary = await fetch_json(summaryUrl);
885
+ if (!summary) {
886
+ return null;
887
+ }
888
+
889
+ var resultsUrl = summaryUrl.replace("testrun_summary.json", "testrun_results_stream.jsos");
890
+ var results = await fetch_json_stream(resultsUrl);
891
+
892
+ return {
893
+ url: url,
894
+ summary: summary,
895
+ results: results || [],
896
+ processedResults: this._processResultsForTrend(results || [])
897
+ };
898
+ }
899
+
900
+ /**
901
+ * Processes results for trend analysis.
902
+ * @param {Array} results - Raw results array.
903
+ * @returns {Object} Processed results map.
904
+ * @private
905
+ */
906
+ _processResultsForTrend(results) {
907
+ var processed = {};
908
+
909
+ for (var i = 0; i < results.length; i++) {
910
+ var result = results[i];
911
+ if (result.rtype === "TEST" && result.stop && result.stop.length > 0) {
912
+ var testName = result.name;
913
+ if (result.monikers && result.monikers.length > 0) {
914
+ testName += ":" + result.monikers.map(function(m) { return "[" + m + "]"; }).join("");
915
+ }
916
+ processed[testName] = this._getTestStatus(result);
917
+ }
918
+ }
919
+
920
+ return processed;
921
+ }
922
+
923
+ /**
924
+ * Gets the status of a test.
925
+ * @param {Object} test - The test object.
926
+ * @returns {string} The test status.
927
+ * @private
928
+ */
929
+ _getTestStatus(test) {
930
+ if (test.detail) {
931
+ if (test.detail.errors && test.detail.errors.length > 0) return 'ERRORED';
932
+ if (test.detail.failures && test.detail.failures.length > 0) return 'FAILED';
933
+ if (test.detail.skipped) return 'SKIPPED';
934
+ if (test.detail.passed) return 'PASSED';
935
+ }
936
+ return test.result || 'UNKNOWN';
937
+ }
938
+
939
+ /**
940
+ * Analyzes trends across historical runs.
941
+ * @private
942
+ */
943
+ _analyzeTrends() {
944
+ if (this._historicalRuns.length === 0) {
945
+ return;
946
+ }
947
+
948
+ var trendData = {
949
+ passRates: [],
950
+ testStability: {},
951
+ flakyTests: [],
952
+ consistentFailures: [],
953
+ recentRegressions: []
954
+ };
955
+
956
+ // Calculate pass rates over time
957
+ for (var i = 0; i < this._historicalRuns.length; i++) {
958
+ var run = this._historicalRuns[i];
959
+ var detail = run.summary.detail || {};
960
+ var total = detail.total || 0;
961
+ var passed = detail.passed || 0;
962
+ var passRate = total > 0 ? (passed / total * 100) : 0;
963
+
964
+ trendData.passRates.push({
965
+ date: run.summary.start,
966
+ passRate: passRate,
967
+ total: total,
968
+ passed: passed,
969
+ failed: detail.failed || 0,
970
+ errors: detail.errors || 0,
971
+ skipped: detail.skipped || 0
972
+ });
973
+ }
974
+
975
+ // Analyze test stability
976
+ var allTestNames = new Set();
977
+ for (var j = 0; j < this._historicalRuns.length; j++) {
978
+ var runResults = this._historicalRuns[j].processedResults;
979
+ for (var testName in runResults) {
980
+ if (runResults.hasOwnProperty(testName)) {
981
+ allTestNames.add(testName);
982
+ }
983
+ }
984
+ }
985
+
986
+ allTestNames.forEach(function(testName) {
987
+ var history = [];
988
+ for (var k = 0; k < this._historicalRuns.length; k++) {
989
+ var runResults = this._historicalRuns[k].processedResults;
990
+ if (runResults.hasOwnProperty(testName)) {
991
+ history.push(runResults[testName]);
992
+ } else {
993
+ history.push('NOT_RUN');
994
+ }
995
+ }
996
+
997
+ var passCount = history.filter(function(s) { return s === 'PASSED'; }).length;
998
+ var failCount = history.filter(function(s) { return s === 'FAILED' || s === 'ERRORED'; }).length;
999
+ var totalRuns = history.filter(function(s) { return s !== 'NOT_RUN'; }).length;
1000
+
1001
+ trendData.testStability[testName] = {
1002
+ history: history,
1003
+ passCount: passCount,
1004
+ failCount: failCount,
1005
+ totalRuns: totalRuns,
1006
+ passRate: totalRuns > 0 ? (passCount / totalRuns * 100) : 0
1007
+ };
1008
+
1009
+ // Identify flaky tests (passed and failed in different runs)
1010
+ if (passCount > 0 && failCount > 0) {
1011
+ trendData.flakyTests.push({
1012
+ name: testName,
1013
+ passRate: (passCount / totalRuns * 100).toFixed(1),
1014
+ history: history
1015
+ });
1016
+ }
1017
+
1018
+ // Identify consistent failures (always failed)
1019
+ if (passCount === 0 && failCount > 0 && failCount === totalRuns) {
1020
+ trendData.consistentFailures.push({
1021
+ name: testName,
1022
+ failCount: failCount
1023
+ });
1024
+ }
1025
+ }.bind(this));
1026
+
1027
+ // Sort flaky tests by pass rate (most unstable first)
1028
+ trendData.flakyTests.sort(function(a, b) {
1029
+ return Math.abs(50 - parseFloat(a.passRate)) - Math.abs(50 - parseFloat(b.passRate));
1030
+ });
1031
+
1032
+ this._trendData = trendData;
1033
+ this._renderTrends();
1034
+ }
1035
+
1036
+ /**
1037
+ * Renders the trend analysis results.
1038
+ * @private
1039
+ */
1040
+ _renderTrends() {
1041
+ var contentEl = this.shadowRoot.querySelector("#id-trend-content");
1042
+ contentEl.innerHTML = "";
1043
+
1044
+ if (!this._trendData) {
1045
+ contentEl.innerHTML = '<div class="ts-trend-placeholder">Load historical test runs to analyze trends over time.</div>';
1046
+ return;
1047
+ }
1048
+
1049
+ // Pass rate chart
1050
+ var chartSection = this._createPassRateChart();
1051
+ contentEl.appendChild(chartSection);
1052
+
1053
+ // Flaky tests section
1054
+ if (this._trendData.flakyTests.length > 0) {
1055
+ var flakySection = this._createFlakyTestsSection();
1056
+ contentEl.appendChild(flakySection);
1057
+ }
1058
+
1059
+ // Consistent failures section
1060
+ if (this._trendData.consistentFailures.length > 0) {
1061
+ var failuresSection = this._createConsistentFailuresSection();
1062
+ contentEl.appendChild(failuresSection);
1063
+ }
1064
+ }
1065
+
1066
+ /**
1067
+ * Creates the pass rate chart section.
1068
+ * @returns {HTMLElement} The chart section element.
1069
+ * @private
1070
+ */
1071
+ _createPassRateChart() {
1072
+ var section = document.createElement("div");
1073
+ section.classList.add("ts-trend-section");
1074
+
1075
+ var header = document.createElement("h3");
1076
+ header.classList.add("ts-trend-section-header");
1077
+ header.innerHTML = "📈 Pass Rate Over Time";
1078
+ section.appendChild(header);
1079
+
1080
+ var chartContainer = document.createElement("div");
1081
+ chartContainer.classList.add("ts-trend-chart-container");
1082
+
1083
+ // Create a simple text-based chart
1084
+ var table = document.createElement("table");
1085
+ table.classList.add("ts-trend-table");
1086
+
1087
+ var thead = document.createElement("thead");
1088
+ thead.innerHTML = "<tr><th>Date</th><th>Pass Rate</th><th>Passed</th><th>Failed</th><th>Errors</th><th>Total</th><th>Trend</th></tr>";
1089
+ table.appendChild(thead);
1090
+
1091
+ var tbody = document.createElement("tbody");
1092
+ for (var i = 0; i < this._trendData.passRates.length; i++) {
1093
+ var data = this._trendData.passRates[i];
1094
+ var row = document.createElement("tr");
1095
+
1096
+ var dateStr = new Date(data.date).toLocaleDateString();
1097
+ var passRateStr = data.passRate.toFixed(1) + "%";
1098
+
1099
+ // Create visual bar
1100
+ var barWidth = Math.min(100, data.passRate);
1101
+ var barColor = data.passRate >= 90 ? "var(--color-pass)" :
1102
+ data.passRate >= 70 ? "orange" : "var(--color-fail)";
1103
+ var barHtml = '<div class="ts-trend-bar" style="width: ' + barWidth + '%; background-color: ' + barColor + ';"></div>';
1104
+
1105
+ row.innerHTML = '<td>' + dateStr + '</td>' +
1106
+ '<td>' + passRateStr + '</td>' +
1107
+ '<td class="color-pass">' + data.passed + '</td>' +
1108
+ '<td class="color-fail">' + data.failed + '</td>' +
1109
+ '<td class="color-error">' + data.errors + '</td>' +
1110
+ '<td>' + data.total + '</td>' +
1111
+ '<td class="ts-trend-bar-cell">' + barHtml + '</td>';
1112
+ tbody.appendChild(row);
1113
+ }
1114
+ table.appendChild(tbody);
1115
+
1116
+ chartContainer.appendChild(table);
1117
+ section.appendChild(chartContainer);
1118
+
1119
+ return section;
1120
+ }
1121
+
1122
+ /**
1123
+ * Creates the flaky tests section.
1124
+ * @returns {HTMLElement} The flaky tests section element.
1125
+ * @private
1126
+ */
1127
+ _createFlakyTestsSection() {
1128
+ var section = document.createElement("div");
1129
+ section.classList.add("ts-trend-section");
1130
+
1131
+ var header = document.createElement("h3");
1132
+ header.classList.add("ts-trend-section-header");
1133
+ header.innerHTML = "⚠️ Flaky Tests (" + this._trendData.flakyTests.length + ")";
1134
+ section.appendChild(header);
1135
+
1136
+ var description = document.createElement("p");
1137
+ description.classList.add("ts-trend-description");
1138
+ description.innerHTML = "Tests that have both passed and failed across different runs:";
1139
+ section.appendChild(description);
1140
+
1141
+ var list = document.createElement("div");
1142
+ list.classList.add("ts-trend-list");
1143
+
1144
+ var maxToShow = Math.min(10, this._trendData.flakyTests.length);
1145
+ for (var i = 0; i < maxToShow; i++) {
1146
+ var test = this._trendData.flakyTests[i];
1147
+ var item = document.createElement("div");
1148
+ item.classList.add("ts-trend-list-item");
1149
+ item.classList.add("ts-trend-flaky-item");
1150
+
1151
+ var historyHtml = test.history.map(function(status) {
1152
+ var color = status === 'PASSED' ? 'var(--color-pass)' :
1153
+ status === 'FAILED' || status === 'ERRORED' ? 'var(--color-fail)' :
1154
+ status === 'SKIPPED' ? 'var(--color-skip)' : '#ccc';
1155
+ return '<span class="ts-trend-history-dot" style="background-color: ' + color + ';" title="' + status + '"></span>';
1156
+ }).join("");
1157
+
1158
+ item.innerHTML = '<div class="ts-trend-item-name">' + this._escapeHTML(test.name) + '</div>' +
1159
+ '<div class="ts-trend-item-rate">' + test.passRate + '% pass rate</div>' +
1160
+ '<div class="ts-trend-item-history">' + historyHtml + '</div>';
1161
+ list.appendChild(item);
1162
+ }
1163
+
1164
+ if (this._trendData.flakyTests.length > maxToShow) {
1165
+ var more = document.createElement("div");
1166
+ more.classList.add("ts-trend-more");
1167
+ more.innerHTML = "... and " + (this._trendData.flakyTests.length - maxToShow) + " more flaky tests";
1168
+ list.appendChild(more);
1169
+ }
1170
+
1171
+ section.appendChild(list);
1172
+ return section;
1173
+ }
1174
+
1175
+ /**
1176
+ * Creates the consistent failures section.
1177
+ * @returns {HTMLElement} The consistent failures section element.
1178
+ * @private
1179
+ */
1180
+ _createConsistentFailuresSection() {
1181
+ var section = document.createElement("div");
1182
+ section.classList.add("ts-trend-section");
1183
+
1184
+ var header = document.createElement("h3");
1185
+ header.classList.add("ts-trend-section-header");
1186
+ header.innerHTML = "🔴 Consistent Failures (" + this._trendData.consistentFailures.length + ")";
1187
+ section.appendChild(header);
1188
+
1189
+ var description = document.createElement("p");
1190
+ description.classList.add("ts-trend-description");
1191
+ description.innerHTML = "Tests that have failed in every run:";
1192
+ section.appendChild(description);
1193
+
1194
+ var list = document.createElement("div");
1195
+ list.classList.add("ts-trend-list");
1196
+
1197
+ var maxToShow = Math.min(10, this._trendData.consistentFailures.length);
1198
+ for (var i = 0; i < maxToShow; i++) {
1199
+ var test = this._trendData.consistentFailures[i];
1200
+ var item = document.createElement("div");
1201
+ item.classList.add("ts-trend-list-item");
1202
+ item.classList.add("ts-trend-failure-item");
1203
+ item.innerHTML = '<div class="ts-trend-item-name">' + this._escapeHTML(test.name) + '</div>' +
1204
+ '<div class="ts-trend-item-count">Failed in ' + test.failCount + ' runs</div>';
1205
+ list.appendChild(item);
1206
+ }
1207
+
1208
+ if (this._trendData.consistentFailures.length > maxToShow) {
1209
+ var more = document.createElement("div");
1210
+ more.classList.add("ts-trend-more");
1211
+ more.innerHTML = "... and " + (this._trendData.consistentFailures.length - maxToShow) + " more consistent failures";
1212
+ list.appendChild(more);
1213
+ }
1214
+
1215
+ section.appendChild(list);
1216
+ return section;
1217
+ }
1218
+
1219
+ /**
1220
+ * Updates the status display.
1221
+ * @param {string} message - The status message.
1222
+ * @param {string} type - The status type.
1223
+ * @private
1224
+ */
1225
+ _updateStatus(message, type) {
1226
+ var statusEl = this.shadowRoot.querySelector("#id-trend-status");
1227
+ statusEl.innerHTML = message;
1228
+ statusEl.className = "ts-trend-status ts-trend-status-" + type;
1229
+ }
1230
+
1231
+ /**
1232
+ * Clears the trend data and resets the UI.
1233
+ * @private
1234
+ */
1235
+ _clearTrends() {
1236
+ this._historicalRuns = [];
1237
+ this._trendData = null;
1238
+
1239
+ var urlInput = this.shadowRoot.querySelector("#id-trend-urls");
1240
+ urlInput.value = "";
1241
+
1242
+ var contentEl = this.shadowRoot.querySelector("#id-trend-content");
1243
+ contentEl.innerHTML = '<div class="ts-trend-placeholder">Load historical test runs to analyze trends over time.</div>';
1244
+
1245
+ this._updateStatus("No historical data loaded", "");
1246
+ }
1247
+
1248
+ /**
1249
+ * Escapes HTML special characters.
1250
+ * @param {string} str - The string to escape.
1251
+ * @returns {string} The escaped string.
1252
+ * @private
1253
+ */
1254
+ _escapeHTML(str) {
1255
+ if (str === null || str === undefined) return "";
1256
+ return String(str)
1257
+ .replace(/&/g, "&amp;")
1258
+ .replace(/</g, "&lt;")
1259
+ .replace(/>/g, "&gt;")
1260
+ .replace(/"/g, "&quot;")
1261
+ .replace(/'/g, "&#039;");
1262
+ }
1263
+
1264
+ /**
1265
+ * Synchronizes the component with current results.
1266
+ * @param {Object} currentResults - The current test results.
1267
+ */
1268
+ syncData(currentResults) {
1269
+ this._currentResults = currentResults;
1270
+ }
1271
+ }
1272
+
1273
+
1274
+ /**
1275
+ * Registers comparison components with customElements.
1276
+ * Should be called once during page initialization.
1277
+ */
1278
+ function register_comparison_components() {
1279
+ if (comparisonComponentsRegistered) {
1280
+ return;
1281
+ }
1282
+
1283
+ customElements.define(TestSummaryResultComparison.tagname, TestSummaryResultComparison);
1284
+ customElements.define(TestSummaryTrendAnalysis.tagname, TestSummaryTrendAnalysis);
1285
+
1286
+ comparisonComponentsRegistered = true;
1287
+ }