Skip to content

[js] hold BiDi numbers to their declared ranges - #18272

Merged
diemol merged 2 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:js-bidi-number-ranges
Nov 2, 2026
Merged

diemol merged 2 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:js-bidi-number-ranges

Conversation

@saiyam-jain-dev

@saiyam-jain-dev saiyam-jain-dev commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Related Issues

Implements JavaScript portion of #18195
Follow-on from #18198 and #18230

💥 What does this PR do?

  • Validates declared numeric bounds (min, max, exclusiveMin, exclusiveMax) during JavaScript BiDi serialization and deserialization.
  • Out-of-bounds numbers now throw ValidationError before sending (constructor) and on receipt ( romWire).
  • Covers both primitive numbers/integers and alias references (e.g. js-uint, js-int), including when fields narrow an alias's bounds (e.g., maxNodeCount).

🔧 Implementation Notes

  • Added checkBounds(typeNode, value, path) in javascript/selenium-webdriver/bidi/serialization/record.js.
  • Checked in �alidateValue for primitive types (integer /
    umber) and upon alias resolution in the
    ef branch.
  • Added comprehensive unit tests in javascript/selenium-webdriver/test/bidi/serialization/record_test.js covering edges in both directions:
    • maxNodeCount (0 and 1, narrowing js-uint with min: 1)
    • devicePixelRatio (0 vs > 0 with exclusiveMin: true)
    • heading (360 vs < 360 with exclusiveMax: true)
    • status (negative integers on receipt with js-uint)
    • Union list elements holding numbers to declared ranges (pageRanges)

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Google Gemini (Antigravity)
    • What was generated: implementation in record.js and tests in record_test.js
    • I reviewed all AI output and can explain the change

🔄 Types of changes

  • Bug fix (backwards compatible)

Validate numeric min, max, exclusiveMin, and exclusiveMax bounds in validateValue for primitive number/integer fields and resolved aliases.

Part of SeleniumHQ#18195
@selenium-ci selenium-ci added C-nodejs JavaScript Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Nov 1, 2026
@qodo-code-review

qodo-code-review Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Enforce declared numeric ranges in JavaScript BiDi records

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Reject out-of-range BiDi numbers during both record construction and wire parsing.
• Enforce inclusive, exclusive, and alias-narrowed bounds across nested values.
• Add tests for boundary values, nullable fields, aliases, and union lists.
Diagram

graph TD
  Constructor["Record constructor"] --> Validate["Validate value"] -->|alias| Resolve["Resolve alias"] --> Bounds{"Within bounds?"} -->|no| Error["ValidationError"]
  Wire["fromWire"] --> Validate
  Validate -->|primitive| Bounds
  Bounds -->|yes| Accepted["Accepted value"]
Loading
High-Level Assessment

Keep bounds enforcement in the shared runtime validator. It covers inbound and outbound records, including nested lists and unions, without duplicating checks in generated types; validating resolved aliases before field-level bounds preserves both constraints.

Files changed (2) +136 / -1

Bug fix (1) +22 / -1
record.jsEnforce numeric bounds in shared record validation +22/-1

Enforce numeric bounds in shared record validation

• Adds inclusive and exclusive minimum and maximum checks for numeric values. Applies them to primitive nodes and, after validating a resolved alias, to bounds declared on the alias reference; failures include the field path in a ValidationError.

javascript/selenium-webdriver/bidi/serialization/record.js

Tests (1) +114 / -0
record_test.jsCover numeric boundaries in both validation directions +114/-0

Cover numeric boundaries in both validation directions

• Tests constructor and fromWire handling of alias ranges, narrowed alias fields, exclusive floating-point bounds, and numeric elements in union lists. Includes accepted boundary-adjacent values and nullable fields.

javascript/selenium-webdriver/test/bidi/serialization/record_test.js

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@diemol
diemol merged commit ac7a079 into SeleniumHQ:trunk Nov 2, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-devtools Includes everything BiDi or Chrome DevTools related C-nodejs JavaScript Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants