n8n/packages/testing/playwright/tests/e2e/instance-ai
Mutasem Aldmour 4ef0d05f1c
fix(editor): Make AI assistant quota-exhausted error states explicit (#33847)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-14 09:46:35 +00:00
..
fixtures.ts feat(core): Support multi-main deployments for Instance AI (no-changelog) (#33296) 2026-07-06 07:25:44 +00:00
instance-ai-artifacts.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-attachments.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-background-lifecycle.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-chat-basics.spec.ts refactor(editor): Rename Instance AI route from /instance-ai to /assistant (#33246) 2026-06-29 18:21:51 +00:00
instance-ai-confirmations.spec.ts test: Skip Instance AI approval-panel e2e tests with stale replay recordings (no-changelog) (#34058) 2026-07-13 09:54:44 +00:00
instance-ai-multimain.spec.ts feat(core): Support multi-main deployments for Instance AI (no-changelog) (#33296) 2026-07-06 07:25:44 +00:00
instance-ai-out-of-credits.spec.ts fix(editor): Make AI assistant quota-exhausted error states explicit (#33847) 2026-07-14 09:46:35 +00:00
instance-ai-remediation-guard.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-sidebar.spec.ts refactor(editor): Rename Instance AI route from /instance-ai to /assistant (#33246) 2026-06-29 18:21:51 +00:00
instance-ai-timeouts.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-workflow-execution.spec.ts test: Stabilize Instance AI workflow execution tests (#33320) 2026-07-02 22:15:24 +00:00
instance-ai-workflow-preview.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
instance-ai-workflow-setup.spec.ts test: Enforce canonical e2e spec owners and fix owner-name drift (no-changelog) (#32591) 2026-06-24 07:44:15 +01:00
README.md feat(core): Use n8n default sandbox for Instance AI (no-changelog) (#31335) 2026-06-04 08:31:27 +00:00
thread-launcher.spec.ts feat(editor): Start Instance AI threads from templates on the website and template page (#33653) 2026-07-13 15:41:54 +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. The shared fixture also starts the sandbox service that the workflow builder requires.

Two run modes

CI / container mode (default)

Spins up an n8n container plus the MockServer proxy and sandbox service. 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 proxy and sandbox services plus 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.