Skip to content

Commit 40a70ae

Browse files
committed
Format codex proxy files with prettier
1 parent 3526c27 commit 40a70ae

6 files changed

Lines changed: 118 additions & 97 deletions

‎src/agent/codex-apply-patch.test.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ describe("extractAffectedPaths", () => {
157157
*** Delete File: obsolete.txt
158158
*** End Patch
159159
`);
160-
expect(extractAffectedPaths(patch)).toEqual([
161-
"hello.txt",
162-
"src/app.py",
163-
"obsolete.txt",
164-
]);
160+
expect(extractAffectedPaths(patch)).toEqual(["hello.txt", "src/app.py", "obsolete.txt"]);
165161
});
166162

167163
test("move path extraction includes source and destination", () => {

‎src/agent/codex-apply-patch.ts‎

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ export function parseCodexApplyPatch(input: string): ParsedPatch {
115115
);
116116
}
117117
// Codex-rs: each '+' line contributes text + "\n".
118-
const content =
119-
contentLines.length === 0 ? "" : contentLines.map((l) => `${l}\n`).join("");
118+
const content = contentLines.length === 0 ? "" : contentLines.map((l) => `${l}\n`).join("");
120119
ops.push({ type: "add", path, content });
121120
continue;
122121
}
@@ -147,7 +146,11 @@ export function parseCodexApplyPatch(input: string): ParsedPatch {
147146
`malformed Update File '${path}': expected hunk ('@@') or next file op, got: ${body[i]}`,
148147
);
149148
}
150-
ops.push(moveTo === undefined ? { type: "update", path, hunks } : { type: "update", path, moveTo, hunks });
149+
ops.push(
150+
moveTo === undefined
151+
? { type: "update", path, hunks }
152+
: { type: "update", path, moveTo, hunks },
153+
);
151154
continue;
152155
}
153156

@@ -198,9 +201,7 @@ export function applyUpdateHunks(original: string, hunks: PatchHunk[]): string {
198201
if (hunk.header !== undefined && hunk.header.length > 0) {
199202
const idx = findLineFrom(lines, hunk.header, cursor);
200203
if (idx === -1) {
201-
throw new CodexApplyPatchError(
202-
`failed to find hunk context header '${hunk.header}'`,
203-
);
204+
throw new CodexApplyPatchError(`failed to find hunk context header '${hunk.header}'`);
204205
}
205206
cursor = idx + 1;
206207
}
@@ -245,10 +246,7 @@ export function contentFromAddOp(op: PatchAddOp): string {
245246
return op.content;
246247
}
247248

248-
function parseHunk(
249-
body: string[],
250-
start: number,
251-
): { hunk: PatchHunk; next: number } {
249+
function parseHunk(body: string[], start: number): { hunk: PatchHunk; next: number } {
252250
const headerLine = body[start]!;
253251
let header: string | undefined;
254252
if (headerLine === "@@") {
@@ -268,9 +266,8 @@ function parseHunk(
268266
if (raw === END_OF_FILE) {
269267
i += 1;
270268
return {
271-
hunk: header === undefined
272-
? { lines, endOfFile: true }
273-
: { header, lines, endOfFile: true },
269+
hunk:
270+
header === undefined ? { lines, endOfFile: true } : { header, lines, endOfFile: true },
274271
next: i,
275272
};
276273
}
@@ -305,11 +302,7 @@ function parseHunk(
305302
}
306303

307304
function isFileOpHeader(line: string): boolean {
308-
return (
309-
line.startsWith(ADD_FILE) ||
310-
line.startsWith(DELETE_FILE) ||
311-
line.startsWith(UPDATE_FILE)
312-
);
305+
return line.startsWith(ADD_FILE) || line.startsWith(DELETE_FILE) || line.startsWith(UPDATE_FILE);
313306
}
314307

315308
function isHunkStart(line: string): boolean {
@@ -366,9 +359,7 @@ function findSequence(
366359
if (pattern.length > lines.length) return -1;
367360

368361
const searchStart =
369-
endOfFile && lines.length >= pattern.length
370-
? lines.length - pattern.length
371-
: from;
362+
endOfFile && lines.length >= pattern.length ? lines.length - pattern.length : from;
372363

373364
const tryFrom = (start: number, eq: (a: string, b: string) => boolean): number => {
374365
for (let i = start; i <= lines.length - pattern.length; i++) {
@@ -385,8 +376,7 @@ function findSequence(
385376
};
386377

387378
// When eof, try the eof-aligned window first, then fall through from `from`.
388-
const starts =
389-
endOfFile && searchStart !== from ? [searchStart, from] : [searchStart];
379+
const starts = endOfFile && searchStart !== from ? [searchStart, from] : [searchStart];
390380

391381
for (const start of starts) {
392382
const exact = tryFrom(start, (a, b) => a === b);

‎src/agent/codex-tool-mount.test.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ describe("Codex tool proxy mount", () => {
132132
runTool: async () => ({ content: "ok" }),
133133
runManageTasks: async () => ({ content: "ok" }),
134134
});
135-
expect(proxies.map((t) => t.definition.name)).toEqual([
136-
"apply_patch",
137-
"shell",
138-
"update_plan",
139-
]);
135+
expect(proxies.map((t) => t.definition.name)).toEqual(["apply_patch", "shell", "update_plan"]);
140136

141137
const allow = new Set<string>(BUILD_TOOLS);
142138
const kept = proxies.filter((t) => allow.has(t.definition.name));
@@ -160,11 +156,7 @@ describe("Codex tool proxy mount", () => {
160156
allowDelete: allowDeleteFromCapabilities(docsCapabilities),
161157
allowShell: allowShellFromCapabilities(docsCapabilities),
162158
});
163-
expect(proxies.map((t) => t.definition.name)).toEqual([
164-
"apply_patch",
165-
"shell",
166-
"update_plan",
167-
]);
159+
expect(proxies.map((t) => t.definition.name)).toEqual(["apply_patch", "shell", "update_plan"]);
168160

169161
const docsAllow = new Set<string>(DOCS_TOOLS);
170162
const docsKept = proxies.filter((t) => docsAllow.has(t.definition.name));

‎src/agent/codex-tool-proxies.test.ts‎

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ describe("createCodexToolProxies", () => {
120120

121121
test("add forwards write_file with Codex trailing newline", async () => {
122122
const { calls, files, runTool } = makeRecorder();
123-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
123+
const tools = createCodexToolProxies({
124+
isCodex: true,
125+
runTool,
126+
runManageTasks: unusedManageTasks,
127+
});
124128
const result = await invokeApplyPatch(
125129
tools,
126130
`*** Begin Patch
@@ -143,7 +147,11 @@ describe("createCodexToolProxies", () => {
143147

144148
test("delete forwards delete_file", async () => {
145149
const { calls, files, runTool } = makeRecorder({ "obsolete.txt": "gone" });
146-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
150+
const tools = createCodexToolProxies({
151+
isCodex: true,
152+
runTool,
153+
runManageTasks: unusedManageTasks,
154+
});
147155
const result = await invokeApplyPatch(
148156
tools,
149157
`*** Begin Patch
@@ -159,7 +167,12 @@ describe("createCodexToolProxies", () => {
159167

160168
test("allowDelete false refuses Delete without calling delete_file", async () => {
161169
const { calls, files, runTool } = makeRecorder({ "obsolete.txt": "gone" });
162-
const tools = createCodexToolProxies({ isCodex: true, runTool, allowDelete: false, runManageTasks: unusedManageTasks });
170+
const tools = createCodexToolProxies({
171+
isCodex: true,
172+
runTool,
173+
allowDelete: false,
174+
runManageTasks: unusedManageTasks,
175+
});
163176
const result = await invokeApplyPatch(
164177
tools,
165178
`*** Begin Patch
@@ -179,7 +192,12 @@ describe("createCodexToolProxies", () => {
179192
print("Hi")
180193
`;
181194
const { calls, files, runTool } = makeRecorder({ "src/app.py": original });
182-
const tools = createCodexToolProxies({ isCodex: true, runTool, allowDelete: false, runManageTasks: unusedManageTasks });
195+
const tools = createCodexToolProxies({
196+
isCodex: true,
197+
runTool,
198+
allowDelete: false,
199+
runManageTasks: unusedManageTasks,
200+
});
183201
const result = await invokeApplyPatch(
184202
tools,
185203
`*** Begin Patch
@@ -203,7 +221,12 @@ print("Hi")
203221
print("Hi")
204222
`;
205223
const { calls, files, runTool } = makeRecorder({ "src/app.py": original });
206-
const tools = createCodexToolProxies({ isCodex: true, runTool, allowDelete: false, runManageTasks: unusedManageTasks });
224+
const tools = createCodexToolProxies({
225+
isCodex: true,
226+
runTool,
227+
allowDelete: false,
228+
runManageTasks: unusedManageTasks,
229+
});
207230
const result = await invokeApplyPatch(
208231
tools,
209232
`*** Begin Patch
@@ -227,7 +250,11 @@ print("Hi")
227250
print("bye")
228251
`;
229252
const { calls, files, runTool } = makeRecorder({ "src/app.py": original });
230-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
253+
const tools = createCodexToolProxies({
254+
isCodex: true,
255+
runTool,
256+
runManageTasks: unusedManageTasks,
257+
});
231258
const result = await invokeApplyPatch(
232259
tools,
233260
`*** Begin Patch
@@ -253,7 +280,11 @@ print("bye")
253280
print("Hi")
254281
`;
255282
const { calls, files, runTool } = makeRecorder({ "src/app.py": original });
256-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
283+
const tools = createCodexToolProxies({
284+
isCodex: true,
285+
runTool,
286+
runManageTasks: unusedManageTasks,
287+
});
257288
const result = await invokeApplyPatch(
258289
tools,
259290
`*** Begin Patch
@@ -284,7 +315,11 @@ print("Hello, world!")
284315
"src/app.py": "old\n",
285316
"obsolete.txt": "x",
286317
});
287-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
318+
const tools = createCodexToolProxies({
319+
isCodex: true,
320+
runTool,
321+
runManageTasks: unusedManageTasks,
322+
});
288323
const result = await invokeApplyPatch(
289324
tools,
290325
`*** Begin Patch
@@ -312,7 +347,11 @@ print("Hello, world!")
312347

313348
test("parse failure surfaces as tool error (isError)", async () => {
314349
const { calls, runTool } = makeRecorder();
315-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
350+
const tools = createCodexToolProxies({
351+
isCodex: true,
352+
runTool,
353+
runManageTasks: unusedManageTasks,
354+
});
316355
const result = await invokeApplyPatch(
317356
tools,
318357
`*** Add File: a.txt
@@ -342,7 +381,11 @@ print("Hello, world!")
342381

343382
test("runTool isError aborts the patch with isError", async () => {
344383
const { runTool } = makeRecorder();
345-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
384+
const tools = createCodexToolProxies({
385+
isCodex: true,
386+
runTool,
387+
runManageTasks: unusedManageTasks,
388+
});
346389
const result = await invokeApplyPatch(
347390
tools,
348391
`*** Begin Patch
@@ -361,29 +404,45 @@ print("Hello, world!")
361404
describe("shell proxy", () => {
362405
test("string command forwards to run_shell", async () => {
363406
const { calls, runTool } = makeRecorder();
364-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
407+
const tools = createCodexToolProxies({
408+
isCodex: true,
409+
runTool,
410+
runManageTasks: unusedManageTasks,
411+
});
365412
const result = await invokeTool(tools, "shell", { command: "ls -la" });
366413
expect(result.isError).toBeFalsy();
367414
expect(calls).toEqual([{ name: "run_shell", args: { command: "ls -la" } }]);
368415
});
369416

370417
test("bash -lc argv triple unwraps to the script", async () => {
371418
const { calls, runTool } = makeRecorder();
372-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
419+
const tools = createCodexToolProxies({
420+
isCodex: true,
421+
runTool,
422+
runManageTasks: unusedManageTasks,
423+
});
373424
await invokeTool(tools, "shell", { command: ["bash", "-lc", "echo 'hi there'"] });
374425
expect(calls).toEqual([{ name: "run_shell", args: { command: "echo 'hi there'" } }]);
375426
});
376427

377428
test("other argv arrays are shell-quoted and joined", async () => {
378429
const { calls, runTool } = makeRecorder();
379-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
430+
const tools = createCodexToolProxies({
431+
isCodex: true,
432+
runTool,
433+
runManageTasks: unusedManageTasks,
434+
});
380435
await invokeTool(tools, "shell", { command: ["echo", "hello world"] });
381436
expect(calls).toEqual([{ name: "run_shell", args: { command: "echo 'hello world'" } }]);
382437
});
383438

384439
test("workdir and timeout_ms translate to cwd and timeout", async () => {
385440
const { calls, runTool } = makeRecorder();
386-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
441+
const tools = createCodexToolProxies({
442+
isCodex: true,
443+
runTool,
444+
runManageTasks: unusedManageTasks,
445+
});
387446
await invokeTool(tools, "shell", {
388447
command: "pwd",
389448
workdir: "/tmp/work",
@@ -396,7 +455,11 @@ describe("shell proxy", () => {
396455

397456
test("missing command surfaces as tool error", async () => {
398457
const { calls, runTool } = makeRecorder();
399-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
458+
const tools = createCodexToolProxies({
459+
isCodex: true,
460+
runTool,
461+
runManageTasks: unusedManageTasks,
462+
});
400463
const result = await invokeTool(tools, "shell", {});
401464
expect(result.isError).toBe(true);
402465
expect(result.content).toMatch(/command/);
@@ -405,7 +468,12 @@ describe("shell proxy", () => {
405468

406469
test("allowShell false refuses without calling run_shell", async () => {
407470
const { calls, runTool } = makeRecorder();
408-
const tools = createCodexToolProxies({ isCodex: true, runTool, allowShell: false, runManageTasks: unusedManageTasks });
471+
const tools = createCodexToolProxies({
472+
isCodex: true,
473+
runTool,
474+
allowShell: false,
475+
runManageTasks: unusedManageTasks,
476+
});
409477
const result = await invokeTool(tools, "shell", { command: "ls" });
410478
expect(result.isError).toBe(true);
411479
expect(result.content).toMatch(/not allowed/);
@@ -414,7 +482,11 @@ describe("shell proxy", () => {
414482

415483
test("run_shell isError propagates as tool error", async () => {
416484
const runTool: CodexRunTool = async () => ({ content: "boom", isError: true });
417-
const tools = createCodexToolProxies({ isCodex: true, runTool, runManageTasks: unusedManageTasks });
485+
const tools = createCodexToolProxies({
486+
isCodex: true,
487+
runTool,
488+
runManageTasks: unusedManageTasks,
489+
});
418490
const result = await invokeTool(tools, "shell", { command: "ls" });
419491
expect(result.isError).toBe(true);
420492
expect(result.content).toMatch(/boom/);
@@ -497,19 +569,11 @@ describe("update_plan proxy", () => {
497569

498570
describe("allowDeleteFromCapabilities", () => {
499571
test("docs allowlist (no delete_file) → false; build → true", () => {
500-
expect(
501-
allowDeleteFromCapabilities({ mode: "allow", tools: DOCS_TOOLS }),
502-
).toBe(false);
503-
expect(
504-
allowDeleteFromCapabilities({ mode: "allow", tools: BUILD_TOOLS }),
505-
).toBe(true);
572+
expect(allowDeleteFromCapabilities({ mode: "allow", tools: DOCS_TOOLS })).toBe(false);
573+
expect(allowDeleteFromCapabilities({ mode: "allow", tools: BUILD_TOOLS })).toBe(true);
506574
expect(allowDeleteFromCapabilities(undefined)).toBe(true);
507-
expect(
508-
allowDeleteFromCapabilities({ mode: "exclude", tools: ["run_shell"] }),
509-
).toBe(true);
510-
expect(
511-
allowDeleteFromCapabilities({ mode: "exclude", tools: ["delete_file"] }),
512-
).toBe(false);
575+
expect(allowDeleteFromCapabilities({ mode: "exclude", tools: ["run_shell"] })).toBe(true);
576+
expect(allowDeleteFromCapabilities({ mode: "exclude", tools: ["delete_file"] })).toBe(false);
513577
});
514578
});
515579

@@ -518,11 +582,7 @@ describe("allowShellFromCapabilities", () => {
518582
expect(allowShellFromCapabilities({ mode: "allow", tools: DOCS_TOOLS })).toBe(false);
519583
expect(allowShellFromCapabilities({ mode: "allow", tools: BUILD_TOOLS })).toBe(true);
520584
expect(allowShellFromCapabilities(undefined)).toBe(true);
521-
expect(
522-
allowShellFromCapabilities({ mode: "exclude", tools: ["delete_file"] }),
523-
).toBe(true);
524-
expect(
525-
allowShellFromCapabilities({ mode: "exclude", tools: ["run_shell"] }),
526-
).toBe(false);
585+
expect(allowShellFromCapabilities({ mode: "exclude", tools: ["delete_file"] })).toBe(true);
586+
expect(allowShellFromCapabilities({ mode: "exclude", tools: ["run_shell"] })).toBe(false);
527587
});
528588
});

0 commit comments

Comments
 (0)