Testing instructions
Three layers. Run 1 and 2 on your laptop in a minute; run 3 inside your n8n before trusting the kit in production.
1. Offline suite (no n8n, no database)
Requires Node.js 18+.
node tests/run-tests.js
It loads the exact Code-node source embedded in the shipped workflow JSON and executes it in an emulated Code-node runtime. Health tests supply synthetic HTTP Request node outputs. This layer checks:
- every workflow: valid graph, one trigger, no unreachable nodes, no embedded credentials, Code nodes compile, SQL only touches
rak.*; - error classification, fingerprinting, alert suppression, Postgres-down fallback, Slack/Discord/generic payloads;
- watchdog states (ok / stale / failing / never ran / recovered) and re-alert timing;
- gate input validation and decisions;
- health checks: wrong status, missing body text, DNS failure, slow response, DOWN/RECOVERED transitions;
- daily report maths;
- recovery: allowlist, error class, max attempts, backoff, per-run cap, dry run;
- free audit scoring.
Expected: every check passes (0 failed).
2. Database suite (real Postgres)
Requires the psql CLI and a throwaway database. The suite truncates the rak tables.
createdb rak_test
psql -d rak_test -f sql/schema.sql
PGDATABASE=rak_test node tests/sql-tests.js # plus PGHOST/PGPORT/PGUSER/PGPASSWORD as needed
It runs the SQL taken from the workflow JSON, with parameters inlined the way n8n's Postgres node formats them, and checks:
- incident suppression window and its expiry;
- gate lifecycle: claim → in_progress → complete → duplicate, release, lease expiry;
- 25 concurrent claims for one event produce exactly one
process; - keys containing quotes and SQL fragments are stored as data;
- watchdog/health upserts, recovery ledger, report aggregate, prune.
Expected: every check passes (0 failed).
3. In-instance acceptance test
Run the disposable Docker lab from the kit directory. The Compose network is internal, it publishes no host ports, PostgreSQL uses temporary storage, and all credentials and HTTP destinations are synthetic. Use a fresh project name if running multiple labs.
RAK_TEST_PROJECT=rak-acceptance node tests/instance/acceptance.js
docker compose -f tests/instance/compose.yaml -p rak-acceptance down -v
PowerShell uses $env:RAK_TEST_PROJECT = 'rak-acceptance' before the Node command. The runner imports the shipped JSON before configuring a second copy for the lab. It preserves the one-minute error generator and uses local webhook triggers for deterministic launches of the other test workflows. For production installation, the configured schedules and the audit's manual trigger remain in the distributed files.
The sections below describe the scenarios the Docker runner exercises with synthetic data.
A. Error Router
- Import
test-data/RAK-TEST_failure_generator.json. In its settings set Error workflow to RAK-01 and activate it. - Within 5 minutes you should get 5 alerts with 5 different classes (
rate_limit,timeout,auth,validation,upstream_5xx). - After minute 6, repeats should be stored but not alerted: ``
sql SELECT error_class, count(*), sum(alerted::int) AS alerts FROM rak.incidents GROUP BY 1;`` - Deactivate the generator.
B. Idempotency Gate under concurrency
- Activate RAK-03b (with the RAK-03 ID pasted in) and copy its production webhook URL.
node tests/send-duplicate-webhooks.js https://<your-n8n>/webhook/rak-demo-orders 5- Check: ``
sql SELECT key, status, attempts, duplicate_hits FROM rak.idempotency ORDER BY claimed_at DESC LIMIT 1;`Expected:status = done,duplicate_hits = 4`, and in Executions exactly one run of RAK-03b reached Your Side Effect (replace). The other four stopped at First Delivery Only.
C. Watchdog, report, recovery and audit against the mock API
The mock API serves synthetic executions and workflows, and records retry calls, so nothing touches your real instance.
- On a machine n8n can reach:
node tests/mock-n8n-api.js(port 5679). - Temporarily set the
n8n APIcredential value torak-test-key, or make a second credential, and setn8nBaseUrltohttp://<that-host>:5679(http://host.docker.internal:5679from Docker on the same machine). - RAK-02: watch
wf_sync(maxSilence 90),wf_nightly(1500),wf_orders(30),wf_new(60). Execute once. Expected digest:wf_nightlysilent,wf_ordersfailing,wf_newsilent (never ran),wf_syncnot mentioned. - RAK-00 audit: run it. Expected grade below A, with
Stripe → CRM (risky)flagged for missing error workflow, missing dedupe, a webhook that waits, a possible secret, and swallowed errors. - RAK-04: endpoints
http://<host>:5679/health/ok,/health/fail, and/health/slowwithmaxLatencyMs: 1000. Execute twice. The second run should reportfailandslowDOWN. - RAK-06: after test A, set
retrySafeWorkflowIdsto the generator's workflow ID and run once in dry run. The digest should list only therate_limit,timeoutandupstream_5xxfailures older than 15 min, neverauthorvalidation. If you setdryRun: falsewhile pointed at the mock,http://<host>:5679/_retriesshows the calls made. - Point the credential and
n8nBaseUrlback at your real instance.
D. What to check before going live
- Every production workflow has RAK-01 as its Error workflow (re-run the audit).
- Alerts arrive in the right channel and are readable on a phone.
watchedintervals match the real schedules.- RAK-06 stays in dry run until each allowlisted workflow is gate-protected.
Known limits (be aware, not surprised)
- Near-simultaneous identical failures can both alert. Suppression is read-then-insert, not locked. Storage stays correct.
- The executions API omits
waitingexecutions on some n8n versions (n8n-io/n8n#14748), so the watchdog does not count them as runs. - The report's execution count reads one API page (250). See CONFIG_REFERENCE.
- RAK-04 uses a native HTTP Request node. Probes run sequentially and measure elapsed wall time around the node, including execution overhead. Configure a threshold that allows for the overhead and keep the full run shorter than the polling interval.