Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: E2E Tests

on:
push:
tags: ["v*"]
workflow_dispatch:

concurrency:
group: e2e-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 15

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: vectorflow_e2e
POSTGRES_PASSWORD: e2e_test_password
POSTGRES_DB: vectorflow_e2e
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
DATABASE_URL: postgresql://vectorflow_e2e:e2e_test_password@localhost:5432/vectorflow_e2e
NEXTAUTH_SECRET: e2e-test-secret-key-at-least-32-chars
NEXTAUTH_URL: http://localhost:3000
ENCRYPTION_KEY: e2e-test-encryption-key-32chars!!

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run database migrations
run: npx prisma migrate deploy

- name: Build application
run: pnpm build

- name: Install Playwright Chromium
run: npx playwright install chromium --with-deps

- name: Start server
run: pnpm start &

- name: Wait for server
run: npx wait-on http://localhost:3000 --timeout 60000

- name: Run E2E tests
run: pnpm test:e2e

- name: Upload test artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
playwright-report/
test-results/
retention-days: 7
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ next-env.d.ts
# worktrees
.worktrees/

# ── GSD baseline (auto-generated) ──
.gsd
Thumbs.db
*.swp
*.swo
Expand All @@ -82,3 +80,10 @@ vendor/
coverage/
.cache/
tmp/

# playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
e2e/.auth/
16 changes: 16 additions & 0 deletions e2e/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: vectorflow_e2e
POSTGRES_PASSWORD: e2e_test_password
POSTGRES_DB: vectorflow_e2e
ports:
- "5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U vectorflow_e2e"]
interval: 5s
timeout: 3s
retries: 5
tmpfs:
- /var/lib/postgresql/data
50 changes: 50 additions & 0 deletions e2e/fixtures/test.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { test as base } from "@playwright/test";
import { LoginPage } from "../pages/login.page";
import { PipelinesPage } from "../pages/pipelines.page";
import { PipelineEditorPage } from "../pages/pipeline-editor.page";
import { FleetPage } from "../pages/fleet.page";
import { AlertsPage } from "../pages/alerts.page";
import { SidebarComponent } from "../pages/components/sidebar.component";
import { ToastComponent } from "../pages/components/toast.component";
import { DeployDialogComponent } from "../pages/components/deploy-dialog.component";

interface E2EFixtures {
loginPage: LoginPage;
pipelinesPage: PipelinesPage;
pipelineEditor: PipelineEditorPage;
fleetPage: FleetPage;
alertsPage: AlertsPage;
sidebar: SidebarComponent;
toast: ToastComponent;
deployDialog: DeployDialogComponent;
}

export const test = base.extend<E2EFixtures>({
loginPage: async ({ page }, use) => {
await use(new LoginPage(page));
},
pipelinesPage: async ({ page }, use) => {
await use(new PipelinesPage(page));
},
pipelineEditor: async ({ page }, use) => {
await use(new PipelineEditorPage(page));
},
fleetPage: async ({ page }, use) => {
await use(new FleetPage(page));
},
alertsPage: async ({ page }, use) => {
await use(new AlertsPage(page));
},
sidebar: async ({ page }, use) => {
await use(new SidebarComponent(page));
},
toast: async ({ page }, use) => {
await use(new ToastComponent(page));
},
deployDialog: async ({ page }, use) => {
await use(new DeployDialogComponent(page));
},
});

export { expect } from "@playwright/test";
39 changes: 39 additions & 0 deletions e2e/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test as setup } from "@playwright/test";
import { PrismaClient } from "../src/generated/prisma";
import { seed } from "./helpers/seed";
import { cleanup } from "./helpers/cleanup";
import { TEST_USER } from "./helpers/constants";

const authFile = "e2e/.auth/user.json";

