From 46fc790fdb3fb1854efcaa73270c0bd676d8e077 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 28 Mar 2026 18:30:13 +0100 Subject: [PATCH] docs: add playwright role file guidance --- .github/PULL_REQUEST_TEMPLATE/server.md | 4 +- docs/agents/README.md | 2 +- docs/agents/action/develop.md | 2 + docs/agents/files/README.md | 2 +- docs/agents/files/role/README.md | 2 + docs/agents/files/role/javascript.js.md | 1 + docs/agents/files/role/playwright.env.j2.md | 35 +++++++++++++++++ docs/agents/files/role/playwright.spec.js.md | 38 +++++++++++++++++++ docs/agents/files/role/style.css.md | 1 + docs/contributing/code/role/README.md | 2 + docs/contributing/code/role/javascript.js.md | 1 + .../code/role/playwright.env.j2.md | 28 ++++++++++++++ .../code/role/playwright.spec.js.md | 29 ++++++++++++++ docs/contributing/code/role/style.css.md | 1 + docs/contributing/development/testing.md | 14 +++---- 15 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 docs/agents/files/role/playwright.env.j2.md create mode 100644 docs/agents/files/role/playwright.spec.js.md create mode 100644 docs/contributing/code/role/playwright.env.j2.md create mode 100644 docs/contributing/code/role/playwright.spec.js.md diff --git a/.github/PULL_REQUEST_TEMPLATE/server.md b/.github/PULL_REQUEST_TEMPLATE/server.md index d49c68b35c..957a27d016 100644 --- a/.github/PULL_REQUEST_TEMPLATE/server.md +++ b/.github/PULL_REQUEST_TEMPLATE/server.md @@ -80,8 +80,8 @@ Check the relevant rows and explain intentional omissions in `Additional Notes`. | [ ] | `templates/javascript.js.j2` or `files/javascript.js` | When the role injects custom frontend behavior | Defines the role-local JavaScript that adapts UI behavior or integration glue in the browser. See [Contributing `javascript.js`](../../docs/contributing/code/role/javascript.js.md). | | [ ] | `users/main.yml` | When the role bootstraps users or identities | Defines user bootstrap or role-specific user management data. | | [ ] | `files/Dockerfile` | When a custom image is required | Provides a custom image build path. Prefer this over `Dockerfile.j2`. | -| [ ] | `templates/playwright.env.j2` | When Playwright coverage is included | Configures the Playwright test environment. | -| [ ] | `files/playwright.spec.js` | When Playwright coverage is included | Defines the Playwright login and logout test flow. | +| [ ] | `templates/playwright.env.j2` | When Playwright coverage is included | Configures the Playwright test environment. See [Contributing `playwright.env.j2`](../../docs/contributing/code/role/playwright.env.j2.md). | +| [ ] | `files/playwright.spec.js` | When Playwright coverage is included | Defines the Playwright login and logout test flow. See [Contributing `playwright.spec.js`](../../docs/contributing/code/role/playwright.spec.js.md). | ### Registered diff --git a/docs/agents/README.md b/docs/agents/README.md index 75cb7c3674..90ffa97ca0 100644 --- a/docs/agents/README.md +++ b/docs/agents/README.md @@ -6,5 +6,5 @@ For contributor-side code structure and repository wiring, see [Code](../contrib ## Read in Order 1. Read [Action](action/README.md) first for commit, development, debugging, iteration, and pull-request workflows. -2. Read [Files](files/README.md) for file-specific implementation guidance such as role `style.css` and `javascript.js`. +2. Read [Files](files/README.md) for file-specific implementation guidance such as role `style.css`, `javascript.js`, and Playwright role files. 3. Read [Meta](meta/README.md) for purpose, help, ethics, and about references. diff --git a/docs/agents/action/develop.md b/docs/agents/action/develop.md index 54638c7d58..877c988cd8 100644 --- a/docs/agents/action/develop.md +++ b/docs/agents/action/develop.md @@ -13,6 +13,8 @@ - Treat the matching Pull Request template described in [Pull Request Templates](../../contributing/flow/pull-request.md) and stored in [PULL_REQUEST_TEMPLATE](../../../.github/PULL_REQUEST_TEMPLATE) as the SPOT for requirements, file checks, validation expectations, and the Definition of Done. - When you implement role-local CSS, check [Role `style.css`](../files/role/style.css.md) first so you can see how CSS should be implemented before you add or rewrite overrides. - When you implement role-local JavaScript, check [Role `javascript.js`](../files/role/javascript.js.md) first so you can see how browser-side behavior should be implemented before you add or rewrite injected scripts. +- When you implement role-local Playwright environment templates, check [Role `playwright.env.j2`](../files/role/playwright.env.j2.md) first so the rendered test inputs match the supported user journey. +- When you implement or refactor role-local Playwright specs, check [Role `playwright.spec.js`](../files/role/playwright.spec.js.md) first so end-to-end coverage stays aligned with the role behavior. - Start from the smallest app-specific change that can be validated locally, then expand only when the requirements or behavior demand it. - Keep the implementation, local validation, and PR template in sync so the app can be reviewed without guessing the intent. diff --git a/docs/agents/files/README.md b/docs/agents/files/README.md index 051dc99417..08f0751d06 100644 --- a/docs/agents/files/README.md +++ b/docs/agents/files/README.md @@ -9,4 +9,4 @@ Store here how recurring files should be implemented, generated, updated, or rev ## Read in Order -1. Read [Role Files](role/README.md) when you need guidance for recurring role files such as `style.css` and `javascript.js`. +1. Read [Role Files](role/README.md) when you need guidance for recurring role files such as `style.css`, `javascript.js`, `playwright.env.j2`, and `playwright.spec.js`. diff --git a/docs/agents/files/role/README.md b/docs/agents/files/role/README.md index da20602225..565c6ff955 100644 --- a/docs/agents/files/role/README.md +++ b/docs/agents/files/role/README.md @@ -11,3 +11,5 @@ Store here how recurring role files should be implemented, generated, extended, 1. Read [`style.css`](style.css.md) when you work on role-local CSS or theming. 2. Read [`javascript.js`](javascript.js.md) when you work on role-local browser behavior or injected frontend scripts. +3. Read [`playwright.env.j2`](playwright.env.j2.md) when you work on role-local Playwright environment templates. +4. Read [`playwright.spec.js`](playwright.spec.js.md) when you work on role-local Playwright end-to-end tests. diff --git a/docs/agents/files/role/javascript.js.md b/docs/agents/files/role/javascript.js.md index 35b2a479fc..68840f477c 100644 --- a/docs/agents/files/role/javascript.js.md +++ b/docs/agents/files/role/javascript.js.md @@ -34,4 +34,5 @@ For injector wiring, activation, and repository-wide behavior rules, see [Contri - Compare the implemented behavior against the rendered UI so missing hooks, duplicate handlers, broken selectors, and unexpected side effects become visible. - At minimum, inspect and compare the start page and the login page because these pages usually expose the most important navigation, authentication, and first-load behavior. - Check the browser console for JavaScript errors or repeated side effects after the script is injected. +- If the change affects user-visible behavior, add or update the matching end-to-end coverage in [Role `playwright.spec.js`](playwright.spec.js.md). - Check that the final JavaScript still feels like a small role-local adaptation of the target application, not a forked frontend implementation. diff --git a/docs/agents/files/role/playwright.env.j2.md b/docs/agents/files/role/playwright.env.j2.md new file mode 100644 index 0000000000..c84a083d9e --- /dev/null +++ b/docs/agents/files/role/playwright.env.j2.md @@ -0,0 +1,35 @@ +[Back to Role Files](README.md) + +# playwright.env.j2 + +This page is the SPOT for automatically generating and updating role-local `playwright.env.j2` files. +Use this page for the rendered test input surface, variable naming, and entry-point selection. +For runner discovery, staging, and repository-side contract rules, see [Contributing `playwright.env.j2`](../../../contributing/code/role/playwright.env.j2.md). +For the matching scenario implementation, see [Role `playwright.spec.js`](playwright.spec.js.md). + +## Goal + +- Provide only the environment values that the role-local Playwright suite actually needs. +- Keep variable names stable between `playwright.env.j2` and `playwright.spec.js`. +- Render the real entry point, URLs, feature flags, and credentials that the deployed role exposes. + +## Implement + +- Define `APP_BASE_URL` as the real start page of the test flow. +- If `compose.services.dashboard.enabled` is enabled for the role, point `APP_BASE_URL` to the dashboard entry instead of jumping directly into the app. +- Expose app-specific base URLs, issuer URLs, feature flags, and credentials only when the spec consumes them. +- Use `dotenv_quote` for values that may contain spaces, special characters, or shell-sensitive content. +- When the suite covers multiple personas such as `biber` and `administrator`, expose separate variables for each scenario instead of overloading one shared credential pair. + +## Avoid + +- Do not expose unused variables, duplicate values, or secrets that the spec never reads. +- Do not hardcode domains or credentials that should come from role variables, inventory, or lookups. +- Do not let variable names drift away from the names consumed in `playwright.spec.js`. +- Do not point tests directly to the app when the supported user journey starts in the dashboard. + +## Review + +- Check that every environment variable referenced in `playwright.spec.js` is present in the rendered `.env`. +- Check that `APP_BASE_URL`, app URLs, issuer URLs, and feature toggles match the deployed role. +- Check that persona-specific credentials such as `biber` and `administrator` map to the intended scenarios. diff --git a/docs/agents/files/role/playwright.spec.js.md b/docs/agents/files/role/playwright.spec.js.md new file mode 100644 index 0000000000..7784843b64 --- /dev/null +++ b/docs/agents/files/role/playwright.spec.js.md @@ -0,0 +1,38 @@ +[Back to Role Files](README.md) + +# playwright.spec.js + +This page is the SPOT for automatically generating and updating role-local `playwright.spec.js` files. +Use this page for scenario design, selector strategy, and live end-to-end review. +For runner integration and repository-wide scenario requirements, see [Contributing `playwright.spec.js`](../../../contributing/code/role/playwright.spec.js.md). +For the matching rendered input contract, see [Role `playwright.env.j2`](playwright.env.j2.md). + +## Goal + +- Verify real user-facing browser flows from the supported entry point through a successful logout. +- Keep the spec aligned with the role's actual login, navigation, and post-login behavior. +- Capture user-visible behavior introduced by role-local `style.css`, `javascript.js`, or authentication integrations. + +## Implement + +- Start from `APP_BASE_URL`, and if the role exposes the dashboard entry path, enter the application from the dashboard. +- Verify login and logout end to end. +- When the role covers both `biber` and `administrator`, keep separate scenarios for both personas. +- When `style.css` or `javascript.js` is implemented or refactored, add or update Playwright assertions for the affected visible behavior. +- Prefer stable selectors, accessible roles, and visible UI states over brittle DOM assumptions. +- Use explicit waits for meaningful page state changes instead of fixed sleeps wherever practical. + +## Avoid + +- Do not stop at URL assertions or static text checks when the real requirement is a user-visible flow. +- Do not skip the logout path or finish while the session is still authenticated. +- Do not bypass the dashboard when the role is meant to start there. +- Do not rely on fragile selectors or timing hacks when more stable hooks exist. + +## Review + +- Run the spec against the live application, not only against the file contents. +- Inspect the start page and the login page as part of the end-to-end path. +- Check the browser console for errors when the flow depends on injected JavaScript. +- Check that changed CSS or JavaScript behavior is covered by the role-local Playwright suite. +- Check that the application returns to a clearly logged-out state at the end of the test. diff --git a/docs/agents/files/role/style.css.md b/docs/agents/files/role/style.css.md index ddbca62a98..bfbb12d7f8 100644 --- a/docs/agents/files/role/style.css.md +++ b/docs/agents/files/role/style.css.md @@ -43,4 +43,5 @@ For repository wiring, inventory keys, and the generated palette contract, see [ - Check the result with live inspection in the running application, not only by reading the CSS or generated files. - Compare the implemented styling against the rendered UI so mismatches between intended tokens and actual browser output become visible. - At minimum, inspect and compare the start page and the login page because both usually expose the most important shared surfaces, text colors, forms, and navigation patterns. +- If the change affects user-visible behavior, add or update the matching end-to-end coverage in [Role `playwright.spec.js`](playwright.spec.js.md). - Check that the final CSS still looks like a themed version of the target application, not a forked redesign. diff --git a/docs/contributing/code/role/README.md b/docs/contributing/code/role/README.md index a1151ea193..d8e7bf9e45 100644 --- a/docs/contributing/code/role/README.md +++ b/docs/contributing/code/role/README.md @@ -11,5 +11,7 @@ Use this page as the entry point for rules that apply to recurring role files an - [`style.css`](style.css.md) - [`javascript.js`](javascript.js.md) +- [`playwright.env.j2`](playwright.env.j2.md) +- [`playwright.spec.js`](playwright.spec.js.md) If you are working on recurring role files, start here before you go deeper. diff --git a/docs/contributing/code/role/javascript.js.md b/docs/contributing/code/role/javascript.js.md index 24e4a16c51..604a185f72 100644 --- a/docs/contributing/code/role/javascript.js.md +++ b/docs/contributing/code/role/javascript.js.md @@ -5,6 +5,7 @@ This page is the SPOT for role-local JavaScript injection and browser-side integration behavior. Use this page for injector wiring, activation, and repository-wide behavior rules. For implementation scope, DOM strategy, and live review, see [Agent `javascript.js`](../../../agents/files/role/javascript.js.md). +For browser-side validation requirements after visible behavior changes, see [Contributing `playwright.spec.js`](playwright.spec.js.md). ## `javascript.js.j2` diff --git a/docs/contributing/code/role/playwright.env.j2.md b/docs/contributing/code/role/playwright.env.j2.md new file mode 100644 index 0000000000..304b6e54e2 --- /dev/null +++ b/docs/contributing/code/role/playwright.env.j2.md @@ -0,0 +1,28 @@ +[Back to Role](README.md) + +# `playwright.env.j2` + +This page is the SPOT for role-local Playwright environment templates. +Use this page for runner discovery, `.env` rendering, and the repository-side variable contract. +For implementation scope, variable naming, and rendered-output review, see [Agent `playwright.env.j2`](../../../agents/files/role/playwright.env.j2.md). +For the matching scenario requirements, see [Contributing `playwright.spec.js`](playwright.spec.js.md). + +## Role Contract + +- `test-e2e-playwright` discovers Playwright-enabled roles through `templates/playwright.env.j2`. +- The file is rendered into `.env` and passed to the Playwright container through `--env-file`. +- The rendered environment must provide the inputs expected by the matching `files/playwright.spec.js`. + +## Variable Rules + +- `APP_BASE_URL` defines the supported start page of the role's test flow. +- If `compose.services.dashboard.enabled` is enabled, `APP_BASE_URL` should resolve to the dashboard URL because the test flow must start there. +- Provide additional app-specific URLs, feature flags, issuer URLs, and credentials only when the spec consumes them. +- Use explicit variable names that match the scenarios in the spec, especially when multiple personas such as `biber` and `administrator` are covered. +- Quote values with `dotenv_quote` when the rendered value may contain spaces or special characters. + +## Scope + +- Keep the template surface small and explicit. +- Do not use `playwright.env.j2` as a general dump for unrelated runtime variables. +- Put the scenario requirements in [Contributing `playwright.spec.js`](playwright.spec.js.md). diff --git a/docs/contributing/code/role/playwright.spec.js.md b/docs/contributing/code/role/playwright.spec.js.md new file mode 100644 index 0000000000..c11ccbe6e9 --- /dev/null +++ b/docs/contributing/code/role/playwright.spec.js.md @@ -0,0 +1,29 @@ +[Back to Role](README.md) + +# `playwright.spec.js` + +This page is the SPOT for role-local Playwright test specs. +Use this page for runner integration, minimum coverage, and repository-wide scenario requirements. +For implementation scope, selector strategy, and live review, see [Agent `playwright.spec.js`](../../../agents/files/role/playwright.spec.js.md). +For the matching rendered environment contract, see [Contributing `playwright.env.j2`](playwright.env.j2.md). + +## Runner Contract + +- `test-e2e-playwright` copies `files/playwright.spec.js` into the staged test project as `tests/playwright.spec.js`. +- The spec consumes the `.env` rendered from `templates/playwright.env.j2`. +- `package.json` and `playwright.config.js` stay centralized in `roles/test-e2e-playwright/files/`. + +## Requirements + +- Every Playwright-enabled role must verify login and logout. +- Every role with `compose.services.dashboard.enabled` must start the test flow from the dashboard. +- When the role provides both `biber` and `administrator` scenarios, login and logout for both must be covered. +- When role-local `javascript.js` or `style.css` is implemented or refactored, the affected user-visible behavior must be added to or updated in the Playwright suite. +- Assertions must verify real UI states and user-visible outcomes, not only URL transitions or static strings. +- The suite must finish in a clearly logged-out state. + +## Scenario Rules + +- Name tests after the real flow they verify, for example dashboard to app login and logout. +- Keep persona-specific scenarios explicit when the role distinguishes between different user paths. +- Add extra coverage when relevant, for example OIDC, LDAP, or dashboard-specific navigation. diff --git a/docs/contributing/code/role/style.css.md b/docs/contributing/code/role/style.css.md index 46a0475ad9..cbeca84a97 100644 --- a/docs/contributing/code/role/style.css.md +++ b/docs/contributing/code/role/style.css.md @@ -5,6 +5,7 @@ This page is the SPOT for role-local CSS and theming. Use this page for repository wiring, inventory keys, and palette mapping. For implementation scope, override strategy, and live review, see [Agent `style.css`](../../../agents/files/role/style.css.md). +For browser-side validation requirements after visible UI changes, see [Contributing `playwright.spec.js`](playwright.spec.js.md). ## `style.css.j2` diff --git a/docs/contributing/development/testing.md b/docs/contributing/development/testing.md index facdc6b2b7..44e13c460c 100644 --- a/docs/contributing/development/testing.md +++ b/docs/contributing/development/testing.md @@ -62,16 +62,19 @@ To enable Playwright for a `web-*` role, provide: - `templates/playwright.env.j2` - `files/playwright.spec.js` +Use [Contributing `playwright.env.j2`](../code/role/playwright.env.j2.md) and [Contributing `playwright.spec.js`](../code/role/playwright.spec.js.md) as the SPOT for the file-level contract and scenario requirements. + During the deploy stage, the shared `test-e2e-playwright` role: - discovers the relevant app roles - stages the test project - renders the `.env` +- copies the role-local `playwright.spec.js` - injects the shared `package.json` and `playwright.config.js` - waits until the app is reachable - runs Playwright in Docker -In practice, Playwright coverage is usually exercised through local deploy flows and deploy CI runs. Every `web-*` suite should verify at least login and logout. +In practice, Playwright coverage is usually exercised through local deploy flows and deploy CI runs. ## Testing Standards @@ -93,19 +96,16 @@ Treat these rules as the baseline for all validation categories below. ### Playwright - Playwright tests are required for `web-*` roles. -- Every Playwright test suite must verify login and logout. +- Use [Contributing `playwright.env.j2`](../code/role/playwright.env.j2.md) and [Contributing `playwright.spec.js`](../code/role/playwright.spec.js.md) as the SPOT for role-local Playwright file requirements. ### Development Procedure - Analyze the code first. - Build hypotheses before writing the test. -- Write the Playwright test. +- Write or update the role-local Playwright files. - Run it against a fresh pure Docker image. - Add additional procedures when relevant, for example OIDC or Keycloak. -- Start from the dashboard. -- End with a successful logout. ### Minimum Requirements -- The test must verify that login is possible. -- The test must verify that logout is possible. +- Follow the scenario requirements in [Contributing `playwright.spec.js`](../code/role/playwright.spec.js.md).