Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(setup): prove api-backed first-session handoff

rcourtman498364820913
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 921a5df08c..1c793dc5d2 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -168,6 +168,14 @@ management, and fleet control surfaces.
8. Keep post-install lifecycle completion explicit inside
`frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx`
and `frontend-modern/src/components/Settings/useInfrastructureInstallState.tsx`.
+9. Keep the dev first-session proof deterministic on the real wizard path:
+ `tests/integration/tests/helpers.ts` and
+ `tests/integration/tests/11-first-session.spec.ts` must refresh first-run
+ state through `/api/security/dev/reset-first-run`, then prove both the
+ canonical `Open Infrastructure Install` handoff and the explicit
+ `Open Platform connections` handoff against the live setup wizard instead
+ of relying on stale bootstrap tokens, dashboard fallbacks, or preview-only
+ coverage.
When the first host reports successfully, the install workflow must treat
that as a completion handoff with direct navigation into `/dashboard` and
`/settings/infrastructure/operations` instead of leaving operators on a
@@ -1311,6 +1319,10 @@ That same `SetupCompletionPanel` boundary must also stay on the direct
`setup-completion-install-surface` proof path, rather than relying only on shared
helper coverage or downstream install tests to catch lifecycle drift in the
setup completion surface.
+That same first-session browser proof must also exercise the explicit
+`Platform connections` completion action through the real setup wizard flow
+for API-backed starts like TrueNAS, rather than relying only on the preview
+route or prose-level assertions to represent the API-backed alternative.
The same ownership also covers manual install fallback in the infrastructure
settings surface: active and ignored Connected infrastructure rows must now
come from the backend-owned `connectedInfrastructure` projection instead of a
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 40e65b7ae3..d3aa5b3a0a 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -272,6 +272,13 @@ Own canonical runtime payload shapes between backend and frontend.
self-serve verification failures may render owned HTML, but they must
preserve originating Pulse context instead of collapsing into generic
control-plane failures.
+24. Keep `/api/security/dev/reset-first-run` transport-backed and genuinely
+ unauthenticated: when the dev reset route clears first-run auth it must
+ also clear any env-backed auth state that feeds `/api/security/status`, so
+ the status payload flips `hasAuthentication` to `false`, preserves
+ `bootstrapTokenPath`, and allows browser-owned first-session proof to
+ re-enter the real setup wizard instead of silently falling back to an
+ authenticated dashboard state.
22. Keep shared SSO test and metadata-preview transport fail-closed: SAML
metadata URLs and OIDC issuer URLs must reject non-HTTP or userinfo-bearing
inputs before any outbound request is attempted, and OIDC discovery must
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index b467f0a74d..5c78d6c66e 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -87,6 +87,12 @@ server-side update execution surfaces.
1. Update this contract when canonical deployment or installer entry points move
2. Keep deployment runtime and shared API proof routing aligned in `registry.json`
3. Preserve explicit coverage for installer parity, update planning, and deployment bootstrap behavior when these surfaces change
+4. Keep managed-runtime first-session helpers deterministic: shared browser
+ helpers under `tests/integration/tests/helpers.ts` may only drive the live
+ setup wizard through the current managed runtime after refreshing the
+ canonical dev reset route, and any helper changes that rely on hot-dev
+ browser/backend behavior must keep a managed-runtime recovery proof updated
+ in the same slice.
## Current State
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 33acb9864d..8bec0fe2f7 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -126,6 +126,12 @@ querying, and the operator-facing storage health presentation layer.
owned for dashboard composition, but when no resources have reported yet it
must route operators to `/settings/infrastructure/install` instead of
leaving the dashboard as a passive dead end.
+8. Keep dependent first-session reset behavior honest on the shared `internal/api/`
+ boundary: when `/api/security/dev/reset-first-run` is used to reopen the
+ setup wizard in browser proof, the resulting status payload must genuinely
+ expose unauthenticated setup so storage/recovery-owned empty-state and
+ dashboard handoff proof does not silently fall back to an authenticated
+ dashboard path.
## Current State
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index eefea89c18..1ee64239a0 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -3886,6 +3886,46 @@ func TestContract_ResetFirstRunSecurityResponseJSONSnapshot(t *testing.T) {
assertJSONSnapshot(t, got, want)
}
+func TestContract_ResetFirstRunSecurityClearsEnvBackedStatus(t *testing.T) {
+ t.Setenv("PULSE_DEV", "true")
+ t.Setenv("NODE_ENV", "")
+ t.Setenv("PULSE_AUTH_USER", "admin")
+ t.Setenv("PULSE_AUTH_PASS", "hashed-password")
+
+ record := newTokenRecord(t, "contract-reset-first-run-token-456.12345678", []string{config.ScopeSettingsWrite}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ cfg.AuthUser = "admin"
+ cfg.AuthPass = "hashed-password"
+
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ resetReq := httptest.NewRequest(http.MethodPost, "/api/security/dev/reset-first-run", nil)
+ resetReq.Header.Set("X-API-Token", "contract-reset-first-run-token-456.12345678")
+ resetRec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(resetRec, resetReq)
+ if resetRec.Code != http.StatusOK {
+ t.Fatalf("reset-first-run status = %d, want 200 (%s)", resetRec.Code, resetRec.Body.String())
+ }
+
+ statusReq := httptest.NewRequest(http.MethodGet, "/api/security/status", nil)
+ statusRec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(statusRec, statusReq)
+ if statusRec.Code != http.StatusOK {
+ t.Fatalf("security status = %d, want 200 (%s)", statusRec.Code, statusRec.Body.String())
+ }
+
+ var payload map[string]any
+ if err := json.Unmarshal(statusRec.Body.Bytes(), &payload); err != nil {
+ t.Fatalf("decode security status payload: %v", err)
+ }
+ if got, _ := payload["hasAuthentication"].(bool); got {
+ t.Fatalf("hasAuthentication = %v, want false", payload["hasAuthentication"])
+ }
+ if got, _ := payload["bootstrapTokenPath"].(string); strings.TrimSpace(got) == "" {
+ t.Fatalf("bootstrapTokenPath = %v, want non-empty", payload["bootstrapTokenPath"])
+ }
+}
+
func TestContract_SetupScriptURLResponseJSONSnapshot(t *testing.T) {
payload := map[string]any{
"type": "pve",
diff --git a/internal/api/security_first_run_reset.go b/internal/api/security_first_run_reset.go
index eeb45e0ff8..7db9a29861 100644
--- a/internal/api/security_first_run_reset.go
+++ b/internal/api/security_first_run_reset.go
@@ -44,6 +44,14 @@ func (r *Router) handleResetFirstRunSecurity(w http.ResponseWriter, req *http.Re
r.config.APITokens = nil
config.Mu.Unlock()
+ for _, key := range []string{
+ "PULSE_AUTH_USER",
+ "PULSE_AUTH_PASS",
+ "REQUIRE_AUTH",
+ } {
+ _ = os.Unsetenv(key)
+ }
+
if previousAuthUser != "" {
InvalidateUserSessions(previousAuthUser)
}
diff --git a/internal/api/security_first_run_reset_test.go b/internal/api/security_first_run_reset_test.go
index a6c5e64134..84eaff08c9 100644
--- a/internal/api/security_first_run_reset_test.go
+++ b/internal/api/security_first_run_reset_test.go
@@ -89,3 +89,43 @@ func TestResetFirstRunSecurityClearsAuthAndReturnsBootstrapToken(t *testing.T) {
t.Fatalf("bootstrap token path = %q, want %q", payload.BootstrapTokenPath, tokenPath)
}
}
+
+func TestResetFirstRunSecurityClearsEnvBackedAuthFromStatus(t *testing.T) {
+ t.Setenv("PULSE_DEV", "true")
+ t.Setenv("NODE_ENV", "")
+ t.Setenv("PULSE_AUTH_USER", "admin")
+ t.Setenv("PULSE_AUTH_PASS", "hashed-password")
+
+ record := newTokenRecord(t, "reset-first-run-token-345.12345678", []string{config.ScopeSettingsWrite}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ cfg.AuthUser = "admin"
+ cfg.AuthPass = "hashed-password"
+
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ resetReq := httptest.NewRequest(http.MethodPost, "/api/security/dev/reset-first-run", nil)
+ resetReq.Header.Set("X-API-Token", "reset-first-run-token-345.12345678")
+ resetRec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(resetRec, resetReq)
+ if resetRec.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d (%s)", resetRec.Code, resetRec.Body.String())
+ }
+
+ statusReq := httptest.NewRequest(http.MethodGet, "/api/security/status", nil)
+ statusRec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(statusRec, statusReq)
+ if statusRec.Code != http.StatusOK {
+ t.Fatalf("security status expected 200, got %d (%s)", statusRec.Code, statusRec.Body.String())
+ }
+
+ var payload map[string]any
+ if err := json.Unmarshal(statusRec.Body.Bytes(), &payload); err != nil {
+ t.Fatalf("decode security status: %v", err)
+ }
+ if got, _ := payload["hasAuthentication"].(bool); got {
+ t.Fatalf("expected hasAuthentication=false after reset, got %v", payload["hasAuthentication"])
+ }
+ if got, _ := payload["bootstrapTokenPath"].(string); strings.TrimSpace(got) == "" {
+ t.Fatalf("expected bootstrapTokenPath in unauthenticated status, got %v", payload["bootstrapTokenPath"])
+ }
+}
diff --git a/tests/integration/tests/11-first-session.spec.ts b/tests/integration/tests/11-first-session.spec.ts
index e59155fe9b..021a068a68 100644
--- a/tests/integration/tests/11-first-session.spec.ts
+++ b/tests/integration/tests/11-first-session.spec.ts
@@ -3,11 +3,11 @@ import { ensureAuthenticated, ensureFirstRunExperience, navigateToSettings, apiR
/**
* Dedicated first-session E2E test covering the full journey:
- * wizard → infrastructure operations handoff → settings discovery → gated panel guards
+ * wizard → canonical first-session handoffs → settings discovery → gated panel guards
*
* This satisfies L8 score-8 criteria: "Dedicated first-session E2E test
- * (wizard → settings discovery)" with the current canonical first-run handoff
- * landing in Infrastructure Operations install rather than the legacy dashboard.
+ * (wizard → settings discovery)" while also keeping the setup-completion
+ * surface on real browser proof for both host-install and API-backed starts.
*
* The opening test in this file forces the backend into deterministic
* first-run state through the dev/test reset route, then completes the real
@@ -43,6 +43,24 @@ test.describe.serial('First-session experience', () => {
await expect(mainContent).toBeVisible();
});
+ test('wizard completion can hand off API-backed starts into platform connections', async ({
+ page,
+ }, testInfo) => {
+ test.skip(testInfo.project.name.startsWith('mobile-'), 'Desktop-only first-session coverage');
+
+ await ensureFirstRunExperience(page, { completionTarget: 'platforms' });
+
+ await expect(page).toHaveURL(/\/settings\/infrastructure\/platforms/);
+ await expect(
+ page.getByRole('heading', { name: 'Infrastructure Operations', exact: true }).first(),
+ ).toBeVisible();
+ await expect(page.getByRole('tab', { name: 'Platform connections' })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ await expect(page.getByText('TrueNAS', { exact: false }).first()).toBeVisible();
+ });
+
test('dashboard shows key navigation elements', async ({ page }, testInfo) => {
test.skip(testInfo.project.name.startsWith('mobile-'), 'Desktop-only first-session coverage');
diff --git a/tests/integration/tests/16-dev-runtime-recovery.spec.ts b/tests/integration/tests/16-dev-runtime-recovery.spec.ts
index ed6b2747ea..383ed832e3 100644
--- a/tests/integration/tests/16-dev-runtime-recovery.spec.ts
+++ b/tests/integration/tests/16-dev-runtime-recovery.spec.ts
@@ -113,6 +113,23 @@ test.describe.serial('Managed dev runtime recovery', () => {
message: 'expected proxied backend health to recover after managed backend restart',
})
.toBe(200);
+ await expect
+ .poll(
+ async () => {
+ const response = await page.request.get('/api/security/status');
+ if (!response.ok()) {
+ return '';
+ }
+ const payload = (await response.json()) as { hasAuthentication?: boolean };
+ return typeof payload.hasAuthentication === 'boolean' ? String(payload.hasAuthentication) : '';
+ },
+ {
+ timeout: 30_000,
+ message:
+ 'expected security status to stay readable through managed backend restart recovery',
+ },
+ )
+ .not.toBe('');
});
test('browser shell recovers after the managed hot-dev owner process is killed', async ({
diff --git a/tests/integration/tests/helpers.ts b/tests/integration/tests/helpers.ts
index 8c714b37f0..c682975d50 100644
--- a/tests/integration/tests/helpers.ts
+++ b/tests/integration/tests/helpers.ts
@@ -65,7 +65,32 @@ type ResetFirstRunResponse = {
bootstrapToken?: string;
};
-async function completeSetupWizard(page: Page, bootstrapToken: string) {
+type SetupCompletionTarget = 'install' | 'platforms' | 'none';
+
+type CompleteSetupWizardOptions = {
+ completionTarget?: SetupCompletionTarget;
+};
+
+const SETUP_COMPLETION_HANDOFFS: Record<
+ Exclude<SetupCompletionTarget, 'none'>,
+ { buttonName: string; urlPattern: RegExp }
+> = {
+ install: {
+ buttonName: 'Open Infrastructure Install',
+ urlPattern: /\/settings\/infrastructure\/install/,
+ },
+ platforms: {
+ buttonName: 'Open Platform connections',
+ urlPattern: /\/settings\/infrastructure\/platforms/,
+ },
+};
+
+async function completeSetupWizard(
+ page: Page,
+ bootstrapToken: string,
+ options: CompleteSetupWizardOptions = {},
+) {
+ const completionTarget = options.completionTarget ?? 'install';
if (!bootstrapToken) {
throw new Error('Pulse requires first-run setup but no bootstrap token is available');
}
@@ -76,30 +101,62 @@ async function completeSetupWizard(page: Page, bootstrapToken: string) {
const wizard = page.getByRole('main', { name: 'Pulse Setup Wizard' });
await expect(wizard).toBeVisible();
- const securityConfigured = wizard.getByText(/security configured/i);
+ const completionHeading = wizard.getByRole('heading', {
+ name: /install your first monitored host|first monitored host connected/i,
+ });
+ const openInstallWorkspaceButton = wizard.getByRole('button', {
+ name: 'Open Infrastructure Install',
+ exact: true,
+ });
+ const openPlatformConnectionsButton = wizard.getByRole('button', {
+ name: 'Open Platform connections',
+ exact: true,
+ });
const secureDashboardHeading = wizard.getByText('Secure Your Dashboard');
- const continueButton = wizard.getByRole('button', { name: /continue to setup|continue/i });
+ const continueButton = wizard.getByRole('button', {
+ name: /verify bootstrap token|continue to setup|continue/i,
+ });
const finishButton = wizard.getByRole('button', { name: /go to dashboard|skip for now/i });
-
- await page.getByPlaceholder('Paste your bootstrap token').fill(bootstrapToken);
-
- // Welcome step auto-submits pasted tokens; only click Continue if no transition happened.
- let onSecurityStep = false;
- let onCompleteStep = false;
- for (let attempt = 0; attempt < 30; attempt++) {
- if (await securityConfigured.isVisible({ timeout: 150 }).catch(() => false)) {
- onCompleteStep = true;
- break;
- }
- if (await secureDashboardHeading.isVisible({ timeout: 150 }).catch(() => false)) {
- onSecurityStep = true;
- break;
+ const bootstrapTokenInput = page.getByPlaceholder('Paste your bootstrap token');
+
+ await bootstrapTokenInput.click();
+ await bootstrapTokenInput.fill('');
+ await bootstrapTokenInput.pressSequentially(bootstrapToken, { delay: 10 });
+
+ const detectWizardStep = async (): Promise<'security' | 'completion' | 'pending'> => {
+ if (
+ await completionHeading.isVisible({ timeout: 100 }).catch(() => false) ||
+ await openInstallWorkspaceButton.isVisible({ timeout: 100 }).catch(() => false) ||
+ await openPlatformConnectionsButton.isVisible({ timeout: 100 }).catch(() => false)
+ ) {
+ return 'completion';
}
- if (attempt === 5 && await continueButton.isVisible({ timeout: 250 }).catch(() => false)) {
- await continueButton.click();
+ if (await secureDashboardHeading.isVisible({ timeout: 100 }).catch(() => false)) {
+ return 'security';
}
- await page.waitForTimeout(200);
+ return 'pending';
+ };
+
+ // The welcome step now prefers auto-submit once the pasted bootstrap token
+ // is long enough. Only fall back to the explicit verify button if the step
+ // stays put after that auto-submit window.
+ let wizardStep = await detectWizardStep();
+ if (wizardStep === 'pending') {
+ await expect.poll(detectWizardStep, { timeout: 10_000 }).not.toBe('pending').catch(() => {});
+ wizardStep = await detectWizardStep();
}
+ if (
+ wizardStep === 'pending' &&
+ await continueButton.isVisible({ timeout: 250 }).catch(() => false) &&
+ await continueButton.isEnabled().catch(() => false)
+ ) {
+ await continueButton.click({ timeout: 1_000 }).catch(() => {});
+ await expect.poll(detectWizardStep, { timeout: 10_000 }).not.toBe('pending');
+ wizardStep = await detectWizardStep();
+ }
+
+ const onSecurityStep = wizardStep === 'security';
+ let onCompleteStep = wizardStep === 'completion';
if (!onSecurityStep && !onCompleteStep) {
throw new Error('Setup wizard did not reach security or completion step');
@@ -115,7 +172,11 @@ async function completeSetupWizard(page: Page, bootstrapToken: string) {
clickedCustomPassword = true;
break;
} catch (error) {
- if (await securityConfigured.isVisible({ timeout: 250 }).catch(() => false)) {
+ if (
+ await completionHeading.isVisible({ timeout: 250 }).catch(() => false) ||
+ await openInstallWorkspaceButton.isVisible({ timeout: 250 }).catch(() => false) ||
+ await openPlatformConnectionsButton.isVisible({ timeout: 250 }).catch(() => false)
+ ) {
onCompleteStep = true;
break;
}
@@ -134,10 +195,17 @@ async function completeSetupWizard(page: Page, bootstrapToken: string) {
await wizard.getByRole('button', { name: /create account/i }).click();
await expect
.poll(async () => {
- if (await securityConfigured.isVisible({ timeout: 250 }).catch(() => false)) {
+ if (
+ await completionHeading.isVisible({ timeout: 250 }).catch(() => false) ||
+ await openInstallWorkspaceButton.isVisible({ timeout: 250 }).catch(() => false) ||
+ await openPlatformConnectionsButton.isVisible({ timeout: 250 }).catch(() => false)
+ ) {
return 'complete';
}
- if (/\/settings\/infrastructure\/install/.test(page.url())) {
+ if (
+ completionTarget === 'install' &&
+ SETUP_COMPLETION_HANDOFFS.install.urlPattern.test(page.url())
+ ) {
return 'handoff';
}
return 'pending';
@@ -146,12 +214,33 @@ async function completeSetupWizard(page: Page, bootstrapToken: string) {
onCompleteStep = true;
}
} else {
- await expect(securityConfigured).toBeVisible();
+ await expect(completionHeading).toBeVisible();
onCompleteStep = true;
}
}
- if (onCompleteStep) {
+ if (onCompleteStep && completionTarget !== 'none') {
+ const completionAction = SETUP_COMPLETION_HANDOFFS[completionTarget];
+ if (!completionAction.urlPattern.test(page.url())) {
+ const completionButton = wizard.getByRole('button', {
+ name: completionAction.buttonName,
+ exact: true,
+ });
+ const completionVisible = await completionButton.isVisible({ timeout: 500 }).catch(() => false);
+
+ if (completionVisible) {
+ await completionButton.scrollIntoViewIfNeeded();
+ await completionButton.click({ timeout: 10_000 });
+ await expect(page).toHaveURL(completionAction.urlPattern);
+ }
+ }
+
+ if (!completionAction.urlPattern.test(page.url())) {
+ throw new Error(
+ `Setup wizard completion did not hand off to ${completionAction.buttonName}: ${page.url()}`,
+ );
+ }
+ } else if (onCompleteStep) {
const finishVisible = await finishButton.isVisible({ timeout: 500 }).catch(() => false);
if (finishVisible) {
await finishButton.scrollIntoViewIfNeeded();
@@ -179,56 +268,49 @@ export async function maybeCompleteSetupWizard(page: Page) {
await completeSetupWizard(page, E2E_CREDENTIALS.bootstrapToken);
}
-export async function ensureFirstRunExperience(page: Page) {
+export async function ensureFirstRunExperience(
+ page: Page,
+ options: CompleteSetupWizardOptions = {},
+) {
await page.addInitScript(() => {
localStorage.setItem('pulse_whats_new_v2_shown', 'true');
});
await waitForPulseReady(page);
+ const completionTarget = options.completionTarget ?? 'install';
let bootstrapToken = E2E_CREDENTIALS.bootstrapToken;
const security = await getSecurityStatus(page);
- if (security.hasAuthentication !== false) {
- let resetRes = await apiRequest(page, '/api/security/dev/reset-first-run', {
+ let resetRes = await apiRequest(page, '/api/security/dev/reset-first-run', {
+ method: 'POST',
+ headers: E2E_CREDENTIALS.primaryApiToken
+ ? { 'X-API-Token': E2E_CREDENTIALS.primaryApiToken }
+ : undefined,
+ });
+ if (resetRes.status() === 401 && !E2E_CREDENTIALS.primaryApiToken && security.hasAuthentication !== false) {
+ await login(page);
+ resetRes = await apiRequest(page, '/api/security/dev/reset-first-run', {
method: 'POST',
- headers: E2E_CREDENTIALS.primaryApiToken
- ? { 'X-API-Token': E2E_CREDENTIALS.primaryApiToken }
- : undefined,
});
- if (resetRes.status() === 401 && !E2E_CREDENTIALS.primaryApiToken) {
- await login(page);
- resetRes = await apiRequest(page, '/api/security/dev/reset-first-run', {
- method: 'POST',
- });
- }
- if (!resetRes.ok()) {
- throw new Error(`Failed to reset first-run state: ${resetRes.status()} ${await resetRes.text()}`);
- }
-
- const payload = (await resetRes.json()) as ResetFirstRunResponse;
- bootstrapToken = String(payload.bootstrapToken || '').trim();
- if (bootstrapToken === '') {
- throw new Error('First-run reset response did not include a bootstrap token');
- }
+ }
+ if (!resetRes.ok()) {
+ throw new Error(`Failed to reset first-run state: ${resetRes.status()} ${await resetRes.text()}`);
+ }
- await expect
- .poll(async () => {
- const current = await getSecurityStatus(page);
- return current.hasAuthentication === false;
- })
- .toBe(true);
-
- await page.goto('/', { waitUntil: 'domcontentloaded' });
- await page.evaluate(() => {
- window.localStorage.clear();
- window.sessionStorage.clear();
- });
- await page.context().clearCookies();
+ const payload = (await resetRes.json()) as ResetFirstRunResponse;
+ bootstrapToken = String(payload.bootstrapToken || '').trim();
+ if (bootstrapToken === '') {
+ throw new Error('First-run reset response did not include a bootstrap token');
}
- await completeSetupWizard(page, bootstrapToken);
+ await completeSetupWizard(page, bootstrapToken, { completionTarget });
const firstRunLandingPattern =
- /\/(settings\/infrastructure\/install|proxmox|dashboard|nodes|hosts|docker|infrastructure)/;
+ completionTarget === 'platforms'
+ ? SETUP_COMPLETION_HANDOFFS.platforms.urlPattern
+ : /\/(settings\/infrastructure\/install|proxmox|dashboard|nodes|hosts|docker|infrastructure)/;
if (!firstRunLandingPattern.test(page.url())) {
+ if (completionTarget === 'platforms') {
+ throw new Error(`First-run setup did not reach Platform connections: ${page.url()}`);
+ }
await login(page);
}
await expect(page).toHaveURL(firstRunLandingPattern);