import fs from 'node:fs' import path from 'node:path' import test from 'node:test' import assert from 'node:assert/strict' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const repoRoot = path.resolve(__dirname, '..', '..') const tokens = fs.readFileSync(path.join(repoRoot, 'frontend', 'standalone-web', 'src', 'styles', 'tokens.css'), 'utf8') const workbench = fs.readFileSync(path.join(repoRoot, 'frontend', 'standalone-web', 'src', 'styles', 'workbench.css'), 'utf8') const app = fs.readFileSync(path.join(repoRoot, 'frontend', 'standalone-web', 'src', 'App.vue'), 'utf8') const requiredTokens = [ '--ui-space-1', '--ui-space-2', '--ui-space-3', '--ui-space-4', '--ui-space-5', '--ui-space-6', '--ui-radius-sm', '--ui-radius-md', '--ui-radius-lg', '--ui-focus-ring', '--ui-duration-fast', ] test('visual tokens remain centralized', () => { for (const token of requiredTokens) assert.match(tokens, new RegExp(`${token}:`), `missing token ${token}`) assert.match(workbench, /var\(--ui-radius-md\)/) assert.match(workbench, /var\(--ui-radius-lg\)/) assert.doesNotMatch(workbench, /#[0-9a-f]{6}\b/i) }) test('semantic states retain readable borders', () => { for (const state of ['good', 'warn', 'bad', 'disabled']) { assert.match(`${workbench}\n${app}`, new RegExp(`\\.${state}`), `missing ${state} state styling`) } assert.match(workbench, /color-mix\(in srgb, var\(--danger\)/) assert.match(workbench, /color-mix\(in srgb, var\(--warn\)/) }) function luminance(hex) { const values = hex.match(/[0-9a-f]{2}/gi).map((value) => Number.parseInt(value, 16) / 255) const linear = values.map((value) => value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4) return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2] } function contrastRatio(first, second) { const firstLuminance = luminance(first) const secondLuminance = luminance(second) return (Math.max(firstLuminance, secondLuminance) + 0.05) / (Math.min(firstLuminance, secondLuminance) + 0.05) } test('dark and light text tokens meet AA contrast targets', () => { assert.ok(contrastRatio('#edf4fb', '#111522') >= 4.5) assert.ok(contrastRatio('#9aa8ba', '#111522') >= 4.5) assert.ok(contrastRatio('#18202b', '#f3f6fb') >= 4.5) assert.ok(contrastRatio('#667085', '#f3f6fb') >= 4.5) })