Skip to content

fix(scoring): harden label glob translation - #1450

Merged
JSONbored merged 3 commits into
mainfrom
codex/fix-glob-to-regexp-conversion-issue
Jun 26, 2026
Merged

fix(scoring): harden label glob translation#1450
JSONbored merged 3 commits into
mainfrom
codex/fix-glob-to-regexp-conversion-issue

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Translating repo-configured label multiplier keys to JavaScript RegExp could throw or mis-match for certain fnmatch-style bracket expressions (e.g. [z-a], [!], [^x]) and thereby crash the scoring preview or produce incorrect multiplier matches.
  • The upstream/validator uses Python fnmatch semantics which tolerate these cases; the preview must preserve parity and fail-safe behavior for untrusted registry keys.

Description

  • Harden labelPatternToRegExp to mirror Python fnmatch edge-case behavior by treating empty/bare bracket classes (like [] or [!]) as literals and by emitting a never-match fragment ((?!)) for descending/invalid ranges instead of compiling a throwing RegExp.
  • Preserve negation semantics for [^x]/[!x] while avoiding accidental RegExp caret-interpretation for literal leading ^ in classes.
  • Add small helpers escapeRegExpLiteral and hasDescendingCharacterRange to support safe translation and range validation.
  • Add unit test coverage in test/unit/scoring.test.ts for [^x], [z-a], and [!] patterns and other bracket-class edge cases to guard against regressions.

Testing

  • Ran the focused unit test: npx vitest run test/unit/scoring.test.ts -t "matches configured label keys" and the full file: both completed and passed (72 tests passed).
  • npm run typecheck completed with no type errors.
  • npm run test:coverage and npm run test:ci were started during validation but did not complete in this environment (coverage run was terminated due to local runtime constraints and test:ci was interrupted during coverage); the unit-level tests validating the fix passed.
  • npm audit --audit-level=moderate could not complete due to the registry audit endpoint returning 403 in this environment.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored JSONbored self-assigned this Jun 26, 2026
@JSONbored JSONbored added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jun 26, 2026
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.42%. Comparing base (0574c0f) to head (06044d4).
⚠️ Report is 45 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1450   +/-   ##
=======================================
  Coverage   95.42%   95.42%           
=======================================
  Files         193      193           
  Lines       21026    21037   +11     
  Branches     7614     7619    +5     
=======================================
+ Hits        20064    20075   +11     
  Misses        383      383           
  Partials      579      579           
Files with missing lines Coverage Δ
src/scoring/preview.ts 99.06% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit a7d1a1c into main Jun 26, 2026
18 checks passed
@JSONbored
JSONbored deleted the codex/fix-glob-to-regexp-conversion-issue branch June 26, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant