import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import test from 'node:test'; const root = path.resolve(import.meta.dirname, '../..'); const page = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.tsx'), 'utf8'); const feature = fs.readFileSync(path.join(root, 'src/web/features/instructions/InstructionsFeature.tsx'), 'utf8'); const boundary = fs.readFileSync(path.join(root, 'src/web/features/instructions/index.ts'), 'utf8'); const blocks = fs.readFileSync(path.join(root, 'src/web/features/instructions/instructionBlocks.ts'), 'utf8'); const prometheus = fs.readFileSync(path.join(root, 'src/web/features/instructions/prometheus.ts'), 'utf8'); test('instructions feature is the sole owner behind one public boundary', () => { assert.equal(fs.existsSync(path.join(root, 'src/web/instructions.js')), false); assert.equal(fs.existsSync(path.join(root, 'src/web/prometheus.js')), false); assert.match(boundary, /InstructionsPanel,[\s\S]*InstructionsToggle,[\s\S]*useInstructionsFeature/); assert.doesNotMatch(boundary, /instructionBlocks|prometheusScrapeConfig|grafanaDashboardJson/); assert.equal((page.match(/useInstructionsFeature\(/g) || []).length, 1); assert.equal((page.match(/ { assert.match(page, /const instructionsFeature = useInstructionsFeature\([\s\S]*const diagnosticsAvailable/); assert.match(page, /\{hasSubscription && \(\{ \.\.\.current, \[action\.id\]: feedback \}\)\)/); assert.match(feature, /requestAnimationFrame\(\(\) => closeRef\.current\?\.focus\(\)\)[\s\S]*panelRef\.current\?\.contains[\s\S]*toggleRef\.current\?\.focus\(\)/); assert.match(feature, /addEventListener\('pointerdown', closeOutside\)/); assert.match(feature, /flushSync[\s\S]*prefers-reduced-motion: reduce[\s\S]*document\.startViewTransition\(update\)/); }); test('private content helpers preserve guide, copy and monitoring contracts', () => { assert.match(page, /const gatewayAddress = isGateway \? window\.location\.hostname : '127\.0\.0\.1'/); assert.match(page, /const controlHost = window\.location\.host \|\| `\$\{gatewayAddress\}:3456`/); assert.match(page, /port: state\?\.clientRuntime\?\.proxyPort \|\| \(isGateway \? 8080 : 8082\)/); assert.match(blocks, /\.\.\.\(isGateway \? \[\{/); assert.match(blocks, /id: 'router'[\s\S]*id: 'prometheus'/); assert.match(blocks, /prometheusScrapeConfig\(controlHost\)[\s\S]*label: 'Grafana dashboard'/); assert.match(prometheus, /\.\.\/\.\.\/\.\.\/\.\.\/monitoring\/grafana\/harbor-gateway\.json/); assert.match(prometheus, /scrape_interval: 30s[\s\S]*scrape_timeout: 3s[\s\S]*metrics_path: \/metrics/); assert.match(feature, /target="_blank" rel="noreferrer"/); assert.match(feature, /client-copy-label">Скопировать/); });