-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapp.js
More file actions
2762 lines (2427 loc) · 99.3 KB
/
app.js
File metadata and controls
2762 lines (2427 loc) · 99.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Kata CI Dashboard - Application Logic
*/
// ============================================
// State
// ============================================
let state = {
data: null,
flakyData: null,
loading: true,
error: null,
filter: 'all',
viewMode: 'all', // 'all', 'tee', 'nvidia', 'ibm', 'autogen-policy' - which section to show
showRequiredOnly: false, // filter to show only required jobs
searchQuery: '',
sortBy: 'failures-desc', // 'name', 'failures-desc', 'pass-rate-asc', 'last-failure', 'status'
expandedSections: new Set(),
expandedGroups: new Set(),
expandedFlakyTests: new Set(),
activeTab: 'nightly',
flakyJobFilter: 'all',
// CoCo-specific state
activeProject: 'kata', // 'kata' or 'coco'
activeCocoTab: 'coco-charts', // 'coco-charts', 'coco-caa', etc.
cocoFilter: 'all',
cocoSearchQuery: '',
cocoSortBy: 'failures-desc',
caaFilter: 'all',
caaSearchQuery: '',
caaSortBy: 'failures-desc'
};
// ============================================
// Data Loading
// ============================================
async function loadData() {
state.loading = true;
state.error = null;
renderLoading();
try {
// Load nightly data
const response = await fetch('data.json?t=' + Date.now());
if (!response.ok) {
throw new Error('Data not available yet');
}
state.data = await response.json();
// Auto-expand sections with failures
state.data.sections.forEach(section => {
const hasFailures = section.tests.some(t => t.status === 'failed');
if (hasFailures) {
state.expandedSections.add(section.id);
state.expandedGroups.add(`${section.id}-failed`);
}
});
// Load flaky data (don't fail if not available)
try {
const flakyResponse = await fetch('flaky-data.json?t=' + Date.now());
if (flakyResponse.ok) {
state.flakyData = await flakyResponse.json();
updateFlakyBadge();
}
} catch (e) {
console.log('Flaky data not available yet');
}
state.loading = false;
render();
} catch (error) {
state.loading = false;
state.error = error.message;
renderError();
}
}
/**
* Update the flaky tests badge count in the tab
*/
function updateFlakyBadge() {
const badge = document.getElementById('flaky-count-badge');
if (badge && state.flakyData) {
const count = state.flakyData.flakyTests?.length || 0;
if (count > 0) {
badge.textContent = count;
badge.style.display = 'inline-flex';
} else {
badge.style.display = 'none';
}
}
}
// ============================================
// Utility Functions
// ============================================
function getWeatherFromHistory(weatherHistory) {
if (!weatherHistory) return [];
return weatherHistory.map(h => h.status);
}
function getWeatherEmoji(weatherHistory) {
if (!weatherHistory || weatherHistory.length === 0) return '❓';
const weather = getWeatherFromHistory(weatherHistory);
const passedCount = weather.filter(w => w === 'passed').length;
const percentage = (passedCount / weather.length) * 100;
if (percentage === 100) return '☀️';
if (percentage >= 85) return '🌤️';
if (percentage >= 70) return '⛅';
if (percentage >= 50) return '🌧️';
return '⛈️';
}
function getWeatherPercentage(weatherHistory) {
if (!weatherHistory || weatherHistory.length === 0) return 0;
const weather = getWeatherFromHistory(weatherHistory);
const passedCount = weather.filter(w => w === 'passed').length;
return Math.round((passedCount / weather.length) * 100);
}
function getSectionStats(tests) {
const failed = tests.filter(t => t.status === 'failed').length;
const passed = tests.filter(t => t.status === 'passed').length;
const notRun = tests.filter(t => t.status === 'not_run' || t.status === 'running').length;
// Count total failure days across all tests in section
const totalFailureDays = tests.reduce((sum, t) => {
const failDays = (t.weatherHistory || []).filter(w => w.status === 'failed').length;
return sum + failDays;
}, 0);
// Calculate overall weather
const allWeather = tests.flatMap(t => t.weatherHistory || []);
const weatherPercent = getWeatherPercentage(allWeather);
const weatherEmoji = getWeatherEmoji(allWeather);
return { failed, passed, notRun, total: tests.length, totalFailureDays, weatherPercent, weatherEmoji };
}
function getTotalStats() {
if (!state.data) return { total: 0, failed: 0, passed: 0, notRun: 0, failureDays: 0 };
// Get tests from the appropriate source based on view mode
let testsToCount = [];
if (state.viewMode === 'tee') {
const section = state.data.sections?.find(s => s.id === 'tee');
testsToCount = section?.tests || [];
} else if (state.viewMode === 'nvidia') {
const section = state.data.sections?.find(s => s.id === 'nvidia-gpu');
testsToCount = section?.tests || [];
} else if (state.viewMode === 'ibm') {
const section = state.data.sections?.find(s => s.id === 'ibm');
testsToCount = section?.tests || [];
} else if (state.viewMode === 'autogen-policy') {
const section = state.data.sections?.find(s => s.id === 'nightly-autogen-policy');
testsToCount = section?.tests || [];
} else if (state.viewMode === 'coco-charts') {
testsToCount = state.data.cocoChartsSection?.tests || [];
} else {
// For 'all' and 'required' views, use allJobsSection
testsToCount = state.data.allJobsSection?.tests || state.data.sections?.flatMap(s => s.tests) || [];
}
// Apply required filter if enabled (not applicable for coco-charts)
if (state.showRequiredOnly && state.viewMode !== 'coco-charts') {
testsToCount = testsToCount.filter(t => matchesCategory(t, 'required'));
}
// Apply status and search filters
const filteredTests = filterTests(testsToCount);
// Count failure DAYS across filtered tests (sum of days each test failed)
const failureDays = filteredTests.reduce((sum, t) => {
return sum + (t.weatherHistory || []).filter(w => w.status === 'failed').length;
}, 0);
return {
total: filteredTests.length,
failed: filteredTests.filter(t => t.status === 'failed').length,
passed: filteredTests.filter(t => t.status === 'passed').length,
notRun: filteredTests.filter(t => t.status === 'not_run').length,
failureDays: failureDays
};
}
/**
* Check if a job matches a category filter
*/
function matchesCategory(test, category) {
if (category === 'all') return true;
const jobName = test.jobName || test.fullName || test.name || '';
// For 'tee', 'nvidia', 'ibm', and 'autogen-policy', use the configured sections (exact match)
if (category === 'tee' || category === 'nvidia' || category === 'ibm' || category === 'autogen-policy') {
// Check if this job is in the configured section
const sectionId = category === 'tee' ? 'tee' : (category === 'nvidia' ? 'nvidia-gpu' : (category === 'ibm' ? 'ibm' : 'nightly-autogen-policy'));
const section = state.data?.sections?.find(s => s.id === sectionId);
if (section) {
return section.tests.some(t => t.fullName === jobName || t.jobName === jobName);
}
return false;
}
// Check required jobs
if (category === 'required') {
if (test.isRequired) return true;
// Fallback: check against requiredTests list from gatekeeper
const requiredTests = state.data?.requiredTests || [];
return requiredTests.some(req => {
const reqLower = req.toLowerCase();
const jobLower = jobName.toLowerCase();
// Check if the required test path ends with this job name
return reqLower === jobLower || reqLower.endsWith(jobLower) || reqLower.endsWith(' / ' + jobLower);
});
}
return false;
}
function filterTests(tests) {
let filtered = tests;
// Filter by required (applies to all view modes)
if (state.showRequiredOnly) {
filtered = filtered.filter(t => matchesCategory(t, 'required'));
}
// Filter by status
if (state.filter !== 'all') {
filtered = filtered.filter(t => t.status === state.filter);
}
// Filter by search query - match against display name AND full job name
// This allows users to search by either the pretty name (e.g. "QEMU + CoCo dev")
// or the full job name (e.g. "qemu-coco-dev-kata-qemu")
if (state.searchQuery) {
const query = state.searchQuery.toLowerCase();
filtered = filtered.filter(t => {
const nameMatch = t.name?.toLowerCase().includes(query);
const jobNameMatch = t.jobName?.toLowerCase().includes(query);
const fullNameMatch = t.fullName?.toLowerCase().includes(query);
return nameMatch || jobNameMatch || fullNameMatch;
});
}
// Apply sorting
filtered = sortTests(filtered);
return filtered;
}
/**
* Sort tests based on current sort setting
*/
function sortTests(tests, sortBy = state.sortBy) {
const sorted = [...tests];
switch (sortBy) {
case 'name':
// Alphabetical by name
sorted.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
break;
case 'failures-desc':
// Most failures first (from weather history)
sorted.sort((a, b) => {
const aFailures = getFailureCount(a);
const bFailures = getFailureCount(b);
// Secondary sort by name for ties
if (bFailures === aFailures) {
return (a.name || '').localeCompare(b.name || '');
}
return bFailures - aFailures;
});
break;
case 'pass-rate-asc':
// Lowest pass rate first
sorted.sort((a, b) => {
const aRate = getPassRate(a);
const bRate = getPassRate(b);
// Secondary sort by name for ties
if (aRate === bRate) {
return (a.name || '').localeCompare(b.name || '');
}
return aRate - bRate;
});
break;
case 'last-failure':
// Most recent failure first
sorted.sort((a, b) => {
const aDate = getLastFailureDate(a);
const bDate = getLastFailureDate(b);
// Tests with no failures go to the end
if (!aDate && !bDate) return (a.name || '').localeCompare(b.name || '');
if (!aDate) return 1;
if (!bDate) return -1;
return bDate - aDate;
});
break;
case 'status':
// Failed first, then not_run, then passed
const statusOrder = { 'failed': 0, 'not_run': 1, 'running': 2, 'passed': 3 };
sorted.sort((a, b) => {
const aOrder = statusOrder[a.status] ?? 4;
const bOrder = statusOrder[b.status] ?? 4;
if (aOrder === bOrder) {
// Secondary sort by failure count
return getFailureCount(b) - getFailureCount(a);
}
return aOrder - bOrder;
});
break;
default:
// No sorting
break;
}
return sorted;
}
/**
* Get failure count from weather history
*/
function getFailureCount(test) {
if (!test.weatherHistory) return 0;
return test.weatherHistory.filter(w => w.status === 'failed').length;
}
/**
* Get pass rate (0-100) from weather history
*/
function getPassRate(test) {
if (!test.weatherHistory || test.weatherHistory.length === 0) return 100;
const total = test.weatherHistory.filter(w => w.status !== 'none').length;
if (total === 0) return 100;
const passed = test.weatherHistory.filter(w => w.status === 'passed').length;
return (passed / total) * 100;
}
/**
* Get last failure date from weather history
*/
function getLastFailureDate(test) {
if (!test.weatherHistory) return null;
const lastFailure = test.weatherHistory
.filter(w => w.status === 'failed')
.sort((a, b) => new Date(b.date) - new Date(a.date))[0];
return lastFailure ? new Date(lastFailure.date) : null;
}
function formatDate() {
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
return new Date().toLocaleDateString('en-US', options);
}
function formatRelativeTime(dateString) {
if (!dateString) return 'N/A';
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffMins = Math.floor(diffMs / 60000);
if (diffMins < 1) return 'Just now';
if (diffMins < 60) return `${diffMins}m ago`;
const diffHours = Math.floor(diffMins / 60);
if (diffHours < 24) return `${diffHours}h ago`;
const diffDays = Math.floor(diffHours / 24);
if (diffDays === 1) return 'Yesterday';
if (diffDays < 7) return `${diffDays} days ago`;
return date.toLocaleDateString();
}
/**
* Resolve maintainer handles to display names with GitHub links
* @param {string[]} handles - Array of maintainer handles (e.g., ["@fidencio"])
* @returns {string} - HTML string with maintainer links
*/
function renderMaintainers(handles) {
if (!handles || handles.length === 0) return '';
const directory = state.data?.maintainersDirectory || {};
const maintainerLinks = handles.map(handle => {
const maintainer = directory[handle];
if (!maintainer) {
// Fallback: just show the handle as a GitHub link
const username = handle.replace(/^@/, '');
return `<a href="https://github.com/${username}" target="_blank" class="maintainer-link">${handle}</a>`;
}
const github = maintainer.github || handle.replace(/^@/, '');
const name = maintainer.name || handle;
return `<a href="https://github.com/${github}" target="_blank" class="maintainer-link" title="${name}">${handle}</a>`;
});
return maintainerLinks.join(', ');
}
/**
* Get maintainer names (without links) for compact display
*/
function getMaintainerNames(handles) {
if (!handles || handles.length === 0) return '';
const directory = state.data?.maintainersDirectory || {};
return handles.map(handle => {
const maintainer = directory[handle];
return maintainer?.name || handle;
}).join(', ');
}
// ============================================
// Render Functions
// ============================================
function renderLoading() {
const container = document.getElementById('sections-container');
container.innerHTML = `
<div class="loading-state">
<div class="loading-spinner">⟳</div>
<h3>Loading dashboard data...</h3>
<p>Fetching latest CI results</p>
</div>
`;
}
function renderError() {
const container = document.getElementById('sections-container');
container.innerHTML = `
<div class="error-state">
<div class="error-icon">📊</div>
<h3>No Data Available Yet</h3>
<p>The dashboard is waiting for the first data refresh.</p>
<p class="error-hint">
Run the "Update CI Dashboard Data" workflow in
<a href="https://github.com/kata-containers/ci-dashboard/actions" target="_blank">GitHub Actions</a>
to fetch initial data.
</p>
<button class="btn btn-primary" onclick="loadData()">
⟳ Try Again
</button>
</div>
`;
// Update stats to show zeros
document.getElementById('total-tests').textContent = '0';
document.getElementById('failed-tests').textContent = '0';
document.getElementById('not-run-tests').textContent = '0';
document.getElementById('passed-tests').textContent = '0';
}
function render() {
if (state.loading) {
renderLoading();
return;
}
if (state.error || !state.data) {
renderError();
return;
}
updateStats();
renderSections();
updateJobCount();
renderRenameWarnings();
// Update last refresh time
if (state.data.lastRefresh) {
document.getElementById('last-refresh-time').textContent =
formatRelativeTime(state.data.lastRefresh);
}
}
/**
* Render warning banner for detected job renames
*/
function renderRenameWarnings() {
const container = document.getElementById('rename-warnings');
if (!container) return;
// Get renames detected within last 3 days
const threeDaysAgo = new Date();
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
const recentRenames = (state.data.detectedRenames || []).filter(rename => {
const detectedDate = new Date(rename.detectedDate);
return detectedDate > threeDaysAgo;
});
if (recentRenames.length === 0) {
container.innerHTML = '';
container.style.display = 'none';
return;
}
container.style.display = 'block';
const renamesList = recentRenames.map(rename => {
const detectedDate = new Date(rename.detectedDate);
const formattedDate = detectedDate.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
return `
<div class="rename-item">
<span class="rename-old">"${escapeHtml(rename.oldName)}"</span>
<span class="rename-arrow">→</span>
<span class="rename-new">"${escapeHtml(rename.newName)}"</span>
<span class="rename-date">(detected ${formattedDate})</span>
</div>
`;
}).join('');
const configPatch = recentRenames.map(rename =>
` - old: "${rename.oldName}"\n new: "${rename.newName}"`
).join('\n');
container.innerHTML = `
<div class="rename-warning-banner">
<div class="rename-warning-header">
<span class="rename-warning-icon">⚠️</span>
<span class="rename-warning-title">Potential Job Renames Detected</span>
</div>
<p class="rename-warning-description">
The following jobs appear to have been renamed. History has been merged automatically.
</p>
<div class="rename-list">
${renamesList}
</div>
<div class="rename-action">
<p>If this is incorrect (these are separate tests), open a PR to add this to <code>ci-dashboard/config.yaml</code>:</p>
<pre class="rename-config-patch">not_a_rename:
${configPatch}</pre>
</div>
</div>
`;
}
/**
* Escape HTML to prevent XSS
*/
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function renderSections() {
const container = document.getElementById('sections-container');
container.innerHTML = '';
if (!state.data) {
container.innerHTML = `
<div class="empty-state">
<h3>No data available</h3>
<p>Waiting for data to load...</p>
</div>
`;
return;
}
// Determine which data source to use based on view mode
let sectionsToRender = [];
if (state.viewMode === 'tee') {
// Use the configured TEE section (with descriptive names)
const teeSection = state.data.sections?.find(s => s.id === 'tee');
if (teeSection) {
const filteredTests = filterTests(teeSection.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...teeSection, tests: filteredTests });
}
}
} else if (state.viewMode === 'nvidia') {
// Use the configured NVIDIA section (with descriptive names)
const nvidiaSection = state.data.sections?.find(s => s.id === 'nvidia-gpu');
if (nvidiaSection) {
const filteredTests = filterTests(nvidiaSection.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...nvidiaSection, tests: filteredTests });
}
}
} else if (state.viewMode === 'ibm') {
// Use the configured IBM section (s390x tests)
const ibmSection = state.data.sections?.find(s => s.id === 'ibm');
if (ibmSection) {
const filteredTests = filterTests(ibmSection.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...ibmSection, tests: filteredTests });
}
}
} else if (state.viewMode === 'autogen-policy') {
const autogenSection = state.data.sections?.find(s => s.id === 'nightly-autogen-policy');
if (autogenSection) {
const filteredTests = filterTests(autogenSection.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...autogenSection, tests: filteredTests });
}
}
} else if (state.viewMode === 'coco-charts') {
// Use the CoCo Charts section (external repo)
const cocoSection = state.data.cocoChartsSection;
if (cocoSection) {
const filteredTests = filterTests(cocoSection.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...cocoSection, tests: filteredTests });
}
}
} else if (state.data.allJobsSection) {
// For 'all' and 'required' views, use allJobsSection (flat list with simplified names)
// The required filter is applied in filterTests() via showRequiredOnly flag
const allJobs = state.data.allJobsSection;
const filteredTests = filterTests(allJobs.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({
...allJobs,
tests: filteredTests
});
}
} else if (state.data.sections && state.data.sections.length > 0) {
// Fallback to configured sections
state.data.sections.forEach(section => {
const filteredTests = filterTests(section.tests || []);
if (filteredTests.length > 0) {
sectionsToRender.push({ ...section, tests: filteredTests });
}
});
}
if (sectionsToRender.length === 0) {
container.innerHTML = `
<div class="empty-state">
<h3>No jobs found</h3>
<p>No jobs match the current filter criteria.</p>
</div>
`;
return;
}
sectionsToRender.forEach(section => {
const tests = section.tests || [];
if (tests.length === 0) return;
const stats = getSectionStats(tests);
const isExpanded = state.expandedSections.has(section.id) || state.viewMode !== 'all' || state.showRequiredOnly || state.searchQuery;
const sectionEl = document.createElement('div');
sectionEl.className = `section ${isExpanded ? 'expanded' : ''}`;
// Build status badges for section
const statusBadges = [];
if (stats.failed > 0) {
statusBadges.push(`<span class="section-status has-failed">(${stats.failed} failed)</span>`);
}
if (stats.notRun > 0) {
statusBadges.push(`<span class="section-status has-not-run">(${stats.notRun} not run)</span>`);
}
if (statusBadges.length === 0 && stats.passed === stats.total) {
statusBadges.push(`<span class="section-status all-green">All Green</span>`);
}
// Build section title
let sectionTitle = section.name;
if (state.showRequiredOnly && section.id === 'all-jobs') {
sectionTitle = 'Required Jobs';
}
sectionEl.innerHTML = `
<div class="section-header" data-section="${section.id}">
<span class="section-toggle">▶</span>
<span class="section-name">${sectionTitle}</span>
<div class="section-meta">
<span class="section-count">${tests.length} jobs</span>
<span class="section-weather">
<span class="section-weather-icon">${stats.weatherEmoji}</span>
${stats.weatherPercent}%
</span>
${statusBadges.join('')}
</div>
</div>
<div class="section-content">
${renderTestGroups(section, tests)}
</div>
`;
container.appendChild(sectionEl);
});
// Add click handlers for section headers
document.querySelectorAll('.section-header').forEach(header => {
header.addEventListener('click', () => {
const sectionId = header.dataset.section;
toggleSection(sectionId);
});
});
// Add click handlers for test group headers
document.querySelectorAll('.test-group-header').forEach(header => {
header.addEventListener('click', (e) => {
if (e.target.closest('.btn')) return;
const groupId = header.dataset.group;
toggleGroup(groupId);
});
});
// Add click handlers for test names (show error if available)
document.querySelectorAll('.test-name-text[data-test-id]').forEach(el => {
el.addEventListener('click', (e) => {
e.stopPropagation();
const testId = el.dataset.testId;
const sectionId = el.dataset.sectionId;
showErrorModal(sectionId, testId);
});
});
// Add click handlers for failure badges (show weather/analysis)
document.querySelectorAll('.test-failure-badge').forEach(badge => {
badge.addEventListener('click', (e) => {
e.stopPropagation();
const testId = badge.dataset.testId;
const sectionId = badge.dataset.sectionId;
showWeatherModal(sectionId, testId);
});
});
// Add click handlers for weather columns
document.querySelectorAll('.test-weather-col[data-test-id]').forEach(col => {
col.addEventListener('click', (e) => {
e.stopPropagation();
const testId = col.dataset.testId;
const sectionId = col.dataset.sectionId;
showWeatherModal(sectionId, testId);
});
});
}
function renderTestGroups(section, tests) {
const failed = tests.filter(t => t.status === 'failed');
const notRun = tests.filter(t => t.status === 'not_run');
const passed = tests.filter(t => t.status === 'passed');
let html = '';
// Failed tests
if (failed.length > 0) {
const groupId = `${section.id}-failed`;
const isExpanded = state.expandedGroups.has(groupId) || state.filter === 'failed';
html += renderTestGroup(section, failed, groupId, 'FAILED', 'failed', isExpanded);
}
// Not run tests
if (notRun.length > 0) {
const groupId = `${section.id}-not-run`;
const isExpanded = state.expandedGroups.has(groupId) || state.filter === 'not_run';
html += renderTestGroup(section, notRun, groupId, 'NOT RUN', 'not-run', isExpanded);
}
// Passed tests
if (passed.length > 0) {
const groupId = `${section.id}-passed`;
const isExpanded = state.expandedGroups.has(groupId) || state.filter === 'passed';
html += renderTestGroup(section, passed, groupId, 'PASSED', 'passed', isExpanded);
}
return html;
}
function renderTestGroup(section, tests, groupId, label, statusClass, isExpanded) {
return `
<div class="test-group ${isExpanded ? 'expanded' : ''}" data-group-id="${groupId}">
<div class="test-group-header" data-group="${groupId}">
<div class="test-group-title">
<span class="test-group-toggle">▶</span>
<span class="dot dot-${statusClass}"></span>
${label} (${tests.length})
</div>
</div>
<div class="test-group-content">
<div class="test-table-header">
<span>Test Name</span>
<span>Maintainers</span>
<span>Run</span>
<span>Last Failure</span>
<span>Last Success</span>
<span class="weather-header">Weather <span class="weather-range">(oldest ← 10 days → newest)</span></span>
<span>Retried</span>
</div>
${tests.map(t => renderTestRow(section.id, t)).join('')}
</div>
</div>
`;
}
function renderTestRow(sectionId, test) {
const weather = getWeatherFromHistory(test.weatherHistory);
const weatherDots = weather.length > 0
? weather.map(w => `<span class="weather-dot ${w}"></span>`).join('')
: '<span class="weather-dot none"></span>'.repeat(10);
const weatherEmoji = getWeatherEmoji(test.weatherHistory);
const passedCount = weather.filter(w => w === 'passed').length;
const failedCount = weather.filter(w => w === 'failed').length;
const statusDisplay = {
'passed': '● Passed',
'failed': '○ Failed',
'not_run': '⊘ Not Run',
'running': '◌ Running'
};
// Check if there are failing tests to show
const hasFailingTests = test.failedTestsInWeather && test.failedTestsInWeather.length > 0;
const failingTestsPreview = hasFailingTests
? test.failedTestsInWeather.slice(0, 2).map(f => f.name.substring(0, 40)).join(', ')
: '';
// Build inline failure info
const failureInfo = [];
if (test.error && test.error.failures?.length > 0) {
failureInfo.push(`${test.error.failures.length} test${test.error.failures.length > 1 ? 's' : ''} failed`);
}
if (hasFailingTests) {
const uniqueCount = test.failedTestsInWeather.length;
const totalOccurrences = test.failedTestsInWeather.reduce((s, f) => s + f.count, 0);
failureInfo.push(`${uniqueCount} unique failure${uniqueCount > 1 ? 's' : ''} in 10 days`);
}
const maintainersHtml = test.maintainers && test.maintainers.length > 0
? renderMaintainers(test.maintainers)
: '<span class="no-maintainer">—</span>';
return `
<div class="test-row ${test.status}">
<div class="test-name-col">
<div class="test-name">
<span class="test-status-dot ${test.status}"></span>
<span class="test-name-text" ${test.error ? `data-test-id="${test.id}" data-section-id="${sectionId}" style="cursor:pointer"` : ''}>${test.name}</span>
${test.isRequired ? '<span class="required-badge">required</span>' : ''}
${failureInfo.length > 0 ? `
<span class="test-failure-badge" data-test-id="${test.id}" data-section-id="${sectionId}">
⚠️ ${failureInfo.join(' · ')}
</span>
` : ''}
</div>
</div>
<div class="test-maintainers-col">
${maintainersHtml}
</div>
<div class="test-run-col">
<span class="test-run-status ${test.status}">${statusDisplay[test.status] || test.status}</span>
<span class="test-run-duration">${test.duration || 'N/A'}</span>
</div>
<div class="test-time-col">
${test.lastFailure === 'Never' || !test.lastFailure ? '<span class="never">Never</span>' : test.lastFailure}
</div>
<div class="test-time-col">
${test.lastSuccess || 'N/A'}
</div>
<div class="test-weather-col" data-test-id="${test.id}" data-section-id="${sectionId}" title="Click for 10-day history">
<div class="weather-dots">${weatherDots}</div>
<div class="weather-summary">
<span class="weather-icon">${weatherEmoji}</span>
${passedCount}/${weather.length || 10}
${failedCount > 0 ? `<span class="weather-failed-count">(${failedCount} ✗)</span>` : ''}
</div>
</div>
<div class="test-retried-col">
${test.retried || 0}
${test.setupRetry ? '<span class="setup-retry">⚙️ (setup)</span>' : ''}
</div>
</div>
`;
}
function updateStats() {
const stats = getTotalStats();
document.getElementById('total-tests').textContent = stats.total;
document.getElementById('failed-tests').textContent = stats.failed;
document.getElementById('not-run-tests').textContent = stats.notRun;
document.getElementById('passed-tests').textContent = stats.passed;
// Get tests based on current view mode for filter counts
let viewTests = [];
if (state.viewMode === 'tee') {
const section = state.data?.sections?.find(s => s.id === 'tee');
viewTests = section?.tests || [];
} else if (state.viewMode === 'nvidia') {
const section = state.data?.sections?.find(s => s.id === 'nvidia-gpu');
viewTests = section?.tests || [];
} else if (state.viewMode === 'ibm') {
const section = state.data?.sections?.find(s => s.id === 'ibm');
viewTests = section?.tests || [];
} else if (state.viewMode === 'autogen-policy') {
const section = state.data?.sections?.find(s => s.id === 'nightly-autogen-policy');
viewTests = section?.tests || [];
} else if (state.viewMode === 'coco-charts') {
viewTests = state.data?.cocoChartsSection?.tests || [];
} else {
// For 'all' and 'required' views, use allJobsSection
viewTests = state.data?.allJobsSection?.tests || state.data?.sections?.flatMap(s => s.tests) || [];
}
// Apply required filter if enabled (not applicable for coco-charts)
if (state.showRequiredOnly && state.viewMode !== 'coco-charts') {
viewTests = viewTests.filter(t => matchesCategory(t, 'required'));
}
document.getElementById('filter-failed-count').textContent = viewTests.filter(t => t.status === 'failed').length;
document.getElementById('filter-not-run-count').textContent = viewTests.filter(t => t.status === 'not_run').length;
document.getElementById('filter-passed-count').textContent = viewTests.filter(t => t.status === 'passed').length;
}
// ============================================
// Event Handlers
// ============================================
function toggleSection(sectionId) {
if (state.expandedSections.has(sectionId)) {
state.expandedSections.delete(sectionId);
} else {
state.expandedSections.add(sectionId);
}
renderSections();
// Scroll to the clicked section after re-render
setTimeout(() => {
const sectionEl = document.querySelector(`.section-header[data-section="${sectionId}"]`);
if (sectionEl) {
sectionEl.scrollIntoView({ behavior: 'instant', block: 'nearest' });
}
}, 0);
}
function toggleGroup(groupId) {
if (state.expandedGroups.has(groupId)) {
state.expandedGroups.delete(groupId);
} else {
state.expandedGroups.add(groupId);
}
// Re-render the appropriate section based on active project and tab
if (state.activeProject === 'coco') {
if (state.activeCocoTab === 'coco-charts') {
renderCocoSections();
} else if (state.activeCocoTab === 'coco-caa') {
renderCAASections();
}
} else {
renderSections();
}
// Scroll to the clicked group after re-render
setTimeout(() => {
const groupEl = document.querySelector(`.test-group-header[data-group="${groupId}"]`);
if (groupEl) {
groupEl.scrollIntoView({ behavior: 'instant', block: 'nearest' });
}
}, 0);
}
function setFilter(filter) {
state.filter = filter;
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.filter === filter);
});
renderSections();
updateJobCount();
}
function setViewMode(mode) {
state.viewMode = mode;
// Update quick filter buttons (TEE/NVIDIA)
document.querySelectorAll('.quick-filter-btn').forEach(btn => {
const btnMode = btn.dataset.category;
btn.classList.toggle('active', btnMode === mode);
});
// When switching to TEE/NVIDIA, the All button should still show the current required state
updateAllRequiredButtons();
updateStats();
renderSections();
updateJobCount();
}
function toggleRequiredFilter() {