mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Both helpers were inlined verbatim in 71 of the role-local
`playwright.spec.js` files (52 with the compact form, 19 with the
verbose form, plus one parameter-name variant). All bodies were
semantically identical.
Changes
-------
- New `roles/test-e2e-playwright/files/personas/utils/dotenv.js` holds
the canonical pair (`decodeDotenvQuotedValue` and `normalizeBaseUrl`),
re-exported through `personas/utils/index.js` so specs that
`require("./personas")` get them via the existing aggregator.
- Every role spec drops its inline copies and pulls the helpers from
`./personas` instead. Specs that only reference one of the two
carry only that one in the destructuring (no unused-import noise).
Doc
---
`docs/contributing/artefact/files/role/playwright.specs.js.md` no
longer carries the "once a third spec needs them, MUST be promoted"
directive: the helpers live at the shared path and inline copies are
forbidden.
Verification
------------
- 419 passed / 1 skipped / 0 failed across `tests/lint/`,
`tests/integration/roles/`, `tests/unit/plugins/lookup/`.
- `make lint-javascript`: 0 errors, 283 warnings (unchanged from
baseline; no new unused-imports introduced).
- 0 inline `function decodeDotenvQuotedValue|normalizeBaseUrl`
definitions remain in any role spec.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
/**
|
|
* Dotenv-quote decoders shared by every Playwright spec.
|
|
*
|
|
* `docker --env-file` preserves the surrounding double-quotes that the
|
|
* project's `dotenv_quote` Jinja filter emits, so specs MUST decode
|
|
* the quoted values before building URLs or typing credentials. The
|
|
* `$$` -> `$` replacement undoes the dollar-sign escape that
|
|
* `dotenv_quote` applies on the way out.
|
|
*
|
|
* `decodeDotenvQuotedValue(raw)` returns the decoded string (or
|
|
* the input untouched when it is not a doubly-quoted dotenv value).
|
|
*
|
|
* `normalizeBaseUrl(raw)` decodes AND strips a trailing slash so
|
|
* callers can append paths without `//` accidents.
|
|
*/
|
|
|
|
function decodeDotenvQuotedValue(value) {
|
|
if (typeof value !== "string" || value.length < 2) {
|
|
return value;
|
|
}
|
|
if (!(value.startsWith('"') && value.endsWith('"'))) {
|
|
return value;
|
|
}
|
|
const encoded = value.slice(1, -1);
|
|
try {
|
|
return JSON.parse(`"${encoded}"`).replace(/\$\$/g, "$");
|
|
} catch {
|
|
return encoded.replace(/\$\$/g, "$");
|
|
}
|
|
}
|
|
|
|
function normalizeBaseUrl(value) {
|
|
return decodeDotenvQuotedValue(value || "").replace(/\/$/, "");
|
|
}
|
|
|
|
module.exports = { decodeDotenvQuotedValue, normalizeBaseUrl };
|