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
29 changes: 11 additions & 18 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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 <service>` 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.
Expand Down Expand Up @@ -91,7 +87,8 @@ npx playwright test path/to/file # a specific file
```

Tests are organized under `tests/features/<topic>/<name>.{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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 13 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
79 changes: 7 additions & 72 deletions tests/fixtures/login.ts
Original file line number Diff line number Diff line change
@@ -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<BrowserContext['addCookies']>[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<string, { at: number, cookies: Cookies }>()

const apiLogin = async (user: string, opts: AccountOpts): Promise<Cookies> => {
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<void>,
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) => {
Expand Down
2 changes: 1 addition & 1 deletion worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading