History

refactor(server): use Effect filesystem for workspace reads

Cursor Agent committed 3 months ago

Commit d8e264e1 parent 53e3c982 files · +103 −95Browse files

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

Unified · Split

apps/server/src/workspace/WorkspaceFileSystem.test.ts+24−3
@@ -1,5 +1,5 @@
11 import * as NodeServices from "@effect/platform-node/NodeServices";
2−import { it, describe, expect } from "@effect/vitest";
2+import { assert, describe, expect, it } from "@effect/vitest";
33 import * as Effect from "effect/Effect";
44 import * as FileSystem from "effect/FileSystem";
55 import * as Layer from "effect/Layer";
@@ -73,6 +73,24 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 67 unmodified lines
7373 }),
7474 );
7575
76+ it.effect("bounds previews while reporting the complete file size", () =>
77+ Effect.gen(function* () {
78+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
79+ const cwd = yield* makeTempDir;
80+ const contents = "a".repeat(1024 * 1024 + 5);
81+ yield* writeTextFile(cwd, "large.txt", contents);
82+
83+ const result = yield* workspaceFileSystem.readFile({
84+ cwd,
85+ relativePath: "large.txt",
86+ });
87+
88+ assert.strictEqual(result.contents.length, 1024 * 1024);
89+ assert.strictEqual(result.byteLength, contents.length);
90+ assert.isTrue(result.truncated);
91+ }),
92+ );
93+
7694 it.effect("rejects reads outside the workspace root", () =>
7795 Effect.gen(function* () {
7896 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
@@ -185,8 +203,11 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 106 unmodified lines
185203 operationPath: resolvedPath,
186204 operation: "realpath-target",
187205 });
188− expect(error.cause).toBeInstanceOf(Error);
189− expect((error.cause as NodeJS.ErrnoException).code).toBe("ENOENT");
206+ expect(error.cause).toMatchObject({
207+ _tag: "PlatformError",
208+ pathOrDescriptor: resolvedPath,
209+ reason: { _tag: "NotFound" },
210+ });
190211 }),
191212 );
192213 });