| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { FilesystemBrowseError, FilesystemGetMetadataInput } from "./filesystem.ts"; |
| 5 | |
| 6 | describe("FilesystemGetMetadataInput", () => { |
| 7 | const decode = Schema.decodeUnknownSync(FilesystemGetMetadataInput); |
| 8 | it("bounds request size and path lengths", () => { |
| 9 | expect(() => decode({ paths: [] })).toThrow(); |
| 10 | expect(() => decode({ paths: Array.from({ length: 65 }, () => "/file") })).toThrow(); |
| 11 | expect(() => decode({ paths: ["/" + "x".repeat(512)] })).toThrow(); |
| 12 | expect(decode({ paths: Array.from({ length: 64 }, () => "/file") }).paths).toHaveLength(64); |
| 13 | }); |
| 14 | }); |
| 15 | |
| 16 | describe("FilesystemBrowseError", () => { |
| 17 | it("derives a stable message from browse context while retaining the cause", () => { |
| 18 | const cause = new Error("sensitive filesystem detail"); |
| 19 | const error = new FilesystemBrowseError({ |
| 20 | cwd: "/workspace", |
| 21 | partialPath: "./src/mai", |
| 22 | failure: "read_directory_failed", |
| 23 | parentPath: "/workspace/src", |
| 24 | cause, |
| 25 | }); |
| 26 | |
| 27 | expect(error.message).toBe("Failed to browse filesystem path './src/mai' from '/workspace'."); |
| 28 | expect(error.message).not.toContain(cause.message); |
| 29 | expect(error.cause).toBe(cause); |
| 30 | }); |
| 31 | |
| 32 | it("decodes legacy message-only errors during rolling upgrades", () => { |
| 33 | const decodeError = Schema.decodeUnknownSync(FilesystemBrowseError); |
| 34 | const error = decodeError({ |
| 35 | _tag: "FilesystemBrowseError", |
| 36 | message: "Legacy filesystem browse failure.", |
| 37 | }); |
| 38 | |
| 39 | expect(error.message).toBe("Legacy filesystem browse failure."); |
| 40 | expect(error.partialPath).toBeUndefined(); |
| 41 | expect(error.failure).toBeUndefined(); |
| 42 | }); |
| 43 | }); |