setup("seed database and authenticate", async ({ page }) => {
const prisma = new PrismaClient();

try {
await cleanup(prisma);
const result = await seed(prisma);

const fs = await import("fs/promises");
await fs.mkdir("e2e/.auth", { recursive: true });
await fs.writeFile(
"e2e/.auth/seed-result.json",
JSON.stringify(result, null, 2),
);
Comment on lines +14 to +21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 e2e/.auth/ directory is never created — CI will throw ENOENT

e2e/.auth/ is listed in .gitignore, so it won't exist on a fresh clone or CI checkout. fs.writeFile("e2e/.auth/seed-result.json", ...) does not create missing parent directories; it throws ENOENT: no such file or directory. This crashes the global-setup before any test runs.

Playwright's own storageState({ path }) call (line 38) handles directory creation internally, so that write is safe — but the manual writeFile here is not.

Add an mkdir before the write:

Suggested change
const result = await seed(prisma);
const fs = await import("fs/promises");
await fs.writeFile(
"e2e/.auth/seed-result.json",
JSON.stringify(result, null, 2),
);
const fs = await import("fs/promises");
await fs.mkdir("e2e/.auth", { recursive: true });
await fs.writeFile(
"e2e/.auth/seed-result.json",
JSON.stringify(result, null, 2),
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: e2e/global-setup.ts
Line: 14-20

Comment:
**`e2e/.auth/` directory is never created — CI will throw ENOENT**

`e2e/.auth/` is listed in `.gitignore`, so it won't exist on a fresh clone or CI checkout. `fs.writeFile("e2e/.auth/seed-result.json", ...)` does **not** create missing parent directories; it throws `ENOENT: no such file or directory`. This crashes the global-setup before any test runs.

Playwright's own `storageState({ path })` call (line 38) handles directory creation internally, so that write is safe — but the manual `writeFile` here is not.

Add an `mkdir` before the write:

```suggestion
    const fs = await import("fs/promises");
    await fs.mkdir("e2e/.auth", { recursive: true });
    await fs.writeFile(
      "e2e/.auth/seed-result.json",
      JSON.stringify(result, null, 2),
    );
```

How can I resolve this? If you propose a fix, please make it concise.

} finally {
await prisma.$disconnect();
}

await page.goto("/login");
await page.getByRole("button", { name: /sign in/i }).waitFor({
state: "visible",
timeout: 15_000,
});

await page.getByRole("textbox", { name: /email/i }).fill(TEST_USER.email);
await page.locator('input[type="password"]').fill(TEST_USER.password);
await page.getByRole("button", { name: /sign in/i }).click();

await page.waitForURL((url) => !url.pathname.includes("/login"), { timeout: 15_000 });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 waitForURL("**/*") matches the login page itself — failed auth is undetected

"**/*" is a glob that matches every URL, including http://localhost:3000/login. Playwright's waitForURL resolves the moment the current URL matches the pattern. Because the page is already on /login when the click happens (and would stay there if credentials are wrong, the server returns an error, or NextAuth rejects the login), this line resolves immediately in those cases. The auth state is then saved to e2e/.auth/user.json with an unauthenticated session, causing every downstream test to fail with confusing "not authenticated" errors rather than a clear setup failure.

The fix is to wait for a URL that is specifically not the login page:

Suggested change
await page.waitForURL((url) => !url.pathname.includes("/login"), { timeout: 15_000 });
Prompt To Fix With AI
This is a comment left during a code review.
Path: e2e/global-setup.ts
Line: 36

Comment:
**`waitForURL("**/*")` matches the login page itself — failed auth is undetected**

`"**/*"` is a glob that matches every URL, including `http://localhost:3000/login`. Playwright's `waitForURL` resolves the moment the current URL matches the pattern. Because the page is already on `/login` when the click happens (and would stay there if credentials are wrong, the server returns an error, or NextAuth rejects the login), this line resolves immediately in those cases. The auth state is then saved to `e2e/.auth/user.json` with an unauthenticated session, causing every downstream test to fail with confusing "not authenticated" errors rather than a clear setup failure.

The fix is to wait for a URL that is specifically *not* the login page:

```suggestion
  await page.waitForURL((url) => !url.pathname.includes("/login"), { timeout: 15_000 });
```

How can I resolve this? If you propose a fix, please make it concise.

await page.context().storageState({ path: authFile });
});
11 changes: 11 additions & 0 deletions e2e/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PrismaClient } from "../src/generated/prisma";
import { cleanup } from "./helpers/cleanup";

