refactor(server): use Effect filesystem for workspace reads
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
53e3c98a55
commit
d8e264ee18
2 files changed
+110
-102
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it, describe, expect } from "@effect/vitest";
|
||||
import { assert, describe, expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -73,6 +73,24 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("bounds previews while reporting the complete file size", () =>
|
||||
Effect.gen(function* () {
|
||||
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
|
||||
const cwd = yield* makeTempDir;
|
||||
const contents = "a".repeat(1024 * 1024 + 5);
|
||||
yield* writeTextFile(cwd, "large.txt", contents);
|
||||
|
||||
const result = yield* workspaceFileSystem.readFile({
|
||||
cwd,
|
||||
relativePath: "large.txt",
|
||||
});
|
||||
|
||||
assert.strictEqual(result.contents.length, 1024 * 1024);
|
||||
assert.strictEqual(result.byteLength, contents.length);
|
||||
assert.isTrue(result.truncated);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects reads outside the workspace root", () =>
|
||||
Effect.gen(function* () {
|
||||
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
|
||||
@@ -185,8 +203,11 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
|
||||
operationPath: resolvedPath,
|
||||
operation: "realpath-target",
|
||||
});
|
||||
expect(error.cause).toBeInstanceOf(Error);
|
||||
expect((error.cause as NodeJS.ErrnoException).code).toBe("ENOENT");
|
||||
expect(error.cause).toMatchObject({
|
||||
_tag: "PlatformError",
|
||||
pathOrDescriptor: resolvedPath,
|
||||
reason: { _tag: "NotFound" },
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user