notices.spec.ts (9879B)
1 import { expect, test } from '@playwright/test'; 2 import { createHash } from 'node:crypto'; 3 import { execFileSync } from 'node:child_process'; 4 import { 5 cp, 6 mkdtemp, 7 mkdir, 8 readFile, 9 readdir, 10 rm, 11 writeFile 12 } from 'node:fs/promises'; 13 import { tmpdir } from 'node:os'; 14 import path from 'node:path'; 15 import { fileURLToPath } from 'node:url'; 16 import { createStaticHarness } from '../integration/harness/static.ts'; 17 18 // Isolated qualification clone: actual components compile into disposable output. 19 // The primary static payload and product route source are never overwritten. 20 const capsule = fileURLToPath(new URL('../../../', import.meta.url)); 21 let directory: string; 22 let server: Awaited<ReturnType<typeof createStaticHarness>>; 23 test.beforeAll(async () => { 24 test.setTimeout(86_400_000); 25 directory = await mkdtemp(path.join(tmpdir(), 'hcp016-notices-')); 26 try { 27 const checkout = path.join(directory, 'checkout'); 28 execFileSync('git', [ 29 'clone', 30 '--quiet', 31 '--no-hardlinks', 32 capsule, 33 checkout 34 ]); 35 for (const relative of [ 36 'web/src/lib/components/Notice.svelte', 37 'web/src/lib/components/OperationStatus.svelte', 38 'web/src/lib/components/ErrorSummary.svelte', 39 'web/src/lib/presentation/status-copy.ts', 40 'web/src/lib/publishing/listing-operation-view.ts', 41 'web/src/lib/publishing/sign-listing.ts', 42 'web/tests/unit/status-copy.test.ts', 43 'web/tests/unit/components/notices.test.ts', 44 'web/tests/unit/components/NoticeHarness.svelte', 45 'web/tests/e2e/notices.spec.ts', 46 'web/tests/e2e/harness/notices.svelte' 47 ]) { 48 await mkdir(path.dirname(path.join(checkout, relative)), { 49 recursive: true 50 }); 51 await cp(path.join(capsule, relative), path.join(checkout, relative)); 52 } 53 const fixture = await readFile( 54 path.join(capsule, 'web/tests/e2e/harness/notices.svelte'), 55 'utf8' 56 ); 57 await writeFile( 58 path.join(checkout, 'web/src/routes/+page.svelte'), 59 fixture.replaceAll('../../../src/lib/', '../lib/') 60 ); 61 // Runtime store metadata is volume-specific; install the exact locked graph 62 // into this disposable clone without a network or lock-repair fallback. 63 const sourceStore = execFileSync('corepack', ['pnpm', 'store', 'path'], { 64 cwd: path.join(capsule, 'web') 65 }) 66 .toString() 67 .trim(); 68 const installed = execFileSync( 69 'corepack', 70 [ 71 'pnpm', 72 'install', 73 '--offline', 74 '--frozen-lockfile', 75 '--store-dir', 76 path.dirname(sourceStore) 77 ], 78 { cwd: path.join(checkout, 'web'), stdio: 'pipe', timeout: 86400000 } 79 ); 80 const sourceAudit = execFileSync( 81 process.execPath, 82 ['tools/check-source.mjs'], 83 { cwd: path.join(checkout, 'web') } 84 ).toString(); 85 const identities = []; 86 for (const relative of [ 87 'web/src/lib/components/AppShell.svelte', 88 'web/src/lib/components/Notice.svelte', 89 'web/src/lib/components/OperationStatus.svelte', 90 'web/src/lib/components/ErrorSummary.svelte', 91 'web/src/lib/presentation/status-copy.ts', 92 'web/src/lib/publishing/listing-operation-view.ts', 93 'web/src/lib/publishing/sign-listing.ts', 94 'web/src/lib/components/primitives/FormField.svelte', 95 'web/src/lib/components/primitives/Button.svelte', 96 'web/src/app.css', 97 'web/src/theme.css', 98 'web/src/routes/+layout.svelte' 99 ]) { 100 identities.push({ 101 name: relative, 102 sha256: createHash('sha256') 103 .update(await readFile(path.join(checkout, relative))) 104 .digest('hex') 105 }); 106 } 107 execFileSync(process.execPath, ['tools/build-info.mjs'], { 108 cwd: path.join(checkout, 'web') 109 }); 110 const compiled = execFileSync( 111 process.execPath, 112 ['node_modules/vite/bin/vite.js', 'build'], 113 { 114 cwd: path.join(checkout, 'web'), 115 stdio: 'pipe', 116 timeout: 86400000 117 } 118 ); 119 async function payload( 120 directory: string, 121 prefix = '' 122 ): Promise<{ path: string; sha256: string }[]> { 123 const files = []; 124 for (const entry of await readdir(directory, { withFileTypes: true })) { 125 const relative = prefix + entry.name; 126 if (entry.isDirectory()) 127 files.push( 128 ...(await payload(path.join(directory, entry.name), relative + '/')) 129 ); 130 else 131 files.push({ 132 path: relative, 133 sha256: createHash('sha256') 134 .update(await readFile(path.join(directory, entry.name))) 135 .digest('hex') 136 }); 137 } 138 return files.sort((left, right) => left.path.localeCompare(right.path)); 139 } 140 console.log( 141 JSON.stringify({ 142 fixture: 'HCP016_TEST_ONLY_COMPILE', 143 identities, 144 sourceAudit, 145 productionRouteSha256: createHash('sha256') 146 .update( 147 await readFile(path.join(capsule, 'web/src/routes/+page.svelte')) 148 ) 149 .digest('hex'), 150 fixtureSourceSha256: createHash('sha256').update(fixture).digest('hex'), 151 compiledRouteSha256: createHash('sha256') 152 .update( 153 await readFile(path.join(checkout, 'web/src/routes/+page.svelte')) 154 ) 155 .digest('hex'), 156 compiledLayoutSha256: createHash('sha256') 157 .update( 158 await readFile(path.join(checkout, 'web/src/routes/+layout.svelte')) 159 ) 160 .digest('hex'), 161 retention: 162 'HASHLOGS_ONLY: disposable compiled fixture output is removed after tests', 163 payload: await payload(path.join(checkout, 'web/build')), 164 sourceStore, 165 installed: installed.toString(), 166 compiled: compiled.toString(), 167 metadata: JSON.parse( 168 await readFile( 169 path.join(checkout, 'web/build/build-info.json'), 170 'utf8' 171 ) 172 ) as unknown 173 }) 174 ); 175 server = await createStaticHarness({ 176 buildRoot: path.join(checkout, 'web/build') 177 }); 178 } catch (error) { 179 await rm(directory, { recursive: true, force: true }); 180 throw error; 181 } 182 }); 183 test.afterAll(async () => { 184 await server?.close(); 185 if (directory) await rm(directory, { recursive: true, force: true }); 186 if (server) 187 expect(server.state()).toEqual({ listening: false, childProcesses: 0 }); 188 }); 189 190 for (const width of [320, 1024]) { 191 test( 192 'persistent notices preserve field values and focus at ' + width + 'px', 193 async ({ browser }) => { 194 const context = await browser.newContext({ 195 viewport: { width, height: 900 } 196 }); 197 const external: string[] = []; 198 try { 199 await context.route('**/*', (route) => { 200 if (new URL(route.request().url()).origin === server.url) 201 return route.continue(); 202 external.push(route.request().url()); 203 return route.abort(); 204 }); 205 const page = await context.newPage(); 206 await page.goto(server.url); 207 const field = page.getByRole('textbox', { name: 'Food', exact: true }); 208 await expect(field).toBeEnabled(); 209 await expect(field).toHaveValue('preserved food'); 210 await field.fill('unchanged multiline\n菜'); 211 await expect( 212 page.getByRole('heading', { name: 'Check the following fields' }) 213 ).toHaveCount(0); 214 await page.getByRole('button', { name: 'Review', exact: true }).click(); 215 await expect(field).toHaveValue('unchanged multiline\n菜'); 216 await expect(field).toHaveAttribute('aria-invalid', 'true'); 217 const link = page.getByRole('link', { 218 name: 'Enter a supported food description.', 219 exact: true 220 }); 221 await expect(link).toHaveAttribute('href', '#food'); 222 await link.focus(); 223 await page.keyboard.press('Enter'); 224 await expect(field).toBeFocused(); 225 await expect( 226 page.getByRole('link', { name: 'Unsafe target remains plain text.' }) 227 ).toHaveCount(0); 228 const update = page.getByRole('button', { name: 'Update information' }); 229 await update.focus(); 230 await page.keyboard.press('Enter'); 231 await expect(update).toBeFocused(); 232 await expect( 233 page.getByText( 234 'One source did not respond. These results may be incomplete.' 235 ) 236 ).toBeVisible(); 237 await expect(field).toHaveValue('unchanged multiline\n菜'); 238 await expect(link).toBeVisible(); 239 await expect( 240 page.getByText( 241 "We could not confirm whether the recipient's inbox accepted this message." 242 ) 243 ).toBeVisible(); 244 await expect( 245 page.getByText('The sender archive relay accepted the event.') 246 ).toBeVisible(); 247 await expect( 248 page.getByText( 249 'Exact read-back is confirmed for this event and target.' 250 ) 251 ).toBeVisible(); 252 const measured = await page.evaluate(() => ({ 253 width: innerWidth, 254 scroll: globalThis.document.documentElement.scrollWidth, 255 controls: Array.from( 256 globalThis.document.querySelectorAll('button,a.shell-link') 257 ).map((el) => el.getBoundingClientRect().height) 258 })); 259 expect(measured.scroll).toBeLessThanOrEqual(width); 260 for (const height of measured.controls) 261 expect(height).toBeGreaterThanOrEqual(44); 262 console.log( 263 JSON.stringify({ 264 fixture: 'HCP016_CONTROLLED_NOTICES_ONLY', 265 measured, 266 inputPreserved: true, 267 informationalFocusPreserved: true, 268 keyboardFieldFocus: true 269 }) 270 ); 271 expect(external).toEqual([]); 272 expect(await page.evaluate(() => 'nostr' in window)).toBe(false); 273 } finally { 274 await context.close(); 275 } 276 } 277 ); 278 }