import type { ProbeTarget } from "./verify-deploy";
import type { ProbeOutcome } from "./verify-deploy.drivers";
import type { FetchLike } from "./verify-deploy.drivers.baseline";
import { probeBaseline } from "./verify-deploy.drivers.baseline";
const DRIVER_LABEL = "dashboard";
const DEFAULT_TIMEOUT_MS = 30_000;
/**
* Production sentinels the dashboard's runtime-config reader emits when a
* required env var is unset on the Railway service. When either of these
* lands in the injected `window.__SHOWCASE_CONFIG__`, the dashboard renders
* with dead Demo/Code/hover-preview links (shellUrl) or dead Status-tab
* live-readers (pocketbaseUrl) — a 200 that is NOT healthy.
*
* These MUST stay in sync with the SSOT in
* `showcase/shell-dashboard/src/lib/runtime-config.ts:39-40`
* (`PROD_INVALID_POCKETBASE_URL` / `PROD_INVALID_SHELL_URL`). That module
* imports `next/cache`, so it cannot be cleanly imported into the scripts
* tsconfig (the scripts typecheck has no Next types and `include` is scoped
* to this directory); we mirror the literals here with this pointer instead
* of pulling Next into the verify-deploy toolchain.
*/
const PROD_INVALID_SHELL_URL = "about:blank#shell-url-missing";
const PROD_INVALID_POCKETBASE_URL = "http://pocketbase.invalid";
function isAbortError(e: unknown): boolean {
if (!e || typeof e !== "object") return false;
return (e as { name?: unknown }).name === "AbortError";
}
/**
* Extract the inlined runtime config from the dashboard's HTML. The root
* layout (`shell-dashboard/src/app/layout.tsx`) injects an inline
* `` close) and then strip the `window.__SHOWCASE_CONFIG__=` prefix
* and trailing `;`, rather than char-class-matching the JSON body. A body
* char-class like `\{[^<]*?\}` truncates at the first `};` that appears inside
* a value and fails entirely on trailing-whitespace / newline / missing-semi
* drift in the injection — and a silent no-match there would let a
* format-drifted-but-present config slip through as "block absent → pass".
* Anchoring on the tag boundary means any present-but-unparseable block
* fails LOUD (throws) instead.
*
* Returns the parsed config object, or `undefined` ONLY when the script tag
* is genuinely not present on the page (some renders may omit it) — in that
* case the probe must NOT false-fail. A present-but-malformed block (bad
* JSON, or a parseable non-object) THROWS so the verifier can never silently
* PASS on a wiring bug.
*/
function extractInjectedConfig(
html: string,
): Record | undefined {
// Match the inline config script by its id, capturing the tag body up to
// the closing . `[\s\S]` so the body may span newlines.
const tagMatch = html.match(
/