AGENT SKILL

n8n-smoke-test

Automated Execution Smoke-Tests for n8n workflows. Use BEFORE marking any pipeline complete or active. Activates when building or modifying any workflow, before calling activateWorkflow or publish_workflow, or when the user says "test it", "is it ready", or "deploy it". Pairs `test_workflow` (or `n8n_test_workflow`) with dummy mock payloads stored in scratch/ to prove the happy path and key error branches execute correctly. Never mark a workflow complete without a passing smoke test.

License 许可
MIT
最近更新
2026-11-05
Stars
★ 0
Forks
0

01 前言 Front Matter

name
n8n-smoke-test
description
Automated Execution Smoke-Tests for n8n workflows. Use BEFORE marking any pipeline complete or active. Activates when building or modifying any workflow, before calling activateWorkflow or publish_workflow, or when the user says "test it", "is it ready", or "deploy it". Pairs `test_workflow` (or `n8n_test_workflow`) with dummy mock payloads stored in scratch/ to prove the happy path and key error branches execute correctly. Never mark a workflow complete without a passing smoke test.

03 SKILL.md 正文

n8n Smoke-Test Protocol

Every pipeline MUST pass a smoke test before it is marked complete, activated, or handed off. Skipping smoke tests is the single highest-risk shortcut in n8n development.


Golden Rule

No smoke test → no activation. Call n8n_test_workflow (or MCP test_workflow) with a representative mock payload before calling activateWorkflow or publish_workflow on any workflow.


Smoke-Test Workflow (step-by-step)

1. WRITE mock payload → scratch/<workflow-slug>-mock.json
2. RUN  n8n_test_workflow({ workflowId, inputData: <mock> })
3. INSPECT result for: execution status, node outputs, error branches
4. IF errors → fix with n8n_update_partial_workflow → go back to step 2
5. IF all branches pass → activateWorkflow / publish_workflow

Step 1 – Write the Mock Payload

Save every mock payload to a file so it is reproducible:

scratch/<workflow-slug>-mock.json

Mock Payload Schema (Webhook trigger example)

{
  "body": {
    "event": "lead.created",
    "leadId": "smoke-001",
    "email": "smoke@example.com",
    "name": "Smoke Test Lead",
    "budget": 500000,
    "timeline": "immediate"
  },
  "headers": {
    "content-type": "application/json",
    "x-webhook-secret": "SMOKE_TEST_PLACEHOLDER"
  },
  "query": {}
}

Mock Payload Schema (Scheduled trigger example)

{
  "triggerTime": "2026-01-01T08:00:00.000Z",
  "workflowId": "smoke-test",
  "runIndex": 0
}

Mock Payload Schema (Execute-Workflow-Trigger sub-workflow)

{
  "payload": {
    "leadId": "smoke-001",
    "score": 85,
    "assignedBroker": "broker-42"
  }
}

Step 2 – Run the Smoke Test

Via MCP tool

n8n_test_workflow({
  workflowId: "wf_abc123",
  inputData: {
    // paste your mock payload here
  }
})

Via REST API (fallback when MCP is unavailable)

curl -X POST https://<n8n-host>/api/v1/workflows/<workflowId>/test \
  -H "X-N8N-API-KEY: <key>" \
  -H "Content-Type: application/json" \
  -d @scratch/<workflow-slug>-mock.json

Step 3 – Inspect the Result

A passing smoke test has ALL of the following:

  • status: "success" at the execution level
  • Every expected node appears in runData with items
  • No node has error set in its run entry
  • Error-branch nodes (e.g. main[1] traps) are NOT triggered in the happy-path run

Reading the result

// result shape from n8n_test_workflow
{
  "id": "exec_xyz",
  "status": "success",      // ← must be "success"
  "data": {
    "resultData": {
      "lastNodeExecuted": "Send WhatsApp Message",
      "runData": {
        "Webhook": [{ "executionTime": 12, "data": { "main": [[...]] } }],
        "AI Qualifier": [{ "executionTime": 843, "data": { ... } }],
        // ...
      }
    }
  }
}

Step 4 – What to Fix

Symptom in result Root cause Fix
status: "error" + expression in message Wrong $json path Check trigger type — webhook data is $json.body.*, not $json.*
Node missing from runData IF branch not hit Add a second mock for the other branch
"error": { "name": "NodeOperationError" } Missing credential reference Wire credential in the node config, then re-test
lastNodeExecuted stops early Upstream node emitted 0 items Add a Set node to emit at least 1 item for smoke testing
Error-trap branch triggered on happy path Condition logic inverted Review the IF/Switch node condition, fix, re-test

Use n8n_update_partial_workflow to apply fixes, then immediately re-run the smoke test. Maximum fix → re-test cycles before escalating: 5. If still failing after 5 cycles, call n8n_autofix_workflow before the next attempt.


Branch Coverage Checklist

For any workflow with branches, run a separate smoke test for each branch:

Branch Mock trigger Expected last node
Happy path (qualified lead) budget: 500000, timeline: "immediate" Send WhatsApp Priority Alert
Cold lead budget: 50000, timeline: "6 months" Schedule Follow-Up Ping
Webhook auth failure missing x-webhook-secret header Return 401 Unauthorized
API timeout mock downstream timeout (use Code node stub) Error Trap → Slack Alert

Save each mock to its own file:

scratch/<workflow-slug>-mock-happy.json
scratch/<workflow-slug>-mock-cold-lead.json
scratch/<workflow-slug>-mock-auth-fail.json
scratch/<workflow-slug>-mock-timeout.json

Scratch Directory Convention

scratch/
├── <workflow-slug>-mock-happy.json       # happy-path payload
├── <workflow-slug>-mock-<branch>.json    # one file per branch
└── <workflow-slug>-smoke-results.json    # optional: store last run result
  • Slug format: lowercase, hyphens only (e.g. whatsapp-lead-qualifier, ad-report-digest).
  • Never commit real secrets to mock files. Use placeholder strings like "SMOKE_TEST_SECRET".
  • Mock files are inputs to n8n_test_workflow — they stay in scratch, not in the workflow itself.

Smoke Test Sign-Off Criteria

All boxes must be checked before activateWorkflow / publish_workflow:

  • [ ] Happy-path smoke test: status: "success"
  • [ ] All expected nodes present in runData
  • [ ] At least one error-branch smoke test (if error traps exist)
  • [ ] Mock payloads saved to scratch/
  • [ ] No hardcoded secrets in mock files
  • [ ] Validation also passes (n8n_validate_workflow or validate_workflow)

Integration with Other Skills

  • n8n-validation-expert — Run validate_workflow BEFORE smoke-testing. Validation catches schema errors; smoke testing catches runtime errors. Both are required.
  • n8n-error-handling — Your error branches (the main[1] traps) must be tested with a mock that provokes an error. A trap that was never triggered in testing is untested code.
  • n8n-run-doctor — If a smoke test fails and the error is unclear, feed the failed execution ID to the run doctor for structured diagnosis.
  • n8n-env-gating — Always smoke test on staging first. Only promote to prod after a clean smoke test result on the staging instance.

04 同仓库更多 Skills