@xynogen/pix-find 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/find.test.ts +0 -255
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-find",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Pi tool — glob file search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"src",
|
|
16
|
+
"!src/**/*.test.*",
|
|
16
17
|
"README.md",
|
|
17
18
|
"LICENSE"
|
|
18
19
|
],
|
package/src/find.test.ts
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import type { CursorStore, FffState } from "@xynogen/pix-pretty/fff";
|
|
3
|
-
import type {
|
|
4
|
-
PiPrettyApi,
|
|
5
|
-
RenderContextLike,
|
|
6
|
-
TextComponentCtor,
|
|
7
|
-
ThemeLike,
|
|
8
|
-
} from "@xynogen/pix-pretty/types";
|
|
9
|
-
import { applyFindDefaults, DEFAULT_FIND_LIMIT, globHighlight, registerFindTool } from "./find";
|
|
10
|
-
|
|
11
|
-
describe("globHighlight", () => {
|
|
12
|
-
it("keeps literal runs from a glob as case-insensitive alternatives", () => {
|
|
13
|
-
const re = globHighlight("**/*.test.ts");
|
|
14
|
-
expect(re).toBeInstanceOf(RegExp);
|
|
15
|
-
expect((re as RegExp).flags).toBe("gi");
|
|
16
|
-
expect("foo.test.ts".match(re as RegExp)).not.toBeNull();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("highlights the extension of a simple glob", () => {
|
|
20
|
-
expect("app.ts".match(globHighlight("*.ts") as RegExp)?.[0]).toBe(".ts");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("returns undefined when the glob has no meaningful literal run", () => {
|
|
24
|
-
expect(globHighlight("*")).toBeUndefined();
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
class MockTextComponent {
|
|
29
|
-
private text = "";
|
|
30
|
-
setText(v: string) {
|
|
31
|
-
this.text = v;
|
|
32
|
-
}
|
|
33
|
-
getText() {
|
|
34
|
-
return this.text;
|
|
35
|
-
}
|
|
36
|
-
render(_width?: number) {
|
|
37
|
-
return this.text.split("\n");
|
|
38
|
-
}
|
|
39
|
-
invalidate() {}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("applyFindDefaults", () => {
|
|
43
|
-
it("applies a conservative default without overriding an explicit limit", () => {
|
|
44
|
-
expect(applyFindDefaults({ pattern: "**/*.ts" })).toEqual({
|
|
45
|
-
pattern: "**/*.ts",
|
|
46
|
-
limit: DEFAULT_FIND_LIMIT,
|
|
47
|
-
});
|
|
48
|
-
expect(applyFindDefaults({ pattern: "**/*.ts", limit: 8 })).toEqual({
|
|
49
|
-
pattern: "**/*.ts",
|
|
50
|
-
limit: 8,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("registerFindTool", () => {
|
|
56
|
-
it("registers a tool named 'find'", () => {
|
|
57
|
-
const tools: string[] = [];
|
|
58
|
-
const mockPi: PiPrettyApi = {
|
|
59
|
-
registerTool(t: unknown) {
|
|
60
|
-
tools.push((t as { name: string }).name);
|
|
61
|
-
},
|
|
62
|
-
registerCommand() {},
|
|
63
|
-
on() {},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
registerFindTool(
|
|
67
|
-
mockPi,
|
|
68
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
69
|
-
{
|
|
70
|
-
cwd: process.cwd(),
|
|
71
|
-
sp: (p: string) => p,
|
|
72
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
73
|
-
fffState: {
|
|
74
|
-
module: null,
|
|
75
|
-
finder: null,
|
|
76
|
-
partialIndex: false,
|
|
77
|
-
dbDir: null,
|
|
78
|
-
} satisfies FffState,
|
|
79
|
-
cursorStore: {
|
|
80
|
-
store: () => "",
|
|
81
|
-
get: () => undefined,
|
|
82
|
-
} as unknown as CursorStore,
|
|
83
|
-
},
|
|
84
|
-
);
|
|
85
|
-
expect(tools).toEqual(["find"]);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("restores result paths when an elapsed card is expanded", () => {
|
|
89
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
90
|
-
const mockPi: PiPrettyApi = {
|
|
91
|
-
registerTool(tool: unknown) {
|
|
92
|
-
Object.assign(registered, tool);
|
|
93
|
-
},
|
|
94
|
-
registerCommand() {},
|
|
95
|
-
on() {},
|
|
96
|
-
};
|
|
97
|
-
registerFindTool(
|
|
98
|
-
mockPi,
|
|
99
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
100
|
-
{
|
|
101
|
-
cwd: process.cwd(),
|
|
102
|
-
sp: (p: string) => p,
|
|
103
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
104
|
-
fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
|
|
105
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
106
|
-
},
|
|
107
|
-
);
|
|
108
|
-
const theme: ThemeLike = {
|
|
109
|
-
fg: (_key: string, value: string) => value,
|
|
110
|
-
bold: (value: string) => value,
|
|
111
|
-
};
|
|
112
|
-
const result = registered.renderResult?.(
|
|
113
|
-
{
|
|
114
|
-
content: [{ type: "text", text: "src/one.ts\nsrc/two.ts" }],
|
|
115
|
-
details: {
|
|
116
|
-
_type: "findResult",
|
|
117
|
-
text: "src/one.ts\nsrc/two.ts",
|
|
118
|
-
pattern: "**/*.ts",
|
|
119
|
-
matchCount: 2,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
undefined,
|
|
123
|
-
theme,
|
|
124
|
-
{
|
|
125
|
-
expanded: true,
|
|
126
|
-
isError: false,
|
|
127
|
-
invalidate: () => {},
|
|
128
|
-
state: { collapsed: true },
|
|
129
|
-
} as unknown as RenderContextLike,
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
|
|
133
|
-
const shown = strip(result?.getText() ?? "");
|
|
134
|
-
expect(shown).toContain("src/one.ts");
|
|
135
|
-
expect(shown).toContain("src/two.ts");
|
|
136
|
-
// No floating count header in the framed view — the collapsed row carries it.
|
|
137
|
-
expect(shown).not.toContain("2 files");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("frames single-file output like multi-file (no inline row)", () => {
|
|
141
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
142
|
-
const mockPi: PiPrettyApi = {
|
|
143
|
-
registerTool(tool: unknown) {
|
|
144
|
-
Object.assign(registered, tool);
|
|
145
|
-
},
|
|
146
|
-
registerCommand() {},
|
|
147
|
-
on() {},
|
|
148
|
-
};
|
|
149
|
-
registerFindTool(
|
|
150
|
-
mockPi,
|
|
151
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
152
|
-
{
|
|
153
|
-
cwd: process.cwd(),
|
|
154
|
-
sp: (p: string) => p,
|
|
155
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
156
|
-
fffState: {
|
|
157
|
-
module: null,
|
|
158
|
-
finder: null,
|
|
159
|
-
partialIndex: false,
|
|
160
|
-
dbDir: null,
|
|
161
|
-
} satisfies FffState,
|
|
162
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
const theme: ThemeLike = { fg: (_k: string, v: string) => v, bold: (v: string) => v };
|
|
166
|
-
const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
|
|
167
|
-
const result = {
|
|
168
|
-
content: [{ type: "text", text: "src/a.ts" }],
|
|
169
|
-
details: { _type: "findResult", text: "src/a.ts", pattern: "*.ts", matchCount: 1 } as never,
|
|
170
|
-
};
|
|
171
|
-
const out =
|
|
172
|
-
registered
|
|
173
|
-
.renderResult?.(result, { isPartial: false }, theme, {
|
|
174
|
-
expanded: false,
|
|
175
|
-
isError: false,
|
|
176
|
-
invalidate: () => {},
|
|
177
|
-
state: {},
|
|
178
|
-
} as unknown as RenderContextLike)
|
|
179
|
-
?.getText() ?? "";
|
|
180
|
-
// Single result is framed just like multi — one shape, no inline row.
|
|
181
|
-
expect(out).toContain("─");
|
|
182
|
-
expect(strip(out)).toContain("src/a.ts");
|
|
183
|
-
expect(strip(out)).not.toContain("file");
|
|
184
|
-
const multi = {
|
|
185
|
-
content: [{ type: "text", text: "a.ts\nb.ts\nc.ts" }],
|
|
186
|
-
details: {
|
|
187
|
-
_type: "findResult",
|
|
188
|
-
text: "a.ts\nb.ts\nc.ts",
|
|
189
|
-
pattern: "*.ts",
|
|
190
|
-
matchCount: 3,
|
|
191
|
-
} as never,
|
|
192
|
-
};
|
|
193
|
-
const multiOut =
|
|
194
|
-
registered
|
|
195
|
-
.renderResult?.(multi, { isPartial: false }, theme, {
|
|
196
|
-
expanded: false,
|
|
197
|
-
isError: false,
|
|
198
|
-
invalidate: () => {},
|
|
199
|
-
state: {},
|
|
200
|
-
} as unknown as RenderContextLike)
|
|
201
|
-
?.getText() ?? "";
|
|
202
|
-
expect(multiOut).toContain("─");
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("collapses structured errors and restores the exact diagnostic on expansion", () => {
|
|
206
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
207
|
-
const mockPi: PiPrettyApi = {
|
|
208
|
-
registerTool(tool: unknown) {
|
|
209
|
-
Object.assign(registered, tool);
|
|
210
|
-
},
|
|
211
|
-
registerCommand() {},
|
|
212
|
-
on() {},
|
|
213
|
-
};
|
|
214
|
-
registerFindTool(
|
|
215
|
-
mockPi,
|
|
216
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
217
|
-
{
|
|
218
|
-
cwd: process.cwd(),
|
|
219
|
-
sp: (p: string) => p,
|
|
220
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
221
|
-
fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
|
|
222
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
223
|
-
},
|
|
224
|
-
);
|
|
225
|
-
const theme: ThemeLike = {
|
|
226
|
-
fg: (_key: string, value: string) => value,
|
|
227
|
-
bold: (value: string) => value,
|
|
228
|
-
};
|
|
229
|
-
const diagnostic = "Invalid glob pattern: [";
|
|
230
|
-
const result = {
|
|
231
|
-
content: [{ type: "text", text: diagnostic }],
|
|
232
|
-
details: {
|
|
233
|
-
_type: "findResult",
|
|
234
|
-
text: diagnostic,
|
|
235
|
-
pattern: "[",
|
|
236
|
-
path: "src",
|
|
237
|
-
matchCount: 0,
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
const render = (state: Record<string, unknown>, expanded = false) => {
|
|
241
|
-
const component = registered.renderResult?.(result, { isPartial: false }, theme, {
|
|
242
|
-
expanded,
|
|
243
|
-
isError: true,
|
|
244
|
-
invalidate: () => {},
|
|
245
|
-
state,
|
|
246
|
-
} as unknown as RenderContextLike);
|
|
247
|
-
return component?.render(120).join("\n") ?? "";
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
expect(render({ timer: 1 })).toContain(diagnostic);
|
|
251
|
-
expect(render({ timer: 1 })).toContain("─");
|
|
252
|
-
expect(render({ collapsed: true })).toContain("✗ find [ in src · failed");
|
|
253
|
-
expect(render({ collapsed: true }, true)).toContain(diagnostic);
|
|
254
|
-
});
|
|
255
|
-
});
|