Skip to main content
< All Topics
Print

n8n + Dify Testing

name: n8n-dify-testing

description: Run, interpret, and extend the ITI infrastructure pytest test suite covering Docker health, n8n webhooks, workflow integration, PostgreSQL/pgvector, and Dify retrieval. Use when running validation tests, adding coverage for new workflows, or diagnosing test failures.

n8n + Dify Testing

Instructions

Operate the pytest test suite at ITI/infrastructure/n8n-dify/tests/. Tests run against the live Docker stack and require all 9 containers to be healthy.

Prerequisites:


/opt/anaconda3/bin/python -m pip install pytest pytest-asyncio httpx psycopg2-binary redis

Test markers and when to use them:

Marker When to run Speed What it validates
smoke After any stack restart or deploy ~2 min Container ports, service health, webhook reachability
integration After workflow changes or upgrades ~3-5 min AI agent response structure, health endpoint JSON, KB retrieval
slow Before releases or after major changes ~5-10 min Same as integration but includes heavy multi-agent pipelines

Running tests:


cd ITI/infrastructure/n8n-dify/tests

# Smoke tests (fast, run daily)
/opt/anaconda3/bin/python -m pytest test_docker_health.py -m smoke -v
/opt/anaconda3/bin/python -m pytest test_n8n_webhooks.py -m smoke -v

# Integration tests (medium, run after changes)
/opt/anaconda3/bin/python -m pytest test_n8n_workflows.py -m integration -v
/opt/anaconda3/bin/python -m pytest test_postgres_pgvector.py -v

# Full suite
/opt/anaconda3/bin/python -m pytest -v

Test file inventory:

File Markers What it tests
test_docker_health.py smoke Container port reachability (5 ports), service health endpoints (5 services)
test_n8n_webhooks.py smoke All 27 production webhook endpoints respond without 5xx
test_n8n_workflows.py integration, slow AI agent workflows return structured JSON; health workflows return expected keys; KB retrieval works
test_postgres_pgvector.py integration Databases exist (n8n, dify, dify_plugin), pgvector extension loaded, vector operations work
test_dify_retrieval.py integration Dify dataset API responds, semantic search returns relevant results
conftest.py Shared fixtures: service URLs, skip conditions, http_client, postgres_dsn, redis_url

Expected “failures” that are normal:

  • consulting-pipeline, proposal-evaluation, patriot-university timeout on 15-30s test limits — these are heavy multi-agent workflows (10-15 min runtime). Timeouts here confirm the workflow is processing, not broken.
  • Design QA Review and Design System Audit return custom JSON structures (not output/response keys) — the test asserts any non-empty dict, which passes.

Adding a new webhook endpoint to tests:

  1. In test_n8n_webhooks.py, add to WEBHOOK_ENDPOINTS:

("POST", "/webhook/new-product", {"query": "test", "sessionId": "smoke"}, "New Product"),
  1. In test_n8n_workflows.py, add to AI_AGENT_WORKFLOWS:

("/webhook/new-product", "New Product"),
  1. Run smoke tests to verify the new endpoint is reachable.

Conftest fixtures:

  • n8n_urlhttp://localhost:5678 (override with N8N_BASE_URL env var)
  • dify_api_urlhttp://localhost:3001
  • http_client — session-scoped httpx.Client with 10s default timeout
  • postgres_dsn — connection string for psycopg2
  • requires_docker_stack — skip decorator that checks PostgreSQL and n8n TCP ports

Fallback testing procedure:

  1. Run smoke tests to confirm baseline
  2. docker compose stop n8n
  3. Verify curl http://localhost:5678/healthz fails with connection refused
  4. Confirm adapter code would detect n8n as unavailable (ConnectError)
  5. docker compose start n8n
  6. Wait 10-15 seconds for n8n to initialize
  7. Verify curl http://localhost:5678/healthz returns {"status":"ok"}
  8. Re-run smoke tests to confirm recovery

CR-6 verification (GHI data isolation):


source ITI/infrastructure/n8n-dify/.env
curl -s "http://localhost:3001/v1/datasets?limit=50" \
  -H "Authorization: Bearer $DIFY_API_KEY" | \
  python3 -c "import sys,json; data=json.load(sys.stdin); [print(d['name']) for d in data.get('data',[])]"

pytest.ini configuration:


[pytest]
markers =
    smoke: Quick reachability and health checks
    integration: Full response validation (requires AI inference)
    slow: Extended tests with long timeouts
testpaths = .
asyncio_mode = auto

Antigravity as an alternative test runner:

For browser-visible integration tests (webhook responses rendered in a UI, Dify console verification, n8n workflow editor validation), Antigravity’s browser sub-agent provides an alternative to pytest:

  • Webhook E2E testing: Dispatch an Antigravity agent to call webhook endpoints through a browser interface and verify the rendered response — captures screenshots of each step.
  • Dify console verification: Use the browser sub-agent to navigate to http://localhost:3000, open a Knowledge Base, and verify document counts and retrieval quality visually.
  • n8n workflow validation: Navigate to http://localhost:5678 and visually verify workflow activation status, execution history, and error states.

These browser-based tests complement (not replace) the pytest suite — pytest verifies programmatic correctness while Antigravity verifies the user-facing experience.

See the antigravity-browser-qa skill for browser sub-agent configuration and the antigravity-testing skill for agent dispatch patterns.

Table of Contents