Skip to content

ci: block new root-level entries - #11903

Merged
nwparker merged 2 commits into
mainfrom
chore/guard-root-directory-additions
Aug 1, 2026
Merged

nwparker merged 2 commits into
mainfrom
chore/guard-root-directory-additions

Conversation

@nwparker

@nwparker nwparker commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a PR check that compares the base and head repository trees.
  • Reject newly introduced root-level files and top-level directories with a clear GitHub landing-page message.
  • Include the check in the aggregate verify gate and cover allowed/rejected cases with fixtures.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts config/scripts/check-root-directory-entries.test.mjs config/scripts/pr-workflow-parallelism.test.mjs config/scripts/pr-workflow-lint-parity.test.mjs config/scripts/pr-e2e-gate-contract.test.mjs (23 passed)
  • pnpm typecheck
  • bash -n .github/scripts/check-root-directory-entries.sh
  • git diff --check

@greptile-apps

greptile-apps Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR introduces a new CI gate (root_directory_guard) that rejects pull requests which add new top-level files or directories to the repository, preventing GitHub landing-page clutter. The shell script compares the root tree of the base and head commits using git ls-tree, and a matching vitest test suite verifies allowed/rejected cases and workflow wiring. Several unrelated housekeeping changes are bundled in: consolidating double-import statements in benchmark files, explicit String() coercions in selector template literals, and a multi-line path.join reformat.

  • New guard script (.github/scripts/check-root-directory-entries.sh): uses declare -A for an O(1) membership lookup, properly null-terminates git ls-tree output with -z/read -d '' to tolerate unusual entry names, and emits a GitHub Actions annotation on failure.
  • Workflow integration: root_directory_guard is added as a standalone job with fetch-depth: 0 (required to resolve the base SHA) and is wired into the verify aggregate gate alongside all existing jobs.
  • Cleanup commits in tests/tools/: two duplicate import statements are merged, String() coercions are made explicit on selector interpolations, and path.join argument lists are reformatted to one-per-line.

Confidence Score: 5/5

Safe to merge — the guard script, workflow job, and tests are all self-contained with no risk to existing jobs or the codebase.

The bash script uses well-established git plumbing commands, the null-delimiter handling is correct, the associative-array membership check is idiomatic, and fetch-depth=0 is properly set so the base SHA is always resolvable. The verify gate wiring follows the same pattern as every other job in the workflow.

Files Needing Attention: config/scripts/check-root-directory-entries.test.mjs — two pre-existing test coverage gaps noted in earlier review threads remain open, but they carry no runtime risk.

Important Files Changed

Filename Overview
.github/scripts/check-root-directory-entries.sh New guard script; correctly uses null-delimited git ls-tree, declare -A membership check, and GitHub Actions annotation format. Logic is sound and handles edge cases like special characters in filenames.
.github/workflows/pr.yml Adds root_directory_guard job with fetch-depth=0 (required for base SHA resolution) and wires it into the verify aggregate gate correctly alongside all existing jobs.
config/scripts/check-root-directory-entries.test.mjs New vitest tests covering nested addition (pass), root file (fail), root directory (fail), and workflow wiring. Step-index assertion on steps[0] is brittle (flagged in prior review thread); no deletion-allowed test case (also noted previously).
config/scripts/pr-workflow-parallelism.test.mjs Adds root_directory_guard to the expected verify.needs list to keep the parallelism snapshot test accurate.

Reviews (2): Last reviewed commit: "fix: clear existing type-aware lint warn..." | Re-trigger Greptile

)

expect(guardJob.name).toBe('root directory guard')
expect(guardJob.steps[0].with['fetch-depth']).toBe(0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Brittle step-index assertion

guardJob.steps[0] hardcodes the position of the checkout step. If any step is ever prepended before it (e.g., an actions/configure-pages or a caching step), this assertion silently tests the wrong step and can pass while the actual checkout step loses the fetch-depth guarantee. The guardStep lookup already shows the right pattern — use .find() with a name match instead.

Comment on lines +53 to +85
describe('root directory guard', () => {
it('allows additions inside an existing top-level directory', () => {
const fixture = makeFixture()
const head = commitFiles(fixture.root, [['config/new.txt', 'nested\n']])

const result = runGuard({ ...fixture, head })

expect(result.status).toBe(0)
expect(result.stdout).toContain('no new root-level files or folders')
})

it('rejects a new root-level file with the landing-page message', () => {
const fixture = makeFixture()
const head = commitFiles(fixture.root, [['new-root.md', 'too prominent\n']])

const result = runGuard({ ...fixture, head })
const output = `${result.stdout}\n${result.stderr}`

expect(result.status).toBe(1)
expect(output).toContain('bloat the GitHub landing page')
expect(output).toContain('new-root.md')
})

it('rejects a new top-level directory', () => {
const fixture = makeFixture()
const head = commitFiles(fixture.root, [['new-folder/file.txt', 'too prominent\n']])

const result = runGuard({ ...fixture, head })
const output = `${result.stdout}\n${result.stderr}`

expect(result.status).toBe(1)
expect(output).toContain('new-folder')
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 No test for entry deletion being allowed

The three test cases cover adding a nested file (pass), adding a root file (fail), and adding a root directory (fail). There is no test confirming that removing a root-level entry does not trigger a failure. If a future maintainer accidentally inverts the comparison logic, deletion-only PRs would start failing the guard with no existing test to catch the regression. A brief fixture that removes the base config tree and expects exit code 0 would close this gap.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: efdec074-6bf3-4a51-9700-69b1dbc74f13

📥 Commits

Reviewing files that changed from the base of the PR and between 0eca019 and 6a917a0.

📒 Files selected for processing (4)
  • tests/tools/benchmarks/terminal-cold-park-resource-bench.mjs
  • tests/tools/benchmarks/terminal-cold-park-reveal-bench.mjs
  • tests/tools/win-update-e2e/app-driver.mjs
  • tests/tools/win-update-e2e/installer-steps.mjs

📝 Walkthrough

Walkthrough

Added a Bash guard that compares root-level entries between two Git revisions and rejects new files or directories. Added a pull request workflow job to run the guard and made the aggregate verification job require its result. Added tests for valid and invalid repository changes, diagnostics, exit statuses, temporary repository cleanup, and workflow wiring. Updated benchmark formatting and string conversion in Windows update tests.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the summary and testing results but omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, state "No visual change" if applicable, and document AI review, cross-platform checks, security audit findings, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary CI change: blocking new root-level entries.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit edb5607 into main Aug 1, 2026
43 checks passed
@nwparker
nwparker deleted the chore/guard-root-directory-additions branch August 1, 2026 08:48
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* ci: guard repository root additions

* fix: clear existing type-aware lint warnings
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