Repository navigation
chore(tests): skip the permission tests as root, and remove the root-test hook - #670
Merged
Merged
Conversation
Root ignores file permissions, so the tests that deny access with chmod fail as root and pass in CI. vitest.config.ts now calls a guard while vitest loads it. As root, the guard reruns the same command as nobody, or as the checkout's owner when root does not own it, after preparing that user's scratch folders and a Node binary it can run. When no rerun is possible it prints one warning and the run continues as root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ommands The PreToolUse hook read every Bash command's text to guess whether vitest would start. It blocked commands that only mentioned a test run and missed runs it could not parse. vitest.config.ts now reruns a root test run itself, so the hook, its test, its settings.json entry and its references go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AGENTS.md drops the removed hook and names scripts/root-test-guard.ts, and its test conventions say a root run reruns itself. CONTRIBUTING.md tells contributors who run the tests as root what to expect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hooks, dev scripts and other local tooling are not the server this repo ships, so their commits use chore, ci or build and stay out of the changelog's Features and Bug Fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vitest 5 writes its results cache to node_modules/.vite/vitest, not node_modules/.vitest, so a rerun as nobody could not update it and lost the failed-first and duration ordering of test files. Ship-Check: pr-review
- Rename stopRootTestRun to rerunRootTestRun, since warning paths let the run continue as root, and readNvmrcMajor to readNodeMajor, which now also reads process.version. - Give the target lookup its own result type instead of sharing the kind field with the warning causes. - Name the target's display label, the folders handed over (which stay with the target), the test HOME folder and the file modes. - Build setpriv's switch flags once, derive the coverage run inside the planner, and replace the version parsing with a documented regex. - Say why the target cannot run root's Node, why an owner gets no copy, why the CA setting is dropped, why the Node folder leads PATH, and why the rerun does not rerun itself. - AGENTS.md: the test-conventions bullet opens with what happens, the tree stays alphabetical, and the commit-type rule names what ships. - CONTRIBUTING.md: say what to do when no rerun is possible. Ship-Check: code-quality
A run without coverage never writes there, so handing the folder over on every root run only left an empty coverage/ owned by another user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three prepareRerun tests asserted that something stayed as it was: coverage/ untouched, an existing Node copy kept, the Node copy's folder not handed over. Each passed if prepareRerun did nothing at all. They now also assert a side effect only a real run produces, and the hand-over test asserts the exact list of handed-over paths instead of filtering it down to an empty one. Ship-Check: test-audit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PkA1FHrosoEim4HpZyQGyQ
The guard's tests covered the planner and the folder preparation, but not rerunRootTestRun, the function vitest.config.ts calls. New tests run it with process.getuid, spawnSync, stderr and process.exit stubbed, and cover: - a non-root run returning at once, so the rerun never reruns itself - the warnings for a missing setpriv and a missing nobody user - the choice of target: nobody's uid and gid for a root-owned checkout, the owner's for any other - a failed preparation warning and continuing as root - the exit status: the rerun's own, and 1 when a signal ended it They also cover a first coverage run in a checkout with no coverage/ folder, a single quote in a quoted path in the printed command, and a Node copy that fails part way leaving nothing at the path a later run reuses. Ship-Check: test-audit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PkA1FHrosoEim4HpZyQGyQ
…st's own command - vite deletes its bundled copy of vitest.config.ts once the import finishes, but the guard exits during that import, so every root run left a bundle in node_modules/.vite-temp. After the rerun, the guard now removes this config's bundles written before it started. - The guard reran whatever script sat in argv[1]. A program that starts vitest through its API with VITEST=true would have had its own script rerun as another user. The guard now reruns only when argv[1] resolves to vitest.mjs, and otherwise warns and continues as root. Ship-Check: bug-check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PkA1FHrosoEim4HpZyQGyQ
|
umm-actually re-reviewed at No new findings (17 tracked finding(s) across all runs). umm-actually · z-ai/glm-5.3-flash |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the suite The root guard reran every root test run as another user, which took about 600 lines and depended on vitest's and vite's internals. Root only breaks the 25 tests that deny file access and expect it to fail, so those tests now skip as root through one shared runsAsRoot flag, and CI still runs them as a normal user. To run them from a root shell, npm run test:as-nobody runs vitest as nobody: it hands nobody the three folders vitest writes in, copies root's Node where nobody can run it, and drops the CA setting nobody can't read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy cut short by a full disk would otherwise sit at the final path and be reused on every later run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Root ignores file permissions, so the 25 tests that deny access with
chmodand expect the access to fail break when the suite runs as root. CI runs as a normal user and passes them. Claude Code's cloud sessions run as root.Until now a
PreToolUsehook stopped root test runs. It read the text of every Bash command and guessed from regular expressions whether vitest would start, so it blocked commands that only mentioned a test run (a commit message, a heredoc, anode -escript) and missed runs it couldn't parse.This PR removes the hook. Instead:
it.skipIf(runsAsRoot), using one flag insrc/__tests__/runs-as-root.ts. A root run passes and reports them as skipped, and CI still runs them on every push.npm run test:as-nobodyruns them from a root shell.scripts/test-as-nobody.ts(50 lines) runsvitest runasnobody, passing along any extra arguments. Before that it:nobodythe three folders vitest writes in;nobodycan enter;nobodycan't read.Earlier commits on this branch rerun every root test run as another user from inside
vitest.config.ts. That guard took about 600 lines plus 865 lines of tests, and depended on vitest's and vite's internals: cache paths, the temporary config bundle, and the entry file's name. The last commit replaces it with the skip, because only these 25 tests are affected.What else changes:
featorfix.Type of change
scripts/test-as-nobody.ts) and the Claude Code hook setupChecklist
npm testpassesnpm run buildsucceeds (no source changes; CI'schecksjob runs it)Live Test Results
Run as root in a Claude Code cloud container. "Before" is
origin/main, where the hook stops root test runs in Claude Code sessions.npm testnpm run test:as-nobodynobody: 5,289 passed, 1 skipped, exit 0; the three folders owned bynobodynpm run test:as-nobody -- src/utilsNo test deploy was run: the change is test tooling and Claude Code settings, and the image contains none of these files.
🤖 Generated with Claude Code