Skip to content

Commit 62e6bd5

Browse files
committed
fix(poe-agent): clean partial file edit temp writes
1 parent 3fef44e commit 62e6bd5

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/poe-agent/src/plugins/poe-agent-plugin-files.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,17 @@ describe("poe-agent-plugin-files", () => {
224224
const originalContent = "export const value = 'old';\n";
225225
const nextContent = "export const value = 'new';\n";
226226
const base = createFsFromVolume(Volume.fromJSON({ [filePath]: originalContent }, "/")).promises;
227+
let temporaryPath: string | undefined;
227228
const fs = {
228229
...base,
229230
async writeFile(targetPath: string, data: Parameters<typeof base.writeFile>[1], options?: Parameters<typeof base.writeFile>[2]) {
230231
if (String(data) === nextContent) {
231-
if (targetPath === filePath) {
232-
await base.writeFile(targetPath, "partial", "utf8");
232+
if (
233+
targetPath.startsWith("/workspace/project/src/.app.ts.") &&
234+
targetPath.endsWith(".tmp")
235+
) {
236+
temporaryPath = targetPath;
237+
await base.writeFile(targetPath, "partial", options);
233238
}
234239
throw new Error("write failed");
235240
}
@@ -247,6 +252,10 @@ describe("poe-agent-plugin-files", () => {
247252
})
248253
).rejects.toThrow("write failed");
249254
await expect(base.readFile(filePath, "utf8")).resolves.toBe(originalContent);
255+
expect(temporaryPath).toBeDefined();
256+
await expect(base.readFile(temporaryPath ?? "", "utf8")).rejects.toMatchObject({
257+
code: "ENOENT"
258+
});
250259
});
251260

252261
it("does not remove a colliding atomic edit temp symlink", async () => {

packages/poe-agent/src/plugins/poe-agent-plugin-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ async function replaceFileAtomically(
385385
await fs.rename(temporaryPath, filePath);
386386
temporaryCreated = false;
387387
} catch (error) {
388-
if (temporaryCreated) {
388+
if (temporaryCreated || !isAlreadyExistsError(error)) {
389389
await fs.unlink(temporaryPath).catch(() => undefined);
390390
}
391391
throw error;

0 commit comments

Comments
 (0)