Skip to content

[Tests] Add unit test coverage for isHandle in wporg-handle.cjs (#484) - #485

Open
noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:test/add-is-handle-unit-tests
Open

noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:test/add-is-handle-unit-tests

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Sep 16, 2026

Copy link
Copy Markdown

Why

src/wporg-handle.cjs exports isHandle(value) to determine whether a value is already a canonical WordPress.org handle before using it in structural positions (such as patch filenames in src/patch-provenance.cjs).

Currently, tests/unit/wporg-handle.test.cjs does not import or test isHandle(value) directly. While parseHandle and handoffFilename have test coverage, isHandle itself lacked dedicated unit tests verifying its exact validation criteria.

What changes

Added dedicated unit test coverage for isHandle in tests/unit/wporg-handle.test.cjs:

  • Valid canonical handles (janedoe, jane-doe, jane_doe, jane.doe, jane1, 1jane, j).
  • Strict lowercase requirement (JaneDoe, JANEDOE, janeDoe rejected).
  • Boundary lengths (MAX_HANDLE_LENGTH = 60 accepted, 61 rejected).
  • Rejection of leading and trailing separators (-janedoe, janedoe-, .janedoe, janedoe., _janedoe, janedoe_).
  • Rejection of invalid characters and path traversal attempts (spaces, slashes, backslashes, ../../etc/passwd, newlines, #, %20, @).
  • Rejection of empty strings, whitespace-only strings, and non-string types (null, undefined, numbers, objects, arrays, booleans).

How to test this

Starting state:

  1. Check out this branch.
  2. Run the unit test suite:
    npm test tests/unit/wporg-handle.test.cjs
  3. Run ESLint:
    npm run lint

What must not have happened:

  • All 16 unit tests in tests/unit/wporg-handle.test.cjs must pass.
  • No production code modified (0 production changes).

Risks and limitations

None. This is a 100% test-only addition.

Use of AI Tools

AI assistance: Yes
Model(s): Gemini 3.8 Flash High
Used for: Identifying missing unit test coverage for isHandle in src/wporg-handle.cjs, structuring test cases, and drafting boundary condition assertions. Final implementation was reviewed, run, and verified by me locally using node --test and ESLint.

Related

Fixes #484

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8c342dfc-4196-4c81-a5e3-52d5b5ad3c23

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@noruzzamans
noruzzamans marked this pull request as ready for review September 16, 2026 09:20
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.

Tests: Missing direct unit test coverage for isHandle() in wporg-handle.cjs

1 participant