The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // @effect-diagnostics nodeBuiltinImport:off - Applies real file modes in a temporary app folder. |
| 2 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 3 | import * as NodeFSP from "node:fs/promises"; |
| 4 | import * as NodeOS from "node:os"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | import { describe, expect, it } from "vite-plus/test"; |
| 7 | |
| 8 | import { removeSharedWriteAccess } from "./linux-after-pack.ts"; |
| 9 | |
| 10 | describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("removeSharedWriteAccess", () => { |
| 11 | it("removes group and other write access from the packed app only", async () => { |
| 12 | const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-after-pack-")); |
| 13 | try { |
| 14 | const appOutDir = NodePath.join(root, "app"); |
| 15 | const modes = { |
| 16 | "app/t3code": [0o777, 0o755], |
| 17 | "app/resources.pak": [0o666, 0o644], |
| 18 | "app/chrome-sandbox": [0o4777, 0o4755], |
| 19 | "app/resources/app.asar": [0o644, 0o644], |
| 20 | "outside/file": [0o666, 0o666], |
| 21 | } as const; |
| 22 | await NodeFSP.mkdir(NodePath.join(appOutDir, "resources"), { recursive: true }); |
| 23 | await NodeFSP.mkdir(NodePath.join(root, "outside")); |
| 24 | for (const [file, [before]] of Object.entries(modes)) { |
| 25 | await NodeFSP.writeFile(NodePath.join(root, file), ""); |
| 26 | await NodeFSP.chmod(NodePath.join(root, file), before); |
| 27 | } |
| 28 | await NodeFSP.chmod(NodePath.join(appOutDir, "resources"), 0o777); |
| 29 | await NodeFSP.symlink("../outside", NodePath.join(appOutDir, "linked-dir")); |
| 30 | |
| 31 | await removeSharedWriteAccess(appOutDir); |
| 32 | |
| 33 | for (const [file, [, after]] of Object.entries(modes)) { |
| 34 | const { mode } = await NodeFSP.stat(NodePath.join(root, file)); |
| 35 | expect([file, mode & 0o7777]).toEqual([file, after]); |
| 36 | } |
| 37 | const { mode: resourcesMode } = await NodeFSP.stat(NodePath.join(appOutDir, "resources")); |
| 38 | expect(resourcesMode & 0o7777).toBe(0o755); |
| 39 | } finally { |
| 40 | await NodeFSP.rm(root, { recursive: true, force: true }); |
| 41 | } |
| 42 | }); |
| 43 | }); |