ceulen 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +317 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.ts +93 -7
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +217 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +286 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +586 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +105 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +161 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/lib/client.ts +61 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +179 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2451 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +223 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +752 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +350 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/usage/index.ts +59 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +193 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +148 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +132 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +151 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +718 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +207 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +345 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
channelLuminance,
|
|
9
|
+
relativeLuminance,
|
|
10
|
+
contrastRatio,
|
|
11
|
+
parseHex,
|
|
12
|
+
parseOklch,
|
|
13
|
+
parseRgb,
|
|
14
|
+
parseHsl,
|
|
15
|
+
parseColor,
|
|
16
|
+
sRGBtoY,
|
|
17
|
+
apcaContrastLc,
|
|
18
|
+
apcaThreshold,
|
|
19
|
+
extractTokens,
|
|
20
|
+
scanOffSystem,
|
|
21
|
+
scanStates,
|
|
22
|
+
scanSlopTells,
|
|
23
|
+
audit,
|
|
24
|
+
} from "../lib/audit.js";
|
|
25
|
+
import { formatAuditResult, resolveAuditCss } from "../index.js";
|
|
26
|
+
|
|
27
|
+
// --- WCAG math ------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
test("channelLuminance linearises sRGB (0 and 255 extremes)", () => {
|
|
30
|
+
assert.equal(channelLuminance(0), 0);
|
|
31
|
+
assert.ok(channelLuminance(255) > 0.99 && channelLuminance(255) < 1.01);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("relativeLuminance handles 3-digit and 6-digit hex", () => {
|
|
35
|
+
assert.equal(relativeLuminance("#000"), relativeLuminance("#000000"));
|
|
36
|
+
assert.equal(relativeLuminance("#fff"), relativeLuminance("#FFFFFF"));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("relativeLuminance strips alpha from 4/8-digit hex (#RRGGBBAA / #RGBA)", () => {
|
|
40
|
+
assert.equal(relativeLuminance("#ff0000"), relativeLuminance("#ff0000ff"));
|
|
41
|
+
assert.equal(relativeLuminance("#f00"), relativeLuminance("#f00f"));
|
|
42
|
+
assert.equal(relativeLuminance("#0066ff"), relativeLuminance("#0066ff80"));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("relativeLuminance returns null for garbage", () => {
|
|
46
|
+
assert.equal(relativeLuminance("red"), null);
|
|
47
|
+
assert.equal(relativeLuminance("#12345"), null);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("contrastRatio: white/black = 21, identical = 1", () => {
|
|
51
|
+
assert.equal(contrastRatio("#000", "#000"), 1);
|
|
52
|
+
// ponytail: 21:1 is the WCAG maximum; allow float rounding.
|
|
53
|
+
const max = contrastRatio("#fff", "#000");
|
|
54
|
+
assert.ok(max >= 20 && max <= 21, `expected ~21, got ${max}`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("contrastRatio returns null when a colour is invalid", () => {
|
|
58
|
+
assert.equal(contrastRatio("#000", "nope"), null);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// --- tokens ---------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
test("extractTokens indexes :root declarations by value", () => {
|
|
64
|
+
const css = `:root { --accent: #0066ff; --space-2: 8px; }`;
|
|
65
|
+
const tokens = extractTokens(css);
|
|
66
|
+
assert.equal(tokens.get("#0066ff"), "--accent");
|
|
67
|
+
assert.equal(tokens.get("8px"), "--space-2");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("extractTokens indexes :root.dark and grouped :root variants", () => {
|
|
71
|
+
const css = `:root { --accent: #0066ff; } :root.dark { --accent: #82b1ff; } :root[data-theme=\"dim\"] { --bg: #111; }`;
|
|
72
|
+
const tokens = extractTokens(css);
|
|
73
|
+
assert.equal(tokens.get("#0066ff"), "--accent");
|
|
74
|
+
assert.equal(tokens.get("#82b1ff"), "--accent", "dark-mode override must be a token");
|
|
75
|
+
assert.equal(tokens.get("#111"), "--bg", "attribute-selector variant must be a token");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("scanOffSystem flags hardcoded hex outside :root", () => {
|
|
79
|
+
const css = `:root { --accent: #0066ff; } .card { color: #ff0000; }`;
|
|
80
|
+
const tokens = extractTokens(css);
|
|
81
|
+
const off = scanOffSystem(css, tokens);
|
|
82
|
+
assert.deepEqual(off.hardcodedHex, ["#ff0000"]);
|
|
83
|
+
assert.deepEqual(off.adhocShadow, []);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("scanOffSystem does NOT flag hex in :root.dark or grouped :root blocks", () => {
|
|
87
|
+
const css = `:root { --accent: #0066ff; } :root.dark { --accent: #82b1ff; }`;
|
|
88
|
+
const tokens = extractTokens(css);
|
|
89
|
+
const off = scanOffSystem(css, tokens);
|
|
90
|
+
assert.deepEqual(off.hardcodedHex, [], "dark-mode token values must not be flagged");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("scanOffSystem does NOT flag hex values that match a token", () => {
|
|
94
|
+
const css = `:root { --accent: #0066ff; } .card { color: #0066ff; }`;
|
|
95
|
+
const tokens = extractTokens(css);
|
|
96
|
+
const off = scanOffSystem(css, tokens);
|
|
97
|
+
assert.deepEqual(off.hardcodedHex, []);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("scanOffSystem ignores commented-out hex (dead code must not fail the gate)", () => {
|
|
101
|
+
const css = `:root { --accent: #0066ff; } /* .card { color: #ff0000; } */ .ok { color: var(--accent); }`;
|
|
102
|
+
const tokens = extractTokens(css);
|
|
103
|
+
const off = scanOffSystem(css, tokens);
|
|
104
|
+
assert.deepEqual(off.hardcodedHex, [], "commented-out hex is dead code, not a violation");
|
|
105
|
+
assert.deepEqual(off.adhocShadow, []);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("scanOffSystem flags box-shadow not built from var()", () => {
|
|
109
|
+
const css = `.card { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }`;
|
|
110
|
+
const tokens = extractTokens(css);
|
|
111
|
+
const off = scanOffSystem(css, tokens);
|
|
112
|
+
assert.ok(off.adhocShadow.length === 1);
|
|
113
|
+
assert.match(off.adhocShadow[0], /rgba/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("scanOffSystem does NOT flag box-shadow using var()", () => {
|
|
117
|
+
const css = `:root { --elev-md: 0 4px 12px rgba(0,0,0,0.1); } .card { box-shadow: var(--elev-md); }`;
|
|
118
|
+
const tokens = extractTokens(css);
|
|
119
|
+
const off = scanOffSystem(css, tokens);
|
|
120
|
+
assert.deepEqual(off.adhocShadow, []);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// --- states ---------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
test("scanStates flags missing focus-visible and disabled", () => {
|
|
126
|
+
const css = `button { color: var(--accent); } a { text-decoration: none; }`;
|
|
127
|
+
const states = scanStates(css);
|
|
128
|
+
assert.ok(states.missingFocusVisible.length === 1);
|
|
129
|
+
assert.ok(states.missingDisabled.length === 1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("scanStates passes when focus-visible and disabled exist", () => {
|
|
133
|
+
const css = `button { color: var(--accent); } button:focus-visible { outline: 2px solid var(--accent); } button:disabled { opacity: 0.5; }`;
|
|
134
|
+
const states = scanStates(css);
|
|
135
|
+
assert.deepEqual(states.missingFocusVisible, []);
|
|
136
|
+
assert.deepEqual(states.missingDisabled, []);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("scanStates returns empty when no interactive selectors present", () => {
|
|
140
|
+
const css = `.card { padding: 8px; }`;
|
|
141
|
+
const states = scanStates(css);
|
|
142
|
+
assert.deepEqual(states.missingFocusVisible, []);
|
|
143
|
+
assert.deepEqual(states.missingDisabled, []);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("scanStates: motion without prefers-reduced-motion fails, with it passes", () => {
|
|
147
|
+
const base = `button { transition: opacity 120ms; } button:focus-visible { outline: none; } button:disabled { opacity: 0.5; }`;
|
|
148
|
+
const without = scanStates(base);
|
|
149
|
+
assert.deepEqual(without.missingReducedMotion, [
|
|
150
|
+
'motion (transition/animation) with no prefers-reduced-motion fallback',
|
|
151
|
+
]);
|
|
152
|
+
const with_ = scanStates(base + `\n@media (prefers-reduced-motion: reduce) { button { transition: none; } }`);
|
|
153
|
+
assert.deepEqual(with_.missingReducedMotion, []);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("scanStates: no motion → no reduced-motion finding, even with no interactive elements", () => {
|
|
157
|
+
const states = scanStates(`.hero { padding: 24px; }`);
|
|
158
|
+
assert.deepEqual(states.missingReducedMotion, []);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("scanStates: transition longhands and scroll-behavior count as motion", () => {
|
|
162
|
+
const longhand = scanStates(`.a { transition-property: opacity; transition-duration: 200ms; }`);
|
|
163
|
+
assert.equal(longhand.missingReducedMotion.length, 1);
|
|
164
|
+
const fixed = scanStates(`.a { transition-property: opacity; transition-duration: 200ms; }\n@media (prefers-reduced-motion: reduce) { .a { transition: none; } }`);
|
|
165
|
+
assert.equal(fixed.missingReducedMotion.length, 0);
|
|
166
|
+
const smooth = scanStates(`html { scroll-behavior: smooth; }`);
|
|
167
|
+
assert.equal(smooth.missingReducedMotion.length, 1);
|
|
168
|
+
const inert = scanStates(`.a { transition-behavior: allow-discrete; }`);
|
|
169
|
+
assert.equal(inert.missingReducedMotion.length, 0);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("scanStates reports hasInteractive", () => {
|
|
173
|
+
assert.equal(scanStates(`button { color: red; }`).hasInteractive, true);
|
|
174
|
+
assert.equal(scanStates(`.card { padding: 24px; }`).hasInteractive, false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("formatAuditResult states hints match the actual failure", () => {
|
|
178
|
+
// Fragment with motion but no reduced-motion fallback and no interactive
|
|
179
|
+
// elements: gate fails; the hint names the real fix, only conditionally
|
|
180
|
+
// suggesting the fragment case (a complete stylesheet deserves the same
|
|
181
|
+
// advice).
|
|
182
|
+
const fragment = audit({ css: `.hero { transition: opacity 200ms; }` });
|
|
183
|
+
assert.equal(fragment.gates.states.pass, false);
|
|
184
|
+
assert.equal(fragment.gates.states.hasInteractive, false);
|
|
185
|
+
const text = formatAuditResult(fragment);
|
|
186
|
+
assert.match(text, /ℹ Motion needs a prefers-reduced-motion fallback/, "hint line (not just the ✗ finding) present");
|
|
187
|
+
assert.equal(text.split("\n").filter((l) => l.includes("ℹ")).length, 1, "exactly the motion hint");
|
|
188
|
+
|
|
189
|
+
// Fragment WITH interactive selectors but focus rules elsewhere: gets the
|
|
190
|
+
// complete-stylesheet hint (this case had no hint at all before 0.4.7).
|
|
191
|
+
const focusFragment = audit({ css: `button { color: red; }` });
|
|
192
|
+
assert.equal(focusFragment.gates.states.pass, false);
|
|
193
|
+
assert.match(formatAuditResult(focusFragment), /states rules may live in another file/);
|
|
194
|
+
|
|
195
|
+
// Motion failure WITH interactive elements: the focus hint fires — button
|
|
196
|
+
// genuinely lacks :focus-visible, so that's a real finding, not a fragment
|
|
197
|
+
// mislabel. Nothing assertively claims "Fragment detected" anymore.
|
|
198
|
+
const full = audit({ css: `button { transition: opacity 200ms; }` });
|
|
199
|
+
assert.equal(full.gates.states.pass, false);
|
|
200
|
+
assert.equal(full.gates.states.hasInteractive, true);
|
|
201
|
+
const fullText = formatAuditResult(full);
|
|
202
|
+
assert.match(fullText, /states rules may live in another file/, "focus hint fires — real finding");
|
|
203
|
+
assert.equal(fullText.split("\n").filter((l) => l.includes("ℹ")).length, 1, "exactly the focus hint");
|
|
204
|
+
assert.ok(!fullText.includes("ℹ Motion needs"), "motion hint stays off when focus/disabled findings take priority");
|
|
205
|
+
|
|
206
|
+
// Interactive + motion WITH complete focus/disabled rules: real reduced-motion
|
|
207
|
+
// finding, no hint at all.
|
|
208
|
+
const statesComplete = audit({ css: `button { transition: opacity 200ms; } button:focus-visible { outline: 2px solid; } button:disabled { opacity: .5; }` });
|
|
209
|
+
assert.equal(statesComplete.gates.states.pass, false);
|
|
210
|
+
assert.equal(formatAuditResult(statesComplete).split("\n").filter((l) => l.includes("ℹ")).length, 0);
|
|
211
|
+
|
|
212
|
+
// Fragment that passes: no hint either.
|
|
213
|
+
const clean = audit({ css: `.card { padding: 24px; }` });
|
|
214
|
+
assert.equal(clean.gates.states.pass, true);
|
|
215
|
+
assert.equal(formatAuditResult(clean).split("\n").filter((l) => l.includes("ℹ")).length, 0);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("scanStates: a commented-out prefers-reduced-motion block does not satisfy the check", () => {
|
|
219
|
+
const r = scanStates(`button { transition: opacity 120ms; } /* @media (prefers-reduced-motion: reduce) { button { transition: none; } } */`);
|
|
220
|
+
assert.equal(r.missingReducedMotion.length, 1);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// FIX (v0.6.2): a quoted word 'a' (e.g. grid-template-areas: "a b") falsely
|
|
224
|
+
// matched the interactive-element regex → dialog-free CSS failed the States
|
|
225
|
+
// gate in strict mode.
|
|
226
|
+
test("scanStates ignores quoted strings (grid-template-areas \"a b\")", () => {
|
|
227
|
+
const css = `:root{--x:#fff} .grid{grid-template-areas:"a b";color:var(--x)}`;
|
|
228
|
+
const states = scanStates(css);
|
|
229
|
+
assert.equal(states.hasInteractive, false);
|
|
230
|
+
assert.deepEqual(states.missingFocusVisible, []);
|
|
231
|
+
assert.deepEqual(states.missingDisabled, []);
|
|
232
|
+
const r = audit({ css, pairs: [{ fg: "#111", bg: "#fff", label: "body", min: 4.5 }] });
|
|
233
|
+
assert.equal(r.gates.states.pass, true);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// FIX (v0.6.3): :root token names like --input-bg contain the substring
|
|
237
|
+
// "input" and falsely matched the interactive-element regex.
|
|
238
|
+
test("scanStates ignores :root token names (--input-bg is not an input selector)", () => {
|
|
239
|
+
const css = `:root { --input-bg: #fff; --button-fg: #111; } .card { color: var(--button-fg); background: var(--input-bg); }`;
|
|
240
|
+
const states = scanStates(css);
|
|
241
|
+
assert.equal(states.hasInteractive, false);
|
|
242
|
+
assert.deepEqual(states.missingFocusVisible, []);
|
|
243
|
+
assert.deepEqual(states.missingDisabled, []);
|
|
244
|
+
const r = audit({ css, pairs: [] });
|
|
245
|
+
assert.equal(r.gates.states.pass, true);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("slop tells: eyebrow label (tracked-out uppercase at ≤13px)", () => {
|
|
249
|
+
const hit = scanSlopTells(`.eyebrow { text-transform: uppercase; font-size: 11px; letter-spacing: 0.1em; }`);
|
|
250
|
+
assert.equal(hit.tells.length, 1);
|
|
251
|
+
assert.match(hit.tells[0], /eyebrow/);
|
|
252
|
+
// 0.8125rem = 13px with wide tracking → still hits
|
|
253
|
+
assert.equal(scanSlopTells(`.k { text-transform: uppercase; font-size: 0.8125rem; letter-spacing: 0.12em; }`).tells.length, 1);
|
|
254
|
+
// normal-tracking uppercase labels are a legitimate table/label style
|
|
255
|
+
assert.equal(scanSlopTells(`.h { text-transform: uppercase; font-size: 12px; letter-spacing: 0.05em; }`).tells.length, 0);
|
|
256
|
+
assert.equal(scanSlopTells(`.display { text-transform: uppercase; font-size: 16px; letter-spacing: 0.1em; }`).tells.length, 0);
|
|
257
|
+
// uppercase without an explicit size could be a display treatment → pass
|
|
258
|
+
assert.equal(scanSlopTells(`.display { text-transform: uppercase; letter-spacing: 0.1em; }`).tells.length, 0);
|
|
259
|
+
// em tracking scales with the element's own font-size: 13px × 0.07em = 0.07em < 0.08 → pass
|
|
260
|
+
assert.equal(scanSlopTells(`.h { text-transform: uppercase; font-size: 13px; letter-spacing: 0.07em; }`).tells.length, 0);
|
|
261
|
+
// 11px × 0.09em = 0.99px — below a naive 1px threshold but ≥0.08em → hit
|
|
262
|
+
assert.equal(scanSlopTells(`.h { text-transform: uppercase; font-size: 11px; letter-spacing: 0.09em; }`).tells.length, 1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("slop tells: tinted near-black background", () => {
|
|
266
|
+
assert.ok(scanSlopTells(`.card { background: #0B0B0B; }`).tells.some((t) => /near-black/.test(t)));
|
|
267
|
+
assert.ok(scanSlopTells(`.card { background-color: #111111; }`).tells.some((t) => /near-black/.test(t)));
|
|
268
|
+
// pure #000 is a deliberate choice; near-black *text* is fine
|
|
269
|
+
assert.equal(scanSlopTells(`.card { background: #000; }`).tells.some((t) => /near-black/.test(t)), false);
|
|
270
|
+
assert.equal(scanSlopTells(`.card { color: #111111; background: var(--surface); }`).tells.some((t) => /near-black/.test(t)), false);
|
|
271
|
+
assert.ok(scanSlopTells(`.card { background: #0b0b0bcc; }`).tells.some((t) => /near-black/.test(t)));
|
|
272
|
+
// #RGBA nibbles double: #0b0b = rgba(0,187,0,.73) — translucent green, correctly NOT near-black
|
|
273
|
+
assert.equal(scanSlopTells(`.card { background: #0b0b; }`).tells.some((t) => /near-black/.test(t)), false);
|
|
274
|
+
assert.ok(scanSlopTells(`.card { background: #1112; }`).tells.some((t) => /near-black/.test(t))); // dark 4-digit alpha form
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("slop tells: commented-out CSS produces zero tells", () => {
|
|
278
|
+
const commented = scanSlopTells(`/* .eyebrow { text-transform: uppercase; font-size: 11px; letter-spacing: 0.1em; } */ /* .hero { background: #0B0B0B } */`);
|
|
279
|
+
assert.equal(commented.tells.length, 0);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("audit: auto-extracts colour/background pairs when none are provided", () => {
|
|
283
|
+
const css = `:root { --surface: #FFFFFF; --surface-alt: #fff; --text: #0F172A; --muted: #57534E; }
|
|
284
|
+
.card { color: var(--text); background: var(--surface); }
|
|
285
|
+
.muted { color: var(--muted); }
|
|
286
|
+
.dup { color: var(--text); background: var(--surface-alt); }`;
|
|
287
|
+
const r = audit({ css, pairs: [] });
|
|
288
|
+
assert.equal(r.autoPairs, true);
|
|
289
|
+
assert.equal(r.gates.contrast.results.length, 1); // .card + .dup dedupe to one resolved pair; .muted skipped (no bg in block)
|
|
290
|
+
assert.equal(r.gates.contrast.results[0].label.startsWith("auto: "), true);
|
|
291
|
+
assert.equal(r.pass, true);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("audit: keeps provided pairs and skips extraction", () => {
|
|
295
|
+
const r = audit({
|
|
296
|
+
css: ".a { color: #fff; background: #000; }",
|
|
297
|
+
pairs: [{ fg: "#579F9A", bg: "#FFFFFF", label: "graphic", min: 3 }],
|
|
298
|
+
});
|
|
299
|
+
assert.equal(r.autoPairs, false);
|
|
300
|
+
assert.equal(r.gates.contrast.results.length, 1);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("audit: auto-extracted failing pair fails the gate", () => {
|
|
304
|
+
const r = audit({ css: ".bad { color: #9ca3af; background: #f9fafb; }" });
|
|
305
|
+
assert.equal(r.autoPairs, true);
|
|
306
|
+
assert.equal(r.pass, false);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// --- aggregate gate -------------------------------------------------------
|
|
310
|
+
|
|
311
|
+
test("audit.pass is true for a clean, token-compliant stylesheet", () => {
|
|
312
|
+
const css = `
|
|
313
|
+
:root { --accent: #0066ff; --text: #111; --bg: #fff; --elev: 0 2px 8px rgba(0,0,0,0.08); }
|
|
314
|
+
.card { color: var(--text); background: var(--bg); box-shadow: var(--elev); padding: 8px; }
|
|
315
|
+
button { color: var(--accent); }
|
|
316
|
+
button:focus-visible { outline: 2px solid var(--accent); }
|
|
317
|
+
button:disabled { opacity: 0.5; }
|
|
318
|
+
`;
|
|
319
|
+
const result = audit({ css, pairs: [{ fg: "#111", bg: "#fff", label: "body", min: 4.5 }] });
|
|
320
|
+
assert.equal(result.pass, true);
|
|
321
|
+
assert.equal(result.gates.contrast.pass, true);
|
|
322
|
+
assert.equal(result.gates.tokens.pass, true);
|
|
323
|
+
assert.equal(result.gates.states.pass, true);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("audit.pass is false when contrast fails", () => {
|
|
327
|
+
// light grey on white — fails AA
|
|
328
|
+
const result = audit({ css: "", pairs: [{ fg: "#bbb", bg: "#fff", min: 4.5 }] });
|
|
329
|
+
assert.equal(result.pass, false);
|
|
330
|
+
assert.equal(result.gates.contrast.pass, false);
|
|
331
|
+
assert.ok(result.gates.contrast.results[0].ratio < 4.5);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test("audit.pass is false when hardcoded hex present", () => {
|
|
335
|
+
const css = `:root { --accent: #0066ff; } .card { color: #ff0000; }`;
|
|
336
|
+
const result = audit({ css, pairs: [] });
|
|
337
|
+
assert.equal(result.pass, false);
|
|
338
|
+
assert.equal(result.gates.tokens.pass, false);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("audit.pass is false when states missing", () => {
|
|
342
|
+
const css = `button { color: red; }`;
|
|
343
|
+
const result = audit({ css, pairs: [] });
|
|
344
|
+
assert.equal(result.pass, false);
|
|
345
|
+
assert.equal(result.gates.states.pass, false);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("audit treats invalid colour as a failed contrast pair (ratio null, pass false)", () => {
|
|
349
|
+
const result = audit({ css: "", pairs: [{ fg: "not-a-color", bg: "#fff", label: "bad" }] });
|
|
350
|
+
assert.equal(result.pass, false);
|
|
351
|
+
assert.equal(result.gates.contrast.results[0].ratio, null);
|
|
352
|
+
assert.equal(result.gates.contrast.results[0].pass, false);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// FIX (v0.6.3 review): CSS Color-4 space syntax — rgb(17 17 17), rgb(0 0 0 / 50%),
|
|
356
|
+
// hsl(0 0% 50% / 0.4) — previously returned null and hard-failed the gate.
|
|
357
|
+
test("parseRgb accepts CSS Color-4 space-separated syntax", () => {
|
|
358
|
+
assert.deepEqual(parseRgb("rgb(17 17 17)"), [17, 17, 17]);
|
|
359
|
+
assert.deepEqual(parseRgb("rgb(0 0 0 / 50%)"), [0, 0, 0]);
|
|
360
|
+
assert.deepEqual(parseRgb("rgba(17, 17, 17, 0.5)"), [17, 17, 17]); // comma syntax still parses
|
|
361
|
+
assert.equal(parseRgb("rgb(17 17"), null);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("parseHsl accepts slash-alpha syntax", () => {
|
|
365
|
+
assert.deepEqual(parseHsl("hsl(0 0% 50% / 0.4)"), [128, 128, 128]);
|
|
366
|
+
assert.deepEqual(parseHsl("hsl(120, 100%, 50%)"), [0, 255, 0]); // comma syntax still parses
|
|
367
|
+
assert.equal(parseHsl("hsl(0 0% 50%"), null);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("audit: rgb() colour-4 pair yields a parsed passing contrast result, not n/a", () => {
|
|
371
|
+
const result = audit({ css: `.x{color:#111;background:rgb(255 255 255)}`, pairs: [] });
|
|
372
|
+
const pair = result.gates.contrast.results.find((r) => /auto: \.x/.test(r.label));
|
|
373
|
+
assert.ok(pair, "pair from rgb() background extracted");
|
|
374
|
+
assert.equal(typeof pair.ratio, "number");
|
|
375
|
+
assert.equal(pair.pass, true);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("scanStates: var() with fallback does not mark stylesheet interactive", () => {
|
|
379
|
+
const states = scanStates(`.x { background: var(--input-bg, #fff); }`);
|
|
380
|
+
assert.equal(states.hasInteractive, false);
|
|
381
|
+
assert.deepEqual(states.missingFocusVisible, []);
|
|
382
|
+
assert.deepEqual(states.missingDisabled, []);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test("audit tolerates { pairs: null } (behaves like an empty list, no throw)", () => {
|
|
386
|
+
const result = audit({ css: "", pairs: null });
|
|
387
|
+
assert.equal(result.gates.contrast.results.length, 0);
|
|
388
|
+
assert.equal(result.gates.contrast.pass, true);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("audit tolerates { css: null } (behaves like empty string, no throw)", () => {
|
|
392
|
+
const result = audit({ css: null, pairs: [] });
|
|
393
|
+
assert.equal(result.gates.tokens.pass, true);
|
|
394
|
+
assert.equal(result.gates.states.pass, true);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// --- colour parsing (hex + oklch) -----------------------------------------
|
|
398
|
+
|
|
399
|
+
test("parseHex accepts 3/4/6/8-digit hex and strips alpha", () => {
|
|
400
|
+
assert.deepEqual(parseHex("#fff"), [255, 255, 255]);
|
|
401
|
+
assert.deepEqual(parseHex("#000000"), [0, 0, 0]);
|
|
402
|
+
assert.deepEqual(parseHex("#0066ff80"), [0, 102, 255]); // 8-digit drops alpha
|
|
403
|
+
assert.deepEqual(parseHex("#f00f"), [255, 0, 0]); // 4-digit drops alpha
|
|
404
|
+
assert.equal(parseHex("garbage"), null);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("parseOklch converts to sRGB (white and black extremes)", () => {
|
|
408
|
+
const white = parseOklch("oklch(100% 0 0)");
|
|
409
|
+
assert.ok(Math.abs(white[0] - 255) < 2, `white R ~255, got ${white[0]}`);
|
|
410
|
+
const black = parseOklch("oklch(0% 0 0)");
|
|
411
|
+
assert.deepEqual(black, [0, 0, 0]);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("parseOklch returns null on garbage", () => {
|
|
415
|
+
assert.equal(parseOklch("not-a-color"), null);
|
|
416
|
+
assert.equal(parseOklch("oklch(x y z)"), null);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// REVIEW FIX 1 (HIGH): percentage lightness must divide by 100, not 1.
|
|
420
|
+
// oklch(50% ...) is mid-grey, NOT white.
|
|
421
|
+
test("parseOklch percentage L does not collapse to white (regression)", () => {
|
|
422
|
+
const mid = parseOklch("oklch(50% 0 0)");
|
|
423
|
+
assert.ok(Math.abs(mid[0] - 99) < 15, `mid-grey ~99, got ${mid[0]}`);
|
|
424
|
+
assert.ok(mid[0] < 200, "must not be near-white");
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("parseOklch saturates correctly (blue hue)", () => {
|
|
428
|
+
const blue = parseOklch("oklch(60% 0.18 250)");
|
|
429
|
+
assert.ok(blue[2] > blue[0], "B must dominate R");
|
|
430
|
+
assert.ok(blue[2] > blue[1], "B must dominate G");
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// REVIEW FIX 1b (latent): linear sRGB must be gamma-encoded to sRGB before
|
|
434
|
+
// *255, or APCA double-linearizes oklch values (contrast becomes wrong).
|
|
435
|
+
test("parseOklch gamma-encodes (APCA contrast on oklch matches hex equivalent)", () => {
|
|
436
|
+
// oklch(~21% 0 0) ≈ #333 grey. Cross-check APCA treats them alike.
|
|
437
|
+
const hexLc = apcaContrastLc("#333333", "#ffffff");
|
|
438
|
+
const okLc = apcaContrastLc("oklch(22.6% 0 0)", "oklch(100% 0 0)");
|
|
439
|
+
assert.ok(Math.abs(hexLc - okLc) < 8, `hex ${hexLc} vs oklch ${okLc} must agree`);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
test("parseColor routes hex and oklch to the right parser", () => {
|
|
443
|
+
assert.deepEqual(parseColor("#111111"), [17, 17, 17]);
|
|
444
|
+
assert.deepEqual(parseColor("oklch(100% 0 0)")[0], 255);
|
|
445
|
+
assert.equal(parseColor("nope"), null);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test("parseRgb parses rgb()/rgba(), drops alpha, rejects out-of-range", () => {
|
|
449
|
+
assert.deepEqual(parseRgb("rgb(17,17,17)"), [17, 17, 17]);
|
|
450
|
+
assert.deepEqual(parseRgb("rgb( 0 , 102 , 255 )"), [0, 102, 255]);
|
|
451
|
+
assert.deepEqual(parseRgb("rgba(0, 0, 0, 0.4)"), [0, 0, 0]); // alpha dropped
|
|
452
|
+
assert.equal(parseRgb("rgb(300,0,0)"), null);
|
|
453
|
+
assert.equal(parseRgb("rgb(1,2)"), null);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test("parseHsl converts to sRGB (primaries and a known mix)", () => {
|
|
457
|
+
assert.deepEqual(parseHsl("hsl(0 100% 50%)"), [255, 0, 0]);
|
|
458
|
+
assert.deepEqual(parseHsl("hsl(120deg 100% 50%)"), [0, 255, 0]);
|
|
459
|
+
assert.deepEqual(parseHsl("hsl(240 100% 50%)"), [0, 0, 255]);
|
|
460
|
+
assert.deepEqual(parseHsl("hsl(0 0% 100%)"), [255, 255, 255]);
|
|
461
|
+
assert.deepEqual(parseHsl("hsl(0 0% 0%)"), [0, 0, 0]);
|
|
462
|
+
assert.deepEqual(parseHsl("hsla(210, 100%, 20%, 0.5)"), parseHsl("hsl(210 100% 20%)")); // alpha dropped
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
test("parseColor routes rgb/hsl to the right parser", () => {
|
|
466
|
+
assert.deepEqual(parseColor("rgb(17,17,17)"), [17, 17, 17]);
|
|
467
|
+
assert.deepEqual(parseColor("hsl(0 100% 50%)"), [255, 0, 0]);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// FIX (v0.6.3): rgb/hsl pairs previously fell through as unparseable.
|
|
471
|
+
test("audit: rgb/hsl colours feed the contrast gate (auto-extracted pair passes, bad rgb pair fails)", () => {
|
|
472
|
+
const pass = audit({ css: ".x { color: rgb(17,17,17); background: #fff; }" });
|
|
473
|
+
assert.equal(pass.autoPairs, true);
|
|
474
|
+
assert.equal(pass.gates.contrast.results.length, 1);
|
|
475
|
+
assert.equal(pass.gates.contrast.results[0].pass, true);
|
|
476
|
+
assert.equal(pass.gates.contrast.pass, true); // contrast only — the raw #fff still trips the token gate
|
|
477
|
+
|
|
478
|
+
const fail = audit({ css: ".x { color: rgb(170,170,170); background: #fff; }" });
|
|
479
|
+
assert.equal(fail.gates.contrast.results[0].pass, false);
|
|
480
|
+
assert.equal(fail.gates.contrast.pass, false);
|
|
481
|
+
|
|
482
|
+
const hsl = audit({ css: ".x { color: hsl(0 0% 7%); background: hsl(0 0% 100%); }" });
|
|
483
|
+
assert.equal(hsl.gates.contrast.results[0].pass, true);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// FIX (v0.6.3): layered background values ("url(x.png) #fff") resolved only
|
|
487
|
+
// the first space-separated token, so the real colour was missed.
|
|
488
|
+
test("audit: bg pairs with the colour token inside a layered background value", () => {
|
|
489
|
+
const r = audit({ css: ".hero { color: #111111; background: url(bg.png) no-repeat #ffffff; }" });
|
|
490
|
+
assert.equal(r.autoPairs, true);
|
|
491
|
+
assert.equal(r.gates.contrast.results.length, 1);
|
|
492
|
+
assert.equal(r.gates.contrast.results[0].bg, "#ffffff");
|
|
493
|
+
assert.equal(r.gates.contrast.results[0].pass, true);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// --- APCA contrast (primary gate) -----------------------------------------
|
|
497
|
+
|
|
498
|
+
test("apcaContrastLc: black on white ≈ Lc 105 (near the known max)", () => {
|
|
499
|
+
const lc = apcaContrastLc("#000000", "#ffffff");
|
|
500
|
+
assert.ok(lc >= 100 && lc <= 107, `expected ~105, got ${lc}`);
|
|
501
|
+
assert.ok(lc > 0, "dark text on light bg must be positive (BoW polarity)");
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("apcaContrastLc: white on black is negative (WoB polarity)", () => {
|
|
505
|
+
const lc = apcaContrastLc("#ffffff", "#000000");
|
|
506
|
+
assert.ok(lc < 0, "light text on dark bg must be negative");
|
|
507
|
+
assert.ok(lc <= -100, `expected ~-106, got ${lc}`);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test("apcaContrastLc: dark-theme thin-text slop FAILS where WCAG passes", () => {
|
|
511
|
+
// #aaa light grey on #1e1e1e dark — the classic text-only-model dark slop.
|
|
512
|
+
// APCA catches this; WCAG ratio would pass it.
|
|
513
|
+
const lc = apcaContrastLc("#aaaaaa", "#1e1e1e");
|
|
514
|
+
assert.ok(lc < 0, "must be negative (WoB)");
|
|
515
|
+
assert.ok(Math.abs(lc) < 75, `Lc ${lc} should fail body threshold (75), proving APCA > WCAG`);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test("apcaContrastLc returns null for unparseable colour", () => {
|
|
519
|
+
assert.equal(apcaContrastLc("not-a-color", "#fff"), null);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
test("apcaThreshold scales by weight and size", () => {
|
|
523
|
+
assert.equal(apcaThreshold(400, 16), 75, "body text = strictest");
|
|
524
|
+
assert.equal(apcaThreshold(700, 16), 60, "bold body stays at 60 (not 45)");
|
|
525
|
+
assert.equal(apcaThreshold(700, 14), 60, "bold small body = 60");
|
|
526
|
+
assert.equal(apcaThreshold(700, 18), 45, "bold + large relaxes to 45");
|
|
527
|
+
assert.equal(apcaThreshold(700, 24), 45, "bold + very large = 45");
|
|
528
|
+
assert.equal(apcaThreshold(400, 24), 45, "large non-bold relaxes to 45");
|
|
529
|
+
assert.equal(apcaThreshold(400, 18), 60, "regular ≥18px = 60");
|
|
530
|
+
assert.equal(apcaThreshold(500, 18), 60, "medium weight + 18px = 60");
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
test("apcaThreshold: non-text pairs gate at Lc 30", () => {
|
|
534
|
+
assert.equal(apcaThreshold(undefined, undefined, true), 30, "non-text = 30");
|
|
535
|
+
assert.equal(apcaThreshold(400, 12, false), 75, "text path unaffected");
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("audit: non-text pair (min 3, no size/weight) passes at Lc >= 30", () => {
|
|
539
|
+
// #579F9A on white ≈ Lc 57.5 — passes the non-text floor, would fail body 75
|
|
540
|
+
const result = audit({
|
|
541
|
+
css: ".col { background: #579F9A; }",
|
|
542
|
+
pairs: [{ fg: "#579F9A", bg: "#FFFFFF", label: "graphic", min: 3 }],
|
|
543
|
+
});
|
|
544
|
+
assert.equal(result.gates.contrast.results[0].apcaMin, 30);
|
|
545
|
+
assert.equal(result.gates.contrast.results[0].pass, true);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
test("audit: min 3 WITH size stays a text pair (body threshold)", () => {
|
|
549
|
+
const result = audit({
|
|
550
|
+
css: ".x { color: #579F9A; }",
|
|
551
|
+
pairs: [{ fg: "#579F9A", bg: "#FFFFFF", label: "small text", min: 3, size: 12 }],
|
|
552
|
+
});
|
|
553
|
+
assert.equal(result.gates.contrast.results[0].apcaMin, 75);
|
|
554
|
+
assert.equal(result.gates.contrast.results[0].pass, false);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
// --- audit with APCA + WCAG sidecar ---------------------------------------
|
|
558
|
+
|
|
559
|
+
test("audit reports both APCA Lc and WCAG ratio in contrast results", () => {
|
|
560
|
+
const result = audit({ css: "", pairs: [{ fg: "#111111", bg: "#ffffff", label: "body", weight: 400, size: 16 }] });
|
|
561
|
+
const r = result.gates.contrast.results[0];
|
|
562
|
+
assert.ok(r.apca !== null && r.apca > 100, "APCA Lc present and high for black-on-white");
|
|
563
|
+
assert.ok(r.ratio > 15, "WCAG ratio present (~21)");
|
|
564
|
+
assert.equal(r.pass, true);
|
|
565
|
+
assert.equal(r.apcaMin, 75);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test("audit fails when APCA Lc is below threshold even if WCAG ratio passes", () => {
|
|
569
|
+
// #aaa on dark bg: APCA Lc ~54 (fails 75), WCAG ratio ~7.8 (passes 4.5)
|
|
570
|
+
const result = audit({ css: "", pairs: [{ fg: "#aaaaaa", bg: "#1e1e1e", label: "dark-body", min: 4.5, weight: 400, size: 16 }] });
|
|
571
|
+
assert.equal(result.gates.contrast.pass, false, "must fail on APCA");
|
|
572
|
+
assert.equal(result.pass, false);
|
|
573
|
+
const r = result.gates.contrast.results[0];
|
|
574
|
+
assert.ok(r.ratio >= 4.5, "WCAG sidecar still passes for reporting");
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test("audit still works with legacy pairs (no weight/size) — APCA default 75", () => {
|
|
578
|
+
const result = audit({ css: "", pairs: [{ fg: "#111111", bg: "#ffffff", min: 4.5 }] });
|
|
579
|
+
assert.equal(result.gates.contrast.pass, true);
|
|
580
|
+
assert.equal(result.gates.contrast.results[0].apcaMin, 75);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
// --- slop tells (Phase 3) --------------------------------------------------
|
|
584
|
+
|
|
585
|
+
test("scanSlopTells flags glassmorphism (backdrop-filter)", () => {
|
|
586
|
+
const { tells } = scanSlopTells(".card { backdrop-filter: blur(10px); } .card { color: red; }");
|
|
587
|
+
assert.equal(tells.length, 1);
|
|
588
|
+
assert.match(tells[0], /glassmorphism/);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
test("scanSlopTells flags the shadcn default-card reflex", () => {
|
|
592
|
+
const css = ".card { border-radius: rounded-2xl; box-shadow: shadow-lg; padding: p-6; }";
|
|
593
|
+
// ponytail: the heuristic checks class-name co-occurrence, not CSS props
|
|
594
|
+
const css2 = '<div class="rounded-2xl shadow-lg p-6">';
|
|
595
|
+
const { tells } = scanSlopTells(css2);
|
|
596
|
+
assert.equal(tells.length, 1);
|
|
597
|
+
assert.match(tells[0], /default card/);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
test("scanSlopTells flags 1px gray card border (tailwind default)", () => {
|
|
601
|
+
const { tells } = scanSlopTells(".card { border-zinc-200: 1px; }");
|
|
602
|
+
assert.equal(tells.length, 1);
|
|
603
|
+
assert.match(tells[0], /1px gray card border/);
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
test("scanSlopTells flags 1px gray card border (literal hex)", () => {
|
|
607
|
+
const { tells } = scanSlopTells(".card { border: 1px solid #e5e7eb; }");
|
|
608
|
+
assert.equal(tells.length, 1);
|
|
609
|
+
assert.match(tells[0], /1px gray card border/);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test("scanSlopTells does NOT flag clean token-based elevation", () => {
|
|
613
|
+
const css = `
|
|
614
|
+
:root { --elev-md: 0 2px 8px rgba(0,0,0,0.08); }
|
|
615
|
+
.card { box-shadow: var(--elev-md); border-radius: 8px; padding: 16px; }
|
|
616
|
+
`;
|
|
617
|
+
const { tells } = scanSlopTells(css);
|
|
618
|
+
assert.deepEqual(tells, []);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
test("scanSlopTells does NOT flag legitimate small radial highlight", () => {
|
|
622
|
+
const css = ".badge { background: radial-gradient(circle, #fff 0%, #eee 100%); }";
|
|
623
|
+
const { tells } = scanSlopTells(css);
|
|
624
|
+
assert.deepEqual(tells, [], "small radial without big blur is not an orb");
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
test("audit integrates slop-tell gate: full slop dump fails", () => {
|
|
628
|
+
const slopCss = `
|
|
629
|
+
.hero { backdrop-filter: blur(20px); }
|
|
630
|
+
.card { @apply rounded-2xl shadow-lg p-6; border-zinc-200; }
|
|
631
|
+
`;
|
|
632
|
+
const result = audit({ css: slopCss, pairs: [] });
|
|
633
|
+
assert.equal(result.gates.slopTells.pass, false);
|
|
634
|
+
assert.ok(result.gates.slopTells.tells.length >= 1);
|
|
635
|
+
assert.equal(result.pass, false);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
test("audit.clean sheet passes all four gates", () => {
|
|
639
|
+
const css = `
|
|
640
|
+
:root { --accent: #0066ff; --text: #111; --bg: #fff; --elev: 0 2px 8px rgba(0,0,0,0.08); }
|
|
641
|
+
.card { color: var(--text); background: var(--bg); box-shadow: var(--elev); padding: 16px; }
|
|
642
|
+
button { color: var(--accent); }
|
|
643
|
+
button:focus-visible { outline: 2px solid var(--accent); }
|
|
644
|
+
button:disabled { opacity: 0.5; }
|
|
645
|
+
`;
|
|
646
|
+
const result = audit({ css, pairs: [{ fg: "#111", bg: "#fff", label: "body", weight: 400, size: 16 }] });
|
|
647
|
+
assert.equal(result.pass, true);
|
|
648
|
+
assert.equal(result.gates.slopTells.pass, true);
|
|
649
|
+
assert.equal(result.gates.contrast.pass, true);
|
|
650
|
+
assert.equal(result.gates.tokens.pass, true);
|
|
651
|
+
assert.equal(result.gates.states.pass, true);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// --- REVIEW FIX regressions (v0.4.2) --------------------------------------
|
|
655
|
+
// These pin each reviewer-found bug to a runnable check so they can't return.
|
|
656
|
+
|
|
657
|
+
// FIX 2 (MEDIUM FP): a normal accent focus shadow (≤12px blur) is NOT neon glow.
|
|
658
|
+
test("scanSlopTells does NOT flag a normal accent shadow (≤12px blur)", () => {
|
|
659
|
+
const { tells } = scanSlopTells(".btn { box-shadow: 0 4px 12px rgba(0,102,255,0.35); }");
|
|
660
|
+
assert.deepEqual(tells, [], "small coloured shadow is normal, not glow");
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// FIX 3 (MEDIUM FN): a large coloured hex shadow IS neon glow (was missed).
|
|
664
|
+
test("scanSlopTells flags large coloured hex shadow as neon glow", () => {
|
|
665
|
+
const { tells } = scanSlopTells(".card { box-shadow: 0 0 40px #8b00ff; }");
|
|
666
|
+
assert.equal(tells.length, 1);
|
|
667
|
+
assert.match(tells[0], /neon glow/);
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
test("scanSlopTells flags large coloured rgba glow", () => {
|
|
671
|
+
const { tells } = scanSlopTells(".hero { box-shadow: 0 0 40px 20px rgba(139,0,255,0.6); }");
|
|
672
|
+
assert.equal(tells.length, 1);
|
|
673
|
+
assert.match(tells[0], /neon glow/);
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
test("scanSlopTells still does NOT flag greyscale large shadow", () => {
|
|
677
|
+
const { tells } = scanSlopTells(".card { box-shadow: 0 0 40px rgba(0,0,0,0.4); }");
|
|
678
|
+
assert.deepEqual(tells, [], "greyscale shadow is elevation, not glow");
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
// FIX 4 (LOW): radial-gradient with nested rgba/hsl stops is fully captured.
|
|
682
|
+
test("scanSlopTells flags gradient orb with nested rgba + filter blur", () => {
|
|
683
|
+
const css = ".orb { background: radial-gradient(circle, rgba(138,43,226,0.8) 0%, #4b0082 100%); filter: blur(80px); }";
|
|
684
|
+
const { tells } = scanSlopTells(css);
|
|
685
|
+
assert.equal(tells.length, 1);
|
|
686
|
+
assert.match(tells[0], /gradient orb/);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
test("scanSlopTells does NOT flag a small warm radial highlight", () => {
|
|
690
|
+
const css = ".badge { background: radial-gradient(circle, #fff 0%, #eee 100%); }";
|
|
691
|
+
const { tells } = scanSlopTells(css);
|
|
692
|
+
assert.deepEqual(tells, [], "non-violet small radial is not an orb");
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// FIX 6 (LOW): alpha hex (#RRGGBBAA / #RGBA) is flagged by the token gate.
|
|
696
|
+
test("scanOffSystem flags 8-digit alpha hex outside :root", () => {
|
|
697
|
+
const off = scanOffSystem(".card { color: #ff000080; }", new Map());
|
|
698
|
+
assert.deepEqual(off.hardcodedHex, ["#ff000080"]);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test("scanOffSystem flags 4-digit alpha hex outside :root", () => {
|
|
702
|
+
const off = scanOffSystem(".card { color: #f00f; }", new Map());
|
|
703
|
+
assert.deepEqual(off.hardcodedHex, ["#f00f"]);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
test("scanOffSystem does NOT partial-match an 8-digit hex as a 6-digit value", () => {
|
|
707
|
+
// Regression guard: must report the full 8-digit value, not '#ff0000'.
|
|
708
|
+
const off = scanOffSystem(".card { color: #ff000080; }", new Map());
|
|
709
|
+
assert.ok(!off.hardcodedHex.includes("#ff0000"), "must not partial-match");
|
|
710
|
+
assert.ok(off.hardcodedHex.includes("#ff000080"));
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// --- resolveAuditCss: path vs css param handling ---------------------------
|
|
714
|
+
|
|
715
|
+
test("resolveAuditCss reads a file verbatim via path", () => {
|
|
716
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ux-audit-"));
|
|
717
|
+
const file = path.join(dir, "app.css");
|
|
718
|
+
fs.writeFileSync(file, ".card { color: #111; background: #fff; }\n");
|
|
719
|
+
try {
|
|
720
|
+
assert.equal(resolveAuditCss({ path: file }), ".card { color: #111; background: #fff; }\n");
|
|
721
|
+
} finally {
|
|
722
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
test("resolveAuditCss passes inline css through and enforces exclusivity", () => {
|
|
727
|
+
assert.equal(resolveAuditCss({ css: ".a { color: red; }" }), ".a { color: red; }");
|
|
728
|
+
assert.throws(() => resolveAuditCss({ css: ".a {}", path: "/tmp/x.css" }), /exactly one/);
|
|
729
|
+
assert.throws(() => resolveAuditCss({}), /Pass a stylesheet/);
|
|
730
|
+
assert.throws(() => resolveAuditCss({ css: " " }), /Pass a stylesheet/);
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
test("resolveAuditCss resolves a relative path against the provided cwd, not process.cwd()", () => {
|
|
734
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ux-audit-"));
|
|
735
|
+
fs.writeFileSync(path.join(dir, "app.css"), ".x { color: red; }");
|
|
736
|
+
const prev = process.cwd();
|
|
737
|
+
try {
|
|
738
|
+
process.chdir(os.tmpdir());
|
|
739
|
+
assert.equal(resolveAuditCss({ path: "app.css" }, dir), ".x { color: red; }");
|
|
740
|
+
assert.throws(() => resolveAuditCss({ path: "app.css" }), /ENOENT/);
|
|
741
|
+
} finally {
|
|
742
|
+
process.chdir(prev);
|
|
743
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
test("resolveAuditCss rejects files over the 1MB cap with a clean error", () => {
|
|
748
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ux-audit-"));
|
|
749
|
+
const file = path.join(dir, "big.css");
|
|
750
|
+
fs.writeFileSync(file, "/* pad */ .x { color: red; }".repeat(60 * 1024)); // ~1.15MB
|
|
751
|
+
try {
|
|
752
|
+
assert.throws(() => resolveAuditCss({ path: file }), /1MB audit cap/);
|
|
753
|
+
} finally {
|
|
754
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
755
|
+
}
|
|
756
|
+
});
|