Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.test.ts (1 of 2 files). Show all
Unified · Split
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | 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"; | |
| 3 | 3 | import * as Effect from "effect/Effect"; |
| 4 | 4 | import * as FileSystem from "effect/FileSystem"; |
| 5 | 5 | import * as Layer from "effect/Layer"; |
| 6 | 6 | import * as Path from "effect/Path"; |
| 7 | +import * as PlatformError from "effect/PlatformError"; | |
| 7 | 8 | |
| 8 | 9 | import * as ServerConfig from "../config.ts"; |
| 9 | 10 | import * 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 | 95 | it.effect("rejects reads outside the workspace root", () => |
| 77 | 96 | Effect.gen(function* () { |
| 78 | 97 | const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; |
| @@ -177,16 +196,25 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i · 98 unmodified lines | ||
| 177 | 196 | .readFile({ cwd, relativePath: "missing.txt" }) |
| 178 | 197 | .pipe(Effect.flip); |
| 179 | 198 | |
| 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 | + { | |
| 182 | 209 | workspaceRoot: cwd, |
| 183 | 210 | relativePath: "missing.txt", |
| 184 | 211 | resolvedPath, |
| 185 | 212 | operationPath: resolvedPath, |
| 186 | 213 | 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"); | |
| 190 | 218 | }), |
| 191 | 219 | ); |
| 192 | 220 | }); |