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 @@
1import * as NodeServices from "@effect/platform-node/NodeServices";1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { it, describe, expect } from "@effect/vitest";2import { assert, it, describe, expect } from "@effect/vitest";
3import * as Effect from "effect/Effect";3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";4import * as FileSystem from "effect/FileSystem";
5import * as Layer from "effect/Layer";5import * as Layer from "effect/Layer";
6import * as Path from "effect/Path";6import * as Path from "effect/Path";
7import * as PlatformError from "effect/PlatformError";
7 8
8import * as ServerConfig from "../config.ts";9import * as ServerConfig from "../config.ts";
9import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";10import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
@@ -73,6 +74,24 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 63 unmodified lines
73 }),74 }),
74 );75 );
75 76
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
76 it.effect("rejects reads outside the workspace root", () =>95 it.effect("rejects reads outside the workspace root", () =>
77 Effect.gen(function* () {96 Effect.gen(function* () {
78 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;97 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
@@ -177,16 +196,25 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 98 unmodified lines
177 .readFile({ cwd, relativePath: "missing.txt" })196 .readFile({ cwd, relativePath: "missing.txt" })
178 .pipe(Effect.flip);197 .pipe(Effect.flip);
179 198
180 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFileSystemOperationError);199 assert.instanceOf(error, WorkspaceFileSystem.WorkspaceFileSystemOperationError);
181 expect(error).toMatchObject({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 {
182 workspaceRoot: cwd,209 workspaceRoot: cwd,
183 relativePath: "missing.txt",210 relativePath: "missing.txt",
184 resolvedPath,211 resolvedPath,
185 operationPath: resolvedPath,212 operationPath: resolvedPath,
186 operation: "realpath-target",213 operation: "realpath-target",
187 });214 },
188 expect(error.cause).toBeInstanceOf(Error);215 );
189 expect((error.cause as NodeJS.ErrnoException).code).toBe("ENOENT");216 assert.instanceOf(error.cause, PlatformError.PlatformError);
217 assert.strictEqual(error.cause.reason._tag, "NotFound");
190 }),218 }),
191 );219 );
192 });220 });