Skip to content

fix(labeling): harden labeler rule matching and add tests#430

Merged
ashleyshaw merged 1 commit into
developfrom
codex/issue-419-labeler-hardening
May 27, 2026
Merged

fix(labeling): harden labeler rule matching and add tests#430
ashleyshaw merged 1 commit into
developfrom
codex/issue-419-labeler-hardening

Conversation

@ashleyshaw
Copy link
Copy Markdown
Member

@ashleyshaw ashleyshaw commented May 27, 2026

Summary

  • harden labeler-utils import compatibility for @actions/core and minimatch export shapes
  • add focused unit tests covering branch regex/glob matching and file pattern modes
  • verify deterministic label derivation (no duplicate label emissions when multiple rules match)

Validation

  • node scripts/validation/validate-labeling-configs.cjs
  • npm run test:js -- scripts/agents/__tests__/labeling.agent.test.js scripts/agents/includes/__tests__/labeler-utils.test.js

Scope

  • no workflow or config schema changes
  • no label taxonomy changes

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for labeling utilities, verifying branch pattern matching, file pattern matching across multiple configuration modes, and label determination logic.
  • Chores

    • Updated module imports for improved dependency compatibility.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Caution

Review failed

Pull request was closed or merged during review

Note

.coderabbit.yml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized keys: "auto_labels", "auto_assign", "auto_review"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

This PR adds Jest test coverage for the labeler-utils.js module and updates its module imports for compatibility. The test suite validates branch pattern matching, file pattern matching across three configuration modes, and label determination from rule definitions. Module imports are refactored to use namespace imports and conditional dependency resolution.

Changes

labeler-utils module compatibility and test coverage

Layer / File(s) Summary
Import compatibility fix
scripts/agents/includes/labeler-utils.js
@actions/core is now imported as a namespace (import * as core); minimatch is resolved via conditional check supporting both function and object exports instead of destructuring.
Comprehensive test coverage for labeler functions
scripts/agents/includes/__tests__/labeler-utils.test.js
Jest suite validates matchesBranchPattern with regex and glob patterns, matchesFilePatterns across three rule modes (any-glob-to-any-file, all-globs-to-all-files, any-glob-to-all-files), and determineLabelsFromRules with branch and file-based label application and deduplication.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides summary and validation steps, but lacks required sections from the template including linked issues, changelog, risk assessment, testing instructions, and checklist items. Add missing required sections: link related issues, provide changelog entry per Keep a Changelog format, complete risk assessment with impact and mitigation, include testing instructions with prerequisites and steps, and verify checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main changes: hardening labeler imports for compatibility and adding comprehensive test coverage for labeler utilities.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 codex/issue-419-labeler-hardening

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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.

@github-actions github-actions Bot added the area:labels Label governance and routing label May 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #430

CI Status:success
Files changed: 2

Recommendations

  • Ready to proceed pending human review

@github-actions github-actions Bot added area:tests Test suites & harnesses area:scripts Scripts & tooling lang:js JavaScript/TypeScript status:needs-review Awaiting code review priority:normal Default priority type:chore Chore / small hygiene change type:bug Bug or defect meta:needs-changelog Requires a changelog entry before merge labels May 27, 2026
Copy link
Copy Markdown
Contributor

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

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 introduces a new test suite for the labeler utilities and updates module imports and package resolution in labeler-utils.js. The review feedback identifies two key issues: first, the test file incorrectly uses CommonJS require to load an ES module, which will fail at runtime; second, there is a logical bug in the all-globs-to-all-files test case and its underlying implementation that needs to be corrected to ensure proper glob matching behavior.

Comment on lines +1 to +5
const {
matchesBranchPattern,
matchesFilePatterns,
determineLabelsFromRules,
} = require("../labeler-utils.js");
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.

high

Since labeler-utils.js is an ES module (using import/export syntax), using CommonJS require to load it will fail at runtime in standard Node.js environments with ERR_REQUIRE_ESM. To ensure compatibility and consistency with the rest of the codebase, use ES module import syntax instead.

Suggested change
const {
matchesBranchPattern,
matchesFilePatterns,
determineLabelsFromRules,
} = require("../labeler-utils.js");
import {
matchesBranchPattern,
matchesFilePatterns,
determineLabelsFromRules,
} from "../labeler-utils.js";

Comment on lines +36 to +41
test("supports all-globs-to-all-files", () => {
const config = {
"all-globs-to-all-files": [".github/workflows/**", "docs/**"],
};
expect(matchesFilePatterns(changedFiles, config)).toBe(true);
});
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.

high

The test for all-globs-to-all-files expects true even though changedFiles contains scripts/agents/labeling.agent.js, which does not match either of the configured glob patterns (.github/workflows/** or docs/**). This test only passes because the underlying implementation of all-globs-to-all-files in labeler-utils.js (line 110) incorrectly uses changedFiles.some instead of changedFiles.every. In a standard GitHub Actions labeler, all-globs-to-all-files requires that all changed files match the glob patterns. To fix this, the test should be updated to use a set of files and patterns where all files actually match the patterns, and the underlying implementation in labeler-utils.js should be corrected to use every instead of some.

Suggested change
test("supports all-globs-to-all-files", () => {
const config = {
"all-globs-to-all-files": [".github/workflows/**", "docs/**"],
};
expect(matchesFilePatterns(changedFiles, config)).toBe(true);
});
test("supports all-globs-to-all-files", () => {
const config = {
"all-globs-to-all-files": ["docs/**"],
};
const docsOnlyFiles = ["docs/ISSUE_LABELS.md", "docs/ISSUE_TYPES.md"];
expect(matchesFilePatterns(docsOnlyFiles, config)).toBe(true);
});

@ashleyshaw ashleyshaw marked this pull request as ready for review May 27, 2026 15:25
@ashleyshaw ashleyshaw added the meta:no-changelog No changelog needed label May 27, 2026
@github-actions github-actions Bot removed the type:chore Chore / small hygiene change label May 27, 2026
@ashleyshaw ashleyshaw merged commit f72ab53 into develop May 27, 2026
15 of 19 checks passed
@ashleyshaw ashleyshaw deleted the codex/issue-419-labeler-hardening branch May 27, 2026 15:28
@ashleyshaw ashleyshaw self-assigned this May 27, 2026
@ashleyshaw ashleyshaw removed the meta:no-changelog No changelog needed label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:labels Label governance and routing area:scripts Scripts & tooling area:tests Test suites & harnesses lang:js JavaScript/TypeScript meta:needs-changelog Requires a changelog entry before merge priority:normal Default priority status:needs-review Awaiting code review type:bug Bug or defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant