From 888334f5ae4266065ba283919dbf83098c3b7e4e Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 27 Jun 2026 18:09:16 +0000 Subject: [PATCH] fix(hwlab): stabilize d518 source workspace browser checks --- scripts/src/hwlab-node-web-sentinel-cicd.ts | 8 +++++- scripts/src/hwlab-node/source-workspace.ts | 28 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/scripts/src/hwlab-node-web-sentinel-cicd.ts b/scripts/src/hwlab-node-web-sentinel-cicd.ts index a99d6697..2c54d788 100644 --- a/scripts/src/hwlab-node-web-sentinel-cicd.ts +++ b/scripts/src/hwlab-node-web-sentinel-cicd.ts @@ -1883,6 +1883,8 @@ function probeSentinelDashboardBrowser(state: SentinelCicdState, options: Extrac `export UNIDESK_SENTINEL_DASHBOARD_HEIGHT=${shellQuote(heightRaw ?? "900")}`, `export UNIDESK_SENTINEL_DASHBOARD_TIMEOUT_MS=${shellQuote(String(options.timeoutMs))}`, `export UNIDESK_SENTINEL_DASHBOARD_FULL_PAGE=${shellQuote(options.fullPage ? "1" : "0")}`, + `export UNIDESK_SENTINEL_DASHBOARD_PLAYWRIGHT_MODULE=${shellQuote(`${state.spec.workspace}/node_modules/playwright/index.mjs`)}`, + "export PLAYWRIGHT_BROWSERS_PATH=0", "if command -v chromium >/dev/null 2>&1; then", " export UNIDESK_SENTINEL_DASHBOARD_EXECUTABLE_PATH=$(command -v chromium)", "elif command -v chromium-browser >/dev/null 2>&1; then", @@ -1949,7 +1951,11 @@ function probeSentinelDashboardBrowser(state: SentinelCicdState, options: Extrac } function sentinelDashboardBrowserModule(): string { - return String.raw`import { chromium } from "playwright"; + return String.raw`import { pathToFileURL } from "node:url"; + +const playwrightModulePath = process.env.UNIDESK_SENTINEL_DASHBOARD_PLAYWRIGHT_MODULE || ""; +const playwrightModuleSpecifier = playwrightModulePath ? pathToFileURL(playwrightModulePath).href : "playwright"; +const { chromium } = await import(playwrightModuleSpecifier); const url = process.env.UNIDESK_SENTINEL_DASHBOARD_URL; const screenshotPath = process.env.UNIDESK_SENTINEL_DASHBOARD_SCREENSHOT || ""; diff --git a/scripts/src/hwlab-node/source-workspace.ts b/scripts/src/hwlab-node/source-workspace.ts index a66fb47d..7a9581ed 100644 --- a/scripts/src/hwlab-node/source-workspace.ts +++ b/scripts/src/hwlab-node/source-workspace.ts @@ -133,6 +133,7 @@ function sourceWorkspaceStatusFromFields(fields: Record, exitCod && missingCommands.length === 0 && missingFiles.length === 0 && fields.playwrightPackagePresent === "yes" + && fields.browserExecutablePresent === "yes" && fields.launcherImportOk === "yes"; return { ok, @@ -155,6 +156,10 @@ function sourceWorkspaceStatusFromFields(fields: Record, exitCod npxVersion: fields.npxVersion || null, playwrightPackagePresent: fields.playwrightPackagePresent === "yes", browserCachePresent: fields.browserCachePresent === "yes", + browserExecutablePresent: fields.browserExecutablePresent === "yes", + browserExecutableExitCode: numericField(fields.browserExecutableExitCode), + browserExecutablePath: fields.browserExecutablePath || null, + browserExecutableErrorTail: fields.browserExecutableErrorTail || null, launcherImportOk: fields.launcherImportOk === "yes", launcherImportExitCode: numericField(fields.launcherImportExitCode), statusShortLines: numericField(fields.statusShortLines), @@ -226,6 +231,24 @@ function sourceWorkspaceStatusScript(spec: HwlabRuntimeLaneSpec, sourceWorkspace " [ -d \"$cache_dir\" ] || continue", " if find \"$cache_dir\" -maxdepth 1 -type d -name '*chromium*' 2>/dev/null | grep -q .; then browser_cache_present=yes; fi", "done", + "browser_executable_present=no", + "browser_executable_exit=", + "browser_executable_path=", + "browser_executable_error_tail=", + "if command -v node >/dev/null 2>&1 && [ \"$playwright_package_present\" = yes ]; then", + " (cd \"$workspace\" && PLAYWRIGHT_BROWSERS_PATH=0 timeout 20s node --input-type=module - <<'NODE'", + "import { existsSync } from 'node:fs';", + "import { chromium } from 'playwright';", + "const executablePath = chromium.executablePath();", + "console.log(executablePath);", + "process.exit(existsSync(executablePath) ? 0 : 2);", + "NODE", + " ) >/tmp/hwlab-source-workspace-browser-executable.out 2>/tmp/hwlab-source-workspace-browser-executable.err", + " browser_executable_exit=$?", + " browser_executable_path=$(head -n 1 /tmp/hwlab-source-workspace-browser-executable.out 2>/dev/null | cut -c1-1000)", + " browser_executable_error_tail=$(tail -n 20 /tmp/hwlab-source-workspace-browser-executable.err 2>/dev/null | tr '\\n\\t' ' ' | cut -c1-1000)", + " [ \"$browser_executable_exit\" = 0 ] && browser_executable_present=yes", + "fi", "launcher_import_ok=no", "launcher_import_exit=", "if command -v node >/dev/null 2>&1 && [ -f \"$workspace/scripts/src/browser-launcher.mjs\" ]; then", @@ -254,6 +277,10 @@ function sourceWorkspaceStatusScript(spec: HwlabRuntimeLaneSpec, sourceWorkspace "printf 'npxVersion\\t%s\\n' \"$npx_version\"", "printf 'playwrightPackagePresent\\t%s\\n' \"$playwright_package_present\"", "printf 'browserCachePresent\\t%s\\n' \"$browser_cache_present\"", + "printf 'browserExecutablePresent\\t%s\\n' \"$browser_executable_present\"", + "printf 'browserExecutableExitCode\\t%s\\n' \"$browser_executable_exit\"", + "printf 'browserExecutablePath\\t%s\\n' \"$browser_executable_path\"", + "printf 'browserExecutableErrorTail\\t%s\\n' \"$browser_executable_error_tail\"", "printf 'launcherImportOk\\t%s\\n' \"$launcher_import_ok\"", "printf 'launcherImportExitCode\\t%s\\n' \"$launcher_import_exit\"", "printf 'statusShortLines\\t%s\\n' \"$status_short_lines\"", @@ -448,6 +475,7 @@ function sourceWorkspaceJobContainerScript( " command -v \"$command_name\" >/dev/null 2>>\"$stderr_log\"", "done <\"$tmp_dir/commands.txt\"", "mkdir -p \"$(dirname \"$workspace\")\"", + "git config --global --add safe.directory \"$workspace\" >>\"$stdout_log\" 2>>\"$stderr_log\" || true", "if [ -d \"$workspace/.git\" ] && git -C \"$workspace\" rev-parse --git-dir >/dev/null 2>&1; then", " status_short=$(git -C \"$workspace\" status --short)", " if [ -n \"$status_short\" ]; then echo \"source workspace is dirty; refusing to overwrite\" >>\"$stderr_log\"; exit 42; fi",