Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

test(e2e): probe every editor colour token, keyed off the stylesheet

Sergey Kozyrenkod58f840702e7
diff --git a/frontend/e2e/helpers/contrast.ts b/frontend/e2e/helpers/contrast.ts
index 2723c087..a8e361d4 100644
--- a/frontend/e2e/helpers/contrast.ts
+++ b/frontend/e2e/helpers/contrast.ts
@@ -32,11 +32,16 @@ export const mountContrastProbes = async (page: Page, probes: Record<string, str
);
};
-// Editor highlight tokens are styled through the `.tiptap-content .ProseMirror .template-*`
-// selector, so a flat probe span (as in mountContrastProbes) would pick up none of it and
-// measure nothing. Reproduce the real ancestor chain on the shipped class. Surface is --card,
-// within ~0.005 L of the editor's real `dark:bg-input/30` ground and conservative for the floor.
-export const mountEditorProbes = async (page: Page, probes: Record<string, string>): Promise<void> => {
+export interface EditorProbe {
+ className?: string;
+ tag: string;
+}
+
+// Editor highlight tokens are styled through `.tiptap-content .ProseMirror <selector>`, so a flat
+// probe span (as in mountContrastProbes) would pick up none of it and measure nothing. Reproduce
+// the real ancestor chain on the shipped element. Surface is --card, within ~0.005 L of the
+// editor's real `dark:bg-input/30` ground and conservative for the floor.
+export const mountEditorProbes = async (page: Page, probes: Record<string, EditorProbe>): Promise<void> => {
await page.evaluate(
({ entries, hostId }) => {
document.getElementById(hostId)?.remove();
@@ -51,10 +56,10 @@ export const mountEditorProbes = async (page: Page, probes: Record<string, strin
surface.className = 'ProseMirror';
surface.style.cssText = 'background:var(--card);display:flex;gap:8px;padding:8px';
- for (const [name, className] of entries) {
- const probe = document.createElement('span');
+ for (const [name, { className, tag }] of entries) {
+ const probe = document.createElement(tag);
- probe.className = className;
+ probe.className = className ?? '';
probe.dataset.contrast = name;
probe.textContent = 'Sample';
surface.append(probe);
@@ -63,13 +68,13 @@ export const mountEditorProbes = async (page: Page, probes: Record<string, strin
host.append(surface);
document.body.append(host);
- // Both token rules paint a chip via color-mix, so a transparent probe
- // means its class matched nothing — a rename, or the rule moving out
- // from under the ancestor chain above. Without this the measurement
- // silently falls back to the page's default text pair, which clears AA.
+ // A probe still wearing the surface's own colour matched no rule. Without this the
+ // measurement falls back to the page's default text pair, which clears AA silently.
+ const inherited = getComputedStyle(surface).color;
+
for (const probe of surface.children) {
- if (getComputedStyle(probe).backgroundColor === 'rgba(0, 0, 0, 0)') {
- throw new Error(`editor contrast probe "${probe.className}" matched no style rule`);
+ if (getComputedStyle(probe).color === inherited) {
+ throw new Error(`editor contrast probe "${probe.getAttribute('data-contrast')}" matched no rule`);
}
}
},
diff --git a/frontend/e2e/specs/cross/contrast.spec.ts b/frontend/e2e/specs/cross/contrast.spec.ts
index 5c11ff2e..0c1756ca 100644
--- a/frontend/e2e/specs/cross/contrast.spec.ts
+++ b/frontend/e2e/specs/cross/contrast.spec.ts
@@ -1,16 +1,29 @@
+import { readFileSync } from 'node:fs';
+
import type { BadgeVariant } from '@/components/ui/badge';
import { badgeVariants } from '@/components/ui/badge';
import { buttonVariants } from '@/components/ui/button';
+import type { EditorProbe } from '../../helpers/contrast.ts';
+
import { expect, test } from '../../fixtures/test.ts';
import { AA_NORMAL, measureContrast, mountContrastProbes, mountEditorProbes } from '../../helpers/contrast.ts';
import { flowsCassette } from '../../mocks/cassettes/flows.ts';
-const EDITOR_TOKENS = {
- 'editor-tag': 'template-tag',
- 'editor-variable': 'template-variable',
-} as const;
+const EDITOR_PROBES = {
+ 'editor-accent': { tag: 'a' },
+ 'editor-code': { tag: 'code' },
+ 'editor-tag': { className: 'template-tag', tag: 'span' },
+ 'editor-variable': { className: 'template-variable', tag: 'span' },
+} satisfies Record<string, EditorProbe>;
+
+/** The stylesheet is the token list, so a newly declared `--editor-*` has to be probed or exempted. */
+const declaredEditorTokens = (): string[] => {
+ const css = readFileSync(new URL('../../../src/styles/index.css', import.meta.url), 'utf8');
+
+ return [...new Set(css.match(/--editor-[\w-]+/g) ?? [])].map((token) => token.slice(2));
+};
// Keyed off the union so a newly added variant fails to compile until it is probed.
const BADGE_VARIANTS = Object.keys({
@@ -29,6 +42,16 @@ const BADGE_VARIANTS = Object.keys({
const THEMES = ['light', 'dark'] as const;
+test('every editor colour token is probed', { tag: '@cross' }, () => {
+ const probed = new Set(Object.keys(EDITOR_PROBES));
+ // A `-bg` token is the paired ground of its base probe, measured with it.
+ const uncovered = declaredEditorTokens().filter(
+ (token) => !probed.has(token) && !(token.endsWith('-bg') && probed.has(token.slice(0, -3))),
+ );
+
+ expect(uncovered).toEqual([]);
+});
+
for (const theme of THEMES) {
test.describe(`contrast (${theme})`, { tag: '@cross' }, () => {
test.use({ cassette: flowsCassette() });
@@ -81,9 +104,9 @@ for (const theme of THEMES) {
await expect(page.getByRole('row', { name: /E2E Alpha/ })).toBeVisible();
await expect(page.locator('html')).toHaveClass(theme === 'dark' ? /dark/ : /light/);
- await mountEditorProbes(page, EDITOR_TOKENS);
+ await mountEditorProbes(page, EDITOR_PROBES);
- for (const token of Object.keys(EDITOR_TOKENS)) {
+ for (const token of Object.keys(EDITOR_PROBES)) {
expect
.soft(await measureContrast(page, token), `${token} (${theme})`)
.toBeGreaterThanOrEqual(AA_NORMAL);