Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 ProjectReadFileError,
6 ProjectSearchContentsError,
7 ProjectSearchContentsInput,
8 ProjectSearchEntriesError,
9 ProjectSearchEntriesInput,
10 ProjectWriteFileError,
11} from "./project.ts";
12
13const decodeSearchEntriesInput = Schema.decodeUnknownSync(ProjectSearchEntriesInput);
14const decodeSearchContentsInput = Schema.decodeUnknownSync(ProjectSearchContentsInput);
15
16describe("project search inputs", () => {
17 it("allows an empty entries query for bounded frecency browsing", () => {
18 const decoded = decodeSearchEntriesInput({
19 cwd: "/workspace",
20 query: " ",
21 limit: 10,
22 kind: "file",
23 });
24 expect(decoded.query).toBe("");
25 });
26
27 it("preserves whitespace in content search queries", () => {
28 const decoded = decodeSearchContentsInput({
29 cwd: "/workspace",
30 query: " foo ",
31 limit: 10,
32 caseSensitive: false,
33 wholeWord: false,
34 useRegex: false,
35 });
36 expect(decoded.query).toBe(" foo ");
37 });
38});
39
40describe("project RPC errors", () => {
41 it("derives stable messages from structured request context while retaining causes", () => {
42 const cause = new Error("sensitive platform detail");
43 const searchError = new ProjectSearchEntriesError({
44 cwd: "/workspace",
45 queryLength: "authorization: Bearer secret-token".length,
46 limit: 20,
47 failure: "search_index_search_failed",
48 normalizedCwd: "/workspace",
49 detail: "index unavailable",
50 cause,
51 });
52 const readError = new ProjectReadFileError({
53 cwd: "/workspace",
54 relativePath: "src/index.ts",
55 failure: "operation_failed",
56 operation: "read",
57 operationPath: "/workspace/src/index.ts",
58 resolvedPath: "/workspace/src/index.ts",
59 cause,
60 });
61
62 expect(searchError.message).toBe("Failed to search workspace entries in '/workspace'.");
63 expect(searchError.message).not.toContain(cause.message);
64 expect(searchError.normalizedCwd).toBe("/workspace");
65 expect(searchError.queryLength).toBe("authorization: Bearer secret-token".length);
66 expect(searchError).not.toHaveProperty("query");
67 expect(searchError.message).not.toMatch(/Bearer|secret-token/);
68 expect(searchError.cause).toBe(cause);
69 expect(readError.message).toBe("Failed to read workspace file 'src/index.ts' in '/workspace'.");
70 expect(readError.message).not.toContain(cause.message);
71 expect(readError.cause).toBe(cause);
72
73 const contentSearchError = new ProjectSearchContentsError({
74 cwd: "/workspace",
75 queryLength: "authorization: Bearer secret-token".length,
76 limit: 100,
77 failure: "search_index_search_failed",
78 cause,
79 });
80 expect(contentSearchError.message).toBe("Failed to search workspace contents in '/workspace'.");
81 expect(contentSearchError.message).not.toContain(cause.message);
82 expect(contentSearchError).not.toHaveProperty("query");
83 expect(contentSearchError.cause).toBe(cause);
84 });
85
86 it("decodes legacy message-only errors during rolling upgrades", () => {
87 const decodeSearchError = Schema.decodeUnknownSync(ProjectSearchEntriesError);
88 const decodeWriteError = Schema.decodeUnknownSync(ProjectWriteFileError);
89
90 const searchError = decodeSearchError({
91 _tag: "ProjectSearchEntriesError",
92 message: "Legacy project search failure.",
93 query: "legacy sensitive query",
94 });
95 const writeError = decodeWriteError({
96 _tag: "ProjectWriteFileError",
97 message: "Legacy project write failure.",
98 });
99
100 expect(searchError.message).toBe("Legacy project search failure.");
101 expect(searchError.cwd).toBeUndefined();
102 expect(searchError.queryLength).toBeUndefined();
103 expect(searchError).not.toHaveProperty("query");
104 expect(searchError.failure).toBeUndefined();
105 expect(writeError.message).toBe("Legacy project write failure.");
106 expect(writeError.relativePath).toBeUndefined();
107 expect(writeError.failure).toBeUndefined();
108 });
109});