Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

project.test.ts

67 lines2.6 KB

1import * as Schema from "effect/Schema";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 ProjectReadFileError,
6 ProjectSearchEntriesError,
7 ProjectWriteFileError,
8} from "./project.ts";
9​
10describe("project RPC errors", () => {
11 it("derives stable messages from structured request context while retaining causes", () => {
12 const cause = new Error("sensitive platform detail");
13 const searchError = new ProjectSearchEntriesError({
14 cwd: "/workspace",
15 queryLength: "authorization: Bearer secret-token".length,
16 limit: 20,
17 failure: "search_index_search_failed",
18 normalizedCwd: "/workspace",
19 detail: "index unavailable",
20 cause,
21 });
22 const readError = new ProjectReadFileError({
23 cwd: "/workspace",
24 relativePath: "src/index.ts",
25 failure: "operation_failed",
26 operation: "read",
27 operationPath: "/workspace/src/index.ts",
28 resolvedPath: "/workspace/src/index.ts",
29 cause,
30 });
31​
32 expect(searchError.message).toBe("Failed to search workspace entries in '/workspace'.");
33 expect(searchError.message).not.toContain(cause.message);
34 expect(searchError.normalizedCwd).toBe("/workspace");
35 expect(searchError.queryLength).toBe("authorization: Bearer secret-token".length);
36 expect(searchError).not.toHaveProperty("query");
37 expect(searchError.message).not.toMatch(/Bearer|secret-token/);
38 expect(searchError.cause).toBe(cause);
39 expect(readError.message).toBe("Failed to read workspace file 'src/index.ts' in '/workspace'.");
40 expect(readError.message).not.toContain(cause.message);
41 expect(readError.cause).toBe(cause);
42 });
43​
44 it("decodes legacy message-only errors during rolling upgrades", () => {
45 const decodeSearchError = Schema.decodeUnknownSync(ProjectSearchEntriesError);
46 const decodeWriteError = Schema.decodeUnknownSync(ProjectWriteFileError);
47​
48 const searchError = decodeSearchError({
49 _tag: "ProjectSearchEntriesError",
50 message: "Legacy project search failure.",
51 query: "legacy sensitive query",
52 });
53 const writeError = decodeWriteError({
54 _tag: "ProjectWriteFileError",
55 message: "Legacy project write failure.",
56 });
57​
58 expect(searchError.message).toBe("Legacy project search failure.");
59 expect(searchError.cwd).toBeUndefined();
60 expect(searchError.queryLength).toBeUndefined();
61 expect(searchError).not.toHaveProperty("query");
62 expect(searchError.failure).toBeUndefined();
63 expect(writeError.message).toBe("Legacy project write failure.");
64 expect(writeError.relativePath).toBeUndefined();
65 expect(writeError.failure).toBeUndefined();
66 });
67});