Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.test.ts (1 of 1 file). Show all
Unified · Split
| @@ -80,6 +80,26 @@ const writeTextFile = Effect.fn("writeTextFile")(function* ( · 79 unmodified lines | |||
| 80 | yield* fileSystem.writeFileString(absolutePath, contents).pipe(Effect.orDie); | 80 | yield* fileSystem.writeFileString(absolutePath, contents).pipe(Effect.orDie); |
| 81 | }); | 81 | }); |
| 82 | 82 | ||
| 83 | it.effect("WorkspaceFileSystem.readFile opens files through the injected FileSystem service", () => | ||
| 84 | Effect.gen(function* () { | ||
| 85 | const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; | ||
| 86 | const cwd = yield* makeTempDir; | ||
| 87 | yield* writeTextFile(cwd, "src/index.ts", "export const answer = 42;\n"); | ||
| 88 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 89 | const resolvedPath = yield* fileSystem.realPath(`${cwd}/src/index.ts`); | ||
| 90 | |||
| 91 | const error = yield* workspaceFileSystem | ||
| 92 | .readFile({ cwd, relativePath: "src/index.ts" }) | ||
| 93 | .pipe(Effect.flip); | ||
| 94 | |||
| 95 | assert.instanceOf(error, WorkspaceFileSystem.WorkspaceFileSystemOperationError); | ||
| 96 | assert.equal(error.operation, "open"); | ||
| 97 | assert.equal(error.operationPath, resolvedPath); | ||
| 98 | assert.instanceOf(error.cause, PlatformError.PlatformError); | ||
| 99 | assert.equal((error.cause as PlatformError.PlatformError).reason._tag, "PermissionDenied"); | ||
| 100 | }).pipe(Effect.provide(WorkspaceFileSystemOpenFailureLayer)), | ||
| 101 | ); | ||
| 102 | |||
| 83 | it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (it) => { | 103 | it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (it) => { |
| 84 | describe("readFile", () => { | 104 | describe("readFile", () => { |
| 85 | it.effect("reads UTF-8 files relative to the workspace root", () => | 105 | it.effect("reads UTF-8 files relative to the workspace root", () => |
| @@ -218,26 +238,6 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 132 unmodified lines | |||
| 218 | expect((error.cause as PlatformError.PlatformError).reason._tag).toBe("NotFound"); | 238 | expect((error.cause as PlatformError.PlatformError).reason._tag).toBe("NotFound"); |
| 219 | }), | 239 | }), |
| 220 | ); | 240 | ); |
| 221 | |||
| 222 | it.effect("opens files through the injected FileSystem service", () => | ||
| 223 | Effect.gen(function* () { | ||
| 224 | const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; | ||
| 225 | const cwd = yield* makeTempDir; | ||
| 226 | yield* writeTextFile(cwd, "src/index.ts", "export const answer = 42;\n"); | ||
| 227 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 228 | const resolvedPath = yield* fileSystem.realPath(`${cwd}/src/index.ts`); | ||
| 229 | |||
| 230 | const error = yield* workspaceFileSystem | ||
| 231 | .readFile({ cwd, relativePath: "src/index.ts" }) | ||
| 232 | .pipe(Effect.flip); | ||
| 233 | |||
| 234 | assert.instanceOf(error, WorkspaceFileSystem.WorkspaceFileSystemOperationError); | ||
| 235 | assert.equal(error.operation, "open"); | ||
| 236 | assert.equal(error.operationPath, resolvedPath); | ||
| 237 | assert.instanceOf(error.cause, PlatformError.PlatformError); | ||
| 238 | assert.equal((error.cause as PlatformError.PlatformError).reason._tag, "PermissionDenied"); | ||
| 239 | }).pipe(Effect.provide(WorkspaceFileSystemOpenFailureLayer)), | ||
| 240 | ); | ||
| 241 | }); | 241 | }); |
| 242 | 242 | ||
| 243 | describe("writeFile", () => { | 243 | describe("writeFile", () => { |