|
1 | 1 | // @effect-diagnostics nodeBuiltinImport:off |
2 | 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
3 | 3 | import { assert, describe, it } from "@effect/vitest"; |
| 4 | +import { symlinksSupported } from "@t3tools/shared/testing/symlinks"; |
4 | 5 | import * as Effect from "effect/Effect"; |
5 | 6 | import * as FileSystem from "effect/FileSystem"; |
6 | 7 | import * as Path from "effect/Path"; |
@@ -122,100 +123,104 @@ describe("acpPermissionDisposition", () => { |
122 | 123 | } |
123 | 124 | }); |
124 | 125 |
|
125 | | - it.effect("denies mutations through workspace symlinks that escape the writable roots", () => |
126 | | - Effect.gen(function* () { |
127 | | - const fileSystem = yield* FileSystem.FileSystem; |
128 | | - const path = yield* Path.Path; |
129 | | - const workspace = yield* fileSystem.makeTempDirectoryScoped({ |
130 | | - prefix: "t3-acp-permission-workspace-", |
131 | | - }); |
132 | | - const outside = yield* fileSystem.makeTempDirectoryScoped({ |
133 | | - prefix: "t3-acp-permission-outside-", |
134 | | - }); |
135 | | - const outsideFile = path.join(outside, "existing.ts"); |
136 | | - yield* fileSystem.writeFileString(outsideFile, "outside"); |
137 | | - yield* fileSystem.symlink(outsideFile, path.join(workspace, "linked-file.ts")); |
138 | | - yield* fileSystem.symlink(outside, path.join(workspace, "linked-directory")); |
| 126 | + it.effect.skipIf(!symlinksSupported)( |
| 127 | + "denies mutations through workspace symlinks that escape the writable roots", |
| 128 | + () => |
| 129 | + Effect.gen(function* () { |
| 130 | + const fileSystem = yield* FileSystem.FileSystem; |
| 131 | + const path = yield* Path.Path; |
| 132 | + const workspace = yield* fileSystem.makeTempDirectoryScoped({ |
| 133 | + prefix: "t3-acp-permission-workspace-", |
| 134 | + }); |
| 135 | + const outside = yield* fileSystem.makeTempDirectoryScoped({ |
| 136 | + prefix: "t3-acp-permission-outside-", |
| 137 | + }); |
| 138 | + const outsideFile = path.join(outside, "existing.ts"); |
| 139 | + yield* fileSystem.writeFileString(outsideFile, "outside"); |
| 140 | + yield* fileSystem.symlink(outsideFile, path.join(workspace, "linked-file.ts")); |
| 141 | + yield* fileSystem.symlink(outside, path.join(workspace, "linked-directory")); |
139 | 142 |
|
140 | | - const realPolicy: AcpRuntimePolicy = { |
141 | | - runtimeMode: "full-access", |
142 | | - cwd: workspace, |
143 | | - approvalPolicy: "never", |
144 | | - sandboxPolicy: { |
145 | | - type: "workspaceWrite", |
146 | | - writableRoots: [], |
147 | | - networkAccess: false, |
148 | | - }, |
149 | | - }; |
| 143 | + const realPolicy: AcpRuntimePolicy = { |
| 144 | + runtimeMode: "full-access", |
| 145 | + cwd: workspace, |
| 146 | + approvalPolicy: "never", |
| 147 | + sandboxPolicy: { |
| 148 | + type: "workspaceWrite", |
| 149 | + writableRoots: [], |
| 150 | + networkAccess: false, |
| 151 | + }, |
| 152 | + }; |
150 | 153 |
|
151 | | - assert.equal( |
152 | | - acpPermissionDisposition( |
153 | | - realPolicy, |
154 | | - permissionRequest("edit", [{ path: "linked-file.ts" }]), |
155 | | - ), |
156 | | - "deny", |
157 | | - ); |
158 | | - assert.equal( |
159 | | - acpPermissionDisposition( |
160 | | - realPolicy, |
161 | | - permissionRequest("edit", [{ path: "linked-directory/new-file.ts" }]), |
162 | | - ), |
163 | | - "deny", |
164 | | - "a missing leaf below an escaping directory symlink must not be auto-approved", |
165 | | - ); |
166 | | - assert.equal( |
167 | | - acpPermissionDisposition( |
168 | | - realPolicy, |
169 | | - permissionRequest("edit", [{ path: "linked-directory/../escaped-file.ts" }]), |
170 | | - ), |
171 | | - "deny", |
172 | | - "physical symlink traversal must be resolved before parent segments", |
173 | | - ); |
174 | | - }).pipe(Effect.provide(NodeServices.layer)), |
| 154 | + assert.equal( |
| 155 | + acpPermissionDisposition( |
| 156 | + realPolicy, |
| 157 | + permissionRequest("edit", [{ path: "linked-file.ts" }]), |
| 158 | + ), |
| 159 | + "deny", |
| 160 | + ); |
| 161 | + assert.equal( |
| 162 | + acpPermissionDisposition( |
| 163 | + realPolicy, |
| 164 | + permissionRequest("edit", [{ path: "linked-directory/new-file.ts" }]), |
| 165 | + ), |
| 166 | + "deny", |
| 167 | + "a missing leaf below an escaping directory symlink must not be auto-approved", |
| 168 | + ); |
| 169 | + assert.equal( |
| 170 | + acpPermissionDisposition( |
| 171 | + realPolicy, |
| 172 | + permissionRequest("edit", [{ path: "linked-directory/../escaped-file.ts" }]), |
| 173 | + ), |
| 174 | + "deny", |
| 175 | + "physical symlink traversal must be resolved before parent segments", |
| 176 | + ); |
| 177 | + }).pipe(Effect.provide(NodeServices.layer)), |
175 | 178 | ); |
176 | 179 |
|
177 | | - it.effect("allows existing and new files beneath canonical writable roots", () => |
178 | | - Effect.gen(function* () { |
179 | | - const fileSystem = yield* FileSystem.FileSystem; |
180 | | - const path = yield* Path.Path; |
181 | | - const workspace = yield* fileSystem.makeTempDirectoryScoped({ |
182 | | - prefix: "t3-acp-permission-workspace-", |
183 | | - }); |
184 | | - const workspaceLinkParent = yield* fileSystem.makeTempDirectoryScoped({ |
185 | | - prefix: "t3-acp-permission-link-parent-", |
186 | | - }); |
187 | | - const workspaceLink = path.join(workspaceLinkParent, "workspace-link"); |
188 | | - yield* fileSystem.makeDirectory(path.join(workspace, "src"), { recursive: true }); |
189 | | - yield* fileSystem.writeFileString(path.join(workspace, "src", "existing.ts"), "existing"); |
190 | | - yield* fileSystem.symlink(workspace, workspaceLink); |
| 180 | + it.effect.skipIf(!symlinksSupported)( |
| 181 | + "allows existing and new files beneath canonical writable roots", |
| 182 | + () => |
| 183 | + Effect.gen(function* () { |
| 184 | + const fileSystem = yield* FileSystem.FileSystem; |
| 185 | + const path = yield* Path.Path; |
| 186 | + const workspace = yield* fileSystem.makeTempDirectoryScoped({ |
| 187 | + prefix: "t3-acp-permission-workspace-", |
| 188 | + }); |
| 189 | + const workspaceLinkParent = yield* fileSystem.makeTempDirectoryScoped({ |
| 190 | + prefix: "t3-acp-permission-link-parent-", |
| 191 | + }); |
| 192 | + const workspaceLink = path.join(workspaceLinkParent, "workspace-link"); |
| 193 | + yield* fileSystem.makeDirectory(path.join(workspace, "src"), { recursive: true }); |
| 194 | + yield* fileSystem.writeFileString(path.join(workspace, "src", "existing.ts"), "existing"); |
| 195 | + yield* fileSystem.symlink(workspace, workspaceLink); |
191 | 196 |
|
192 | | - const realPolicy: AcpRuntimePolicy = { |
193 | | - runtimeMode: "full-access", |
194 | | - cwd: workspaceLink, |
195 | | - approvalPolicy: "never", |
196 | | - sandboxPolicy: { |
197 | | - type: "workspaceWrite", |
198 | | - writableRoots: [], |
199 | | - networkAccess: false, |
200 | | - }, |
201 | | - }; |
| 197 | + const realPolicy: AcpRuntimePolicy = { |
| 198 | + runtimeMode: "full-access", |
| 199 | + cwd: workspaceLink, |
| 200 | + approvalPolicy: "never", |
| 201 | + sandboxPolicy: { |
| 202 | + type: "workspaceWrite", |
| 203 | + writableRoots: [], |
| 204 | + networkAccess: false, |
| 205 | + }, |
| 206 | + }; |
202 | 207 |
|
203 | | - assert.equal( |
204 | | - acpPermissionDisposition( |
205 | | - realPolicy, |
206 | | - permissionRequest("edit", [{ path: "src/existing.ts" }]), |
207 | | - ), |
208 | | - "allow", |
209 | | - ); |
210 | | - assert.equal( |
211 | | - acpPermissionDisposition( |
212 | | - realPolicy, |
213 | | - permissionRequest("edit", [{ path: "src/generated/new-file.ts" }]), |
214 | | - ), |
215 | | - "allow", |
216 | | - "non-existent descendants of a real in-root ancestor remain writable", |
217 | | - ); |
218 | | - }).pipe(Effect.provide(NodeServices.layer)), |
| 208 | + assert.equal( |
| 209 | + acpPermissionDisposition( |
| 210 | + realPolicy, |
| 211 | + permissionRequest("edit", [{ path: "src/existing.ts" }]), |
| 212 | + ), |
| 213 | + "allow", |
| 214 | + ); |
| 215 | + assert.equal( |
| 216 | + acpPermissionDisposition( |
| 217 | + realPolicy, |
| 218 | + permissionRequest("edit", [{ path: "src/generated/new-file.ts" }]), |
| 219 | + ), |
| 220 | + "allow", |
| 221 | + "non-existent descendants of a real in-root ancestor remain writable", |
| 222 | + ); |
| 223 | + }).pipe(Effect.provide(NodeServices.layer)), |
219 | 224 | ); |
220 | 225 | }); |
221 | 226 |
|
|
0 commit comments