Repository navigation
chore(tests): skip the permission tests as root, and remove the root-test hook #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2f06bcd
chore(tests): rerun a root vitest run as another user from the config
claude 9238225
chore(hooks): remove the hook that guessed root test runs from Bash c…
claude 363d901
docs: describe how a root test run reruns as another user
claude 95e663a
docs: say local tooling commits are never feat or fix
claude 84cc147
fix(review): hand vitest's results cache to the rerun user
claude 999d72e
chore(tests): make the root test guard read without tracing
claude 28184ce
chore(tests): hand coverage/ to the rerun user only on a coverage run
claude fe68552
chore(tests): prove prepareRerun ran in the guard's keep-as-is tests
claude db06763
chore(tests): cover the guard's root-run wiring and its failure paths
claude 2e0956c
chore(tests): remove the root run's config bundle and rerun only vite…
claude ad4cccb
docs: put CONTRIBUTING's root test run in a table
claude 73d2bc0
chore(tests): say which tools skip the root test guard
claude f99891d
chore(tests): skip the permission tests as root instead of rerunning …
claude 081605e
chore(tests): copy nobody's Node under a temporary name first
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Runs vitest as `nobody` from a root shell, so the tests that skip as root | ||
| * (they deny file access, which root ignores) run too. Extra arguments go to | ||
| * `vitest run`: `npm run test:as-nobody -- src/utils`. | ||
| */ | ||
|
|
||
| import { execFileSync, spawnSync } from "node:child_process" | ||
| import { chmodSync, copyFileSync, existsSync, mkdirSync, renameSync } from "node:fs" | ||
| import { join } from "node:path" | ||
|
|
||
| const readNobodyId = (flag: "-u" | "-g"): string => | ||
| execFileSync("id", [flag, "nobody"], { encoding: "utf8" }).trim() | ||
| const [uid, gid] = (["-u", "-g"] as const).map(readNobodyId) | ||
| const nodeModules = join(process.cwd(), "node_modules") | ||
| const testHome = join(nodeModules, ".test-home") | ||
|
|
||
| // nobody writes only vite's config bundle, vitest's results cache, and its HOME. | ||
| const writableFolders = [".vite-temp", ".vite/vitest", ".test-home"].map((folder) => | ||
| join(nodeModules, folder), | ||
| ) | ||
|
aliasunder marked this conversation as resolved.
|
||
| for (const folder of writableFolders) mkdirSync(folder, { recursive: true }) | ||
| execFileSync("chown", ["-R", `${uid}:${gid}`, ...writableFolders]) | ||
|
aliasunder marked this conversation as resolved.
|
||
|
|
||
| // Root's Node usually sits where nobody can't enter, such as /root/.nvm. | ||
| const nodeFolder = join(nodeModules, ".nobody-node", `node-${process.version}`) | ||
| const nodePath = join(nodeFolder, "node") | ||
|
|
||
| if (!existsSync(nodePath)) { | ||
| mkdirSync(nodeFolder, { recursive: true }) | ||
| // A temporary name keeps a copy cut short (a full disk) from being reused. | ||
| copyFileSync(process.execPath, `${nodePath}.partial`) | ||
| chmodSync(`${nodePath}.partial`, 0o755) | ||
| renameSync(`${nodePath}.partial`, nodePath) | ||
| } | ||
|
aliasunder marked this conversation as resolved.
|
||
|
|
||
| const asNobody = [`--reuid=${uid}`, `--regid=${gid}`, "--clear-groups", "/usr/bin/env"] | ||
| // nobody may be unable to read root's CA bundle, and Node then warns on every start. | ||
| const nobodyEnv = ["-u", "NODE_EXTRA_CA_CERTS", `HOME=${testHome}`] | ||
| const path = `PATH=${nodeFolder}:${process.env.PATH ?? ""}` | ||
| const vitestEntry = join(nodeModules, "vitest", "vitest.mjs") | ||
| const vitest = [nodePath, vitestEntry, "run", ...process.argv.slice(2)] | ||
| const run = spawnSync("setpriv", [...asNobody, ...nobodyEnv, path, ...vitest], { | ||
| stdio: "inherit", | ||
| }) | ||
|
|
||
| if (run.error) throw run.error | ||
| process.exit(run.status ?? 1) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.