From 69e5f2257af5ef717af0605a13933833b33ac238 Mon Sep 17 00:00:00 2001 From: oabrivard Date: Mon, 23 Mar 2026 11:27:19 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20UAT=20test=20=E2=80=94=20ESM=20compat,?= =?UTF-8?q?=20correct=20status=20codes,=20idempotent=20source=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use import.meta.url for ESM-compatible __dirname - Source creation expects 201, not 200 - Clean up existing sources before adding to avoid unique constraint violation - Fix E2E docker-compose build context to project root Co-Authored-By: Claude Opus 4.6 (1M context) --- e2e/docker-compose.test.yml | 4 ++-- e2e/tests/generation-live.spec.ts | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/e2e/docker-compose.test.yml b/e2e/docker-compose.test.yml index f419676..fc456bd 100644 --- a/e2e/docker-compose.test.yml +++ b/e2e/docker-compose.test.yml @@ -1,8 +1,8 @@ services: app: build: - context: ../backend - dockerfile: Dockerfile + context: .. + dockerfile: backend/Dockerfile container_name: ai-synth-test restart: "no" environment: diff --git a/e2e/tests/generation-live.spec.ts b/e2e/tests/generation-live.spec.ts index c3044c7..1308c1a 100644 --- a/e2e/tests/generation-live.spec.ts +++ b/e2e/tests/generation-live.spec.ts @@ -12,9 +12,12 @@ import { test, expect } from '@playwright/test'; import type { Page } from '@playwright/test'; import * as dotenv from 'dotenv'; import * as path from 'path'; +import { fileURLToPath } from 'url'; import { loginAsUser } from '../helpers/auth'; -// Load .env.test from the e2e directory +// Load .env.test from the e2e directory (ESM-compatible __dirname) +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); dotenv.config({ path: path.resolve(__dirname, '..', '.env.test') }); const OPENAI_KEY = process.env.OPENAI_TEST_API_KEY; @@ -120,10 +123,11 @@ test.describe('Live generation with OpenAI', () => { }) => { test.setTimeout(180_000); - // Navigate to app first (required for cookie domain), then login + // Set session cookie, then navigate to a stable page // OpenAI provider is already enabled from the migration seed data - await page.goto('/'); await loginAsUser(page); + await page.goto('/'); + await page.waitForLoadState('networkidle'); // Step 2: Configure settings const settingsResp = await apiCall(page, 'PUT', '/api/v1/settings', { @@ -145,12 +149,19 @@ test.describe('Live generation with OpenAI', () => { }); expect(keyResp.status).toBe(200); - // Step 4: Add a source + // Step 4: Clean up existing sources, then add a fresh one + const existingSources = await apiCall(page, 'GET', '/api/v1/sources'); + if (existingSources.data && Array.isArray(existingSources.data)) { + for (const source of existingSources.data) { + await apiCall(page, 'DELETE', `/api/v1/sources/${source.id}`); + } + } + const sourceResp = await apiCall(page, 'POST', '/api/v1/sources', { title: 'OpenAI Blog', url: 'https://openai.com/blog', }); - expect(sourceResp.status).toBe(200); + expect(sourceResp.status).toBe(201); // Step 5: Trigger generation const genResp = await apiCall(