History

refactor(server): use Effect filesystem for workspace reads

Cursor Agent committed 3 months ago

Commit 7c8c0b61 parent ecb35f72 files · +108 −91Browse 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+34−6
@@ -1,9 +1,10 @@
11 import * as NodeServices from "@effect/platform-node/NodeServices";
2−import { it, describe, expect } from "@effect/vitest";
2+import { assert, it, describe, expect } from "@effect/vitest";
33 import * as Effect from "effect/Effect";
44 import * as FileSystem from "effect/FileSystem";
55 import * as Layer from "effect/Layer";
66 import * as Path from "effect/Path";
7+import * as PlatformError from "effect/PlatformError";
78
89 import * as ServerConfig from "../config.ts";
910 import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
@@ -73,6 +74,24 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 63 unmodified lines
7374 }),
7475 );
7576
77+ it.effect("limits previews while preserving the full file byte length", () =>
78+ Effect.gen(function* () {
79+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
80+ const cwd = yield* makeTempDir;
81+ const contents = "a".repeat(1024 * 1024 + 1);
82+ yield* writeTextFile(cwd, "large.txt", contents);
83+
84+ const result = yield* workspaceFileSystem.readFile({
85+ cwd,
86+ relativePath: "large.txt",
87+ });
88+
89+ assert.strictEqual(result.contents.length, 1024 * 1024);
90+ assert.strictEqual(result.byteLength, contents.length);
91+ assert.strictEqual(result.truncated, true);
92+ }),
93+ );
94+
7695 it.effect("rejects reads outside the workspace root", () =>
7796 Effect.gen(function* () {
7897 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
@@ -177,16 +196,25 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 98 unmodified lines
177196 .readFile({ cwd, relativePath: "missing.txt" })
178197 .pipe(Effect.flip);
179198
180− expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFileSystemOperationError);
181− expect(error).toMatchObject({
199+ assert.instanceOf(error, WorkspaceFileSystem.WorkspaceFileSystemOperationError);
200+ assert.deepEqual(
201+ {
202+ workspaceRoot: error.workspaceRoot,
203+ relativePath: error.relativePath,
204+ resolvedPath: error.resolvedPath,
205+ operationPath: error.operationPath,
206+ operation: error.operation,
207+ },
208+ {
182209 workspaceRoot: cwd,
183210 relativePath: "missing.txt",
184211 resolvedPath,
185212 operationPath: resolvedPath,
186213 operation: "realpath-target",
187− });
188− expect(error.cause).toBeInstanceOf(Error);
189− expect((error.cause as NodeJS.ErrnoException).code).toBe("ENOENT");
214+ },
215+ );
216+ assert.instanceOf(error.cause, PlatformError.PlatformError);
217+ assert.strictEqual(error.cause.reason._tag, "NotFound");
190218 }),
191219 );
192220 });