Skip to content

Chrome DevTools for coding agents

test: add eval scenarios for get_css_styles (#2802)

Samiya Caura0c44a429e6c
diff --git a/scripts/eval_gemini.ts b/scripts/eval_gemini.ts
index 4e584e96..3c1adbd4 100644
--- a/scripts/eval_gemini.ts
+++ b/scripts/eval_gemini.ts
@@ -166,7 +166,7 @@ async function runSingleScenario(
debugLog(`\n--- Response ---\n${result.text}`);
debugLog('\nVerifying expectations...');
- scenario.expectations(new Result(allCalls, args));
+ scenario.expectations(new Result(allCalls, args, result.text ?? ''));
} finally {
try {
await client?.close();
diff --git a/scripts/eval_result.ts b/scripts/eval_result.ts
index 8460b56d..b4b3734b 100644
--- a/scripts/eval_result.ts
+++ b/scripts/eval_result.ts
@@ -15,10 +15,13 @@ export class Result {
private nextCallIndex = 0;
public readonly calls: CapturedFunctionCall[];
public readonly serverArgs: string[];
+ /** The model's final response text. */
+ public readonly text: string;
- constructor(calls: CapturedFunctionCall[], serverArgs: string[]) {
+ constructor(calls: CapturedFunctionCall[], serverArgs: string[], text = '') {
this.calls = calls;
this.serverArgs = serverArgs;
+ this.text = text;
}
get hasPageIdRouting(): boolean {
@@ -96,6 +99,20 @@ export class Result {
this.nextCallIndex++;
return call;
}
+
+ /**
+ * Asserts that the model's response contains every given substring,
+ * ignoring case.
+ */
+ assertTextIncludes(...substrings: string[]): void {
+ const textInLowerCase = this.text.toLowerCase();
+ for (const substring of substrings) {
+ assert.ok(
+ textInLowerCase.includes(substring.toLowerCase()),
+ `Expected response to mention '${substring}'. Response: ${this.text}`,
+ );
+ }
+ }
}
export interface TestScenario {
diff --git a/scripts/eval_scenarios/css_cascade_layer_override_test.ts b/scripts/eval_scenarios/css_cascade_layer_override_test.ts
new file mode 100644
index 00000000..decd153e
--- /dev/null
+++ b/scripts/eval_scenarios/css_cascade_layer_override_test.ts
@@ -0,0 +1,65 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Eval scenario: a cascade layer losing to an unlayered rule.
+ */
+
+import assert from 'node:assert';
+
+import type {TestScenario} from '../eval_gemini.ts';
+
+/**
+ * uid of `div#card` (`2_3`) or of its `StaticText` child (`1_1`): a text node
+ * uid resolves to its parent element, so both target the card.
+ */
+const CARD_UIDS = ['1_1', '2_3'];
+
+export const scenario: TestScenario = {
+ prompt: `The featured card on <TEST_URL> is stuck at 400px wide even though I set max-width: 900px for it. Why isn't my rule winning? Do not take screenshots.`,
+ maxTurns: 10,
+ htmlRoute: {
+ path: '/css_layer.html',
+ htmlContent: `
+ <style>
+ @layer base, overrides;
+
+ @layer base {
+ .card { background: #eef; }
+ }
+
+ .layout .card { max-width: 400px; }
+
+ @layer overrides {
+ .card.featured { max-width: 900px; }
+ }
+ </style>
+ <div class="layout">
+ <div class="card featured" id="card">Featured card</div>
+ </div>
+ `,
+ },
+ expectations: result => {
+ const pageId = result.consumePageNavigation();
+ result.assertNextCall(
+ 'take_snapshot',
+ result.hasPageIdRouting ? {pageId} : undefined,
+ );
+
+ const cssCalls = result.calls.filter(c => c.name === 'get_css_styles');
+ assert.ok(
+ cssCalls.length >= 1,
+ `Expected get_css_styles to be called, got: ${result.calls.map(c => c.name).join(', ')}`,
+ );
+ for (const call of cssCalls) {
+ assert.ok(
+ CARD_UIDS.includes(String(call.args.uid)),
+ `get_css_styles should inspect the featured card (${CARD_UIDS.join(' or ')}), got ${call.args.uid}`,
+ );
+ }
+
+ // The winning selector and the reason, neither of which is in the prompt.
+ result.assertTextIncludes('.layout .card', 'layer');
+ },
+};
diff --git a/scripts/eval_scenarios/css_custom_property_resolution_test.ts b/scripts/eval_scenarios/css_custom_property_resolution_test.ts
new file mode 100644
index 00000000..d2a8f2d1
--- /dev/null
+++ b/scripts/eval_scenarios/css_custom_property_resolution_test.ts
@@ -0,0 +1,60 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Eval scenario: resolving a CSS custom property through inheritance.
+ */
+
+import assert from 'node:assert';
+
+import type {TestScenario} from '../eval_gemini.ts';
+
+/**
+ * uids that resolve to `span#label`: the `StaticText "Label"` node in the
+ * default snapshot, or the element itself once a verbose snapshot reveals it.
+ */
+const LABEL_UIDS = ['1_1', '2_3'];
+
+export const scenario: TestScenario = {
+ prompt: `The Label text on <TEST_URL> renders red, even though I set my brand color to blue at the root. Where is the red coming from?`,
+ maxTurns: 6,
+ htmlRoute: {
+ path: '/css_custom_props.html',
+ htmlContent: `
+ <style>
+ @property --gap {
+ syntax: '<length>';
+ inherits: true;
+ initial-value: 4px;
+ }
+ :root { --brand: #00aaff; --gap: 16px; }
+ .panel { --brand: #ff0000; }
+ .panel .label { color: var(--brand); padding: var(--gap); }
+ </style>
+ <div class="panel"><span class="label" id="label">Label</span></div>
+ `,
+ },
+ expectations: result => {
+ const pageId = result.consumePageNavigation();
+ result.assertNextCall(
+ 'take_snapshot',
+ result.hasPageIdRouting ? {pageId} : undefined,
+ );
+
+ const cssCalls = result.calls.filter(c => c.name === 'get_css_styles');
+ assert.ok(
+ cssCalls.length >= 1,
+ `Expected get_css_styles to be called, got: ${result.calls.map(c => c.name).join(', ')}`,
+ );
+ for (const call of cssCalls) {
+ assert.ok(
+ LABEL_UIDS.includes(String(call.args.uid)),
+ `get_css_styles should inspect the Label span (${LABEL_UIDS.join(' or ')}), got ${call.args.uid}`,
+ );
+ }
+
+ // The overriding definition and its value, neither of which is in the prompt.
+ result.assertTextIncludes('.panel', '#ff0000', 'custom property');
+ },
+};
diff --git a/scripts/eval_scenarios/css_descendant_specificity_test.ts b/scripts/eval_scenarios/css_descendant_specificity_test.ts
new file mode 100644
index 00000000..47d90e82
--- /dev/null
+++ b/scripts/eval_scenarios/css_descendant_specificity_test.ts
@@ -0,0 +1,62 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Eval scenario: specificity of long descendant selector chains.
+ */
+
+import assert from 'node:assert';
+
+import type {TestScenario} from '../eval_gemini.ts';
+
+/**
+ * uid of `a#deeplink` (`1_2`) or of its `StaticText` child (`1_3`): a text node
+ * uid resolves to its parent element, so both target the link.
+ */
+const LINK_UIDS = ['1_2', '1_3'];
+
+export const scenario: TestScenario = {
+ prompt: `The Deep link on <TEST_URL> shows up purple, but I have a rule that should make it teal. Why isn't my rule applying?`,
+ maxTurns: 6,
+ htmlRoute: {
+ path: '/css_descendant.html',
+ htmlContent: `
+ <style>
+ main .content .list .item a { color: teal; }
+ .list a { color: olive; }
+ #sidebar a { color: maroon; }
+ html body main .content .list .item.active a { color: rebeccapurple; }
+ </style>
+ <main>
+ <div class="content">
+ <ul class="list">
+ <li class="item active"><a id="deeplink" href="#">Deep link</a></li>
+ </ul>
+ </div>
+ </main>
+ `,
+ },
+ expectations: result => {
+ const pageId = result.consumePageNavigation();
+ result.assertNextCall(
+ 'take_snapshot',
+ result.hasPageIdRouting ? {pageId} : undefined,
+ );
+
+ const cssCalls = result.calls.filter(c => c.name === 'get_css_styles');
+ assert.ok(
+ cssCalls.length >= 1,
+ `Expected get_css_styles to be called, got: ${result.calls.map(c => c.name).join(', ')}`,
+ );
+ for (const call of cssCalls) {
+ assert.ok(
+ LINK_UIDS.includes(String(call.args.uid)),
+ `get_css_styles should inspect the Deep link (${LINK_UIDS.join(' or ')}), got ${call.args.uid}`,
+ );
+ }
+
+ // The winning selector and the reason, neither of which is in the prompt.
+ result.assertTextIncludes('.item.active', 'specificity');
+ },
+};
diff --git a/scripts/eval_scenarios/css_important_vs_specificity_test.ts b/scripts/eval_scenarios/css_important_vs_specificity_test.ts
new file mode 100644
index 00000000..7f5ccc06
--- /dev/null
+++ b/scripts/eval_scenarios/css_important_vs_specificity_test.ts
@@ -0,0 +1,53 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Eval scenario: `!important` beats specificity.
+ */
+
+import assert from 'node:assert';
+
+import type {TestScenario} from '../eval_gemini.ts';
+
+/** uid of `button#cta` in the first page snapshot. */
+const BUTTON_UID = '1_1';
+
+export const scenario: TestScenario = {
+ prompt: `The Buy button on <TEST_URL> renders crimson even though I added a rule to set it to navy. Why does this happen?`,
+ maxTurns: 6,
+ htmlRoute: {
+ path: '/css_important.html',
+ htmlContent: `
+ <style>
+ #cta.primary.large { background-color: navy; }
+ .btn { background-color: crimson !important; }
+ button.btn.primary { background-color: green; }
+ </style>
+ <button id="cta" class="btn primary large">Buy</button>
+ `,
+ },
+ expectations: result => {
+ const pageId = result.consumePageNavigation();
+ result.assertNextCall(
+ 'take_snapshot',
+ result.hasPageIdRouting ? {pageId} : undefined,
+ );
+
+ const cssCalls = result.calls.filter(c => c.name === 'get_css_styles');
+ assert.ok(
+ cssCalls.length >= 1,
+ `Expected get_css_styles to be called, got: ${result.calls.map(c => c.name).join(', ')}`,
+ );
+ for (const call of cssCalls) {
+ assert.strictEqual(
+ call.args.uid,
+ BUTTON_UID,
+ 'get_css_styles should inspect the Buy button',
+ );
+ }
+
+ // The winning rule and the reason it wins, neither of which is in the prompt.
+ result.assertTextIncludes('.btn', '!important');
+ },
+};
diff --git a/scripts/eval_scenarios/css_inline_style_override_test.ts b/scripts/eval_scenarios/css_inline_style_override_test.ts
new file mode 100644
index 00000000..c0a5c0d5
--- /dev/null
+++ b/scripts/eval_scenarios/css_inline_style_override_test.ts
@@ -0,0 +1,54 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Eval scenario: an inline `style` attribute overrides stylesheet rules.
+ */
+
+import assert from 'node:assert';
+
+import type {TestScenario} from '../eval_gemini.ts';
+
+/**
+ * uids that resolve to `span#badge`: the `StaticText "New"` node in the default
+ * snapshot, or the element itself once a verbose snapshot reveals it.
+ */
+const BADGE_UIDS = ['1_1', '2_2'];
+
+export const scenario: TestScenario = {
+ prompt: `On <TEST_URL> the New badge should be purple according to my stylesheet, but it renders green. What is overriding my rule?`,
+ maxTurns: 6,
+ htmlRoute: {
+ path: '/css_inline.html',
+ htmlContent: `
+ <style>
+ #badge.badge { color: purple; font-size: 20px; }
+ .badge { color: navy; }
+ </style>
+ <span class="badge" id="badge" style="color: green; font-size: 30px;">New</span>
+ `,
+ },
+ expectations: result => {
+ const pageId = result.consumePageNavigation();
+ result.assertNextCall(
+ 'take_snapshot',
+ result.hasPageIdRouting ? {pageId} : undefined,
+ );
+
+ const cssCalls = result.calls.filter(c => c.name === 'get_css_styles');
+ assert.ok(
+ cssCalls.length >= 1,
+ `Expected get_css_styles to be called, got: ${result.calls.map(c => c.name).join(', ')}`,
+ );
+ for (const call of cssCalls) {
+ assert.ok(
+ BADGE_UIDS.includes(String(call.args.uid)),
+ `get_css_styles should inspect the New badge (${BADGE_UIDS.join(' or ')}), got ${call.args.uid}`,
+ );
+ }
+
+ // The losing rule must be identified, and the winner named as the inline style.
+ result.assertTextIncludes('#badge', 'element.style', 'inline style');
+ },
+};