Skip to content

Simplify callback type checking in audit site test - #63

Merged
JustasMonkev merged 5 commits into
mainfrom
claude/update-dependencies-IoMJK
Apr 8, 2026
Merged

JustasMonkev merged 5 commits into
mainfrom
claude/update-dependencies-IoMJK

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Apr 7, 2026 •

Copy link
Copy Markdown
Owner

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

  • Simplified callback conversion: Replaced typeof callback === 'function' ? callback.toString() : '' with String(callback) in the evaluate mock function
    • The String() constructor handles both function and non-function types uniformly
    • Reduces code complexity while maintaining the same behavior
    • The conditional was unnecessary since String() will convert any value to its string representation

Dependencies

Updated multiple dependencies to their latest versions:

  • @modelcontextprotocol/sdk: 1.27.1 → 1.29.0
  • playwright and playwright-core: 1.58.2 → 1.59.1
  • @typescript-eslint/*: 8.54.0 → 8.58.0
  • vitest and related packages: 4.0.18 → 4.1.2
  • And various other minor and patch version updates

https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz

Summary by CodeRabbit

  • Chores

    • Bumped runtime and development packages and raised Node engine requirement to >=24.0.0.
    • Updated build/runtime container to Node 24 to match the engine requirement.
    • Switched snapshot collection to use the public snapshot API.
  • Tests

    • Updated test mocks to match the snapshot API change and improved navigation-link detection for reliability.

- @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
@coderabbitai

coderabbitai Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a08dddeb-765f-4a0f-b878-9b1a5b05eb8e

📥 Commits

Reviewing files that changed from the base of the PR and between bcc4e71 and 3a3f8f0.

📒 Files selected for processing (1)
  • tests/tab.test.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/tab.test.ts

📝 Walkthrough

Walkthrough

Bumps Node and package versions in package.json (engines.node → >=24.0.0), switches Docker base image to Node 24, replaces private Playwright _snapshotForAI() usage with public page.ariaSnapshot({ mode: 'ai' }) in src/tab.ts, and updates tests/mocks and a crawl-page evaluate callback stringification/regex.

Changes

Cohort / File(s) Summary
Package manifest
package.json
Dependency and devDependency version bumps (e.g., @modelcontextprotocol/sdk → ^1.29.0, dotenv → ^17.4.1, playwright/playwright-core → ^1.59.1, re2 → ^1.24.0, ws → ^8.20.0, ESLint/TS/Vitest and @types/* upgrades). engines.node raised from >=18.0.0 to >=24.0.0.
Docker base image
Dockerfile
Build and runtime base image changed from node:22-bookworm-slim to node:24-bookworm-slim. No other Dockerfile steps altered.
Tab / Playwright API
src/tab.ts
Removed local PageEx type and replaced private _snapshotForAI() calls with public page.ariaSnapshot({ mode: 'ai' }) in captureSnapshot() and refLocators().
Tests (mocks & expectations)
tests/tab.test.ts, tests/tools-auditSite.test.ts
Mocks updated to use mockPage.ariaSnapshot instead of _snapshotForAI; tests now assert ariaSnapshot({ mode: 'ai' }) invocation. In tools-auditSite.test.ts, crawlPage.page.evaluate stringifies callback via String(callback) and navigation-link detection uses a regex test on that text.

Sequence Diagram(s)

(Skipped)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nudged the versions, soft and spry,
Swapped whispered snaps for aria's cry.
Tests sing strings, regex hops to see,
Node put on twenty-four for me.
A carrot-coded cheer — let's ship with glee!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title references simplifying callback type checking in audit site test, but the changeset encompasses much broader scope: dependency version bumps, Node.js engine requirement change, migration to Playwright's public ariaSnapshot API, and test updates across multiple files. Update the title to reflect the primary change (e.g., 'Update dependencies and migrate to Playwright ariaSnapshot API') or ensure the title matches if the callback simplification is truly the main focus.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 claude/update-dependencies-IoMJK

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
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d6e5bc and d3a246d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • tests/tools-auditSite.test.ts

Comment thread package.json Resolved
Comment thread tests/tools-auditSite.test.ts Resolved
- 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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tests/tools-auditSite.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread package.json Resolved
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
@JustasMonkev

Copy link
Copy Markdown
Owner Author

@coderabbitai review it again

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@JustasMonkev Sure! I'll re-review the changes in PR #63 now.


🧠 Learnings used
Learnt from: CR
Repo: JustasMonkev/mcp-accessibility-scanner PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-12T06:39:07.144Z
Learning: Applies to src/tools/**/*.ts : Accessibility behavior centers around Axe + Playwright integrations in `src/tools/axe.ts`, `src/tools/auditSite.ts`, `src/tools/auditKeyboard.ts`, and related helpers

Learnt from: CR
Repo: JustasMonkev/mcp-accessibility-scanner PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-02-23T15:13:53.847Z
Learning: Applies to tests/tools-*.test.ts : Tool tests should follow existing patterns in `tests/tools-*.test.ts` and mock Playwright/tab/context behavior
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/tab.ts (1)

26-28: Drop the hand-written PageEx overlay.

Playwright already exposes page.ariaSnapshot(options) on Page, and the documented option bag also includes depth and timeout. This local type narrows that signature, so it can drift again on the next Playwright bump. Prefer this.page.ariaSnapshot(...) directly, or reuse playwright.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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d6e5bc and e9573f3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • src/tab.ts
  • tests/tab.test.ts
  • tests/tools-auditSite.test.ts

Comment thread package.json Resolved
Comment thread tests/tab.test.ts Resolved
- 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
@JustasMonkev

Copy link
Copy Markdown
Owner Author

@coderabbitai review it again

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
tests/tab.test.ts (1)

35-35: ⚠️ Potential issue | 🟡 Minor

Add mode assertions for ref-based snapshot tests too.

Line 188 and Line 199 re-mock ariaSnapshot, but refLocator/refLocators still 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.ts

As 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

📥 Commits

Reviewing files that changed from the base of the PR and between e9573f3 and bcc4e71.

📒 Files selected for processing (3)
  • Dockerfile
  • src/tab.ts
  • tests/tab.test.ts
✅ Files skipped from review due to trivial changes (1)
  • Dockerfile

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@JustasMonkev Understood—kicking off a fresh review of PR #63 now.

Focus areas:

  • tests/tools-auditSite.test.ts: String(callback) conversion and new nav-link detection regex behavior.
  • src/tab.ts and tests: migration to page.ariaSnapshot({ mode: 'ai' }) with Playwright 1.59 compatibility.
  • package.json: engines.node >= 24.0.0 and dependency bumps for any breaking/tooling impacts.

I’ll apply the prior learning about Axe + Playwright integrations and existing test patterns while reviewing.


🧠 Learnings used
Learnt from: CR
Repo: JustasMonkev/mcp-accessibility-scanner PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-12T06:39:07.144Z
Learning: Applies to src/tools/**/*.ts : Accessibility behavior centers around Axe + Playwright integrations in `src/tools/axe.ts`, `src/tools/auditSite.ts`, `src/tools/auditKeyboard.ts`, and related helpers
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Verify that ariaSnapshot is called with { mode: 'ai' } in refLocator,
refLocators, and ref-not-found test cases.

https://claude.ai/code/session_015R3AFZfpJBKW2R4wPED1Gz
@JustasMonkev
JustasMonkev merged commit 0bfc3e8 into main Apr 8, 2026
2 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants