feat: two maintenance actions in the setup screen

This commit is contained in:
2026-10-05 17:03:13 +08:00
parent d27c4374fe
commit e7c61c4268
10 changed files with 418 additions and 54 deletions
+10 -11
View File
@@ -107,44 +107,43 @@ describe("removeSnipFiles", () => {
await rm(OUTSIDE, { force: true });
});
it("deletes a capture inside the snip directory", async () => {
it("deletes a capture inside the snip directory and counts it", async () => {
const path = `${DIRECTORY}/one.png`;
await writeFile(path, "png");
await removeSnipFiles([path]);
await expect(removeSnipFiles([path])).resolves.toBe(1);
await expect(access(path)).rejects.toThrow();
});
it("shrugs at a file that is already gone", async () => {
await expect(removeSnipFiles([`${DIRECTORY}/never-existed.png`])).resolves.toBeUndefined();
it("counts a file that was already gone, because the question is whether it is still there", async () => {
await expect(removeSnipFiles([`${DIRECTORY}/never-existed.png`])).resolves.toBe(1);
});
it("refuses a path outside the snip directory", async () => {
it("refuses a path outside the snip directory and does not count it", async () => {
// These paths come out of stored JSON, which is data rather than code, so
// this must not be a general-purpose delete-any-file helper.
await removeSnipFiles([OUTSIDE]);
await expect(removeSnipFiles([OUTSIDE])).resolves.toBe(0);
await expect(access(OUTSIDE)).resolves.toBeUndefined();
});
it("refuses a path that climbs out of the directory", async () => {
await removeSnipFiles([`${DIRECTORY}/../../lam-agent-not-a-snip.png`]);
await expect(removeSnipFiles([`${DIRECTORY}/../../lam-agent-not-a-snip.png`])).resolves.toBe(0);
await expect(access(OUTSIDE)).resolves.toBeUndefined();
});
it("refuses the directory itself", async () => {
await removeSnipFiles([DIRECTORY]);
await expect(removeSnipFiles([DIRECTORY])).resolves.toBe(0);
await expect(access(DIRECTORY)).resolves.toBeUndefined();
});
it("keeps going when one path in the batch is refused", async () => {
it("keeps going when one path in the batch is refused, and counts only the one it acted on", async () => {
const inside = `${DIRECTORY}/one.png`;
await writeFile(inside, "png");
await removeSnipFiles([OUTSIDE, inside]);
await expect(removeSnipFiles([OUTSIDE, inside])).resolves.toBe(1);
await expect(access(inside)).rejects.toThrow();
await expect(access(OUTSIDE)).resolves.toBeUndefined();