History

Test workspace reads use injected filesystem

Cursor Agent committed 4 months ago

Commit ccfad541 parent ddf731d1 file · +20 −20Browse files

Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.test.ts (1 of 1 file). Show all

Unified · Split

apps/server/src/workspace/WorkspaceFileSystem.test.ts+20−20
@@ -80,6 +80,26 @@ const writeTextFile = Effect.fn("writeTextFile")(function* ( · 79 unmodified lines
8080 yield* fileSystem.writeFileString(absolutePath, contents).pipe(Effect.orDie);
8181 });
8282
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+
83103 it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (it) => {
84104 describe("readFile", () => {
85105 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
218238 expect((error.cause as PlatformError.PlatformError).reason._tag).toBe("NotFound");
219239 }),
220240 );
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− );
241241 });
242242
243243 describe("writeFile", () => {