← 返回首页
test: add Jest tests for validate-filepaths by okwn · Pull Request #20615 · github/dmca · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

test: add Jest tests for validate-filepaths#20615

Open
okwn wants to merge 2 commits into
github:masterfrom
okwn:contrib/dmca/test-validate-filepaths
Open

test: add Jest tests for validate-filepaths#20615
okwn wants to merge 2 commits into
github:masterfrom
okwn:contrib/dmca/test-validate-filepaths

Conversation

Copy link
Copy Markdown

okwn commented May 21, 2026

Adds Jest tests for the validate-filepaths script, covering file path validation logic for the YYYY-MM-DD-brand.markdown naming pattern.

Copilot AI review requested due to automatic review settings May 21, 2026 01:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Pull request overview

Adds a Jest test suite for the .github/script/validate-filepaths tooling intended to validate DMCA notice filepath conventions.

Changes:

  • Added a new Jest test file covering year-folder detection and YYYY-MM-DD date substring matching in filenames.
  • Added basic “structure” scenarios combining the above checks.
Comments suppressed due to low confidence (3)

.github/script/validate-filepaths/tests/validate.test.js:36

  • isFilepathDateValid is redefined here rather than importing the real implementation from utils/validators.js. That means changes to the actual validator won’t be caught by these tests. Importing the exported function will make this test suite a true regression check for the repo’s validation behavior.
function isFilepathDateValid(filepath) { const filename = filepath.split("/").pop(); const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/); return dateStringInFilename !== null; }

.github/script/validate-filepaths/tests/validate.test.js:67

  • The helper functions are duplicated across describe blocks (isFileInsideAYearFolder and isFilepathDateValid are declared twice). Once you switch to importing production code, this duplication will go away; otherwise, consider defining these helpers once at the top-level to avoid divergence between blocks.
function isFileInsideAYearFolder(filepath) { return filepath.match(/^\d{4}/) !== null; } function isFilepathDateValid(filepath) { const filename = filepath.split("/").pop(); const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/); return dateStringInFilename !== null; }

.github/script/validate-filepaths/tests/validate.test.js:91

  • The last two tests are labeled as “structure validation”, but they only assert isFilepathDateValid is true (even when the year/month folders don’t match the filename date). If the intent is to validate structure, these should assert against the real isFileInCorrectFolder validator (from utils/validators.js) so the tests actually catch mis-foldered notices.
test("incorrect structure with missing year folder", () => { const invalidPath = "brand/2024-06-15-brand.markdown"; expect(isFileInsideAYearFolder(invalidPath)).toBe(false); expect(isFilepathDateValid(invalidPath)).toBe(true); }); test("incorrect structure with non-matching date in filename", () => { const invalidPath = "2024/06/2023-06-15-brand.markdown"; expect(isFileInsideAYearFolder(invalidPath)).toBe(true); expect(isFilepathDateValid(invalidPath)).toBe(true); });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/script/validate-filepaths/__tests__/validate.test.js Outdated Show resolved Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Vsehffhf

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants

Footer

© 2026 GitHub, Inc.