Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(e2e): sweep the throwaway state roots the lane leaves behind

Yudhi Armyndharis1451eb2d4bef
diff --git a/.env.example b/.env.example
index 0ff0a312b..4c2e5557d 100644
--- a/.env.example
+++ b/.env.example
@@ -687,6 +687,9 @@ PLUGINS_DIR=./data/plugins # Plugin directory (default: ./data/plugins)
# PLUGINS_DIR, which is where plugin packages are installed. It moves plugin state only: the
# databases, sessions, media and auth dirs each carry their own path knob and none of them follow
# this one.
+# Moving it does NOT carry the existing registry across: point it at an empty directory and the
+# gateway starts with no record of installed plugins, even though their packages are still under
+# PLUGINS_DIR. Move data/plugins/registry.json yourself when you change this.
# PLUGIN_STATE_DIR=./data
# Cap on a plugin .zip downloaded by install-from-URL (matches the 5 MB upload limit). A non-positive
# or non-numeric value falls back to the default.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05f300d06..a0103e4ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Outbound webhook deliveries survive a hard crash. Fan-out is fire-and-forget, so a crash between persisting a message and completing its POST lost the delivery with no record in either mode, while the documented contract promises at-least-once. Each delivery is now recorded before it is attempted, retired once the queue or the inline send owns it, and a bounded sweep replays whatever is left stranded using the stored idempotency key so the retry stays deduplicable at the receiver.
- Settled outbound delivery records are pruned after `WEBHOOK_OUTBOX_RETENTION_DAYS` (default 7). A record that can still be replayed is never pruned on age, and a non-positive window falls back to the default rather than letting the table grow without bound.
- `PLUGIN_STATE_DIR` moves the plugin registry and per-plugin storage off the default `./data`. It was the one piece of state with no path knob, so a test run rewrote the developer's own registry and every suite in that run inherited whatever the previous one left in it.
+- The e2e lane sweeps the throwaway state roots it creates. Each suite gets its own, nothing removed them, and the temp directory accumulated hundreds of entries over a few days of runs.
### Tests
diff --git a/test/jest-e2e.json b/test/jest-e2e.json
index eda40d9e4..5fa273096 100644
--- a/test/jest-e2e.json
+++ b/test/jest-e2e.json
@@ -10,5 +10,6 @@
"transformIgnorePatterns": [
"node_modules/(?!(archiver|compress-commons|crc32-stream|zip-stream|archiver-utils|https-proxy-agent|socks-proxy-agent|agent-base|proxy-agent-negotiate)/)"
],
- "maxWorkers": 1
+ "maxWorkers": 1,
+ "globalTeardown": "<rootDir>/teardown-e2e.ts"
}
diff --git a/test/teardown-e2e.ts b/test/teardown-e2e.ts
new file mode 100644
index 000000000..045d7ec7a
--- /dev/null
+++ b/test/teardown-e2e.ts
@@ -0,0 +1,32 @@
+import { readdirSync, rmSync, statSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+/**
+ * Remove the throwaway state roots the lane creates.
+ *
+ * Every suite gets its own root (setupFiles runs once per test file), so a run leaves one directory
+ * per suite behind. Nothing removed them before and the temp dir accumulated hundreds of entries.
+ * Anything older than an hour is swept rather than only this run's roots: a killed run leaves its
+ * own litter, and the age bound keeps this from deleting a root a concurrent run is still using.
+ */
+const MAX_AGE_MS = 60 * 60 * 1000;
+
+export default function teardown(): void {
+ const root = tmpdir();
+ const cutoff = Date.now() - MAX_AGE_MS;
+ let entries: string[];
+ try {
+ entries = readdirSync(root).filter(name => name.startsWith('openwa-e2e-'));
+ } catch {
+ return;
+ }
+ for (const name of entries) {
+ const target = join(root, name);
+ try {
+ if (statSync(target).mtimeMs < cutoff) rmSync(target, { force: true, recursive: true });
+ } catch {
+ // A root the OS or another run removed underneath us is already the outcome we wanted.
+ }
+ }
+}