export default async function globalTeardown(): Promise<void> {
const prisma = new PrismaClient();
try {
await cleanup(prisma);
} finally {
await prisma.$disconnect();
}
}
90 changes: 90 additions & 0 deletions e2e/helpers/cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { PrismaClient } from "../../src/generated/prisma";
import { TEST_USER, TEST_TEAM } from "./constants";

export async function cleanup(prisma: PrismaClient): Promise<void> {
const user = await prisma.user.findUnique({
where: { email: TEST_USER.email },
});
if (!user) return;

const team = await prisma.team.findFirst({
where: { name: TEST_TEAM.name },
});

if (team) {
const alertRules = await prisma.alertRule.findMany({
where: { teamId: team.id },
select: { id: true },
});
const alertRuleIds = alertRules.map((r) => r.id);

if (alertRuleIds.length > 0) {
await prisma.deliveryAttempt.deleteMany({
where: { alertEvent: { alertRuleId: { in: alertRuleIds } } },
});
await prisma.alertEvent.deleteMany({
where: { alertRuleId: { in: alertRuleIds } },
});
await prisma.alertRule.deleteMany({
where: { id: { in: alertRuleIds } },
});
}

const environments = await prisma.environment.findMany({
where: { teamId: team.id },
select: { id: true },
});
const envIds = environments.map((e) => e.id);

if (envIds.length > 0) {
await prisma.notificationChannel.deleteMany({
where: { environmentId: { in: envIds } },
});

const pipelines = await prisma.pipeline.findMany({
where: { environmentId: { in: envIds } },
select: { id: true },
});
const pipelineIds = pipelines.map((p) => p.id);

if (pipelineIds.length > 0) {
await prisma.pipelineEdge.deleteMany({
where: { pipelineId: { in: pipelineIds } },
});
await prisma.pipelineNode.deleteMany({
where: { pipelineId: { in: pipelineIds } },
});
await prisma.pipelineVersion.deleteMany({
where: { pipelineId: { in: pipelineIds } },
});
await prisma.pipeline.deleteMany({
where: { id: { in: pipelineIds } },
});
}

await prisma.vectorNode.deleteMany({
where: { environmentId: { in: envIds } },
});

await prisma.team.update({
where: { id: team.id },
data: { defaultEnvironmentId: null },
});

await prisma.environment.deleteMany({
where: { id: { in: envIds } },
});
}

await prisma.teamMember.deleteMany({
where: { teamId: team.id },
});
await prisma.team.delete({
where: { id: team.id },
});
}

await prisma.user.delete({
where: { id: user.id },
});
}
40 changes: 40 additions & 0 deletions e2e/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const TEST_USER = {
email: "e2e@test.local",
password: "TestPassword123!",
name: "E2E Test User",
} as const;

export const TEST_TEAM = {
name: "E2E Test Team",
} as const;

export const TEST_ENVIRONMENT = {
name: "e2e-test-env",
} as const;

export const TEST_PIPELINE = {
name: "E2E Test Pipeline",
description: "Pipeline created by E2E seed script",
} as const;

export const TEST_NODE = {
name: "e2e-node-01",
host: "e2e-host-01.local",
apiPort: 8686,
} as const;

export const TEST_ALERT_RULE = {
name: "E2E Error Rate Alert",
} as const;

export const SELECTORS = {
sidebar: {
nav: '[data-slot="sidebar"]',
menuButton: (title: string) => `a:has(span:text("${title}"))`,
},
toast: {
container: '[data-sonner-toaster]',
success: '[data-type="success"]',
error: '[data-type="error"]',
},
} as const;
Loading
Loading