Skip to content

GH#681: Add Playwright E2E tests for benchmark page - #682

Merged
superdav42 merged 3 commits into
mainfrom
feature/benchmark-e2e-tests
Mar 29, 2026
Merged

GH#681: Add Playwright E2E tests for benchmark page#682
superdav42 merged 3 commits into
mainfrom
feature/benchmark-e2e-tests

Conversation

@superdav42

@superdav42 superdav42 commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Registers ModelBenchmarkPage under the Tools menu so the standalone benchmark React SPA is accessible at tools.php?page=gratis-ai-agent-benchmark (fixes regression from UnifiedAdminMenu PR docs: update AGENTS.md #679)
  • Removes the legacy redirect for gratis-ai-agent-benchmark from UnifiedAdminMenu::handleLegacyRedirects() so the page renders instead of redirecting to #/settings
  • Adds goToBenchmarkPage() navigation helper to tests/e2e/utils/wp-admin.js
  • Creates tests/e2e/benchmark-page.spec.js with 19 test cases across 4 describe blocks

Test Coverage

Describe block Tests
Page Render 4 — wrap/heading, React app mount, tab panel, Configure Benchmark card
Form Inputs 8 — Run Name, Description, Test Suite, Model Selector, Start Benchmark button, model selection, Select All, Deselect All
Run List 5 — History tab, Benchmark History heading, run name, View/Delete buttons, status badge
Empty Run List 1 — empty state message

REST API responses (/benchmark/suites, /providers, /benchmark/runs) are mocked via page.route() for deterministic, provider-independent tests.

Runtime Testing

  • Risk level: Low (test files only + PHP registration hook)
  • Level: self-assessed — test files and a one-line PHP hook addition
  • Smoke check: JS syntax validated with node --check; PHP validated with PHPCS (0 violations)

Files Changed

File What / Why
gratis-ai-agent.php Add ModelBenchmarkPage::register() hook — restores benchmark page access removed in #679
includes/Admin/UnifiedAdminMenu.php Remove gratis-ai-agent-benchmark from legacy redirect map — allows page to render
tests/e2e/utils/wp-admin.js Add goToBenchmarkPage() helper + export
tests/e2e/benchmark-page.spec.js New: 19 E2E test cases for benchmark page

Actionable Findings

  • actionable_findings_total=0
  • fixed_in_pr=0
  • deferred_tasks_created=0
  • coverage=100%

Closes #681


aidevops.sh v3.5.126 plugin for OpenCode v1.3.0 with claude-sonnet-4-6 spent 24m and 24,372 tokens on this as a headless worker.

Summary by CodeRabbit

  • New Features

    • Model Benchmark page is now directly accessible from the admin Tools menu as a standalone interface.
  • Bug Fixes

    • Removed legacy redirect for the old benchmark admin page so the standalone page loads without redirection.
  • Tests

    • Added end-to-end tests and a test helper for benchmark configuration, model selection, history display, and empty-state behavior.

- Register ModelBenchmarkPage under Tools menu so the standalone React
  SPA is accessible at tools.php?page=gratis-ai-agent-benchmark
- Remove the legacy redirect for gratis-ai-agent-benchmark from
  UnifiedAdminMenu::handleLegacyRedirects() so the page is not
  intercepted before it can render
- Add goToBenchmarkPage() helper to tests/e2e/utils/wp-admin.js
- Create tests/e2e/benchmark-page.spec.js with 19 test cases across
  4 describe blocks covering:
  - Page render: wrap/heading, React app mount, tab panel, form card
  - Form inputs: Run Name, Description, Test Suite, Model Selector,
    Start Benchmark button, model selection, Select/Deselect All
  - Run list: History tab, Benchmark History heading, run name,
    View/Delete buttons, status badge
  - Empty run list: empty state message

REST API responses are mocked via page.route() for deterministic tests.

Closes #681
@github-actions github-actions Bot added the enhancement Auto-created from TODO.md tag label Mar 29, 2026
@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b528f139-c92f-4254-bafa-558da8fc5df4

📥 Commits

Reviewing files that changed from the base of the PR and between 108bc80 and 44a2f11.

📒 Files selected for processing (1)
  • tests/e2e/benchmark-page.spec.js
✅ Files skipped from review due to trivial changes (1)
  • tests/e2e/benchmark-page.spec.js

📝 Walkthrough

Walkthrough

This PR registers the Model Benchmark admin page as a standalone Tools menu item, removes an old legacy redirect for the benchmark page, and adds Playwright E2E tests plus a test helper to exercise rendering, form interactions, model selection, and run history behaviors.

Changes

Cohort / File(s) Summary
Admin registration & routing
gratis-ai-agent.php, includes/Admin/UnifiedAdminMenu.php
Register GratisAiAgent\Admin\ModelBenchmarkPage::register() on admin_menu to expose a Tools page; remove legacy redirect entry for page=gratis-ai-agent-benchmark from unified menu redirect map.
E2E tests
tests/e2e/benchmark-page.spec.js
Add comprehensive Playwright tests for benchmark page: render checks, tabs (New Benchmark / History), form inputs (run name/description, suite select), model selector interactions (provider groups, select all/deselect), start button state, run history list and empty state, and mocked REST intercepts.
E2E utilities
tests/e2e/utils/wp-admin.js
Add and export goToBenchmarkPage(page) helper to navigate to /wp-admin/tools.php?page=gratis-ai-agent-benchmark and wait for benchmark root to appear (non-fatal timeout).

Sequence Diagram(s)

sequenceDiagram
  participant Browser as "Admin Browser\n(runs Playwright)"
  participant WP as "WordPress Admin\nPHP (menu registration)"
  participant REST as "WP REST API\n(gratis-ai-agent endpoints)"
  participant DB as "Database / Storage"

  rect rgba(135,206,250,0.5)
    Browser->>WP: GET /wp-admin/tools.php?page=gratis-ai-agent-benchmark
    WP->>Browser: Serve admin page + React app root
  end

  rect rgba(144,238,144,0.5)
    Browser->>REST: GET /wp/v2/gratis-ai-agent/suites (mocked in tests)
    REST->>Browser: 200 { suites: [...] }
    Browser->>REST: GET /.../providers (mocked)
    REST->>Browser: 200 { providers: [...] }
  end

  rect rgba(255,182,193,0.5)
    Browser->>Browser: User fills form, selects models
    Browser->>REST: POST /.../runs (creates benchmark run)
    REST->>DB: persist run
    DB->>REST: persisted run
    REST->>Browser: 201 { run: {...} }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I hopped into Tools, a page newly sown,

Benchmarks and tests now have a safe home.
Playwright scurries, mocks all in tune —
Models selected beneath the full moon.
Hooray for green runs and carrots at noon!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding E2E tests for the benchmark page, with an issue reference for traceability.
Linked Issues check ✅ Passed The PR implements all coding objectives from #681: provides E2E test coverage with 19 test cases exceeding the ≥4 requirement, covers page render/tabs, model and suite selectors, form inputs, run list display, and mocks REST API responses.
Out of Scope Changes check ✅ Passed All changes directly support the E2E test implementation. The PHP registration hook and legacy redirect removal restore benchmark page accessibility that was removed in PR #679, enabling the E2E tests to function properly.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/benchmark-e2e-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/e2e/benchmark-page.spec.js (1)

414-466: Consider extracting a parameterized mock helper to reduce duplication.

The beforeEach block duplicates most of mockBenchmarkApi(), only differing in the runs response. You could parameterize the helper:

Optional refactor
-async function mockBenchmarkApi( page ) {
+async function mockBenchmarkApi( page, { runs = MOCK_RUNS } = {} ) {
	// ... suites and providers intercepts unchanged ...

	await page.route(
		( url ) => {
			const decoded = decodeURIComponent( url.toString() );
			return (
				decoded.includes( 'gratis-ai-agent/v1/benchmark/runs' ) &&
				! decoded.includes( '/run-next' )
			);
		},
		async ( route ) => {
			if ( route.request().method() === 'GET' ) {
				await route.fulfill( {
					status: 200,
					contentType: 'application/json',
-					body: JSON.stringify( MOCK_RUNS ),
+					body: JSON.stringify( runs ),
				} );
			} else {
				await route.continue();
			}
		}
	);
}

Then in Empty Run List:

test.beforeEach( async ( { page } ) => {
	await loginToWordPress( page );
	await mockBenchmarkApi( page, { runs: { runs: [] } } );
	await goToBenchmarkPage( page );
} );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/benchmark-page.spec.js` around lines 414 - 466, The beforeEach in
the "Benchmark Page - Empty Run List" test duplicates the routes from
mockBenchmarkApi() except for the runs response; refactor by extracting a
parameterized helper mockBenchmarkApi(page, overrides) that registers the same
routes (suites -> MOCK_SUITES, providers -> MOCK_PROVIDERS, runs -> default or
overridden response) and accepts an overrides object (e.g., { runs: { runs: [] }
}) to replace the runs body, then update this test's test.beforeEach to call
loginToWordPress(page); await mockBenchmarkApi(page, { runs: { runs: [] } });
and await goToBenchmarkPage(page) so duplication is removed and the runs
response is customized via the helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/e2e/benchmark-page.spec.js`:
- Around line 262-274: Rename the test title to match the assertion and
behavior: update the test(...) description currently "Start Benchmark button is
disabled when no model is selected" to something like "Start Benchmark button is
enabled when no model is selected (clicking shows notice)"; leave the assertion
that startBtn (obtained via page.getByRole('button', { name: /start benchmark/i
})) is enabled and keep the surrounding comment about handleCreateRun showing a
notice instead of submitting.

---

Nitpick comments:
In `@tests/e2e/benchmark-page.spec.js`:
- Around line 414-466: The beforeEach in the "Benchmark Page - Empty Run List"
test duplicates the routes from mockBenchmarkApi() except for the runs response;
refactor by extracting a parameterized helper mockBenchmarkApi(page, overrides)
that registers the same routes (suites -> MOCK_SUITES, providers ->
MOCK_PROVIDERS, runs -> default or overridden response) and accepts an overrides
object (e.g., { runs: { runs: [] } }) to replace the runs body, then update this
test's test.beforeEach to call loginToWordPress(page); await
mockBenchmarkApi(page, { runs: { runs: [] } }); and await
goToBenchmarkPage(page) so duplication is removed and the runs response is
customized via the helper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31fd01d1-add7-4a21-984f-44d45fc3c027

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8dd1a and 108bc80.

📒 Files selected for processing (4)
  • gratis-ai-agent.php
  • includes/Admin/UnifiedAdminMenu.php
  • tests/e2e/benchmark-page.spec.js
  • tests/e2e/utils/wp-admin.js
💤 Files with no reviewable changes (1)
  • includes/Admin/UnifiedAdminMenu.php

Comment thread tests/e2e/benchmark-page.spec.js Outdated
The test name said 'disabled when no model is selected' but the
assertion was toBeEnabled(). The button is always enabled — validation
fires at runtime via a notice, not by disabling the button.

Addresses CodeRabbit review on PR #682.
…ators

Use exact: true for 'Select All' and 'Deselect All' button locators to
prevent Playwright strict mode violations. The regex /select all/i
matched both buttons because 'Deselect All' contains 'select all'.

Fixes CI failure on PR #682.
@superdav42
superdav42 merged commit 899f291 into main Mar 29, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add E2E tests for model benchmark page (PR #663)

1 participant