chatccc 0.2.226 → 0.2.227

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.
Files changed (64) hide show
  1. package/.agents/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  2. package/.claude/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  3. package/.cursor/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  4. package/README.md +90 -90
  5. package/package.json +1 -1
  6. package/src/__tests__/agent-activity.test.ts +76 -76
  7. package/src/__tests__/builtin-chat-session.test.ts +350 -350
  8. package/src/__tests__/builtin-config.test.ts +26 -26
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +275 -275
  11. package/src/__tests__/builtin-permissions.test.ts +211 -211
  12. package/src/__tests__/builtin-session-select.test.ts +116 -116
  13. package/src/__tests__/builtin-skills.test.ts +185 -74
  14. package/src/__tests__/card-action-routing.test.ts +18 -18
  15. package/src/__tests__/ccc-adapter.test.ts +136 -136
  16. package/src/__tests__/claude-adapter.test.ts +614 -614
  17. package/src/__tests__/codex-adapter.test.ts +58 -58
  18. package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
  19. package/src/__tests__/cursor-adapter.test.ts +268 -268
  20. package/src/__tests__/feishu-avatar.test.ts +164 -164
  21. package/src/__tests__/feishu-message-ingress.test.ts +138 -138
  22. package/src/__tests__/package-files.test.ts +24 -24
  23. package/src/__tests__/progress-reducer.test.ts +110 -110
  24. package/src/__tests__/response-stall.test.ts +49 -49
  25. package/src/__tests__/sim-platform.test.ts +16 -16
  26. package/src/__tests__/startup-lifecycle.test.ts +231 -231
  27. package/src/__tests__/stop-session.test.ts +34 -34
  28. package/src/__tests__/terminal-renderer.test.ts +247 -247
  29. package/src/__tests__/update-command-guard.test.ts +144 -144
  30. package/src/__tests__/web-ui.test.ts +326 -326
  31. package/src/adapters/adapter-interface.ts +18 -18
  32. package/src/adapters/ccc-adapter.ts +131 -131
  33. package/src/adapters/claude-adapter.ts +620 -620
  34. package/src/adapters/codex-adapter.ts +426 -426
  35. package/src/adapters/cursor-adapter.ts +681 -681
  36. package/src/agent-activity.ts +170 -170
  37. package/src/agent-delegate-task.ts +91 -91
  38. package/src/builtin/cli.ts +61 -2
  39. package/src/builtin/config.ts +84 -84
  40. package/src/builtin/context.ts +323 -323
  41. package/src/builtin/file-log.ts +38 -38
  42. package/src/builtin/index.ts +44 -24
  43. package/src/builtin/proc-tree-kill.ts +61 -61
  44. package/src/builtin/progress/cards-helpers.ts +76 -76
  45. package/src/builtin/progress/reducer.ts +108 -108
  46. package/src/builtin/progress/terminal-renderer.ts +294 -294
  47. package/src/builtin/progress/view.ts +77 -77
  48. package/src/builtin/raw-stream-log.ts +124 -124
  49. package/src/builtin/session-select.ts +48 -48
  50. package/src/builtin/skills.ts +126 -44
  51. package/src/card-action-routing.ts +14 -14
  52. package/src/feishu-api.ts +193 -193
  53. package/src/feishu-message-ingress.ts +195 -195
  54. package/src/index.ts +306 -306
  55. package/src/orchestrator.ts +2388 -2388
  56. package/src/platform-adapter.ts +6 -6
  57. package/src/progress/reducer.ts +108 -108
  58. package/src/progress/terminal-renderer.ts +294 -294
  59. package/src/progress/view.ts +77 -77
  60. package/src/response-stall.ts +28 -28
  61. package/src/session-chat-binding.ts +82 -82
  62. package/src/startup-lifecycle.ts +250 -250
  63. package/src/stream-state.ts +18 -18
  64. package/src/update-command-guard.ts +165 -165
