Repository navigation
fix(dev): Windows worktree setup no longer fails when symlinks are denied #28812
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
Closed
+101
−3
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f97db28
fix(dev): copy env files when worktree setup cannot symlink
only21mil 8a3f48d
fix(dev): never overwrite a file with the env copy, say how to refres…
only21mil cf3d381
test(dev): cover worktree setup when symlinks are denied
only21mil 0860203
test(dev): simplify the denied-symlink setup fixture
only21mil 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 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,86 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off - Runs the real setup script against a fixture checkout. | ||
| import * as NodeChildProcess from "node:child_process"; | ||
| import * as NodeFS from "node:fs"; | ||
| import * as NodeOS from "node:os"; | ||
| import * as NodePath from "node:path"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| // Windows without Developer Mode or admin rights rejects every symlink this way. | ||
| const DENY_SYMLINKS = `import fs from "node:fs"; | ||
| import { syncBuiltinESMExports } from "node:module"; | ||
| fs.symlinkSync = () => { | ||
| throw Object.assign(new Error("EPERM: operation not permitted, symlink"), { code: "EPERM" }); | ||
| }; | ||
| syncBuiltinESMExports(); | ||
| `; | ||
|
|
||
| describe("setup-worktree", () => { | ||
| it("copies env files when symlinks are denied and keeps the copies on later runs", () => { | ||
| const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-setup-worktree-")); | ||
| try { | ||
| const main = NodePath.join(root, "main"); | ||
| const worktree = NodePath.join(root, "worktree"); | ||
| const bin = NodePath.join(root, "bin"); | ||
| for (const dir of [ | ||
| NodePath.join(main, "infra", "relay"), | ||
| NodePath.join(worktree, "infra", "relay"), | ||
| NodePath.join(worktree, "node_modules"), | ||
| NodePath.join(worktree, "scripts"), | ||
| bin, | ||
| ]) { | ||
| NodeFS.mkdirSync(dir, { recursive: true }); | ||
| } | ||
| NodeFS.writeFileSync(NodePath.join(main, ".env"), "ROOT=1\n"); | ||
| NodeFS.writeFileSync(NodePath.join(main, "infra", "relay", ".env"), "RELAY=1\n"); | ||
| const script = NodePath.join(worktree, "scripts", "setup-worktree.ts"); | ||
| NodeFS.copyFileSync(NodePath.join(import.meta.dirname, "setup-worktree.ts"), script); | ||
| NodeFS.writeFileSync(NodePath.join(worktree, "scripts", "package.json"), '{"type":"module"}'); | ||
| // A no-op install keeps the run on the env-file step. | ||
| NodeFS.writeFileSync(NodePath.join(bin, "vp"), "#!/bin/sh\n", { mode: 0o755 }); | ||
| NodeFS.writeFileSync(NodePath.join(bin, "vp.cmd"), "@exit /b 0\r\n"); | ||
| NodeFS.writeFileSync(NodePath.join(worktree, "node_modules", ".modules.yaml"), "{}"); | ||
|
|
||
| const setup = () => { | ||
| const run = NodeChildProcess.spawnSync( | ||
| process.execPath, | ||
| ["--import", `data:text/javascript,${encodeURIComponent(DENY_SYMLINKS)}`, script], | ||
| { | ||
| cwd: worktree, | ||
| encoding: "utf8", | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${bin}${NodePath.delimiter}${process.env.PATH ?? ""}`, | ||
| T3CODE_PROJECT_ROOT: main, | ||
| }, | ||
| }, | ||
| ); | ||
| expect(run.status, run.stderr).toBe(0); | ||
| }; | ||
| const envFiles = () => | ||
| [".env", NodePath.join("infra", "relay", ".env")].map((file) => { | ||
| const target = NodePath.join(worktree, file); | ||
| return { | ||
| symlink: NodeFS.lstatSync(target).isSymbolicLink(), | ||
| text: NodeFS.readFileSync(target, "utf8"), | ||
| }; | ||
| }); | ||
|
|
||
| setup(); | ||
| expect(NodeFS.existsSync(NodePath.join(worktree, ".t3", "setup-done"))).toBe(true); | ||
| expect(envFiles()).toEqual([ | ||
| { symlink: false, text: "ROOT=1\n" }, | ||
| { symlink: false, text: "RELAY=1\n" }, | ||
| ]); | ||
|
|
||
| NodeFS.writeFileSync(NodePath.join(main, ".env"), "ROOT=2\n"); | ||
| NodeFS.writeFileSync(NodePath.join(worktree, "infra", "relay", ".env"), "LOCAL=1\n"); | ||
| setup(); | ||
| expect(envFiles()).toEqual([ | ||
| { symlink: false, text: "ROOT=1\n" }, | ||
| { symlink: false, text: "LOCAL=1\n" }, | ||
| ]); | ||
| } finally { | ||
| NodeFS.rmSync(root, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); |
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.
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.