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/routing/RoutingFeature.tsx'), 'utf8'); const boundary = fs.readFileSync(path.join(root, 'src/web/features/routing/index.ts'), 'utf8'); test('routing feature is the sole owner at the four existing composition positions', () => { assert.match(boundary, /RoutingDiscardDialog,[\s\S]*RoutingPanel,[\s\S]*RoutingPendingStatus,[\s\S]*RoutingToggle,[\s\S]*useRoutingFeature/); assert.equal((page.match(/useRoutingFeature\(/g) || []).length, 1); assert.equal((page.match(/ { assert.match(feature, /const savedRules = route\?\.localRules \|\| \[\]/); assert.match(feature, /baselineRef\.current = JSON\.stringify\(savedRules\.map/); assert.match(feature, /setRules\(savedRules\.map\(createLocalRuleDraft\)\)/); assert.match(feature, /setRevision\(route\?\.localRulesRevision \|\| 0\)/); assert.match(feature, /if \(dirty\) \{[\s\S]*setConfirmingClose\(true\);[\s\S]*return false/); assert.match(feature, /const result = routingSaveState\(await onSave\(values, revision\)\)/); assert.match(feature, /if \(!result\) return;[\s\S]*baselineRef\.current = JSON\.stringify\(values\);[\s\S]*setRevision\(result\.localRulesRevision\)/); assert.match(feature, /if \(!connected \|\| !result\.localRulesPendingRestart\) setIsOpen\(false\)/); assert.match(feature, /Number\.isSafeInteger\(localRulesRevision\)[\s\S]*localRulesRevision as number\) < 0[\s\S]*typeof localRulesPendingRestart !== 'boolean'/); }); test('routing lifecycle and Page orchestration keep the existing guards and blocking scopes', () => { assert.match(feature, /keyboardEvent\.key !== 'Escape' \|\| keyboardEvent\.defaultPrevented/); assert.match(feature, /addEventListener\('beforeunload', warnBeforeUnload\)/); assert.match(feature, /matchMedia\('\(prefers-reduced-motion: reduce\)'\)[\s\S]*removing: true/); assert.match(feature, /document\.startViewTransition\(update\)/); assert.match(feature, /operationBlocked\(operations, 'routeRules'\) \|\| rules\.some/); assert.match(page, /current === 'routing' && routingFeature\.dirty[\s\S]*routingFeature\.requestClose\(\)/); assert.match(page, /routing:[\s\S]*show: routingFeature\.open,[\s\S]*close: routingFeature\.forceClose/); assert.match(page, /routingSlot=\{