Skip to content

Commit 439a145

Browse files
anandgupta42claude
andcommitted
test: cover cleanup's stat-failure fail-safe; hoist duplicated dates
A dangling symlink is listed by readDirectory but fails stat — the fail-safe branch must keep it rather than delete on uncertainty; asserted via lstat (fs.exists follows links and would miss a surviving dangling link). Duplicated `new Date(Date.now() - …)` constructions hoisted. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent c51ce48 commit 439a145

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎packages/opencode/test/tool/truncation.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,27 @@ describe("Truncate", () => {
255255
// ~795 days — see Truncate.cleanup), so set mtimes explicitly.
256256
const old = path.join(Truncate.DIR, Identifier.create("tool", "ascending"))
257257
const recent = path.join(Truncate.DIR, Identifier.create("tool", "ascending"))
258+
// Dangling symlink: listed by readDirectory, but stat fails — the
259+
// fail-safe branch must KEEP it rather than delete on uncertainty.
260+
const dangling = path.join(Truncate.DIR, Identifier.create("tool", "ascending"))
258261

259262
yield* writeFileStringScoped(old, "old content")
260263
yield* writeFileStringScoped(recent, "recent content")
261264
const nfs = yield* Effect.promise(() => import("node:fs/promises"))
262-
yield* Effect.promise(() => nfs.utimes(old, new Date(Date.now() - 10 * DAY_MS), new Date(Date.now() - 10 * DAY_MS)))
263-
yield* Effect.promise(() => nfs.utimes(recent, new Date(Date.now() - 3 * DAY_MS), new Date(Date.now() - 3 * DAY_MS)))
265+
yield* Effect.promise(() => nfs.symlink(path.join(Truncate.DIR, "nonexistent-target"), dangling))
266+
const oldTime = new Date(Date.now() - 10 * DAY_MS)
267+
const recentTime = new Date(Date.now() - 3 * DAY_MS)
268+
yield* Effect.promise(() => nfs.utimes(old, oldTime, oldTime))
269+
yield* Effect.promise(() => nfs.utimes(recent, recentTime, recentTime))
264270
yield* svc.cleanup()
265271

266272
expect(yield* fs.exists(old)).toBe(false)
267273
expect(yield* fs.exists(recent)).toBe(true)
274+
// lstat: fs.exists follows symlinks and would report false for a
275+
// dangling link even when the link itself survived.
276+
const danglingKept = yield* Effect.promise(() => nfs.lstat(dangling).then(() => true).catch(() => false))
277+
expect(danglingKept).toBe(true)
278+
yield* Effect.promise(() => nfs.unlink(dangling).catch(() => {}))
268279
}),
269280
)
270281
})

0 commit comments

Comments
 (0)