Skip to content

chore(tests): skip the permission tests as root, and remove the root-test hook - #670

Merged
aliasunder merged 14 commits into
mainfrom
chore/root-test-guard-in-vitest
Oct 12, 2026
Merged

aliasunder merged 14 commits into
mainfrom
chore/root-test-guard-in-vitest

Conversation

@aliasunder

@aliasunder aliasunder commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

What does this PR do?

Root ignores file permissions, so the 25 tests that deny access with chmod and 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 PreToolUse hook 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, a node -e script) and missed runs it couldn't parse.

This PR removes the hook. Instead:

  • The 25 tests skip as root. Each is marked it.skipIf(runsAsRoot), using one flag in src/__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-nobody runs them from a root shell. scripts/test-as-nobody.ts (50 lines) runs vitest run as nobody, passing along any extra arguments. Before that it:
    • hands nobody the three folders vitest writes in;
    • copies root's Node to a folder nobody can enter;
    • drops the CA setting nobody can'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:

  • AGENTS.md: drops the hook, and the test-conventions bullet says how to mark a new permission test and how to run these tests from a root shell. It also gains a line saying local tooling commits are never feat or fix.
  • CONTRIBUTING.md: says which tests skip as root and how to run them.

Type of change

  • New MCP tool
  • Bug fix
  • Refactoring
  • Documentation
  • CI / workflow change
  • Infrastructure (SST, Docker)
  • Other: test tooling (the root skip, scripts/test-as-nobody.ts) and the Claude Code hook setup

Checklist

  • The pre-commit hook passed: typecheck, knip, and ESLint, Prettier, markdownlint and ShellCheck on the staged files
  • npm test passes
  • npm run build succeeds (no source changes; CI's checks job runs it)
  • New MCP tools follow the naming and description conventions in AGENTS.md (no tool changes)
  • README or ARCHITECTURE.md updated (no user-facing behavior change; CONTRIBUTING.md and AGENTS.md cover the contributor-facing change)

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.

Probe (as root) Before (main) This branch
npm test stopped by the hook 116 files, 5,264 passed, 26 skipped (the 25 permission tests and one already skipped), exit 0
The suite as root with no skip and no hook (what a contributor gets outside Claude Code) 25 failed the same 25 tests skip
npm run test:as-nobody not available ran as nobody: 5,289 passed, 1 skipped, exit 0; the three folders owned by nobody
npm run test:as-nobody -- src/utils not available 17 files, 183 passed
Bash commands that only mention a test run blocked by the hook not inspected; they run

No 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

claude added 10 commits October 12, 2026 01:31
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
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
@umm-actually

umm-actually Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

umm-actually re-reviewed at 081605e

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>
Comment thread scripts/__tests__/root-test-guard.test.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/__tests__/root-test-guard.test.ts Outdated
Comment thread scripts/root-test-guard.ts Outdated
Comment thread vitest.config.ts Outdated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread scripts/root-test-guard.ts Outdated
Comment thread scripts/__tests__/root-test-guard.test.ts Outdated
…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>
@aliasunder aliasunder changed the title chore(tests): rerun a root test run as another user from inside vitest, and remove the root-test hook chore(tests): skip the permission tests as root, and remove the root-test hook Oct 12, 2026
Comment thread AGENTS.md
Comment thread CONTRIBUTING.md
Comment thread scripts/test-as-nobody.ts
Comment thread scripts/test-as-nobody.ts
Comment thread scripts/test-as-nobody.ts
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>
@aliasunder
aliasunder merged commit 5f087f4 into main Oct 12, 2026
18 checks passed
@aliasunder
aliasunder deleted the chore/root-test-guard-in-vitest branch October 12, 2026 19:52
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