Files
computer-playbook/roles/web-app-discourse/files/playwright/addons/docker_manager.spec.js
kevinveenbirkenbachandClaude Opus 4.8 07c6ad8e7c test(e2e): scale every nav click + timeout literal for onion targets
Over Tor the redirect chain behind a login/logout/OIDC click routinely exceeds Playwright's fixed 30s action timeout, so the click throws before the flow's scaled waits run. Sweep all role Playwright suites and the shared persona helpers: give every navigation/auth-transition click an onion-scaled timeout (.click({ timeout: resolveTimeout(30_000) })) and route the remaining raw millisecond literals (timeout options, waitForTimeout, sleep-promise setTimeout, positional wait args) through resolveTimeout. Local UI clicks (menus, toggles, modal dismissals, DOM clicks inside evaluate) stay untouched.

Two new lints keep it that way: test_no_raw_timeout_literals forbids raw numeric timeout literals in Playwright specs (opt-out: nocheck: raw-timeout), test_persona_clicks_scaled requires every click in the shared persona auth flows to carry a resolveTimeout timeout (opt-out: nocheck: unscaled-click).

Verified: node --check on all 133 changed JS files, all 13 playwright lints green, make autoformat clean, make test green (2745+196+163+4 tests OK).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-14 11:35:53 +02:00

111 lines
4.1 KiB
JavaScript

const { test, expect } = require("@playwright/test");
const { resolveTimeout } = require("../timeouts");
const { skipUnlessAddonEnabled } = require("../addon-gating");
const { normalizeBaseUrl, decodeDotenvQuotedValue, performKeycloakLoginForm, gotoOnion } = require("../personas");
test.use({ ignoreHTTPSErrors: true });
const oidcIssuerUrl = normalizeBaseUrl(process.env.OIDC_ISSUER_URL || "");
const discourseBaseUrl = normalizeBaseUrl(process.env.DISCOURSE_BASE_URL || "");
const adminUsername = decodeDotenvQuotedValue(process.env.ADMIN_USERNAME);
const adminPassword = decodeDotenvQuotedValue(process.env.ADMIN_PASSWORD);
async function signInViaOidc(page) {
const expectedOidcAuthUrl = `${oidcIssuerUrl}/protocol/openid-connect/auth`;
await gotoOnion(page, `${discourseBaseUrl}/`);
const oidcSignIn = page
.locator("a, button")
.filter({ hasText: /sign\s*in\s+with\s+oidc|sign\s*in\s+with\s+sso|continue\s+with\s+oidc|continue\s+with\s+sso|single\s+sign[-\s]*on|log\s*in|sign\s*up/i })
.first();
if ((await oidcSignIn.count().catch(() => 0)) > 0) {
await oidcSignIn.click({ timeout: resolveTimeout(30_000) });
} else {
await gotoOnion(page, `${discourseBaseUrl}/auth/oidc`).catch(() => {});
}
await expect
.poll(() => page.url(), {
timeout: resolveTimeout(60_000),
message: `expected redirect to Keycloak OIDC auth (${expectedOidcAuthUrl})`,
})
.toContain(expectedOidcAuthUrl);
await performKeycloakLoginForm(page, adminUsername, adminPassword);
await expect
.poll(() => page.url(), {
timeout: resolveTimeout(60_000),
message: `expected redirect back to discourse at ${discourseBaseUrl}`,
})
.toContain(discourseBaseUrl);
}
function pluginName(plugin) {
return String((plugin && (plugin.name || plugin.id)) || "").toLowerCase();
}
test("docker_manager: the docker_manager plugin is installed and registered on the Discourse instance", async ({ page }) => {
skipUnlessAddonEnabled("docker_manager");
expect(oidcIssuerUrl, "OIDC_ISSUER_URL must be set").toBeTruthy();
expect(discourseBaseUrl, "DISCOURSE_BASE_URL must be set").toBeTruthy();
expect(adminUsername, "ADMIN_USERNAME must be set").toBeTruthy();
expect(adminPassword, "ADMIN_PASSWORD must be set").toBeTruthy();
try {
await page.context().clearCookies();
await signInViaOidc(page);
await expect(page.locator("body")).toContainText(
/topic|category|welcome|latest|discourse/i,
{ timeout: resolveTimeout(60_000) },
);
const plugins = await page.evaluate(async (base) => {
const res = await fetch(`${base}/admin/plugins.json`, {
headers: { Accept: "application/json" },
credentials: "include",
});
if (!res.ok) return { ok: false, status: res.status };
const body = await res.json();
return { ok: true, plugins: (body && body.plugins) || [] };
}, discourseBaseUrl);
expect(
plugins.ok,
`expected /admin/plugins.json to be reachable as admin (status ${plugins.status})`,
).toBe(true);
const dockerManager = plugins.plugins.find(
(p) => pluginName(p) === "docker_manager" || pluginName(p) === "discourse-docker-manager",
);
expect(
dockerManager,
"the docker_manager plugin must be present in /admin/plugins.json (proves the upstream plugin was cloned and registered; when docker_manager is enabled but absent the install failed — the test MUST fail here, not skip)",
).toBeTruthy();
expect(
dockerManager.enabled,
"the docker_manager plugin must be enabled on the running instance",
).toBe(true);
const upgradeResponse = await page.evaluate(async (base) => {
const res = await fetch(`${base}/admin/upgrade.json`, {
headers: { Accept: "application/json" },
credentials: "include",
});
return { ok: res.ok, status: res.status };
}, discourseBaseUrl);
expect(
upgradeResponse.ok,
`the docker_manager upgrade surface (/admin/upgrade.json) the plugin owns must be served (status ${upgradeResponse.status})`,
).toBe(true);
} finally {
await page.context().clearCookies().catch(() => {});
}
});