@@ -1,275 +1,275 @@
1
- import { createHash } from "node:crypto";
2
- import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- import { afterEach, describe, expect, it } from "vitest";
7
-
8
- import {
9
- applyPatchForTool,
10
- createFileForTool,
11
- deleteFileForTool,
12
- editFileForTool,
13
- listDirForTool,
14
- moveFileForTool,
15
- readFileForTool,
16
- runCommandForTool,
17
- searchCodeForTool,
18
- } from "../builtin/file-tools.ts";
19
-
20
- const tempDirs: string[] = [];
21
-
22
- async function makeTempDir(): Promise<string> {
23
- const dir = await mkdtemp(join(tmpdir(), "chatccc-builtin-tools-"));
24
- tempDirs.push(dir);
25
- return dir;
26
- }
27
-
28
- function sha256(text: string): string {
29
- return createHash("sha256").update(text).digest("hex");
30
- }
31
-
32
- afterEach(async () => {
33
- await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
34
- });
35
-
36
- describe("builtin file tools", () => {
37
- it("reads a text file with line ranges", async () => {
38
- const dir = await makeTempDir();
39
- await writeFile(join(dir, ".secret.txt"), "one\ntwo\nthree\n", "utf8");
40
-
41
- const result = await readFileForTool(dir, { path: ".secret.txt", startLine: 2, endLine: 3 });
42
-
43
- expect(result).toEqual(expect.objectContaining({
44
- sha256: sha256("one\ntwo\nthree\n"),
45
- isBinary: false,
46
- content: "two\nthree",
47
- startLine: 2,
48
- endLine: 3,
49
- totalLines: 4,
50
- }));
51
- expect(result.path).toContain(".secret.txt");
52
- });
53
-
54
- it("lists directory entries including hidden files", async () => {
55
- const dir = await makeTempDir();
56
- await writeFile(join(dir, ".env"), "TOKEN=x", "utf8");
57
-
58
- const result = await listDirForTool(dir);
59
-
60
- expect(result.entries).toContainEqual(expect.objectContaining({
61
- name: ".env",
62
- type: "file",
63
- }));
64
- });
65
-
66
- it("searches with the project-bundled ripgrep even when rg is absent from PATH", async () => {
67
- const dir = await makeTempDir();
68
- await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
69
- const originalPath = process.env.PATH;
70
- process.env.PATH = "";
71
-
72
- try {
73
- const result = await searchCodeForTool(dir, { query: "marker", glob: "*.ts" });
74
-
75
- expect(result.matches).toEqual([
76
- expect.objectContaining({
77
- line: 1,
78
- column: 7,
79
- text: "const marker = 1;",
80
- }),
81
- ]);
82
- } finally {
83
- process.env.PATH = originalPath;
84
- }
85
- });
86
-
87
- it("falls back to Node search when no ripgrep executable can be used", async () => {
88
- const dir = await makeTempDir();
89
- await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
90
- await mkdir(join(dir, "nested"));
91
- await writeFile(join(dir, "nested", "b.md"), "xx marker = 2\n", "utf8");
92
- await writeFile(join(dir, "ignored.txt"), "marker = 3\n", "utf8");
93
- const originalPath = process.env.PATH;
94
- process.env.PATH = "";
95
-
96
- try {
97
- const result = await searchCodeForTool(
98
- dir,
99
- { query: "marker\\s*=\\s*\\d", glob: "**/*.{ts,md}", maxResults: 10 },
100
- undefined,
101
- { ripgrepCommands: [join(dir, "missing-rg")] },
102
- );
103
-
104
- expect(result.matches).toEqual([
105
- expect.objectContaining({ path: join(dir, "a.ts"), line: 1, column: 7 }),
106
- expect.objectContaining({ path: join(dir, "nested", "b.md"), line: 1, column: 4 }),
107
- ]);
108
- expect(result.truncated).toBe(false);
109
- } finally {
110
- process.env.PATH = originalPath;
111
- }
112
- });
113
-
114
- it("runs non-interactive shell commands in the requested cwd", async () => {
115
- const dir = await makeTempDir();
116
-
117
- const result = await runCommandForTool(dir, {
118
- command: "node -e \"process.stdout.write(process.cwd())\"",
119
- timeoutMs: 5_000,
120
- });
121
-
122
- expect(result.exitCode).toBe(0);
123
- expect(result.timedOut).toBe(false);
124
- expect(result.stdout.toLowerCase()).toBe(dir.toLowerCase());
125
- expect(result.stderr).toBe("");
126
- });
127
-
128
- it("returns non-zero command exits without throwing", async () => {
129
- const dir = await makeTempDir();
130
-
131
- const result = await runCommandForTool(dir, {
132
- command: "node -e \"process.stderr.write('failed'); process.exit(7)\"",
133
- timeoutMs: 5_000,
134
- });
135
-
136
- expect(result.exitCode).toBe(7);
137
- expect(result.stderr).toBe("failed");
138
- expect(result.timedOut).toBe(false);
139
- });
140
-
141
- it("edits a file with exact replacements and a SHA-256 precondition", async () => {
142
- const dir = await makeTempDir();
143
- const file = join(dir, "edit.txt");
144
- await writeFile(file, "alpha\nbeta\ngamma\n", "utf8");
145
-
146
- const result = await editFileForTool(dir, {
147
- path: "edit.txt",
148
- expectedSha256: sha256("alpha\nbeta\ngamma\n"),
149
- edits: [{ oldText: "beta", newText: "BETA" }],
150
- });
151
-
152
- expect(result).toEqual(expect.objectContaining({
153
- changed: true,
154
- editsApplied: 1,
155
- beforeSha256: sha256("alpha\nbeta\ngamma\n"),
156
- afterSha256: sha256("alpha\nBETA\ngamma\n"),
157
- }));
158
- await expect(readFile(file, "utf8")).resolves.toBe("alpha\nBETA\ngamma\n");
159
- });
160
-
161
- it("edits a CRLF file with LF oldText by normalizing line endings", async () => {
162
- const dir = await makeTempDir();
163
- const file = join(dir, "crlf.txt");
164
- const crlfContent = "alpha\r\nbeta\r\ngamma\r\n";
165
- await writeFile(file, crlfContent, "utf8");
166
-
167
- const result = await editFileForTool(dir, {
168
- path: "crlf.txt",
169
- expectedSha256: sha256(crlfContent),
170
- edits: [{ oldText: "alpha\nbeta", newText: "ALPHA\nBETA" }],
171
- });
172
-
173
- expect(result).toEqual(expect.objectContaining({
174
- changed: true,
175
- editsApplied: 1,
176
- beforeSha256: sha256(crlfContent),
177
- afterSha256: sha256("ALPHA\r\nBETA\r\ngamma\r\n"),
178
- }));
179
- await expect(readFile(file, "utf8")).resolves.toBe("ALPHA\r\nBETA\r\ngamma\r\n");
180
- });
181
-
182
- it("rejects a multi-line oldText that still does not match after EOL normalization", async () => {
183
- const dir = await makeTempDir();
184
- await writeFile(join(dir, "crlf.txt"), "alpha\r\nbeta\r\n", "utf8");
185
-
186
- await expect(editFileForTool(dir, {
187
- path: "crlf.txt",
188
- edits: [{ oldText: "alpha\ngamma", newText: "x" }],
189
- })).rejects.toThrow("oldText was not found");
190
- });
191
-
192
- it("rejects edits when the SHA-256 precondition does not match", async () => {
193
- const dir = await makeTempDir();
194
- await writeFile(join(dir, "edit.txt"), "current\n", "utf8");
195
-
196
- await expect(editFileForTool(dir, {
197
- path: "edit.txt",
198
- expectedSha256: sha256("stale\n"),
199
- edits: [{ oldText: "current", newText: "next" }],
200
- })).rejects.toThrow("SHA-256 mismatch");
201
- });
202
-
203
- it("creates and deletes files", async () => {
204
- const dir = await makeTempDir();
205
-
206
- const created = await createFileForTool(dir, {
207
- path: "created.txt",
208
- content: "created\n",
209
- });
210
- expect(created).toEqual(expect.objectContaining({
211
- changed: true,
212
- afterSha256: sha256("created\n"),
213
- }));
214
- await expect(readFile(join(dir, "created.txt"), "utf8")).resolves.toBe("created\n");
215
-
216
- const deleted = await deleteFileForTool(dir, {
217
- path: "created.txt",
218
- expectedSha256: sha256("created\n"),
219
- });
220
- expect(deleted).toEqual(expect.objectContaining({
221
- deleted: true,
222
- beforeSha256: sha256("created\n"),
223
- }));
224
- await expect(stat(join(dir, "created.txt"))).rejects.toThrow();
225
- });
226
-
227
- it("moves files and creates the destination directory", async () => {
228
- const dir = await makeTempDir();
229
- await writeFile(join(dir, "old.txt"), "move me\n", "utf8");
230
-
231
- const result = await moveFileForTool(dir, {
232
- sourcePath: "old.txt",
233
- destinationPath: "nested/new.txt",
234
- expectedSourceSha256: sha256("move me\n"),
235
- });
236
-
237
- expect(result).toEqual(expect.objectContaining({
238
- moved: true,
239
- sourceSha256: sha256("move me\n"),
240
- }));
241
- await expect(stat(join(dir, "old.txt"))).rejects.toThrow();
242
- await expect(readFile(join(dir, "nested", "new.txt"), "utf8")).resolves.toBe("move me\n");
243
- });
244
-
245
- it("applies a unified diff patch", async () => {
246
- const dir = await makeTempDir();
247
- await writeFile(join(dir, "patch.txt"), "one\ntwo\nthree\n", "utf8");
248
-
249
- const result = await applyPatchForTool(dir, {
250
- patch: [
251
- "--- a/patch.txt",
252
- "+++ b/patch.txt",
253
- "@@ -1,4 +1,4 @@",
254
- " one",
255
- "-two",
256
- "+TWO",
257
- " three",
258
- " ",
259
- "",
260
- ].join("\n"),
261
- expectedSha256ByPath: {
262
- "patch.txt": sha256("one\ntwo\nthree\n"),
263
- },
264
- });
265
-
266
- expect(result.changedFiles).toEqual([
267
- expect.objectContaining({
268
- action: "edit",
269
- beforeSha256: sha256("one\ntwo\nthree\n"),
270
- afterSha256: sha256("one\nTWO\nthree\n"),
271
- }),
272
- ]);
273
- await expect(readFile(join(dir, "patch.txt"), "utf8")).resolves.toBe("one\nTWO\nthree\n");
274
- });
275
- });
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ import { afterEach, describe, expect, it } from "vitest";
7
+
8
+ import {
9
+ applyPatchForTool,
10
+ createFileForTool,
11
+ deleteFileForTool,
12
+ editFileForTool,
13
+ listDirForTool,
14
+ moveFileForTool,
15
+ readFileForTool,
16
+ runCommandForTool,
17
+ searchCodeForTool,
18
+ } from "../builtin/file-tools.ts";
19
+
20
+ const tempDirs: string[] = [];
21
+
22
+ async function makeTempDir(): Promise<string> {
23
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-builtin-tools-"));
24
+ tempDirs.push(dir);
25
+ return dir;
26
+ }
27
+
28
+ function sha256(text: string): string {
29
+ return createHash("sha256").update(text).digest("hex");
30
+ }
31
+
32
+ afterEach(async () => {
33
+ await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
34
+ });
35
+
36
+ describe("builtin file tools", () => {
37
+ it("reads a text file with line ranges", async () => {
38
+ const dir = await makeTempDir();
39
+ await writeFile(join(dir, ".secret.txt"), "one\ntwo\nthree\n", "utf8");
40
+
41
+ const result = await readFileForTool(dir, { path: ".secret.txt", startLine: 2, endLine: 3 });
42
+
43
+ expect(result).toEqual(expect.objectContaining({
44
+ sha256: sha256("one\ntwo\nthree\n"),
45
+ isBinary: false,
46
+ content: "two\nthree",
47
+ startLine: 2,
48
+ endLine: 3,
49
+ totalLines: 4,
50
+ }));
51
+ expect(result.path).toContain(".secret.txt");
52
+ });
53
+
54
+ it("lists directory entries including hidden files", async () => {
55
+ const dir = await makeTempDir();
56
+ await writeFile(join(dir, ".env"), "TOKEN=x", "utf8");
57
+
58
+ const result = await listDirForTool(dir);
59
+
60
+ expect(result.entries).toContainEqual(expect.objectContaining({
61
+ name: ".env",
62
+ type: "file",
63
+ }));
64
+ });
65
+
66
+ it("searches with the project-bundled ripgrep even when rg is absent from PATH", async () => {
67
+ const dir = await makeTempDir();
68
+ await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
69
+ const originalPath = process.env.PATH;
70
+ process.env.PATH = "";
71
+
72
+ try {
73
+ const result = await searchCodeForTool(dir, { query: "marker", glob: "*.ts" });
74
+
75
+ expect(result.matches).toEqual([
76
+ expect.objectContaining({
77
+ line: 1,
78
+ column: 7,
79
+ text: "const marker = 1;",
80
+ }),
81
+ ]);
82
+ } finally {
83
+ process.env.PATH = originalPath;
84
+ }
85
+ });
86
+
87
+ it("falls back to Node search when no ripgrep executable can be used", async () => {
88
+ const dir = await makeTempDir();
89
+ await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
90
+ await mkdir(join(dir, "nested"));
91
+ await writeFile(join(dir, "nested", "b.md"), "xx marker = 2\n", "utf8");
92
+ await writeFile(join(dir, "ignored.txt"), "marker = 3\n", "utf8");
93
+ const originalPath = process.env.PATH;
94
+ process.env.PATH = "";
95
+
96
+ try {
97
+ const result = await searchCodeForTool(
98
+ dir,
99
+ { query: "marker\\s*=\\s*\\d", glob: "**/*.{ts,md}", maxResults: 10 },
100
+ undefined,
101
+ { ripgrepCommands: [join(dir, "missing-rg")] },
102
+ );
103
+
104
+ expect(result.matches).toEqual([
105
+ expect.objectContaining({ path: join(dir, "a.ts"), line: 1, column: 7 }),
106
+ expect.objectContaining({ path: join(dir, "nested", "b.md"), line: 1, column: 4 }),
107
+ ]);
108
+ expect(result.truncated).toBe(false);
109
+ } finally {
110
+ process.env.PATH = originalPath;
111
+ }
112
+ });
113
+
114
+ it("runs non-interactive shell commands in the requested cwd", async () => {
115
+ const dir = await makeTempDir();
116
+
117
+ const result = await runCommandForTool(dir, {
118
+ command: "node -e \"process.stdout.write(process.cwd())\"",
119
+ timeoutMs: 5_000,
120
+ });
121
+
122
+ expect(result.exitCode).toBe(0);
123
+ expect(result.timedOut).toBe(false);
124
+ expect(result.stdout.toLowerCase()).toBe(dir.toLowerCase());
125
+ expect(result.stderr).toBe("");
126
+ });
127
+
128
+ it("returns non-zero command exits without throwing", async () => {
129
+ const dir = await makeTempDir();
130
+
131
+ const result = await runCommandForTool(dir, {
132
+ command: "node -e \"process.stderr.write('failed'); process.exit(7)\"",
133
+ timeoutMs: 5_000,
134
+ });
135
+
136
+ expect(result.exitCode).toBe(7);
137
+ expect(result.stderr).toBe("failed");
138
+ expect(result.timedOut).toBe(false);
139
+ });
140
+
141
+ it("edits a file with exact replacements and a SHA-256 precondition", async () => {
142
+ const dir = await makeTempDir();
143
+ const file = join(dir, "edit.txt");
144
+ await writeFile(file, "alpha\nbeta\ngamma\n", "utf8");
145
+
146
+ const result = await editFileForTool(dir, {
147
+ path: "edit.txt",
148
+ expectedSha256: sha256("alpha\nbeta\ngamma\n"),
149
+ edits: [{ oldText: "beta", newText: "BETA" }],
150
+ });
151
+
152
+ expect(result).toEqual(expect.objectContaining({
153
+ changed: true,
154
+ editsApplied: 1,
155
+ beforeSha256: sha256("alpha\nbeta\ngamma\n"),
156
+ afterSha256: sha256("alpha\nBETA\ngamma\n"),
157
+ }));
158
+ await expect(readFile(file, "utf8")).resolves.toBe("alpha\nBETA\ngamma\n");
159
+ });
160
+
161
+ it("edits a CRLF file with LF oldText by normalizing line endings", async () => {
162
+ const dir = await makeTempDir();
163
+ const file = join(dir, "crlf.txt");
164
+ const crlfContent = "alpha\r\nbeta\r\ngamma\r\n";
165
+ await writeFile(file, crlfContent, "utf8");
166
+
167
+ const result = await editFileForTool(dir, {
168
+ path: "crlf.txt",
169
+ expectedSha256: sha256(crlfContent),
170
+ edits: [{ oldText: "alpha\nbeta", newText: "ALPHA\nBETA" }],
171
+ });
172
+
173
+ expect(result).toEqual(expect.objectContaining({
174
+ changed: true,
175
+ editsApplied: 1,
176
+ beforeSha256: sha256(crlfContent),
177
+ afterSha256: sha256("ALPHA\r\nBETA\r\ngamma\r\n"),
178
+ }));
179
+ await expect(readFile(file, "utf8")).resolves.toBe("ALPHA\r\nBETA\r\ngamma\r\n");
180
+ });
181
+
182
+ it("rejects a multi-line oldText that still does not match after EOL normalization", async () => {
183
+ const dir = await makeTempDir();
184
+ await writeFile(join(dir, "crlf.txt"), "alpha\r\nbeta\r\n", "utf8");
185
+
186
+ await expect(editFileForTool(dir, {
187
+ path: "crlf.txt",
188
+ edits: [{ oldText: "alpha\ngamma", newText: "x" }],
189
+ })).rejects.toThrow("oldText was not found");
190
+ });
191
+
192
+ it("rejects edits when the SHA-256 precondition does not match", async () => {
193
+ const dir = await makeTempDir();
194
+ await writeFile(join(dir, "edit.txt"), "current\n", "utf8");
195
+
196
+ await expect(editFileForTool(dir, {
197
+ path: "edit.txt",
198
+ expectedSha256: sha256("stale\n"),
199
+ edits: [{ oldText: "current", newText: "next" }],
200
+ })).rejects.toThrow("SHA-256 mismatch");
201
+ });
202
+
203
+ it("creates and deletes files", async () => {
204
+ const dir = await makeTempDir();
205
+
206
+ const created = await createFileForTool(dir, {
207
+ path: "created.txt",
208
+ content: "created\n",
209
+ });
210
+ expect(created).toEqual(expect.objectContaining({
211
+ changed: true,
212
+ afterSha256: sha256("created\n"),
213
+ }));
214
+ await expect(readFile(join(dir, "created.txt"), "utf8")).resolves.toBe("created\n");
215
+
216
+ const deleted = await deleteFileForTool(dir, {
217
+ path: "created.txt",
218
+ expectedSha256: sha256("created\n"),
219
+ });
220
+ expect(deleted).toEqual(expect.objectContaining({
221
+ deleted: true,
222
+ beforeSha256: sha256("created\n"),
223
+ }));
224
+ await expect(stat(join(dir, "created.txt"))).rejects.toThrow();
225
+ });
226
+
227
+ it("moves files and creates the destination directory", async () => {
228
+ const dir = await makeTempDir();
229
+ await writeFile(join(dir, "old.txt"), "move me\n", "utf8");
230
+
231
+ const result = await moveFileForTool(dir, {
232
+ sourcePath: "old.txt",
233
+ destinationPath: "nested/new.txt",
234
+ expectedSourceSha256: sha256("move me\n"),
235
+ });
236
+
237
+ expect(result).toEqual(expect.objectContaining({
238
+ moved: true,
239
+ sourceSha256: sha256("move me\n"),
240
+ }));
241
+ await expect(stat(join(dir, "old.txt"))).rejects.toThrow();
242
+ await expect(readFile(join(dir, "nested", "new.txt"), "utf8")).resolves.toBe("move me\n");
243
+ });
244
+
245
+ it("applies a unified diff patch", async () => {
246
+ const dir = await makeTempDir();
247
+ await writeFile(join(dir, "patch.txt"), "one\ntwo\nthree\n", "utf8");
248
+
249
+ const result = await applyPatchForTool(dir, {
250
+ patch: [
251
+ "--- a/patch.txt",
252
+ "+++ b/patch.txt",
253
+ "@@ -1,4 +1,4 @@",
254
+ " one",
255
+ "-two",
256
+ "+TWO",
257
+ " three",
258
+ " ",
259
+ "",
260
+ ].join("\n"),
261
+ expectedSha256ByPath: {
262
+ "patch.txt": sha256("one\ntwo\nthree\n"),
263
+ },
264
+ });
265
+
266
+ expect(result.changedFiles).toEqual([
267
+ expect.objectContaining({
268
+ action: "edit",
269
+ beforeSha256: sha256("one\ntwo\nthree\n"),
270
+ afterSha256: sha256("one\nTWO\nthree\n"),
271
+ }),
272
+ ]);
273
+ await expect(readFile(join(dir, "patch.txt"), "utf8")).resolves.toBe("one\nTWO\nthree\n");
274
+ });
275
+ });