hub-dashboard-ia-inbox.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago
| 1 | /** |
| 2 | * Seven-tier contracts for HUB-DASH-IA-c (Review inbox + Vault search + Insights). |
| 3 | * Ground truth: docs/reviews/2026-07-29-hub-dashboard-ia.md (expert items 2–6, 8, 13, 17). |
| 4 | */ |
| 5 | import { describe, it } from 'node:test'; |
| 6 | import assert from 'node:assert/strict'; |
| 7 | import fs from 'node:fs'; |
| 8 | import path from 'node:path'; |
| 9 | import { fileURLToPath } from 'node:url'; |
| 10 | import { |
| 11 | hubChromeVisibility, |
| 12 | formatRelativeTime, |
| 13 | reviewRowNeedsPendingEvalChip, |
| 14 | formatReviewSplitPosition, |
| 15 | shouldExpandVaultAdvancedFilters, |
| 16 | emptyReviewPrimaryCtaLabel, |
| 17 | emptyReviewSecondaryCtaLabel, |
| 18 | shouldShowPendingEvalQuickChip, |
| 19 | clampListKeyboardIndex, |
| 20 | hubCriticalDataTabs, |
| 21 | } from '../web/hub/hub-shell-ia.mjs'; |
| 22 | |
| 23 | const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); |
| 24 | const hubHtml = fs.readFileSync(path.join(root, 'web/hub/index.html'), 'utf8'); |
| 25 | const hubJs = fs.readFileSync(path.join(root, 'web/hub/hub.js'), 'utf8'); |
| 26 | const hubCss = fs.readFileSync(path.join(root, 'web/hub/hub.css'), 'utf8'); |
| 27 | |
| 28 | describe('HUB-DASH-IA-c unit', () => { |
| 29 | it('chrome visibility: Review hides note search; Vault shows; Insights hides search', () => { |
| 30 | assert.deepEqual(hubChromeVisibility('suggested', 'list'), { |
| 31 | noteSearch: false, |
| 32 | browseToolbar: false, |
| 33 | proposalFilters: true, |
| 34 | insights: false, |
| 35 | }); |
| 36 | assert.deepEqual(hubChromeVisibility('notes', 'list'), { |
| 37 | noteSearch: true, |
| 38 | browseToolbar: true, |
| 39 | proposalFilters: false, |
| 40 | insights: false, |
| 41 | }); |
| 42 | assert.deepEqual(hubChromeVisibility('notes', 'graph'), { |
| 43 | noteSearch: false, |
| 44 | browseToolbar: false, |
| 45 | proposalFilters: false, |
| 46 | insights: true, |
| 47 | }); |
| 48 | assert.equal(hubChromeVisibility('activity', 'list').proposalFilters, true); |
| 49 | }); |
| 50 | |
| 51 | it('relative time + pending-eval chip + N of M + keyboard clamp', () => { |
| 52 | const now = Date.parse('2026-07-29T12:00:00Z'); |
| 53 | assert.equal(formatRelativeTime('2026-07-29T11:59:30Z', now), 'just now'); |
| 54 | assert.equal(formatRelativeTime('2026-07-29T11:00:00Z', now), '1h ago'); |
| 55 | assert.equal(formatRelativeTime('2026-07-28T12:00:00Z', now), '1d ago'); |
| 56 | assert.equal(formatRelativeTime('', now), ''); |
| 57 | assert.equal(reviewRowNeedsPendingEvalChip('pending'), true); |
| 58 | assert.equal(reviewRowNeedsPendingEvalChip('pass'), false); |
| 59 | assert.equal(formatReviewSplitPosition(3, 12), '3 of 12'); |
| 60 | assert.equal(formatReviewSplitPosition(0, 5), ''); |
| 61 | assert.equal(clampListKeyboardIndex(99, 5), 4); |
| 62 | assert.equal(clampListKeyboardIndex(-1, 5), 0); |
| 63 | assert.equal(clampListKeyboardIndex(1, 0), 0); |
| 64 | }); |
| 65 | |
| 66 | it('empty Review CTAs and pending-eval quick chip policy', () => { |
| 67 | assert.equal(emptyReviewPrimaryCtaLabel(), 'New proposal'); |
| 68 | assert.equal(emptyReviewSecondaryCtaLabel(), 'How Review works'); |
| 69 | assert.equal(shouldShowPendingEvalQuickChip(true), true); |
| 70 | assert.equal(shouldShowPendingEvalQuickChip(false), false); |
| 71 | assert.equal(shouldExpandVaultAdvancedFilters(false, false), false); |
| 72 | assert.equal(shouldExpandVaultAdvancedFilters(true, false), true); |
| 73 | assert.equal(shouldExpandVaultAdvancedFilters(false, true), true); |
| 74 | }); |
| 75 | }); |
| 76 | |
| 77 | describe('HUB-DASH-IA-c integration (source wiring)', () => { |
| 78 | it('syncModeToolbars hides search on Review and wires Insights → graph + consolidation', () => { |
| 79 | assert.match(hubJs, /function\s+syncModeToolbars\s*\(/); |
| 80 | assert.match(hubJs, /hubChromeVisibility\s*\(/); |
| 81 | assert.match(hubJs, /function\s+runHubSecondaryAction\s*\(/); |
| 82 | assert.match( |
| 83 | hubJs, |
| 84 | /key\s*===\s*['"]insights['"][\s\S]{0,200}switchNotesView\(\s*['"]graph['"]\s*\)/, |
| 85 | ); |
| 86 | assert.match(hubJs, /view\s*===\s*['"]graph['"][\s\S]{0,120}refreshConsolidationCard/); |
| 87 | assert.match(hubHtml, /id="consolidation-card"/); |
| 88 | assert.match(hubHtml, /id="notes-view-graph"/); |
| 89 | assert.match(hubHtml, /data-view="graph"/); |
| 90 | }); |
| 91 | |
| 92 | it('Review empty CTAs + pending-eval chip toggle filter', () => { |
| 93 | assert.match(hubJs, /empty-suggested-new/); |
| 94 | assert.match(hubJs, /How Review works|emptyReviewSecondaryCtaLabel/); |
| 95 | assert.match(hubHtml, /id="proposal-pending-eval-chip"/); |
| 96 | assert.match(hubJs, /proposal-pending-eval-chip[\s\S]{0,400}proposal-filter-pending-eval/); |
| 97 | assert.match(hubJs, /id="empty-suggested-how-to"/); |
| 98 | }); |
| 99 | |
| 100 | it('primary actions / eval sit above diffs; detail-actions before body wrap', () => { |
| 101 | const detail = hubHtml.match(/id="detail-panel"[\s\S]*?<\/aside>/); |
| 102 | assert.ok(detail); |
| 103 | const actionsAt = detail[0].indexOf('id="detail-actions"'); |
| 104 | const bodyAt = detail[0].indexOf('detail-body-wrap'); |
| 105 | assert.ok(actionsAt >= 0 && bodyAt > actionsAt, 'detail-actions must precede detail-body-wrap'); |
| 106 | assert.match(hubJs, /proposal-primary-eval/); |
| 107 | assert.match(hubJs, /primaryEvalBlock[\s\S]{0,200}proposal-diff-grid/); |
| 108 | }); |
| 109 | }); |
| 110 | |
| 111 | describe('HUB-DASH-IA-c e2e static contract', () => { |
| 112 | it('Vault search-first command bar; advanced filters in collapsed details', () => { |
| 113 | assert.match(hubHtml, /id="hub-search-section"/); |
| 114 | assert.match(hubHtml, /id="hub-search-advanced"/); |
| 115 | assert.match(hubHtml, /class="search-row search-row-primary"/); |
| 116 | assert.match(hubCss, /\.search-row-primary\s*\{[\s\S]*?max-width:\s*42rem/); |
| 117 | assert.match(hubCss, /\.search-row-primary #search-query\s*\{[\s\S]*?max-width:\s*18rem/); |
| 118 | const adv = hubHtml.match(/id="hub-search-advanced"[\s\S]*?<\/details>/); |
| 119 | assert.ok(adv); |
| 120 | assert.match(adv[0], /id="filter-project"/); |
| 121 | assert.match(adv[0], /id="btn-apply-filters"/); |
| 122 | assert.match(adv[0], /id="btn-reindex"/); |
| 123 | // Primary row keeps Meaning/Keyword + Search/Clear |
| 124 | const primary = hubHtml.match(/search-row-primary[\s\S]*?<\/div>/); |
| 125 | assert.ok(primary); |
| 126 | assert.match(primary[0], /id="search-query"/); |
| 127 | assert.match(primary[0], /id="search-mode"/); |
| 128 | assert.match(primary[0], /id="btn-search"/); |
| 129 | assert.match(primary[0], /id="btn-clear-search"/); |
| 130 | assert.doesNotMatch(primary[0], /id="filter-project"/); |
| 131 | }); |
| 132 | |
| 133 | it('Review row density hooks + split position + keyboard arrows', () => { |
| 134 | assert.match(hubJs, /review-row/); |
| 135 | assert.match(hubJs, /proposal-chip-pending-eval|Pending eval/); |
| 136 | assert.match(hubJs, /formatRelativeTime/); |
| 137 | assert.match(hubHtml, /id="detail-split-position"/); |
| 138 | assert.match(hubJs, /ArrowDown/); |
| 139 | assert.match(hubJs, /ArrowUp/); |
| 140 | assert.match(hubJs, /updateProposalListSelection/); |
| 141 | }); |
| 142 | }); |
| 143 | |
| 144 | describe('HUB-DASH-IA-c stress', () => { |
| 145 | it('relative time and N-of-M safe across large indices', () => { |
| 146 | const now = Date.now(); |
| 147 | for (let i = 0; i < 200; i++) { |
| 148 | const iso = new Date(now - i * 3600_000).toISOString(); |
| 149 | const t = formatRelativeTime(iso, now); |
| 150 | assert.equal(typeof t, 'string'); |
| 151 | assert.ok(t.length > 0); |
| 152 | } |
| 153 | for (let n = 1; n <= 100; n++) { |
| 154 | assert.equal(formatReviewSplitPosition(n, 100), n + ' of 100'); |
| 155 | assert.equal(clampListKeyboardIndex(n + 50, n), n - 1); |
| 156 | } |
| 157 | }); |
| 158 | }); |
| 159 | |
| 160 | describe('HUB-DASH-IA-c data-integrity', () => { |
| 161 | it('critical search/proposal/detail IDs and data-tab values preserved', () => { |
| 162 | assert.deepEqual(hubCriticalDataTabs(), ['notes', 'suggested', 'activity', 'problem']); |
| 163 | const ids = [ |
| 164 | 'search-query', |
| 165 | 'search-mode', |
| 166 | 'btn-search', |
| 167 | 'btn-clear-search', |
| 168 | 'btn-apply-filters', |
| 169 | 'btn-reindex', |
| 170 | 'hub-index-status', |
| 171 | 'browse-toolbar', |
| 172 | 'proposal-filters-bar', |
| 173 | 'proposal-filter-pending-eval', |
| 174 | 'btn-new-proposal', |
| 175 | 'proposals-suggested', |
| 176 | 'detail-panel', |
| 177 | 'detail-actions', |
| 178 | 'detail-body', |
| 179 | 'consolidation-card', |
| 180 | 'hub-rail-insights', |
| 181 | ]; |
| 182 | for (const id of ids) { |
| 183 | assert.match(hubHtml, new RegExp('id="' + id + '"')); |
| 184 | } |
| 185 | // empty-suggested-how-to / proposal-eval IDs are injected in JS for empty/detail states |
| 186 | assert.match(hubJs, /empty-suggested-how-to/); |
| 187 | assert.match(hubJs, /proposal-eval-save/); |
| 188 | assert.match(hubJs, /proposal-waiver-reason/); |
| 189 | assert.match(hubJs, /proposal-open-note-btn/); |
| 190 | assert.match(hubJs, /\/api\/v1\/proposals\/['"]\s*\+\s*encodeURIComponent\(id\)\s*\+\s*['"]\/approve/); |
| 191 | assert.match(hubJs, /\/api\/v1\/proposals\/['"]\s*\+\s*encodeURIComponent\(id\)\s*\+\s*['"]\/discard/); |
| 192 | }); |
| 193 | }); |
| 194 | |
| 195 | describe('HUB-DASH-IA-c performance', () => { |
| 196 | it('advanced filters default-collapsed; Review does not mount note filter row', () => { |
| 197 | assert.equal(shouldExpandVaultAdvancedFilters(false, false), false); |
| 198 | const detailsOpen = /id="hub-search-advanced"[^>]*\sopen[\s>]/; |
| 199 | assert.doesNotMatch(hubHtml, detailsOpen); |
| 200 | assert.match(hubJs, /syncModeToolbars/); |
| 201 | assert.match(hubCss, /\.search-section\.hidden/); |
| 202 | // Review chrome: noteSearch false when suggested |
| 203 | assert.equal(hubChromeVisibility('suggested').noteSearch, false); |
| 204 | }); |
| 205 | }); |
| 206 | |
| 207 | describe('HUB-DASH-IA-c security', () => { |
| 208 | it('row/empty state use escapeHtml; no RBAC contract changes; no secrets', () => { |
| 209 | assert.match(hubJs, /escapeHtml\(primaryCta\)|escapeHtml\(secondaryCta\)/); |
| 210 | assert.match(hubJs, /escapeHtml\(rel\)|escapeHtml\(p\.path\)/); |
| 211 | assert.doesNotMatch(hubJs, /proposal-pending-eval-chip[\s\S]{0,80}innerHTML\s*=/); |
| 212 | assert.match(hubJs, /canApprove\s*=\s*isAdmin\s*\|\|\s*\(isEvaluator\s*&&\s*window\.__hubEvaluatorMayApprove\)/); |
| 213 | assert.match(hubJs, /canDiscard\s*=\s*isAdmin/); |
| 214 | assert.doesNotMatch(hubHtml + hubJs, /sk-[a-zA-Z0-9]{20,}/); |
| 215 | assert.doesNotMatch(hubHtml + hubJs, /BEGIN (RSA |OPENSSH )?PRIVATE KEY/); |
| 216 | }); |
| 217 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago