Skip to content

test: add Jest tests for validate-filepaths#20615

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

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

Conversation

@okwn
Copy link
Copy Markdown

@okwn 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.

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 on lines +5 to +52
describe("isFileInsideAYearFolder", () => {
// This function is defined in index.js - we test the logic it's testing

function isFileInsideAYearFolder(filepath) {
return filepath.match(/^\d{4}/) !== null;
}

test("returns true for file in year folder", () => {
expect(isFileInsideAYearFolder("2024/2024-01-01-brand.markdown")).toBe(true);
});

test("returns true for file in year/month subfolder", () => {
expect(isFileInsideAYearFolder("2024/01/2024-01-01-brand.markdown")).toBe(true);
});

test("returns false for file not in year folder", () => {
expect(isFileInsideAYearFolder("README.md")).toBe(false);
});

test("returns false for file with non-year folder", () => {
expect(isFileInsideAYearFolder("foo/2024-01-01-brand.markdown")).toBe(false);
});
});

describe("filepath date validation pattern", () => {
// Tests for the YYYY-MM-DD brand.markdown naming pattern

function isFilepathDateValid(filepath) {
const filename = filepath.split("/").pop();
const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/);
return dateStringInFilename !== null;
}

test("validates correct YYYY-MM-DD format in filename", () => {
expect(isFilepathDateValid("2024/01/2024-01-15-brand.markdown")).toBe(true);
expect(isFilepathDateValid("2023/12/2023-12-31-company.markdown")).toBe(true);
});

test("invalidates incorrect date formats", () => {
expect(isFilepathDateValid("2024/1-01-15-brand.markdown")).toBe(false);
expect(isFilepathDateValid("2024/01/24-01-15-brand.markdown")).toBe(false);
expect(isFilepathDateValid("2024/01/2024-1-15-brand.markdown")).toBe(false);
expect(isFilepathDateValid("2024/01/2024-01-5-brand.markdown")).toBe(false);
});

test("invalidates filenames without date", () => {
expect(isFilepathDateValid("README.md")).toBe(false);
expect(isFilepathDateValid("2024/01/brand.markdown")).toBe(false);
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.

2 participants