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.

Add managed dev-runtime recovery proof

rcourtmanf4a8ac477354
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index eeed0f56c1..3b8c0de318 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -31,6 +31,7 @@ server-side update execution surfaces.
9. `scripts/pulse-auto-update.sh`
10. `scripts/hot-dev.sh`
11. `scripts/hot-dev-bg.sh`
+12. `tests/integration/scripts/managed-dev-runtime.mjs`
## Shared Boundaries
@@ -45,7 +46,7 @@ server-side update execution surfaces.
2. Add or change release-build metadata injection, release artifact assembly, or governed promotion metadata resolution through `scripts/build-release.sh`, `scripts/release_ldflags.sh`, and `scripts/release_control/resolve_release_promotion.py`, plus the container Dockerfile and governed release workflows that consume those same contracts
3. Add or change shell installer, Windows installer, container-agent installer, or auto-update script behavior through `scripts/install.sh`, `scripts/install.ps1`, `scripts/install-container-agent.sh`, and `scripts/pulse-auto-update.sh`
4. Add or change server update transport through `internal/api/updates.go` and `frontend-modern/src/api/updates.ts`
-5. Add or change local dev-runtime orchestration, managed ownership, or frontend/backend coherence diagnostics through `scripts/hot-dev.sh` and `scripts/hot-dev-bg.sh`
+5. Add or change local dev-runtime orchestration, managed ownership, browser-runtime proof wiring, or frontend/backend coherence diagnostics through `scripts/hot-dev.sh`, `scripts/hot-dev-bg.sh`, and `tests/integration/scripts/managed-dev-runtime.mjs`
## Forbidden Paths
@@ -150,6 +151,15 @@ managed takeover must surface that competing job in diagnostics and boot it
out before starting a new managed session, otherwise launchd can immediately
recreate the legacy `0.0.0.0` dev runtime beside the managed `127.0.0.1`
session.
+That same managed dev-runtime boundary now also owns operator-safe recovery
+control and browser proof. `scripts/hot-dev-bg.sh` must provide a canonical
+managed-backend restart command instead of forcing operators or tests to kill
+listener PIDs ad hoc, and the integration harness must be able to attach
+Playwright to the browser entrypoint on `5173` rather than only the backend
+port on `7655`. Recovery proof for this surface must run through the managed
+browser runtime, bounce the real backend through the launcher contract, and
+prove that the shell degrades and recovers through the proxy instead of
+relying on backend-only API checks that miss browser/runtime drift.
That shared `scripts/install.sh` boundary must also keep one canonical service
argument builder for the runtime flags it persists. Token-bearing install
paths, token-file systemd paths, wrapper-script launches, and later service
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index c8f4516d58..dd3776e05e 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -1994,7 +1994,8 @@
"scripts/install.sh",
"scripts/pulse-auto-update.sh",
"scripts/release_control/resolve_release_promotion.py",
- "scripts/release_ldflags.sh"
+ "scripts/release_ldflags.sh",
+ "tests/integration/scripts/managed-dev-runtime.mjs"
],
"verification": {
"allow_same_subsystem_tests": false,
@@ -2086,12 +2087,14 @@
"match_prefixes": [],
"match_files": [
"scripts/hot-dev-bg.sh",
- "scripts/hot-dev.sh"
+ "scripts/hot-dev.sh",
+ "tests/integration/scripts/managed-dev-runtime.mjs"
],
"allow_same_subsystem_tests": false,
"test_prefixes": [],
"exact_files": [
- "scripts/tests/test-hot-dev-bg.sh"
+ "scripts/tests/test-hot-dev-bg.sh",
+ "tests/integration/tests/16-dev-runtime-recovery.spec.ts"
]
},
{
diff --git a/scripts/hot-dev-bg.sh b/scripts/hot-dev-bg.sh
index 7168b3423d..1f26e49ee8 100755
--- a/scripts/hot-dev-bg.sh
+++ b/scripts/hot-dev-bg.sh
@@ -6,6 +6,7 @@
# ./scripts/hot-dev-bg.sh start [--takeover]
# ./scripts/hot-dev-bg.sh stop
# ./scripts/hot-dev-bg.sh restart
+# ./scripts/hot-dev-bg.sh backend-restart
# ./scripts/hot-dev-bg.sh status
# ./scripts/hot-dev-bg.sh logs
@@ -125,6 +126,22 @@ port_has_unmanaged_listener() {
return 1
}
+first_managed_listener_pid() {
+ local port="$1"
+ local session_pid="$2"
+ local listener_pid
+
+ while IFS= read -r listener_pid; do
+ [[ -n "${listener_pid}" ]] || continue
+ if pid_is_managed "${listener_pid}" "${session_pid}"; then
+ printf "%s\n" "${listener_pid}"
+ return 0
+ fi
+ done < <(listener_pids "${port}")
+
+ return 1
+}
+
wait_for_managed_listener() {
local port="$1"
local session_pid="$2"
@@ -520,6 +537,59 @@ logs_bg() {
tail -n 120 -f "${LOG_FILE}"
}
+restart_backend_bg() {
+ if ! is_running; then
+ fail "Managed hot-dev session is not running"
+ fi
+
+ local session_pid backend_pid next_backend_pid restart_sentinel
+ session_pid="$(cat "${PID_FILE}")"
+ backend_pid="$(first_managed_listener_pid "${PULSE_DEV_API_PORT}" "${session_pid}" || true)"
+ restart_sentinel="${ROOT_DIR}/tmp/hot-dev.restart"
+
+ if [[ ! -f "${restart_sentinel}" ]]; then
+ fail "Managed restart sentinel not found at ${restart_sentinel}"
+ fi
+
+ log "Requesting managed backend restart via hot-dev file watcher"
+ touch "${restart_sentinel}"
+
+ local checks=180
+ while (( checks > 0 )); do
+ next_backend_pid="$(first_managed_listener_pid "${PULSE_DEV_API_PORT}" "${session_pid}" || true)"
+ if [[ -z "${backend_pid}" && -n "${next_backend_pid}" ]]; then
+ break
+ fi
+ if [[ -n "${backend_pid}" && -n "${next_backend_pid}" && "${backend_pid}" != "${next_backend_pid}" ]]; then
+ break
+ fi
+ sleep 0.5
+ checks=$((checks - 1))
+ done
+
+ if [[ -n "${backend_pid}" && "${backend_pid}" == "${next_backend_pid:-}" ]]; then
+ log "Managed backend restart did not replace the listener process. Showing recent logs:"
+ tail -n 80 "${LOG_FILE}" || true
+ fail "Managed backend restart did not replace the listener process on port ${PULSE_DEV_API_PORT}"
+ fi
+
+ log "Waiting for managed backend listener to become healthy on port ${PULSE_DEV_API_PORT}..."
+ if ! wait_for_managed_listener "${PULSE_DEV_API_PORT}" "${session_pid}" 90; then
+ log "Managed backend did not recover. Showing recent logs:"
+ tail -n 80 "${LOG_FILE}" || true
+ fail "Managed backend failed to recover after restart"
+ fi
+
+ local backend_health_url backend_code
+ backend_health_url="http://127.0.0.1:${PULSE_DEV_API_PORT}/api/health"
+ backend_code="$(http_status_code "${backend_health_url}")"
+ if ! http_status_ok "${backend_code}"; then
+ fail "Managed backend listener recovered but health probe returned ${backend_code}"
+ fi
+
+ log "Managed backend recovered and is healthy on port ${PULSE_DEV_API_PORT}"
+}
+
usage() {
cat <<EOF
Usage: $(basename "$0") <command>
@@ -528,6 +598,7 @@ Commands:
start [--takeover]
stop
restart
+ backend-restart
status
logs
EOF
@@ -550,7 +621,7 @@ parse_takeover_flag() {
usage
return 1
;;
- stop|status|logs)
+ stop|backend-restart|status|logs)
if [[ -n "${flag}" ]]; then
usage
return 1
@@ -579,6 +650,7 @@ main() {
stop_bg
start_bg "${takeover}"
;;
+ backend-restart) restart_backend_bg ;;
status) status_bg ;;
logs) logs_bg ;;
*) usage; exit 1 ;;
diff --git a/scripts/hot-dev.sh b/scripts/hot-dev.sh
index b79f5064ec..508a5a408b 100755
--- a/scripts/hot-dev.sh
+++ b/scripts/hot-dev.sh
@@ -190,6 +190,7 @@ export PULSE_DEV_API_HOST PULSE_DEV_API_PORT PULSE_DEV_API_URL PULSE_DEV_WS_URL
export ALLOWED_ORIGINS
EXTRA_CLEANUP_PORT=$((PULSE_DEV_API_PORT + 1))
+HOT_DEV_RESTART_SENTINEL="${ROOT_DIR}/tmp/hot-dev.restart"
# --- Startup Checks ---
@@ -269,6 +270,9 @@ set -o pipefail
log_info "Ports are clean!"
+mkdir -p "$(dirname "${HOT_DEV_RESTART_SENTINEL}")"
+touch "${HOT_DEV_RESTART_SENTINEL}"
+
# Self-restart check
check_script_change() {
local current_mtime
@@ -602,10 +606,13 @@ log_info "Starting backend file watcher..."
inotifywait -r -m -e modify,create,delete,move,attrib \
--exclude '(vendor/|node_modules/|\.git/|\.swp$|\.tmp$|~$)' \
--format '%e %w%f' \
- "${ROOT_DIR}/cmd" "${ROOT_DIR}/internal" "${ROOT_DIR}/pkg" "${ROOT_DIR}/pulse" 2>/dev/null | \
+ "${ROOT_DIR}/cmd" "${ROOT_DIR}/internal" "${ROOT_DIR}/pkg" "${ROOT_DIR}/pulse" "${HOT_DEV_RESTART_SENTINEL}" 2>/dev/null | \
while read -r event changed_file; do
check_script_change "$@"
- if [[ "$changed_file" == "${ROOT_DIR}/pulse" ]]; then
+ if [[ "$changed_file" == "${HOT_DEV_RESTART_SENTINEL}" ]]; then
+ log_info "πŸš€ Managed restart requested, restarting backend..."
+ restart_backend
+ elif [[ "$changed_file" == "${ROOT_DIR}/pulse" ]]; then
log_info "πŸš€ Manual build detected (pulse binary changed), restarting..."
restart_backend
elif [[ "$changed_file" == *.go ]] || [[ "$event" =~ CREATE|DELETE|MOVED|ATTRIB ]]; then
@@ -622,9 +629,13 @@ log_info "Starting backend file watcher..."
# Watch the pulse binary too β€” if someone does `go build -o pulse`
# manually, we should restart without rebuilding.
fswatch --event Created --event Updated --event Renamed --event AttributeModified \
- "${ROOT_DIR}/pulse" 2>/dev/null | \
- while read -r _; do
- log_info "πŸš€ Manual build detected (pulse binary changed), restarting..."
+ "${ROOT_DIR}/pulse" "${HOT_DEV_RESTART_SENTINEL}" 2>/dev/null | \
+ while read -r changed_file; do
+ if [[ "$changed_file" == "${HOT_DEV_RESTART_SENTINEL}" ]]; then
+ log_info "πŸš€ Managed restart requested, restarting backend..."
+ else
+ log_info "πŸš€ Manual build detected (pulse binary changed), restarting..."
+ fi
restart_backend
done &
BINARY_WATCH_PID=$!
diff --git a/scripts/tests/test-hot-dev-bg.sh b/scripts/tests/test-hot-dev-bg.sh
index 9a12d4c11e..3e51216c45 100755
--- a/scripts/tests/test-hot-dev-bg.sh
+++ b/scripts/tests/test-hot-dev-bg.sh
@@ -103,6 +103,7 @@ test_cli_parses_takeover_flag() {
source "${HOT_DEV_BG_PATH}"
printf "start=%s\n" "$(parse_takeover_flag start --takeover)"
printf "restart=%s\n" "$(parse_takeover_flag restart --takeover)"
+ printf "backend_restart=%s\n" "$(parse_takeover_flag backend-restart)"
printf "plain=%s\n" "$(parse_takeover_flag start)"
if parse_takeover_flag status --takeover >/tmp/hot-dev-bg.invalid 2>&1; then
printf "invalid=accepted\n"
@@ -114,10 +115,37 @@ test_cli_parses_takeover_flag() {
assert_contains "takeover parsing enables start" "${output}" "start=true"
assert_contains "takeover parsing enables restart" "${output}" "restart=true"
+ assert_contains "backend restart remains flagless" "${output}" "backend_restart=false"
assert_contains "start without flag stays false" "${output}" "plain=false"
assert_contains "unexpected status flag is rejected" "${output}" "invalid=rejected"
}
+test_backend_restart_requires_managed_runtime() {
+ local frontend_port backend_port output
+ local state_dir
+ frontend_port="$(pick_free_port)"
+ backend_port="$(pick_free_port)"
+ if [[ "${backend_port}" == "${frontend_port}" ]]; then
+ backend_port="$(pick_free_port)"
+ fi
+ state_dir="$(make_isolated_hot_dev_bg_state)"
+
+ output="$(
+ set +e
+ HOT_DEV_BG_PID_FILE="${state_dir}/hot-dev-bg.pid" \
+ HOT_DEV_BG_LOG_FILE="${state_dir}/hot-dev-bg.log" \
+ FRONTEND_DEV_HOST=127.0.0.1 \
+ FRONTEND_DEV_PORT="${frontend_port}" \
+ PULSE_DEV_API_HOST=127.0.0.1 \
+ PULSE_DEV_API_PORT="${backend_port}" \
+ "${HOT_DEV_BG}" backend-restart 2>&1
+ printf '\nexit_code=%s' "$?"
+ )"
+
+ assert_contains "backend restart refuses missing managed runtime" "${output}" "Managed hot-dev session is not running"
+ assert_contains "backend restart returns failure without managed runtime" "${output}" "exit_code=1"
+}
+
test_detects_unmanaged_listeners() {
local frontend_port backend_port status_output start_output
local state_dir
@@ -166,6 +194,7 @@ test_detects_unmanaged_listeners() {
main() {
test_cli_parses_takeover_flag
+ test_backend_restart_requires_managed_runtime
test_status_without_runtime
test_detects_unmanaged_listeners
diff --git a/tests/integration/README.md b/tests/integration/README.md
index 96c7f9f007..55b93676d0 100644
--- a/tests/integration/README.md
+++ b/tests/integration/README.md
@@ -122,6 +122,20 @@ This mode starts an isolated Pulse backend from the local repo binary in a tempo
Each `npm test` invocation gets its own runtime-state file and managed-backend root automatically, so separate managed-local-backend runs can execute in parallel without sharing PID or cleanup state. Shared embedded-frontend and backend-binary refreshes are serialized by the harness.
+### Run Against The Managed Hot-Dev Browser Runtime
+```bash
+cd tests/integration
+PULSE_E2E_USE_HOT_DEV=1 \
+PULSE_E2E_SKIP_PLAYWRIGHT_INSTALL=1 \
+npm test -- tests/16-dev-runtime-recovery.spec.ts --project=chromium
+```
+
+This mode attaches Playwright to the canonical dev browser entrypoint on `http://127.0.0.1:5173`, uses `scripts/hot-dev-bg.sh` as the runtime control surface, and writes browser runtime connection state for Playwright instead of targeting the backend port directly.
+
+If the managed runtime is not already running, the harness starts it. If you need the harness to reclaim existing unmanaged `5173`/`7655` listeners first, add `PULSE_E2E_HOT_DEV_TAKEOVER=1`.
+
+The managed recovery proof bounces the real backend through `./scripts/hot-dev-bg.sh backend-restart` and verifies that the browser shell reports the outage and then recovers through the proxy. When the harness attaches to an already-running managed dev session, `posttest` leaves that runtime running.
+
For deterministic paid-feature runs against an existing instance, provide one of:
- `PULSE_E2E_BILLING_STATE_PATH=/absolute/path/to/billing.json` to let the harness write the billing state file directly.
- `PULSE_E2E_ENTITLEMENT_WRITE_COMMAND='ssh host "cat > /etc/pulse/billing.json"'` to pipe the billing JSON to a remote/local writer command.
diff --git a/tests/integration/scripts/managed-dev-runtime.mjs b/tests/integration/scripts/managed-dev-runtime.mjs
new file mode 100644
index 0000000000..90ae52d13d
--- /dev/null
+++ b/tests/integration/scripts/managed-dev-runtime.mjs
@@ -0,0 +1,150 @@
+import { spawn } from 'node:child_process';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+import { clearRuntimeState, readRuntimeState, writeRuntimeState } from './runtime-state.mjs';
+
+const truthy = (value) =>
+ ['1', 'true', 'yes', 'on'].includes(String(value || '').trim().toLowerCase());
+
+const trim = (value) => String(value || '').trim();
+
+function repoRootFromEnv(env = process.env) {
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
+ return trim(env.PULSE_E2E_REPO_ROOT) || path.resolve(scriptDir, '..', '..', '..');
+}
+
+function hotDevBgScriptPath(env = process.env) {
+ return path.join(repoRootFromEnv(env), 'scripts', 'hot-dev-bg.sh');
+}
+
+function hotDevBrowserURL(env = process.env) {
+ const host = trim(env.FRONTEND_DEV_HOST) || '127.0.0.1';
+ const port = trim(env.FRONTEND_DEV_PORT) || '5173';
+ return `http://${host}:${port}`;
+}
+
+function hotDevBackendURL(env = process.env) {
+ const host = trim(env.PULSE_DEV_API_HOST) || '127.0.0.1';
+ const port = trim(env.PULSE_DEV_API_PORT) || '7655';
+ return `http://${host}:${port}`;
+}
+
+function run(command, args, options = {}) {
+ return new Promise((resolve, reject) => {
+ const child = spawn(command, args, { ...options });
+ let stdout = '';
+ let stderr = '';
+
+ child.stdout?.on('data', (chunk) => {
+ stdout += chunk.toString();
+ });
+ child.stderr?.on('data', (chunk) => {
+ stderr += chunk.toString();
+ });
+ child.on('error', reject);
+ child.on('close', (code) => resolve({ code: code ?? 1, stdout, stderr }));
+ });
+}
+
+async function runHotDevBg(args, env = process.env) {
+ const mergedEnv = { ...process.env, ...env };
+ return run(hotDevBgScriptPath(mergedEnv), args, {
+ cwd: repoRootFromEnv(mergedEnv),
+ env: mergedEnv,
+ });
+}
+
+function statusReportsRunning(output) {
+ return output.includes('[hot-dev-bg] Running');
+}
+
+async function ensureHealthyStatus(env = process.env) {
+ const status = await runHotDevBg(['status'], env);
+ if (status.code !== 0) {
+ throw new Error(`hot-dev-bg status failed: ${status.stderr || status.stdout}`);
+ }
+
+ const output = `${status.stdout}${status.stderr}`;
+ const requiredMarkers = [
+ '[hot-dev-bg] Frontend shell HTTP: 200',
+ '[hot-dev-bg] Frontend proxy /api/health: 200',
+ '[hot-dev-bg] Backend /api/health: 200',
+ ];
+ for (const marker of requiredMarkers) {
+ if (!output.includes(marker)) {
+ throw new Error(`Managed dev runtime is not healthy enough for browser proof:\n${output}`);
+ }
+ }
+
+ return output;
+}
+
+export async function startManagedDevRuntime({
+ env = process.env,
+ logger = console,
+} = {}) {
+ await clearRuntimeState(env);
+
+ const statusBefore = await runHotDevBg(['status'], env);
+ if (statusBefore.code !== 0) {
+ throw new Error(`hot-dev-bg status failed before start: ${statusBefore.stderr || statusBefore.stdout}`);
+ }
+ const wasRunning = statusReportsRunning(`${statusBefore.stdout}${statusBefore.stderr}`);
+
+ const startArgs = ['start'];
+ if (truthy(env.PULSE_E2E_HOT_DEV_TAKEOVER)) {
+ startArgs.push('--takeover');
+ }
+ const startResult = await runHotDevBg(startArgs, env);
+ if (startResult.code !== 0) {
+ throw new Error(`hot-dev-bg start failed: ${startResult.stderr || startResult.stdout}`);
+ }
+
+ await ensureHealthyStatus(env);
+
+ const runtimeState = {
+ managedDevRuntime: true,
+ baseURL: hotDevBrowserURL(env),
+ browserURL: hotDevBrowserURL(env),
+ backendURL: hotDevBackendURL(env),
+ startedByHarness: !wasRunning,
+ };
+ await writeRuntimeState(runtimeState, env);
+ logger.log(
+ `[integration] Managed dev runtime ready at ${runtimeState.browserURL} (backend ${runtimeState.backendURL})`,
+ );
+ return runtimeState;
+}
+
+export async function restartManagedDevRuntimeBackend({
+ env = process.env,
+} = {}) {
+ const result = await runHotDevBg(['backend-restart'], env);
+ if (result.code !== 0) {
+ throw new Error(`hot-dev-bg backend-restart failed: ${result.stderr || result.stdout}`);
+ }
+ await ensureHealthyStatus(env);
+}
+
+export async function stopManagedDevRuntime({
+ env = process.env,
+ logger = console,
+} = {}) {
+ const runtimeState = await readRuntimeState(env);
+ if (!runtimeState?.managedDevRuntime) {
+ await clearRuntimeState(env);
+ return false;
+ }
+
+ if (runtimeState.startedByHarness) {
+ const result = await runHotDevBg(['stop'], env);
+ if (result.code !== 0) {
+ throw new Error(`hot-dev-bg stop failed: ${result.stderr || result.stdout}`);
+ }
+ logger.log('[integration] Stopped managed dev runtime started by harness');
+ }
+
+ await clearRuntimeState(env);
+ return true;
+}
diff --git a/tests/integration/scripts/posttest.mjs b/tests/integration/scripts/posttest.mjs
index a0a72dacd3..6f4bf82574 100644
--- a/tests/integration/scripts/posttest.mjs
+++ b/tests/integration/scripts/posttest.mjs
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process';
+import { stopManagedDevRuntime } from './managed-dev-runtime.mjs';
import { stopManagedLocalBackend } from './managed-local-backend.mjs';
const truthy = (value) => {
@@ -11,6 +12,11 @@ if (truthy(process.env.PULSE_E2E_USE_LOCAL_BACKEND)) {
process.exit(0);
}
+if (truthy(process.env.PULSE_E2E_USE_HOT_DEV)) {
+ await stopManagedDevRuntime();
+ process.exit(0);
+}
+
if (truthy(process.env.PULSE_E2E_SKIP_DOCKER)) {
console.log('[integration] PULSE_E2E_SKIP_DOCKER enabled, skipping docker compose down');
process.exit(0);
diff --git a/tests/integration/scripts/pretest.mjs b/tests/integration/scripts/pretest.mjs
index 8ae6bba2bb..12631e0ccf 100644
--- a/tests/integration/scripts/pretest.mjs
+++ b/tests/integration/scripts/pretest.mjs
@@ -3,6 +3,7 @@ import http from 'node:http';
import { resolveComposeInvocation } from './compose-command.mjs';
import { applyRequestedEntitlementProfile } from './entitlement-bootstrap.mjs';
import { startManagedLocalBackend } from './managed-local-backend.mjs';
+import { startManagedDevRuntime } from './managed-dev-runtime.mjs';
import { clearRuntimeState } from './runtime-state.mjs';
// Add signal handlers to debug unexpected termination
@@ -32,6 +33,7 @@ const truthy = (value) => {
const shouldSkipDocker = truthy(process.env.PULSE_E2E_SKIP_DOCKER);
const shouldSkipPlaywrightInstall = truthy(process.env.PULSE_E2E_SKIP_PLAYWRIGHT_INSTALL);
const shouldUseManagedLocalBackend = truthy(process.env.PULSE_E2E_USE_LOCAL_BACKEND);
+const shouldUseManagedDevRuntime = truthy(process.env.PULSE_E2E_USE_HOT_DEV);
const DEFAULT_E2E_BOOTSTRAP_TOKEN = '0123456789abcdef0123456789abcdef0123456789abcdef';
if (!process.env.PULSE_E2E_BOOTSTRAP_TOKEN) {
@@ -107,6 +109,11 @@ if (!shouldSkipPlaywrightInstall) {
await clearRuntimeState();
+if (shouldUseManagedDevRuntime) {
+ await startManagedDevRuntime();
+ process.exit(0);
+}
+
if (shouldUseManagedLocalBackend) {
await startManagedLocalBackend();
process.exit(0);
diff --git a/tests/integration/tests/16-dev-runtime-recovery.spec.ts b/tests/integration/tests/16-dev-runtime-recovery.spec.ts
new file mode 100644
index 0000000000..d99c8aa7ba
--- /dev/null
+++ b/tests/integration/tests/16-dev-runtime-recovery.spec.ts
@@ -0,0 +1,60 @@
+import { expect, test } from '@playwright/test';
+
+import { ensureAuthenticated } from './helpers';
+import { restartManagedDevRuntimeBackend } from '../scripts/managed-dev-runtime.mjs';
+
+const truthy = (value: string | undefined) =>
+ ['1', 'true', 'yes', 'on'].includes(String(value || '').trim().toLowerCase());
+
+test.describe.serial('Managed dev runtime recovery', () => {
+ test('browser shell stays usable and recovers after a managed backend bounce', async ({
+ page,
+ }, testInfo) => {
+ test.setTimeout(120_000);
+ test.skip(testInfo.project.name.startsWith('mobile-'), 'Desktop-only managed dev runtime coverage');
+ test.skip(!truthy(process.env.PULSE_E2E_USE_HOT_DEV), 'Runs only against the managed hot-dev runtime');
+
+ await ensureAuthenticated(page);
+ await page.goto('/infrastructure', { waitUntil: 'domcontentloaded' });
+
+ const mainContent = page.locator('main, [role="main"], #root > div').first();
+ await expect(mainContent).toBeVisible();
+ await expect(
+ page.getByRole('status', { name: 'Backend and live data stream are connected.' }),
+ ).toBeVisible({ timeout: 20_000 });
+
+ const restartPromise = restartManagedDevRuntimeBackend();
+
+ await expect
+ .poll(
+ async () => {
+ const labels = await page.locator('[role="status"]').evaluateAll((nodes) =>
+ nodes.map((node) => node.getAttribute('aria-label') || ''),
+ );
+ return labels.find((label) =>
+ label === 'Backend and live data stream are unavailable.' ||
+ label === 'Attempting to reconnect to the backend and live data stream.',
+ ) || '';
+ },
+ {
+ timeout: 30_000,
+ message: 'expected the browser shell to report a real backend outage during restart',
+ },
+ )
+ .not.toBe('');
+
+ await expect(mainContent).toBeVisible();
+
+ await restartPromise;
+
+ await expect(
+ page.getByRole('status', { name: 'Backend and live data stream are connected.' }),
+ ).toBeVisible({ timeout: 30_000 });
+ await expect
+ .poll(async () => (await page.request.get('/api/health')).status(), {
+ timeout: 30_000,
+ message: 'expected proxied backend health to recover after managed backend restart',
+ })
+ .toBe(200);
+ });
+});