@xynogen/pix-edit 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/edit.test.ts +0 -255
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-edit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Pi tool — precise text replacement edit with diff rendering",
|
|
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/edit.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 { getEditOperations, registerEditTool, summarizeEditOperations } from "./edit";
|
|
10
|
-
|
|
11
|
-
class MockTextComponent {
|
|
12
|
-
private text = "";
|
|
13
|
-
setText(v: string) {
|
|
14
|
-
this.text = v;
|
|
15
|
-
}
|
|
16
|
-
getText() {
|
|
17
|
-
return this.text;
|
|
18
|
-
}
|
|
19
|
-
render(_width: number) {
|
|
20
|
-
return this.text.split("\n");
|
|
21
|
-
}
|
|
22
|
-
invalidate() {}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("registerEditTool", () => {
|
|
26
|
-
it("registers a self-rendered edit tool", () => {
|
|
27
|
-
const tools: Array<{ name: string; renderShell?: string }> = [];
|
|
28
|
-
const mockPi: PiPrettyApi = {
|
|
29
|
-
registerTool(t: unknown) {
|
|
30
|
-
tools.push(t as { name: string; renderShell?: string });
|
|
31
|
-
},
|
|
32
|
-
registerCommand() {},
|
|
33
|
-
on() {},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
registerEditTool(
|
|
37
|
-
mockPi,
|
|
38
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
39
|
-
{
|
|
40
|
-
cwd: process.cwd(),
|
|
41
|
-
sp: (p: string) => p,
|
|
42
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
43
|
-
fffState: {
|
|
44
|
-
module: null,
|
|
45
|
-
finder: null,
|
|
46
|
-
partialIndex: false,
|
|
47
|
-
dbDir: null,
|
|
48
|
-
} satisfies FffState,
|
|
49
|
-
cursorStore: {
|
|
50
|
-
store: () => "",
|
|
51
|
-
get: () => undefined,
|
|
52
|
-
} as unknown as CursorStore,
|
|
53
|
-
},
|
|
54
|
-
(_id: string, _inv: () => void) => {},
|
|
55
|
-
);
|
|
56
|
-
expect(tools).toHaveLength(1);
|
|
57
|
-
expect(tools[0]?.name).toBe("edit");
|
|
58
|
-
expect(tools[0]?.renderShell).toBe("self");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("restores the bounded diff when an elapsed card is expanded", () => {
|
|
62
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
63
|
-
const mockPi: PiPrettyApi = {
|
|
64
|
-
registerTool(tool: unknown) {
|
|
65
|
-
Object.assign(registered, tool);
|
|
66
|
-
},
|
|
67
|
-
registerCommand() {},
|
|
68
|
-
on() {},
|
|
69
|
-
};
|
|
70
|
-
registerEditTool(
|
|
71
|
-
mockPi,
|
|
72
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
73
|
-
{
|
|
74
|
-
cwd: process.cwd(),
|
|
75
|
-
sp: (p: string) => p,
|
|
76
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
77
|
-
fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
|
|
78
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
79
|
-
},
|
|
80
|
-
() => {},
|
|
81
|
-
);
|
|
82
|
-
const theme: ThemeLike = {
|
|
83
|
-
fg: (key: string, value: string) => `[${key}]${value}[/${key}]`,
|
|
84
|
-
bold: (value: string) => value,
|
|
85
|
-
};
|
|
86
|
-
const result = registered.renderResult?.(
|
|
87
|
-
{
|
|
88
|
-
content: [{ type: "text", text: "edited" }],
|
|
89
|
-
details: {
|
|
90
|
-
_type: "editInfo",
|
|
91
|
-
filePath: "sample.ts",
|
|
92
|
-
summary: "+1 -1",
|
|
93
|
-
oldContent: "old",
|
|
94
|
-
newContent: "new",
|
|
95
|
-
language: "typescript",
|
|
96
|
-
editLine: 1,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
undefined,
|
|
100
|
-
theme,
|
|
101
|
-
{
|
|
102
|
-
expanded: true,
|
|
103
|
-
isError: false,
|
|
104
|
-
invalidate: () => {},
|
|
105
|
-
state: { collapsed: true },
|
|
106
|
-
} as unknown as RenderContextLike,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const lines = result?.render(80) ?? [];
|
|
110
|
-
expect(lines[0]).toBe(`[success]${"─".repeat(80)}[/success]`);
|
|
111
|
-
expect(lines.join("\n")).toContain("rendering diff");
|
|
112
|
-
expect(lines.join("\n")).not.toContain("✓ edit");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("renders single-step output inline as one compact line, framed when expanded", () => {
|
|
116
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
117
|
-
const mockPi: PiPrettyApi = {
|
|
118
|
-
registerTool(tool: unknown) {
|
|
119
|
-
Object.assign(registered, tool);
|
|
120
|
-
},
|
|
121
|
-
registerCommand() {},
|
|
122
|
-
on() {},
|
|
123
|
-
};
|
|
124
|
-
registerEditTool(
|
|
125
|
-
mockPi,
|
|
126
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
127
|
-
{
|
|
128
|
-
cwd: process.cwd(),
|
|
129
|
-
sp: (p: string) => p,
|
|
130
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
131
|
-
fffState: {
|
|
132
|
-
module: null,
|
|
133
|
-
finder: null,
|
|
134
|
-
partialIndex: false,
|
|
135
|
-
dbDir: null,
|
|
136
|
-
} as unknown as FffState,
|
|
137
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
138
|
-
},
|
|
139
|
-
() => {},
|
|
140
|
-
);
|
|
141
|
-
const theme: ThemeLike = { fg: (_k: string, v: string) => v, bold: (v: string) => v };
|
|
142
|
-
const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
|
|
143
|
-
// edit today shows summary + diff; the ask is that single-step call already covers summary
|
|
144
|
-
// so collapsed result stays compact — this test documents current behavior does NOT duplicate
|
|
145
|
-
const result = {
|
|
146
|
-
content: [{ type: "text", text: "edited" }],
|
|
147
|
-
details: {
|
|
148
|
-
_type: "editInfo",
|
|
149
|
-
filePath: "app.py",
|
|
150
|
-
summary: "-1",
|
|
151
|
-
oldContent: "old line\n",
|
|
152
|
-
newContent: "new line\n",
|
|
153
|
-
language: "python",
|
|
154
|
-
editLine: 1,
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
const out =
|
|
158
|
-
registered
|
|
159
|
-
.renderResult?.(result, { isPartial: false }, theme, {
|
|
160
|
-
expanded: false,
|
|
161
|
-
isError: false,
|
|
162
|
-
invalidate: () => {},
|
|
163
|
-
state: {},
|
|
164
|
-
} as unknown as RenderContextLike)
|
|
165
|
-
?.getText() ?? "";
|
|
166
|
-
// collapsed/resting: diff placeholder path covered; when expanded framing should not duplicate header
|
|
167
|
-
expect(strip(out).split("\n").length).toBeGreaterThanOrEqual(1);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("collapses structured errors and restores the exact diagnostic on expansion", () => {
|
|
171
|
-
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
172
|
-
const mockPi: PiPrettyApi = {
|
|
173
|
-
registerTool(tool: unknown) {
|
|
174
|
-
Object.assign(registered, tool);
|
|
175
|
-
},
|
|
176
|
-
registerCommand() {},
|
|
177
|
-
on() {},
|
|
178
|
-
};
|
|
179
|
-
registerEditTool(
|
|
180
|
-
mockPi,
|
|
181
|
-
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
182
|
-
{
|
|
183
|
-
cwd: process.cwd(),
|
|
184
|
-
sp: (p: string) => p,
|
|
185
|
-
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
186
|
-
fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
|
|
187
|
-
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
188
|
-
},
|
|
189
|
-
() => {},
|
|
190
|
-
);
|
|
191
|
-
const theme: ThemeLike = {
|
|
192
|
-
fg: (key: string, value: string) => `[${key}]${value}[/${key}]`,
|
|
193
|
-
bold: (value: string) => value,
|
|
194
|
-
};
|
|
195
|
-
const diagnostic = "oldText was not found in sample.ts";
|
|
196
|
-
const result = {
|
|
197
|
-
content: [{ type: "text", text: diagnostic }],
|
|
198
|
-
details: {
|
|
199
|
-
_type: "editInfo",
|
|
200
|
-
filePath: "sample.ts",
|
|
201
|
-
summary: "+1 -1",
|
|
202
|
-
oldContent: "old",
|
|
203
|
-
newContent: "new",
|
|
204
|
-
language: "typescript",
|
|
205
|
-
editLine: 0,
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
const render = (state: Record<string, unknown>, expanded = false, isPartial = false) =>
|
|
209
|
-
registered
|
|
210
|
-
.renderResult?.(result, { isPartial }, theme, {
|
|
211
|
-
expanded,
|
|
212
|
-
isError: true,
|
|
213
|
-
invalidate: () => {},
|
|
214
|
-
state,
|
|
215
|
-
} as unknown as RenderContextLike)
|
|
216
|
-
?.render(80) ?? [];
|
|
217
|
-
|
|
218
|
-
expect(render({ timer: 1 })[0]).toBe(`[error]${"─".repeat(80)}[/error]`);
|
|
219
|
-
expect(render({ timer: 1 }).join("\n")).toContain(diagnostic);
|
|
220
|
-
const collapsed = render({ collapsed: true }).join("\n");
|
|
221
|
-
expect(collapsed).toContain("edit");
|
|
222
|
-
expect(collapsed).toContain("sample.ts");
|
|
223
|
-
expect(collapsed).toContain("failed");
|
|
224
|
-
expect(render({ collapsed: true })[0]).not.toContain("────");
|
|
225
|
-
expect(render({ collapsed: true }, true).join("\n")).toContain(diagnostic);
|
|
226
|
-
expect(render({ collapsed: true }, true)[0]).toContain("[error]────");
|
|
227
|
-
expect(render({}, false, true)[0]).not.toContain("[error]────");
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
describe("getEditOperations", () => {
|
|
232
|
-
it("extracts array edits", () => {
|
|
233
|
-
const ops = getEditOperations({
|
|
234
|
-
path: "f.ts",
|
|
235
|
-
edits: [{ oldText: "a", newText: "b" }],
|
|
236
|
-
});
|
|
237
|
-
expect(ops).toEqual([{ oldText: "a", newText: "b" }]);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("filters ops where old === new", () => {
|
|
241
|
-
const ops = getEditOperations({
|
|
242
|
-
path: "f.ts",
|
|
243
|
-
edits: [{ oldText: "x", newText: "x" }],
|
|
244
|
-
});
|
|
245
|
-
expect(ops).toHaveLength(0);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe("summarizeEditOperations", () => {
|
|
250
|
-
it("returns a summary string", () => {
|
|
251
|
-
const { summary } = summarizeEditOperations([{ oldText: "a\nb", newText: "c\nd\ne" }]);
|
|
252
|
-
expect(typeof summary).toBe("string");
|
|
253
|
-
expect(summary.length).toBeGreaterThan(0);
|
|
254
|
-
});
|
|
255
|
-
});
|