mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-08-24 12:06:36 +00:00
test(e2e): fail the contrast probe on an unparseable colour
paint() set fillStyle to black, then to the requested colour — but an unparseable colour is a silent no-op on fillStyle, leaving black, which measures as a spurious ~21:1 pass. Assign the colour against two different sentinels and throw when it doesn't land on the same value, so a broken colour surfaces the gate instead of clearing it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
cb0ec25319
commit
abef4e29b8
@@ -100,8 +100,21 @@ export const measureContrast = async (page: Page, probe: string): Promise<number
|
||||
context.clearRect(0, 0, 1, 1);
|
||||
|
||||
for (const layer of layers) {
|
||||
// An unparseable colour is a silent no-op on fillStyle, leaving the previous
|
||||
// value — which measures as a spurious ~21:1 pass. Assign it against two
|
||||
// different sentinels: a colour that applied lands on the same value both
|
||||
// times, an invalid one keeps whichever sentinel preceded it.
|
||||
context.fillStyle = '#000000';
|
||||
context.fillStyle = layer;
|
||||
const fromBlack = context.fillStyle;
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillStyle = layer;
|
||||
|
||||
if (context.fillStyle !== fromBlack) {
|
||||
throw new Error(`contrast: colour "${layer}" did not apply`);
|
||||
}
|
||||
|
||||
context.fillRect(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user