diff --git a/AGENTS.md b/AGENTS.md index 65b9f04..a6a6689 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Project Overview -`@data-fair/catalogs` is a sister service of `data-fair`. It imports datasets from external +`@data-fair/catalogs` is a service of Data Fair, the open-source data platform, alongside its core service `data-fair`. It imports datasets from external catalogs into a running `data-fair` instance and publishes `data-fair` datasets to those catalogs, through NPM-installable plugins. The project is a monorepo with four workspaces: @@ -30,11 +30,7 @@ never overwritten. Production names (`MONGO_URL`, `PRIVATE_DIRECTORY_URL`, `PRIV `worker/config/development.mjs`. Without the `events` profile, the api and the worker log a failure per pushed event; an empty `EVENTS_PORT` (when another environment provides the containers) turns the integration off. -- Read the logs before restarting: nodemon (api, worker) and vite (ui) already reload on file changes. -- Do not start, stop or restart the dev processes or containers of the user: ask. -- Never `npm ci` / `npm install` while the env runs. -- If a service is down, do not try to fix the infrastructure: read its logs (`dev/logs/`, or - `docker compose logs ` for a container) and report the problem to the user with the relevant lines. +nodemon (api, worker) and vite (ui) reload on file changes. The dev environment also serves as the test environment: the Playwright test suite hits the running dev API, dev worker and dev UI. There is no separate test server. @@ -91,7 +87,8 @@ npx playwright test path/to/file # a specific file ``` Tests are organized under `tests/features//.{unit,api,e2e}.spec.ts`; api and e2e -specs import `test` / `expect` from `tests/fixtures/login.ts`. The `state-setup` project +specs import `test` / `expect` from `tests/fixtures/login.ts`, a thin wrapper over the shared +login helper `@data-fair/lib-node/playwright-login.js`. The `state-setup` project checks that the dev API is up, `e2e-warmup` visits every UI route once so a cold vite transforms them before the e2e tests; dependency discovery is off, so a blank page there with a module named in the console means a commonjs dependency is missing from `optimizeDeps.include` in `ui/vite.config.ts` (use the @@ -100,18 +97,14 @@ worker logs (`dev/logs/`) are attached to the trace (`npx playwright show-trace per-test durations of the last run are in `dev/logs/test-timings.json`. Keep the 30 s test timeout (hooks included): a heavy spec calls `test.slow()`. -Quality gates: +Quality gates: `npm run lint` on commit; on push (`dev/pre-push.sh`) the type check, the unit +tests, the `@smoke` api/e2e tests and the api/e2e spec files changed since `origin/master`; on a +pull request and a release tag (`reuse-quality.yml`) lint, types, UI build, audit and the whole +suite. No nightly: the suite is small. `npm run quality` runs the full gate locally. -| When | What | -|---|---| -| commit (`.husky/pre-commit`) | `npm run lint` | -| push (`.husky/pre-push` → `dev/pre-push.sh`) | type check, unit tests, the `@smoke` api/e2e tests, and the api/e2e spec files changed since `origin/master` | -| pull request, release tag (`reuse-quality.yml`) | lint, types, UI build, audit, and the whole unit/api/e2e suite (no nightly: the suite is small) | - -`@smoke` (`test('...', { tag: '@smoke' }, ...)`) marks a few fast tests over the core flows -(catalog CRUD, import, publication, plugin resolution, list page, configuration edition, -plugin picker). Tag a test only if it is fast and covers a path many features depend on. -When iterating, run only the related test cases; `npm run quality` runs the full gate locally. +The `@smoke` set (`test('...', { tag: '@smoke' }, ...)`) covers catalog CRUD, import, +publication, plugin resolution, the list page, configuration edition and the plugin picker. +When iterating, run only the related test cases. ### AI assistant diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 519a600..1c1c00a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,7 +70,7 @@ what those accounts own; dev data under other accounts is left untouched. *Note : the snippets below use `http://localhost:5800` as the Data Fair URL (`NGINX_PORT` of `.env`).* -A. Congifure the publication site +A. Configure the publication site You can configure the publication site for each organization on which you want to run your tests. diff --git a/api/package.json b/api/package.json index 96187d6..19e172e 100644 --- a/api/package.json +++ b/api/package.json @@ -20,7 +20,7 @@ "@data-fair/catalogs-shared": "*", "@data-fair/lib-common-types": "^1.28.1", "@data-fair/lib-express": "^2.2.0", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-node-registry": "^0.7.2", "@data-fair/lib-utils": "^1.15.0", "config": "^5.0.1", diff --git a/package-lock.json b/package-lock.json index 3a1c4e0..4b6f844 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "devDependencies": { "@commitlint/cli": "^21.2.3", "@commitlint/config-conventional": "^21.2.3", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-utils": "^1.15.0", "@data-fair/openapi-mcp": "^0.14.2", "@json-layout/agents": "^0.5.0", @@ -53,7 +53,7 @@ "@data-fair/catalogs-shared": "*", "@data-fair/lib-common-types": "^1.28.1", "@data-fair/lib-express": "^2.2.0", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-node-registry": "^0.7.2", "@data-fair/lib-utils": "^1.15.0", "config": "^5.0.1", @@ -581,9 +581,9 @@ } }, "node_modules/@data-fair/lib-node": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@data-fair/lib-node/-/lib-node-3.0.0.tgz", - "integrity": "sha512-kVFuDxUqSwlEyvIXSyviZYa7wTJiXc1RHVTnIjnk+yZafCA09D3aWNWpKbKvOtwxbAGYh3sBi0jGy91cX4xVag==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@data-fair/lib-node/-/lib-node-3.1.0.tgz", + "integrity": "sha512-kaSrMtAYOfyXpFw/mQzjRD0M9mvcYd3TfEXTS7ZR+TtwOk5inmJlj1CJlX51OEqseHmpbG2kOhchYwLuifFR1g==", "license": "MIT", "dependencies": { "@data-fair/lib-common-types": "^1.25.0", @@ -601,6 +601,7 @@ "semver": "^7.6.3" }, "peerDependencies": { + "@playwright/test": "1", "mongodb": "6", "pino-pretty": "13", "prom-client": "15", @@ -608,6 +609,9 @@ "ws": "8" }, "peerDependenciesMeta": { + "@playwright/test": { + "optional": true + }, "mongodb": { "optional": true }, @@ -2455,7 +2459,7 @@ "version": "1.63.0", "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.63.0.tgz", "integrity": "sha512-oxMK4vllB9RK5NQ2l1pq1IfOf2AvnEuj/vYGDj0H2nMtmtZpKtCwt/l00GEO6xjGfpBNAvjovvYdCm50dRQkpQ==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "dependencies": { "playwright": "1.63.0" @@ -7659,7 +7663,7 @@ "version": "1.63.0", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.63.0.tgz", "integrity": "sha512-+7ziBLidS4NaNCdt57SUDT+wYmmd5fmiQejUic/kb+YsYSCPyOOE9sebzMjNmQrsnNpDJqd4WHvV/8lfKfUDUg==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "dependencies": { "playwright-core": "1.63.0" @@ -7675,7 +7679,7 @@ "version": "1.63.0", "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz", "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" @@ -10477,7 +10481,7 @@ "worker": { "dependencies": { "@data-fair/catalogs-shared": "*", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-node-registry": "^0.7.2", "axios": "^1.20.0", "config": "^5.0.1", diff --git a/package.json b/package.json index 4d42374..476d4af 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "devDependencies": { "@commitlint/cli": "^21.2.3", "@commitlint/config-conventional": "^21.2.3", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-utils": "^1.15.0", "@data-fair/openapi-mcp": "^0.14.2", "@json-layout/agents": "^0.5.0", diff --git a/tests/fixtures/login.ts b/tests/fixtures/login.ts index 3eb474f..67a568a 100644 --- a/tests/fixtures/login.ts +++ b/tests/fixtures/login.ts @@ -1,82 +1,17 @@ -import { test as base, expect, request, type BrowserContext } from '@playwright/test' +import { test as base, expect } from '@playwright/test' +import { loginFixtures, type GoToWithAuth } from '@data-fair/lib-node/playwright-login.js' import { processLogs } from '../support/process-logs.ts' -/** - * The `test` of every api and e2e spec. - * - * Sessions come from simple-directory's API, not its login form: one login per user and account - * (POST /api/auth/password, then its callback), shared by every test of the worker. - * Sharing is safe because no page ever presents the exchange token (id_token_ex): lib-vue skips - * its session keepalive while localStorage['sd-keepalive'] is recent, and the init script below - * sets it in the future. Without that, each page load would rotate the single-use token and the - * next test replaying the old one outside simple-directory's 60 s grace would be logged out. - * The id_token itself expires after 15 min, so a session older than 10 min is logged in again. - */ -type AccountOpts = { org?: string, dep?: string, adminMode?: boolean } -type Cookies = Parameters[0] - const baseUrl = `http://${process.env.DEV_HOST}:${process.env.NGINX_PORT}` -const directoryUrl = `${baseUrl}/simple-directory` -const maxAge = 10 * 60 * 1000 -const sessions = new Map() - -const apiLogin = async (user: string, opts: AccountOpts): Promise => { - const ctx = await request.newContext() - try { - const res = await ctx.post(`${directoryUrl}/api/auth/password`, { - params: { redirect: `${baseUrl}/catalogs/` }, - data: { email: `${user}@test.com`, password: 'passwd', ...opts } - }) - expect(res.ok(), `login of ${user} failed: ${res.status()} ${await res.text()}`).toBe(true) - // the callback sets the session cookies and redirects to the app - const callback = await ctx.get(await res.text(), { maxRedirects: 0 }) - expect(callback.status(), `login callback of ${user} failed: ${callback.headers().location}`).toBe(302) - return (await ctx.storageState()).cookies - } finally { - await ctx.dispose() - } -} - -const sessionCookies = async (user: string, opts: AccountOpts) => { - const key = [user, opts.org ?? '', opts.dep ?? '', opts.adminMode ?? ''].join('|') - let session = sessions.get(key) - if (!session || Date.now() - session.at > maxAge) { - session = { at: Date.now(), cookies: await apiLogin(user, opts) } - sessions.set(key, session) - } - return session.cookies -} /** - * - `goToWithAuth(url, user, opts?)`: lands on url logged in as user, with the organization / - * department of opts as active account, or in admin mode (super admins). - * - `page` override: French, cache bypass, and no session keepalive (see above). + * The `test` of every api and e2e spec. + * - `goToWithAuth(url, user, account?)` and the `page` override: the shared login helper of + * @data-fair/lib-node (sessions from simple-directory's API, one login per user and account). * - on a failure, the last lines of the api and worker logs are attached to the report and the trace. */ -export const test = base.extend<{ - goToWithAuth: (url: string, user: string, opts?: AccountOpts) => Promise, - diagnostics: void -}>({ - page: async ({ page }, use) => { - await page.context().addCookies([ - { name: 'i18n_lang', value: 'fr', url: baseUrl }, - { name: 'cache_bypass', value: '1', url: baseUrl } - ]) - // ponytail: relies on lib-vue's internal key (decided: option A of the playwright standard §4.1) - await page.context().addInitScript(() => { - window.localStorage.setItem('sd-keepalive', String(Date.now() + 365 * 86400_000)) - }) - await use(page) - }, - - goToWithAuth: async ({ page, context }, use) => { - await use(async (url, user, opts = {}) => { - // replace the session of a previous call (another user or account) as a whole - await context.clearCookies({ name: /^id_token/ }) - await context.addCookies(await sessionCookies(user, opts)) - await page.goto(url) - }) - }, +export const test = base.extend<{ goToWithAuth: GoToWithAuth, diagnostics: void }>({ + ...loginFixtures({ baseUrl, redirect: `${baseUrl}/catalogs/` }), // eslint-disable-next-line no-empty-pattern -- playwright requires a destructuring pattern here diagnostics: [async ({}, use, testInfo) => { diff --git a/worker/package.json b/worker/package.json index d0bbaac..e9ef65f 100644 --- a/worker/package.json +++ b/worker/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@data-fair/catalogs-shared": "*", - "@data-fair/lib-node": "^3.0.0", + "@data-fair/lib-node": "^3.1.0", "@data-fair/lib-node-registry": "^0.7.2", "axios": "^1.20.0", "config": "^5.0.1",