n8n/packages/testing/playwright/tests/e2e/instance-ai
Mutasem Aldmour afe119be14
fix(core): Improve AI chat file upload handling and error states (#29701)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 11:26:58 +00:00
..
fixtures.ts feat(instance-ai): Orchestrator-executed checkpoint tasks for planned workflow verification (#29049) 2026-04-28 14:58:49 +00:00
instance-ai-artifacts.spec.ts feat(instance-ai): Orchestrator-executed checkpoint tasks for planned workflow verification (#29049) 2026-04-28 14:58:49 +00:00
instance-ai-attachments.spec.ts fix(core): Improve AI chat file upload handling and error states (#29701) 2026-05-08 11:26:58 +00:00
instance-ai-chat-basics.spec.ts feat(editor): Polish Instance AI chat list sidebar (no-changelog) (#29463) 2026-05-04 07:17:47 +00:00
instance-ai-confirmations.spec.ts fix(ai-builder): Allow restoring archived workflows from Instance AI (#29813) 2026-05-06 08:15:16 +00:00
instance-ai-remediation-guard.spec.ts fix(ai-builder): Add boundaries on the workflow builder remediation loops (#29430) 2026-05-04 12:05:20 +00:00
instance-ai-sidebar.spec.ts feat(editor): Polish Instance AI chat list sidebar (no-changelog) (#29463) 2026-05-04 07:17:47 +00:00
instance-ai-timeline.spec.ts feat(instance-ai): Orchestrator-executed checkpoint tasks for planned workflow verification (#29049) 2026-04-28 14:58:49 +00:00
instance-ai-workflow-execution.spec.ts feat(instance-ai): Orchestrator-executed checkpoint tasks for planned workflow verification (#29049) 2026-04-28 14:58:49 +00:00
instance-ai-workflow-preview.spec.ts feat(instance-ai): Orchestrator-executed checkpoint tasks for planned workflow verification (#29049) 2026-04-28 14:58:49 +00:00
instance-ai-workflow-setup-actions.spec.ts test(editor): Make instance AI partial-apply test deterministic (no-changelog) (#29248) 2026-04-27 19:55:57 +00:00
instance-ai-workflow-setup.spec.ts test(core): Add E2E coverage for Instance AI workflow setup apply actions (no-changelog) (#28907) 2026-04-23 07:03:56 +00:00
README.md test: Add isolated local Playwright runner (#28427) 2026-04-14 07:57:24 +00:00

Instance AI Playwright tests

These tests cover the /instance-ai UI and exercise the end-to-end agent flow (chat, tool calls, workflow preview). They're tagged @capability:proxy because the standard CI run uses a MockServer proxy to record/replay LLM traffic instead of hitting the real Anthropic API.

Two run modes

CI / container mode (default)

Spins up an n8n container plus a MockServer proxy. The proxy either:

  • Replays previously-recorded responses from expectations/instance-ai/<test-slug>/ when no real Anthropic key is present (the default in CI).
  • Records real Anthropic traffic into expectations/... when ANTHROPIC_API_KEY is set and CI is not (use this to refresh fixtures locally).

Run via:

pnpm test:container:sqlite tests/e2e/instance-ai

Local-build mode (no docker, real Anthropic key)

Use this when iterating on instance-ai code and you want a fast feedback loop against your local n8n build, without the docker proxy stack. Tests hit the real Anthropic API directly — no recording, no replay.

cd packages/testing/playwright
export ANTHROPIC_API_KEY=sk-ant-...
pnpm test:local:instance-ai

That's the whole setup. Extra args flow through to playwright test:

# Single file
pnpm test:local:instance-ai instance-ai-workflow-preview.spec.ts

# Grep
pnpm test:local:instance-ai --grep "preview"

# Multiple instances in parallel — each gets its own random port + temp DB
pnpm test:local:instance-ai --grep "preview" &
pnpm test:local:instance-ai --grep "sidebar"  &
wait

# Pin the port (e.g. for browser inspection at http://localhost:5680)
N8N_BASE_URL=http://localhost:5680 pnpm test:local:instance-ai --grep "preview"

# Headed browser for visual debugging
pnpm test:local:instance-ai --grep "preview" --headed

What test:local:instance-ai does

It's a thin wrapper over the generic test:local:isolated runner that pre-fills the four env vars n8n needs to boot the instance-ai module (N8N_ENABLED_MODULES, N8N_INSTANCE_AI_MODEL, N8N_INSTANCE_AI_MODEL_API_KEY, N8N_INSTANCE_AI_LOCAL_GATEWAY_DISABLED).

From the isolated runner you get:

  • Random free OS ports for n8n + the task-runner broker, so multiple invocations don't collide.
  • Throwaway N8N_USER_FOLDER under the OS temp dir, cleaned up on exit. ~/.n8n/database.sqlite is never touched.
  • PLAYWRIGHT_ALLOW_CONTAINER_ONLY=true so the @capability:proxy tag is honoured locally.
  • Self-managed n8n with a real /rest/e2e/reset readiness check (not the racy default favicon poll), PLAYWRIGHT_SKIP_WEBSERVER=true to stop Playwright from spawning a duplicate, and process-group cleanup so node ./n8n doesn't get orphaned.

The instanceAiProxySetup fixture (fixtures.ts) detects the missing n8nContainer and short-circuits all proxy + tool-trace setup, so every LLM call goes straight to Anthropic.

Cost note: Each run makes real Anthropic calls. Scope with --grep or a filename while iterating; reserve full-suite runs for fixture refreshes (see Adding a new test below).

Adding a new test

  1. Write the test against fixtures from ./fixtures (not the base playwright fixture). The instanceAiTestConfig brings in the @capability:proxy services and the env vars n8n needs.
  2. Iterate in local-build mode until the test passes against real Anthropic.
  3. Refresh recorded expectations:
    ANTHROPIC_API_KEY=sk-ant-... pnpm test:container:sqlite \
      tests/e2e/instance-ai/<your-test>.spec.ts --workers 1
    
    Recording requires a real key + non-CI env. The instanceAiProxySetup fixture writes both expectations/instance-ai/<slug>/<n>.json (proxy responses) and expectations/instance-ai/<slug>/trace.jsonl (tool I/O for ID remapping during replay).
  4. Commit the regenerated expectations/ files alongside the test.

Reference files

File Purpose
fixtures.ts instanceAiTestConfig capability + instanceAiProxySetup auto-fixture (record/replay/local).
../../../pages/InstanceAiPage.ts Page object — locators for chat, timeline, preview iframe, etc.
../../../scripts/run-local-instance-ai.mjs Wrapper that powers pnpm test:local:instance-ai — pre-fills instance-ai env vars over the generic runner.
../../../scripts/run-local-isolated.mjs Generic runner (random port + temp DB) that powers pnpm test:local:isolated.
expectations/instance-ai/<test-slug>/ Per-test recordings — proxy responses + tool trace events.