Repository navigation
Simplify callback type checking in audit site test - #63
Conversation
- @modelcontextprotocol/sdk 1.27.1 → 1.29.0 - playwright/playwright-core 1.58.2 → 1.59.1 - dotenv 17.2.4 → 17.4.1, re2 1.23.2 → 1.24.0, ws 8.19.0 → 8.20.0 - vitest 4.0.18 → 4.1.2, typescript-eslint 8.54.0 → 8.58.0 - Other devDependency minor/patch updates - Fix test mock compatibility with Playwright 1.59 callback serialization https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughBumps Node and package versions in Changes
Sequence Diagram(s)(Skipped) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Around line 40-48: Update the package.json engines.node field to match the
actual runtime requirements of the upgraded dev dependencies: change the current
"engines.node" declaration (in package.json) from ">=18.0.0" to either "^18.18.0
|| ^20.9.0 || >=21.1.0" to satisfy eslint/@typescript-eslint constraints, or set
it to ">=20.0.0" (or another single policy like "^20.0.0") to satisfy vitest;
update the engines.node value accordingly and run a quick npm install/check to
verify no tool complains.
In `@tests/tools-auditSite.test.ts`:
- Around line 54-56: The evaluate mock currently detects navigation callbacks by
exact substring matching of callbackText which is brittle; update the mock in
tests/tools-auditSite.test.ts to use a tolerant regex or strategy-aware signal
to detect nav callbacks instead of the exact string match — e.g., change the
check around callbackText.includes('nav a[href], header a[href],
[role="navigation"] a[href]') to a regex test or use an explicit flag in the
evaluate mock so that when the mock is supposed to emulate the nav strategy it
returns navLinkMap[currentUrl] ?? []; ensure you update the evaluate mock logic
that references callbackText, navLinkMap, and currentUrl so it reliably
identifies navigation callbacks across serialization changes.
🪄 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: 2d6f985c-3398-4cd2-b835-9f2e801404c9
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.jsontests/tools-auditSite.test.ts
- Use tolerant regex for nav callback detection in test mock to handle varying serialization of evaluate callbacks across Playwright versions - Update engines.node from >=18.0.0 to >=24.0.0 - Properly install @modelcontextprotocol/sdk 1.29.0 https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
There was a problem hiding this comment.
Code Review
This pull request updates numerous dependencies, including @modelcontextprotocol/sdk, playwright, dotenv, and vitest, and upgrades vite to version 8.0.5. In the test suite, a change was made to simplify the string conversion of callbacks; however, feedback suggests that maintaining an explicit type check for functions is safer to avoid issues with non-function objects.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8187a6cffb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Playwright 1.59 removed the private _snapshotForAI method. Replace all
usages with the public page.ariaSnapshot({ mode: 'ai' }) API and update
test mocks accordingly. Also update engines.node to >=24.0.0 and use
tolerant regex for nav callback detection in test mock.
https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
|
@coderabbitai review it again |
|
🧠 Learnings used✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/tab.ts (1)
26-28: Drop the hand-writtenPageExoverlay.Playwright already exposes
page.ariaSnapshot(options)onPage, and the documented option bag also includesdepthandtimeout. This local type narrows that signature, so it can drift again on the next Playwright bump. Preferthis.page.ariaSnapshot(...)directly, or reuseplaywright.Page['ariaSnapshot'], instead of maintaining a shadow API. (playwright.dev)♻️ Proposed cleanup
-type PageEx = playwright.Page & { - ariaSnapshot: (options?: { mode?: 'ai' | 'default' }) => Promise<string>; -};- const snapshot = await (this.page as PageEx).ariaSnapshot({ mode: 'ai' }); + const snapshot = await this.page.ariaSnapshot({ mode: 'ai' });- const snapshot = await (this.page as PageEx).ariaSnapshot({ mode: 'ai' }); + const snapshot = await this.page.ariaSnapshot({ mode: 'ai' });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tab.ts` around lines 26 - 28, The local PageEx type narrows Playwright's Page.ariaSnapshot signature and should be removed; replace uses of PageEx and any casts to PageEx with the real Playwright API (use this.page.ariaSnapshot(...) directly) or reference the declared type via playwright.Page['ariaSnapshot'] if a type is needed, and ensure call sites accept the documented options (including depth and timeout) instead of the limited { mode?: 'ai' | 'default' } shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Around line 89-90: The package.json declares "engines.node": ">=24.0.0" but
the project Dockerfile uses a Node 22 base image; make these consistent by
either updating the Dockerfile FROM image to a Node 24 variant (e.g., change the
FROM lines to node:24-bookworm-slim) or relaxing package.json engines.node back
to ">=22.0.0". Update the Dockerfile if you intend to require Node 24+ (ensure
any Dockerfile-specific build steps remain compatible), otherwise change the
package.json engines.node value to ">=22.0.0" so the advertised Node floor
matches the shipped container.
In `@tests/tab.test.ts`:
- Line 35: The tests set mockPage.ariaSnapshot to always return AI-style
snapshots, so they don't verify that production code calls ariaSnapshot with the
{ mode: 'ai' } option; update the mocks and assertions: change
mockPage.ariaSnapshot (used in tests/tab.test.ts) to a mockImplementation that
returns AI-format only when options?.mode === 'ai' and otherwise returns a
non-AI snapshot, then add expect(mockPage.ariaSnapshot).toHaveBeenCalledWith({
mode: 'ai' }) assertions at the places corresponding to the two usages (the
setup at the top of the test and the later mock at line ~198) to ensure
ariaSnapshot is invoked with the correct option.
---
Nitpick comments:
In `@src/tab.ts`:
- Around line 26-28: The local PageEx type narrows Playwright's
Page.ariaSnapshot signature and should be removed; replace uses of PageEx and
any casts to PageEx with the real Playwright API (use
this.page.ariaSnapshot(...) directly) or reference the declared type via
playwright.Page['ariaSnapshot'] if a type is needed, and ensure call sites
accept the documented options (including depth and timeout) instead of the
limited { mode?: 'ai' | 'default' } shape.
🪄 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: aca207f4-ad6f-4bcf-9fa1-7006c41c1066
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
package.jsonsrc/tab.tstests/tab.test.tstests/tools-auditSite.test.ts
- Remove unnecessary PageEx type extension; use native Playwright
page.ariaSnapshot() types directly
- Add mock assertion verifying ariaSnapshot is called with { mode: 'ai' }
- Update Dockerfile from node:22 to node:24 to align with engines.node
https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
|
@coderabbitai review it again |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
tests/tab.test.ts (1)
35-35:⚠️ Potential issue | 🟡 MinorAdd mode assertions for ref-based snapshot tests too.
Line 188 and Line 199 re-mock
ariaSnapshot, butrefLocator/refLocatorsstill don’t assert{ mode: 'ai' }. Those tests can pass even if options are dropped in those paths.Suggested test hardening
@@ describe('refLocator', () => { @@ it('should throw error if ref not found', async () => { const tab = new Tab(mockContext, mockPage as any, onPageClose); mockPage.ariaSnapshot = vi.fn().mockResolvedValue('button "Other"'); @@ await expect( tab.refLocator({ element: 'Submit button', ref: '999' }) ).rejects.toThrow('Ref 999 not found'); + expect(mockPage.ariaSnapshot).toHaveBeenCalledWith({ mode: 'ai' }); }); }); @@ describe('refLocators', () => { @@ it('should get multiple locators', async () => { const tab = new Tab(mockContext, mockPage as any, onPageClose); mockPage.ariaSnapshot = vi.fn().mockResolvedValue('button "Submit" [ref=1] button "Cancel" [ref=2]'); @@ expect(locators).toHaveLength(2); expect(mockPage.locator).toHaveBeenCalledWith('aria-ref=1'); expect(mockPage.locator).toHaveBeenCalledWith('aria-ref=2'); + expect(mockPage.ariaSnapshot).toHaveBeenCalledWith({ mode: 'ai' }); }); });#!/bin/bash set -euo pipefail # Verify current assertions around ariaSnapshot mode in tab tests rg -n "ariaSnapshot|toHaveBeenCalledWith\\(\\{ mode: 'ai' \\}\\)" tests/tab.test.ts -C2 sed -n '180,215p' tests/tab.test.tsAs per coding guidelines "Use nearby Vitest coverage when adding or changing behavior that is already tested".
Also applies to: 188-193, 199-209
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/tab.test.ts` at line 35, The tests re-mock mockPage.ariaSnapshot in the ref-based scenarios but do not assert that the options include { mode: 'ai' }, allowing regressions; update the ref-based tests that exercise refLocator/refLocators to include assertions on mockPage.ariaSnapshot (e.g., expect(mockPage.ariaSnapshot).toHaveBeenCalledWith(expect.objectContaining({ mode: 'ai' })) or the exact object) so both the initial and re-mocked calls verify the { mode: 'ai' } option is passed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@tests/tab.test.ts`:
- Line 35: The tests re-mock mockPage.ariaSnapshot in the ref-based scenarios
but do not assert that the options include { mode: 'ai' }, allowing regressions;
update the ref-based tests that exercise refLocator/refLocators to include
assertions on mockPage.ariaSnapshot (e.g.,
expect(mockPage.ariaSnapshot).toHaveBeenCalledWith(expect.objectContaining({
mode: 'ai' })) or the exact object) so both the initial and re-mocked calls
verify the { mode: 'ai' } option is passed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ca9abef5-1675-44f4-bf9b-b47c9ddb2aa1
📒 Files selected for processing (3)
Dockerfilesrc/tab.tstests/tab.test.ts
✅ Files skipped from review due to trivial changes (1)
- Dockerfile
|
Focus areas:
I’ll apply the prior learning about Axe + Playwright integrations and existing test patterns while reviewing. 🧠 Learnings used✅ Actions performedReview triggered.
|
Verify that ariaSnapshot is called with { mode: 'ai' } in refLocator,
refLocators, and ref-not-found test cases.
https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
Summary
This PR simplifies the callback type checking logic in the audit site test harness by using
String()constructor instead of a conditional ternary operator.Changes
typeof callback === 'function' ? callback.toString() : ''withString(callback)in theevaluatemock functionString()constructor handles both function and non-function types uniformlyString()will convert any value to its string representationDependencies
Updated multiple dependencies to their latest versions:
@modelcontextprotocol/sdk: 1.27.1 → 1.29.0playwrightandplaywright-core: 1.58.2 → 1.59.1@typescript-eslint/*: 8.54.0 → 8.58.0vitestand related packages: 4.0.18 → 4.1.2https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
Summary by CodeRabbit
Chores
Tests