@firstpick/pi-package-webui 0.3.7 → 0.3.8

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.
@@ -0,0 +1,38 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdir, mkdtemp, readdir, rm, utimes, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { sweepStaleTempEntries } from "../lib/temp-artifacts.mjs";
6
+
7
+ const root = await mkdtemp(path.join(tmpdir(), "pi-webui-temp-sweep-"));
8
+ try {
9
+ const missing = await sweepStaleTempEntries(path.join(root, "missing"), { ttlMs: 1_000 });
10
+ assert.deepEqual(missing, [], "missing directory must sweep to nothing without throwing");
11
+
12
+ const staleDir = path.join(root, "stale-upload");
13
+ await mkdir(staleDir, { recursive: true });
14
+ await writeFile(path.join(staleDir, "attachment.txt"), "old", "utf8");
15
+ const freshDir = path.join(root, "fresh-upload");
16
+ await mkdir(freshDir, { recursive: true });
17
+ const staleFile = path.join(root, "stale-export.html");
18
+ await writeFile(staleFile, "old", "utf8");
19
+ const freshFile = path.join(root, "fresh-export.html");
20
+ await writeFile(freshFile, "new", "utf8");
21
+
22
+ const past = new Date(Date.now() - 60_000);
23
+ await utimes(staleDir, past, past);
24
+ await utimes(staleFile, past, past);
25
+
26
+ const removed = await sweepStaleTempEntries(root, { ttlMs: 30_000 });
27
+ assert.deepEqual(new Set(removed), new Set([staleDir, staleFile]), "only entries older than the TTL are removed");
28
+
29
+ const remaining = (await readdir(root)).sort();
30
+ assert.deepEqual(remaining, ["fresh-export.html", "fresh-upload"], "fresh entries must survive the sweep");
31
+
32
+ const repeat = await sweepStaleTempEntries(root, { ttlMs: 30_000 });
33
+ assert.deepEqual(repeat, [], "repeat sweep with no stale entries removes nothing");
34
+ } finally {
35
+ await rm(root, { recursive: true, force: true });
36
+ }
37
+
38
+ console.log("temp-artifacts-harness.test.mjs passed");