Skip to content

Fix JSON validation to require the cows directory - #52

Open
floze-the-genius wants to merge 2 commits into
codeday:mainfrom
floze-the-genius:fix/49-require-cows-directory
Open

Fix JSON validation to require the cows directory#52
floze-the-genius wants to merge 2 commits into
codeday:mainfrom
floze-the-genius:fix/49-require-cows-directory

Conversation

@floze-the-genius

@floze-the-genius floze-the-genius commented Jul 18, 2026

Copy link
Copy Markdown

Summary

  • only treat .json files under cows/ as cow descriptions
  • add regression coverage for root-level and unrelated JSON files
  • run the validator tests in the pull request workflow
  • let validator-only maintenance PRs pass after tests instead of requiring a cow payload

Closes #49.

Testing

  • npm ci
  • npm test (5 tests)
  • node --check .github/scripts/validate-pr.js
  • node --check .github/scripts/validation-helpers.js
  • node --check .github/scripts/validation-helpers.test.js
  • git diff --check

AI assistance disclosure

This fix, its regression tests, and this pull request description were prepared with OpenAI Codex under the contributor account owner’s direction. The submitted change was validated locally with the commands above.

@cla-assistant

cla-assistant Bot commented Jul 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

🧪 PR Validation Results for #52


❌ No JSON file found! Please include your .json file.

@cla-assistant

cla-assistant Bot commented Jul 18, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@oohwooh

oohwooh commented Jul 18, 2026

Copy link
Copy Markdown
Member

Thanks so much for the contribution! I especially appreciate that you disclosed your AI use. It is very helpful context to have as a maintainer.

I am busy attending a conference this/next week but will do my best to review this when I can!

@oohwooh
oohwooh self-requested a review July 18, 2026 21:51
@floze-the-genius

Copy link
Copy Markdown
Author

Hi @oohwooh — hope the conference went well. This PR is still current with main, clean and mergeable, both validation runs pass, and the CLA is signed. It narrows validation to require the JSON submission inside cows/ while preventing unrelated repository JSON files from satisfying that rule. When convenient, could you take another look?

@oohwooh oohwooh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your patience on my review!

Adding tests and exemptions to the validator for maintenance changes should be their own PRs instead of included in this one. You are welcome to open PRs for those additions, but please remove those changes from this PR so it's just the the cows directory fix.

I think the fix you identified is great, my only feedback on it is that it probably doesn't need it's own helper function since it's just one line.

Thanks for this PR! Once it's just the cows directory fix I think it is good to merge 😄

if (isValidatorMaintenancePullRequest(files)) {
console.log("✅ Validator maintenance PR detected; cow submission checks skipped.");
process.exit(0);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is out of scope for this PR. I think it's a good idea for a feature but should be in a PR of it's own vs this one.

@@ -0,0 +1,15 @@
export function isCowJsonFile(filename) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my opinion, this doesn't need to be it's own function, it can be inline like on validate-pr L58: https://github.com/codeday/fantasy-cow/pull/52/changes#diff-0e0c95e0e9e8936d11f2fa26475f0476bf09ed38718744d8cf60c6212f3f8a72L49

This would make the code easier to skim and prevent any confusion of the name isCowJsonFile since that could imply that it does validation of the JSON when that isn't the point of the function

return filename.startsWith("cows/") && filename.endsWith(".json");
}

export function isValidatorMaintenancePullRequest(files) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned in my other comment, this is out of scope for this PR.

If you're interested in making a different PR for this work, I think an easier way to detect if it's a maintenance PR is make a label that gets manually applied (and could even trigger a different set of GH actions, like running tests)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a testing framework should be split into its own PR as well.

It would also be useful to have some tests where we run entire changesets through the flow and check validation outputs, we can look through past PRs for real-world examples to include in that suite.

@HanCotterell any thoughts on testing? I know you did a lot of testing by hand when developing this, what cases do you think would be most important to include?

- name: Install dependencies
run: npm ci

- name: Run validator tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding tests out of scope for this PR

Comment thread package.json
"description": "A small project that teaches how to create a first Pull Request.",
"type": "module",
"scripts": {
"test": "node --test .github/scripts/*.test.js"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding tests out of scope for this PR

// --- Basic pre-checks ---
if (jsonFiles.length === 0) {
commentString += `\n---\n\n`;
commentString += "❌ No JSON file found! Please include your **<cow>.json** file.\n";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it would make sense to update the error message to specify cows/cow.json to give people a starting point to figure out why the test failed if they submitted a JSON that is outside the cows folder.

It doesn't need to explain perfectly the issue, the philosophy for fantasy-cow is to mimic real-world PR workflows, which often times are opaque and wouldn't give this granular of feedback.

If you think it's better left as-is I'd also be okay with that, though!

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.

JSON validation doesn't require being inside cows directory

2 participants