import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";

import {
  INI_PANEL_ENTRIES,
  controlPageStatusText,
  createControlPageBrowserApiManifest,
  createControlPageSessionLoadState,
  createControlPageBrowserApiMethods,
  createControlPageBrowserApiSchema,
  createIniPanelLaunchApiManifest,
  createIniPanelLaunchApiSchema,
  createIniPanelLauncherLinkViewModel,
  createIniPanelShellControlPageContract,
  createIniPanelShellIntegrationManifest,
  createIniPanelShellIntegrationReadiness,
  createIniPanelShellIntegrationSchema,
  createIniPanelShellIntegrationWorkflowPlan,
  createIniPanelShellSessionHandoffActionPlan,
  createIniPanelShellSessionHandoffChecklist,
  createIniPanelShellSessionHandoffCompatibilityReport,
  createIniPanelShellSessionHandoffDisplayViewModel,
  createIniPanelShellSessionHandoffPackage,
  createIniPanelShellSessionHandoffPackageDisplayViewModel,
  createIniPanelShellSessionHandoffPackageMountDisplayViewModel,
  createIniPanelShellSessionHandoffPackageMountRenderState,
  createIniPanelShellSessionHandoffPackageMountState,
  createIniPanelShellSessionHandoffMountDomContract,
  createIniPanelShellSessionHandoffMountDomReadiness,
  mountIniPanelShellSessionHandoff,
  mountIniPanelShellSessionHandoffFromControlPage,
  readIniPanelShellSessionHandoffStatusFromControlPage,
  createIniPanelShellSessionHandoffWorkflowSummary,
  createIniPanelShellSessionHandoffWorkflowDisplayViewModel,
  createIniPanelShellSessionHandoffWorkflowRenderState,
  createIniPanelShellSessionHandoffWorkflowDomContract,
  createIniPanelShellSessionHandoffWorkflowDomReadiness,
  createIniPanelShellWorkflowOverviewContract,
  createIniPanelShellWorkflowOverviewReadiness,
  createIniPanelShellWorkflowOverviewEmbeddingReport,
  createIniPanelShellWorkflowOverviewEmbeddingDisplayViewModel,
  createIniPanelShellWorkflowOverviewEmbeddingRenderState,
  createIniPanelShellWorkflowOverviewEmbeddingDomContract,
  createIniPanelShellWorkflowOverviewEmbeddingDomReadiness,
  mountIniPanelShellWorkflowOverviewEmbedding,
  renderIniPanelShellWorkflowOverviewEmbeddingState,
  mountIniPanelShellWorkflowOverviewEmbeddingState,
  createIniPanelShellWorkflowOverviewEmbeddingMountDisplayViewModel,
  createIniPanelShellWorkflowOverviewEmbeddingMountRenderState,
  createIniPanelShellWorkflowOverviewEmbeddingMountDomContract,
  createIniPanelShellWorkflowOverviewEmbeddingMountDomReadiness,
  renderIniPanelShellWorkflowOverviewEmbeddingMountState,
  mountIniPanelShellWorkflowOverviewEmbeddingMountState,
  renderIniPanelShellSessionHandoffWorkflowState,
  mountIniPanelShellSessionHandoffWorkflow,
  renderIniPanelShellSessionHandoffMountState,
  createIniPanelShellSessionHandoffPackageReport,
  createIniPanelShellSessionHandoffPackageRenderState,
  createIniPanelShellSessionHandoffPackageSchema,
  createIniPanelShellSessionHandoffRenderState,
  createIniPanelShellSessionHandoffSnapshot,
  createIniPanelShellSessionHandoffSummary,
  createIniPanelShellSessionHandoffSummarySchema,
  createIniPanelShellViewModel,
  createMachineSessionReadonlyStatus,
  createMachineSessionReadonlyStatusApiManifest,
  createMachineSessionReadinessFieldState,
  machineSessionReadinessLogLines,
  readMachineSessionReadinessWorkflow,
  loadMachineSessionForControlPageWorkflow,
  readMachineSessionReadonlyStatus,
  refreshMachineSessionControlPage,
  getVisibleIniPanelEntries,
  isSupportedIniPanelControlPageApiManifest,
  isSupportedIniPanelLaunchApiManifest,
  isSupportedIniPanelShellIntegrationManifest,
  isSupportedIniPanelShellSessionHandoffPackage,
  isSupportedIniPanelShellSessionHandoffSummary,
} from "../../../runtime/ui/ini-panel/ui-shell.js";

const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, "../../..");
const docText = readFileSync(resolve(root, "docs/panel-entry.md"), "utf8");
const shellText = readFileSync(resolve(root, "runtime/ui/ini-panel/ui-shell.js"), "utf8");
const controlPageText = readFileSync(resolve(root, "runtime/ui/ini-panel/control-page.js"), "utf8");
const launchText = readFileSync(resolve(root, "runtime/ui/ini-panel/launch.html"), "utf8");
const browserIniPanelText = readFileSync(resolve(root, "tests/browser/verify_ini_panel_browser.sh"), "utf8");
const shellIntegrationWorkflowSmokeText = readFileSync(
  resolve(root, "tests/browser/ini_panel_shell_integration_workflow_smoke.html"),
  "utf8",
);
const refreshWorkflowText = readFileSync(
  resolve(root, "runtime/ui/ini-panel/control-page-refresh-workflow.js"),
  "utf8",
);
const sessionWorkflowText = readFileSync(
  resolve(root, "runtime/ui/ini-panel/control-page-session-workflow.js"),
  "utf8",
);
const iniPanelSessionWorkflowText = readFileSync(
  resolve(root, "runtime/ui/ini-panel/session-workflow.js"),
  "utf8",
);

const requiredShellExports = [
  "INI_PANEL_ENTRIES",
  "controlPageStatusText",
  "createControlPageBrowserApiManifest",
  "createControlPageBrowserApiMethods",
  "createControlPageBrowserApiSchema",
  "createControlPageSessionLoadState",
  "createIniPanelLaunchApiManifest",
  "createIniPanelLaunchApiSchema",
  "createIniPanelLauncherLinkViewModel",
  "createIniPanelShellControlPageContract",
  "createIniPanelShellIntegrationManifest",
  "createIniPanelShellIntegrationReadiness",
  "createIniPanelShellIntegrationSchema",
  "createIniPanelShellIntegrationWorkflowPlan",
  "createIniPanelShellSessionHandoffActionPlan",
  "createIniPanelShellSessionHandoffChecklist",
  "createIniPanelShellSessionHandoffCompatibilityReport",
  "createIniPanelShellSessionHandoffDisplayViewModel",
  "createIniPanelShellSessionHandoffPackage",
  "createIniPanelShellSessionHandoffPackageDisplayViewModel",
  "createIniPanelShellSessionHandoffPackageMountDisplayViewModel",
  "createIniPanelShellSessionHandoffPackageMountRenderState",
  "createIniPanelShellSessionHandoffPackageMountState",
  "createIniPanelShellSessionHandoffMountDomContract",
  "createIniPanelShellSessionHandoffMountDomReadiness",
  "mountIniPanelShellSessionHandoff",
  "mountIniPanelShellSessionHandoffFromControlPage",
  "readIniPanelShellSessionHandoffStatusFromControlPage",
  "createIniPanelShellSessionHandoffWorkflowSummary",
  "createIniPanelShellSessionHandoffWorkflowDisplayViewModel",
  "createIniPanelShellSessionHandoffWorkflowRenderState",
  "createIniPanelShellSessionHandoffWorkflowDomContract",
  "createIniPanelShellSessionHandoffWorkflowDomReadiness",
  "createIniPanelShellWorkflowOverviewContract",
  "createIniPanelShellWorkflowOverviewReadiness",
  "createIniPanelShellWorkflowOverviewEmbeddingReport",
  "createIniPanelShellWorkflowOverviewEmbeddingDisplayViewModel",
  "createIniPanelShellWorkflowOverviewEmbeddingRenderState",
  "createIniPanelShellWorkflowOverviewEmbeddingDomContract",
  "createIniPanelShellWorkflowOverviewEmbeddingDomReadiness",
  "mountIniPanelShellWorkflowOverviewEmbedding",
  "renderIniPanelShellWorkflowOverviewEmbeddingState",
  "mountIniPanelShellWorkflowOverviewEmbeddingState",
  "createIniPanelShellWorkflowOverviewEmbeddingMountDisplayViewModel",
  "createIniPanelShellWorkflowOverviewEmbeddingMountRenderState",
  "createIniPanelShellWorkflowOverviewEmbeddingMountDomContract",
  "createIniPanelShellWorkflowOverviewEmbeddingMountDomReadiness",
  "renderIniPanelShellWorkflowOverviewEmbeddingMountState",
  "mountIniPanelShellWorkflowOverviewEmbeddingMountState",
  "renderIniPanelShellSessionHandoffWorkflowState",
  "mountIniPanelShellSessionHandoffWorkflow",
  "renderIniPanelShellSessionHandoffMountState",
  "createIniPanelShellSessionHandoffPackageReport",
  "createIniPanelShellSessionHandoffPackageRenderState",
  "createIniPanelShellSessionHandoffPackageSchema",
  "createIniPanelShellSessionHandoffRenderState",
  "createIniPanelShellSessionHandoffSnapshot",
  "createIniPanelShellSessionHandoffSummary",
  "createIniPanelShellSessionHandoffSummarySchema",
  "createIniPanelShellViewModel",
  "getIniPanelEntryByHref",
  "getVisibleIniPanelEntries",
  "isSupportedIniPanelControlPageApiManifest",
  "isSupportedIniPanelLaunchApiManifest",
  "isSupportedIniPanelShellIntegrationManifest",
  "isSupportedIniPanelShellSessionHandoffPackage",
  "isSupportedIniPanelShellSessionHandoffSummary",
  "createMachineSessionControlPageController",
  "createMachineSessionReadonlyStatus",
  "createMachineSessionReadonlyStatusApiManifest",
  "createMachineSessionReadinessFieldState",
  "machineSessionReadinessLogLines",
  "readMachineSessionReadinessWorkflow",
  "loadMachineSessionForControlPageWorkflow",
  "readMachineSessionReadonlyStatus",
  "refreshMachineSessionControlPage",
  "renderMachineSessionControlView",
];

for (const exportName of requiredShellExports) {
  assert.match(shellText, new RegExp(`\\b${exportName}\\b`));
  assert.match(docText, new RegExp(`\\b${exportName}\\b`));
}

for (const exportName of [
  "controlPageStatusText",
  "createControlPageRefreshState",
  "refreshMachineSessionControlPage",
]) {
  assert.match(refreshWorkflowText, new RegExp(`\\bexport function ${exportName}\\b`));
  assert.match(docText, new RegExp(`\\b${exportName}\\b`));
}

for (const exportName of [
  "createControlPageSessionLoadState",
  "loadMachineSessionForControlPageWorkflow",
]) {
  assert.match(sessionWorkflowText, new RegExp(`\\bexport function ${exportName}\\b`));
  assert.match(docText, new RegExp(`\\b${exportName}\\b`));
}

for (const exportName of [
  "createMachineSessionReadinessFieldState",
  "machineSessionReadinessLogLines",
  "readMachineSessionReadinessWorkflow",
]) {
  assert.match(iniPanelSessionWorkflowText, new RegExp(`\\bexport (?:async )?function ${exportName}\\b`));
  assert.match(docText, new RegExp(`\\b${exportName}\\b`));
}

const requiredPages = [
  ["Launch", "runtime/ui/ini-panel/launch.html"],
  ["Edit and run", "runtime/ui/ini-panel/index.html"],
  ["Read-only control view", "runtime/ui/ini-panel/control-page.html"],
  ["Workflow overview", "runtime/ui/ini-panel/workflow-overview.html"],
];

for (const [label, path] of requiredPages) {
  assert.match(docText, new RegExp(`\\| ${label} \\| \`${path.replaceAll("/", "\\/")}\``));
}

assert.deepEqual(getVisibleIniPanelEntries(), INI_PANEL_ENTRIES);
assert.deepEqual(
  createIniPanelLauncherLinkViewModel(),
  INI_PANEL_ENTRIES.map(({ id, href, title }) => ({
    entryId: id,
    href,
    label: title,
  })),
);
assert.deepEqual(createIniPanelShellViewModel().pages, getVisibleIniPanelEntries());
assert.deepEqual(createIniPanelShellViewModel().launcherLinks, createIniPanelLauncherLinkViewModel());
assert.deepEqual(
  createIniPanelShellViewModel().shellIntegrationSchema,
  createIniPanelShellIntegrationSchema(),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellIntegrationManifest,
  createIniPanelShellIntegrationManifest(),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellIntegrationReadiness,
  createIniPanelShellIntegrationReadiness(createIniPanelShellViewModel().shellIntegrationManifest),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellIntegrationWorkflowPlan,
  createIniPanelShellIntegrationWorkflowPlan({
    manifest: createIniPanelShellViewModel().shellIntegrationManifest,
    readiness: createIniPanelShellViewModel().shellIntegrationReadiness,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffSummary,
  createIniPanelShellSessionHandoffSummary({
    manifest: createIniPanelShellViewModel().shellIntegrationManifest,
    readiness: createIniPanelShellViewModel().shellIntegrationReadiness,
    workflowPlan: createIniPanelShellViewModel().shellIntegrationWorkflowPlan,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffSummarySchema,
  createIniPanelShellSessionHandoffSummarySchema(),
);
assert.equal(isSupportedIniPanelShellSessionHandoffSummary(createIniPanelShellViewModel().shellSessionHandoffSummary), true);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffCompatibilityReport,
  createIniPanelShellSessionHandoffCompatibilityReport(createIniPanelShellViewModel().shellSessionHandoffSummary),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffDisplayViewModel,
  createIniPanelShellSessionHandoffDisplayViewModel(createIniPanelShellViewModel().shellSessionHandoffCompatibilityReport),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffSnapshot,
  createIniPanelShellSessionHandoffSnapshot({
    readiness: createIniPanelShellViewModel().shellIntegrationReadiness,
    summary: createIniPanelShellViewModel().shellSessionHandoffSummary,
    compatibilityReport: createIniPanelShellViewModel().shellSessionHandoffCompatibilityReport,
    displayViewModel: createIniPanelShellViewModel().shellSessionHandoffDisplayViewModel,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffRenderState,
  createIniPanelShellSessionHandoffRenderState(createIniPanelShellViewModel().shellSessionHandoffSnapshot),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffActionPlan,
  createIniPanelShellSessionHandoffActionPlan({
    snapshot: createIniPanelShellViewModel().shellSessionHandoffSnapshot,
    renderState: createIniPanelShellViewModel().shellSessionHandoffRenderState,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffChecklist,
  createIniPanelShellSessionHandoffChecklist({
    actionPlan: createIniPanelShellViewModel().shellSessionHandoffActionPlan,
    renderState: createIniPanelShellViewModel().shellSessionHandoffRenderState,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackage,
  createIniPanelShellSessionHandoffPackage({
    shellIntegrationManifest: createIniPanelShellViewModel().shellIntegrationManifest,
    launchApiManifest: createIniPanelShellViewModel().shellIntegrationManifest.launchApiManifest,
    controlPageApiManifest: createIniPanelShellViewModel().shellIntegrationManifest.controlPageApiManifest,
    snapshot: createIniPanelShellViewModel().shellSessionHandoffSnapshot,
    renderState: createIniPanelShellViewModel().shellSessionHandoffRenderState,
    actionPlan: createIniPanelShellViewModel().shellSessionHandoffActionPlan,
    checklist: createIniPanelShellViewModel().shellSessionHandoffChecklist,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageSchema,
  createIniPanelShellSessionHandoffPackageSchema(),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageReport,
  createIniPanelShellSessionHandoffPackageReport(createIniPanelShellViewModel().shellSessionHandoffPackage),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageDisplayViewModel,
  createIniPanelShellSessionHandoffPackageDisplayViewModel(
    createIniPanelShellViewModel().shellSessionHandoffPackageReport,
  ),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageRenderState,
  createIniPanelShellSessionHandoffPackageRenderState(
    createIniPanelShellViewModel().shellSessionHandoffPackageDisplayViewModel,
  ),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageMountState,
  createIniPanelShellSessionHandoffPackageMountState({
    handoffPackage: createIniPanelShellViewModel().shellSessionHandoffPackage,
    packageRenderState: createIniPanelShellViewModel().shellSessionHandoffPackageRenderState,
  }),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageMountDisplayViewModel,
  createIniPanelShellSessionHandoffPackageMountDisplayViewModel(
    createIniPanelShellViewModel().shellSessionHandoffPackageMountState,
  ),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffPackageMountRenderState,
  createIniPanelShellSessionHandoffPackageMountRenderState(
    createIniPanelShellViewModel().shellSessionHandoffPackageMountDisplayViewModel,
  ),
);
assert.deepEqual(
  createIniPanelShellViewModel().shellSessionHandoffMountDomContract,
  createIniPanelShellSessionHandoffMountDomContract(),
);
assert.equal(
  createIniPanelShellSessionHandoffMountDomReadiness({ documentRef: null }).ready,
  false,
);
assert.equal(
  mountIniPanelShellSessionHandoff({ documentRef: null }).phase,
  "blocked",
);
assert.equal(
  mountIniPanelShellSessionHandoffFromControlPage({ documentRef: null }).mountWorkflow.phase,
  "blocked",
);
assert.equal(
  readIniPanelShellSessionHandoffStatusFromControlPage().phase,
  "blocked",
);
assert.equal(
  createIniPanelShellSessionHandoffWorkflowSummary().phase,
  "blocked",
);
assert.equal(
  createIniPanelShellSessionHandoffWorkflowDisplayViewModel().phase,
  "blocked",
);
assert.equal(
  createIniPanelShellSessionHandoffWorkflowRenderState().phase,
  "blocked",
);
assert.equal(
  createIniPanelShellSessionHandoffWorkflowDomContract().selectors.mount,
  "[data-handoff-workflow]",
);
assert.equal(
  createIniPanelShellSessionHandoffWorkflowDomReadiness().phase,
  "blocked",
);
assert.equal(
  mountIniPanelShellSessionHandoffWorkflow().phase,
  "blocked",
);
assert.equal(isSupportedIniPanelShellSessionHandoffPackage(createIniPanelShellViewModel().shellSessionHandoffPackage), true);
assert.equal(isSupportedIniPanelShellIntegrationManifest(createIniPanelShellViewModel().shellIntegrationManifest), true);
assert.deepEqual(createIniPanelShellViewModel().launchApiSchema, createIniPanelLaunchApiSchema());
assert.deepEqual(createIniPanelShellViewModel().launchApiManifest, createIniPanelLaunchApiManifest());
assert.equal(isSupportedIniPanelLaunchApiManifest(createIniPanelShellViewModel().launchApiManifest), true);
assert.equal(createIniPanelShellViewModel().launchApiManifest.manifestVersion, createIniPanelLaunchApiSchema().manifestVersion);
assert.deepEqual(
  createIniPanelShellViewModel().controlPage.browserApiSchema,
  createControlPageBrowserApiSchema(),
);
assert.deepEqual(
  createIniPanelShellViewModel().controlPage.browserApiManifest,
  createControlPageBrowserApiManifest(),
);
assert.equal(isSupportedIniPanelControlPageApiManifest(createIniPanelShellViewModel().controlPage.browserApiManifest), true);
assert.deepEqual(
  createIniPanelShellViewModel().controlPage.contract,
  createIniPanelShellControlPageContract(),
);
assert.deepEqual(
  createIniPanelShellViewModel().controlPage.browserApiMethods,
  createControlPageBrowserApiMethods(),
);
assert.equal(controlPageStatusText({ lastAction: "run-gcode", runStatus: "ok", error: null }), "run-gcode | ok | -");
assert.deepEqual(createControlPageSessionLoadState({ phase: "waiting-panel" }), {
  phase: "waiting-panel",
  panelReady: false,
  apiReady: false,
  controlViewReady: false,
  stateBundle: null,
  workflowStatus: null,
  sessionReadiness: null,
  controlView: null,
  error: null,
});
assert.equal(typeof createIniPanelShellViewModel().controlPage.createController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(typeof createMachineSessionReadonlyStatusApiManifest, "function");
assert.equal(createIniPanelShellViewModel().controlPage.loadSessionState, loadMachineSessionForControlPageWorkflow);
assert.equal(createIniPanelShellViewModel().controlPage.readonlyStatusApiManifest.apiName, "machine-session-readonly-status");
assert.deepEqual(
  createIniPanelShellViewModel().controlPage.readonlyStatusApiManifest,
  createMachineSessionReadonlyStatusApiManifest(),
);
assert.equal(createIniPanelShellViewModel().controlPage.readStatus, readMachineSessionReadonlyStatus);
assert.equal(createIniPanelShellViewModel().controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(typeof createIniPanelShellViewModel().controlPage.renderView, "function");
assert.match(shellText, /\bexport function createControlPageBrowserApiMethods\b/);
assert.match(shellText, /\bexport function createControlPageBrowserApiManifest\b/);
assert.match(shellText, /\bexport function createControlPageBrowserApiSchema\b/);
assert.match(shellText, /\bexport function createIniPanelLaunchApiSchema\b/);
assert.match(shellText, /\bexport function createIniPanelLaunchApiManifest\b/);
assert.match(shellText, /\bexport function createIniPanelShellIntegrationSchema\b/);
assert.match(shellText, /\bexport function createIniPanelShellIntegrationManifest\b/);
assert.match(shellText, /\bexport function createIniPanelShellIntegrationReadiness\b/);
assert.match(shellText, /\bexport function createIniPanelShellIntegrationWorkflowPlan\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffActionPlan\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffChecklist\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffCompatibilityReport\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffDisplayViewModel\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffPackage\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffPackageReport\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffPackageSchema\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffRenderState\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffSnapshot\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffSummary\b/);
assert.match(shellText, /\bexport function createIniPanelShellSessionHandoffSummarySchema\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingReport\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingDisplayViewModel\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingRenderState\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingDomContract\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingDomReadiness\b/);
assert.match(shellText, /\bexport function renderIniPanelShellWorkflowOverviewEmbeddingState\b/);
assert.match(shellText, /\bexport function mountIniPanelShellWorkflowOverviewEmbeddingState\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingMountDisplayViewModel\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingMountRenderState\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingMountDomContract\b/);
assert.match(shellText, /\bexport function createIniPanelShellWorkflowOverviewEmbeddingMountDomReadiness\b/);
assert.match(shellText, /\bexport function renderIniPanelShellWorkflowOverviewEmbeddingMountState\b/);
assert.match(shellText, /\bexport function mountIniPanelShellWorkflowOverviewEmbeddingMountState\b/);
assert.match(shellText, /\bexport function isSupportedIniPanelControlPageApiManifest\b/);
assert.match(shellText, /\bexport function isSupportedIniPanelLaunchApiManifest\b/);
assert.match(shellText, /\bexport function isSupportedIniPanelShellIntegrationManifest\b/);
assert.match(shellText, /\bexport function isSupportedIniPanelShellSessionHandoffPackage\b/);
assert.match(shellText, /\bexport function isSupportedIniPanelShellSessionHandoffSummary\b/);
assert.match(controlPageText, /\bisSupportedControlPageApiManifest\b/);
assert.match(controlPageText, /\bgetControlPageApiSchema\b/);
assert.match(controlPageText, /\bgetControlPageApiManifest\b/);
assert.match(controlPageText, /\bgetControlPageApiMethods\b/);
assert.match(launchText, /\blinuxCncIniPanelLaunchApi\b/);
assert.match(launchText, /\bisSupportedLaunchApiManifest\b/);
assert.match(launchText, /\bgetLaunchApiSchema\b/);
assert.match(launchText, /\bgetLaunchApiManifest\b/);
assert.match(launchText, /\bgetShellIntegrationSchema\b/);
assert.match(launchText, /\bgetShellIntegrationManifest\b/);
assert.match(launchText, /\bgetShellIntegrationReadiness\b/);
assert.match(launchText, /\bgetShellSessionHandoffSummarySchema\b/);
assert.match(launchText, /\bgetShellSessionHandoffSummary\b/);
assert.match(launchText, /\bisSupportedShellSessionHandoffSummary\b/);
assert.match(launchText, /\bgetShellSessionHandoffCompatibilityReport\b/);
assert.match(launchText, /\bgetShellSessionHandoffDisplayViewModel\b/);
assert.match(launchText, /\bgetShellSessionHandoffSnapshot\b/);
assert.match(launchText, /\bgetShellSessionHandoffRenderState\b/);
assert.match(launchText, /\bgetShellSessionHandoffActionPlan\b/);
assert.match(launchText, /\bgetShellSessionHandoffChecklist\b/);
assert.match(launchText, /\bgetShellSessionHandoffPackageSchema\b/);
assert.match(launchText, /\bgetShellSessionHandoffPackage\b/);
assert.match(launchText, /\bgetShellSessionHandoffPackageReport\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingReport\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingDisplayViewModel\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingRenderState\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingDomContract\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingDomReadiness\b/);
assert.match(launchText, /\brenderWorkflowOverviewEmbeddingState\b/);
assert.match(launchText, /\bmountWorkflowOverviewEmbeddingState\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingMountDisplayViewModel\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingMountRenderState\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingMountDomContract\b/);
assert.match(launchText, /\bgetWorkflowOverviewEmbeddingMountDomReadiness\b/);
assert.match(launchText, /\brenderWorkflowOverviewEmbeddingMountState\b/);
assert.match(launchText, /\bmountWorkflowOverviewEmbeddingMountState\b/);
assert.match(launchText, /\bisSupportedShellSessionHandoffPackage\b/);
assert.match(launchText, /\bdata-handoff-shell\b/);
assert.match(launchText, /\bdata-handoff-status\b/);
assert.match(launchText, /\bdata-handoff-rows\b/);
assert.match(launchText, /\bgetControlPageApiMethods\b/);
assert.match(controlPageText, /\bgetControlPageContract\b/);
assert.match(controlPageText, /\breadControlPageStatus\b/);
assert.match(controlPageText, /\bcreateIniPanelShellControlPageContract\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageApiMethods\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageApiSchema\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.isSupportedControlPageApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageContract\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.readControlPageStatus\b/);
assert.match(docText, /\bcreateControlPageBrowserApiManifest\b/);
assert.match(docText, /\bcreateControlPageBrowserApiSchema\b/);
assert.match(docText, /\bcreateIniPanelLaunchApiManifest\b/);
assert.match(docText, /\bcreateIniPanelLaunchApiSchema\b/);
assert.match(docText, /\bcreateIniPanelShellIntegrationManifest\b/);
assert.match(docText, /\bcreateIniPanelShellIntegrationReadiness\b/);
assert.match(docText, /\bcreateIniPanelShellIntegrationSchema\b/);
assert.match(docText, /\bcreateIniPanelShellIntegrationWorkflowPlan\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffActionPlan\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffChecklist\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffCompatibilityReport\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffDisplayViewModel\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffPackage\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffPackageReport\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffPackageSchema\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffRenderState\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffSnapshot\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffSummary\b/);
assert.match(docText, /\bcreateIniPanelShellSessionHandoffSummarySchema\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingReport\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingDisplayViewModel\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingRenderState\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingDomContract\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingDomReadiness\b/);
assert.match(docText, /\brenderIniPanelShellWorkflowOverviewEmbeddingState\b/);
assert.match(docText, /\bmountIniPanelShellWorkflowOverviewEmbeddingState\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingMountDisplayViewModel\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingMountRenderState\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingMountDomContract\b/);
assert.match(docText, /\bcreateIniPanelShellWorkflowOverviewEmbeddingMountDomReadiness\b/);
assert.match(docText, /\brenderIniPanelShellWorkflowOverviewEmbeddingMountState\b/);
assert.match(docText, /\bmountIniPanelShellWorkflowOverviewEmbeddingMountState\b/);
assert.match(docText, /\bisSupportedIniPanelControlPageApiManifest\b/);
assert.match(docText, /\bisSupportedIniPanelLaunchApiManifest\b/);
assert.match(docText, /\bisSupportedIniPanelShellIntegrationManifest\b/);
assert.match(docText, /\bisSupportedIniPanelShellSessionHandoffPackage\b/);
assert.match(docText, /\bisSupportedIniPanelShellSessionHandoffSummary\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.isSupportedLaunchApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getLaunchApiSchema\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getLaunchApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellIntegrationSchema\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellIntegrationManifest\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellIntegrationReadiness\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffSummarySchema\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffSummary\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.isSupportedShellSessionHandoffSummary\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffCompatibilityReport\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffDisplayViewModel\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffSnapshot\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffRenderState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffActionPlan\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffChecklist\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffPackageSchema\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffPackage\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffPackageReport\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingReport\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingDisplayViewModel\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingRenderState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingDomContract\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingDomReadiness\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.renderWorkflowOverviewEmbeddingState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.mountWorkflowOverviewEmbeddingState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingMountDisplayViewModel\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingMountRenderState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingMountDomContract\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getWorkflowOverviewEmbeddingMountDomReadiness\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.renderWorkflowOverviewEmbeddingMountState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.mountWorkflowOverviewEmbeddingMountState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.isSupportedShellSessionHandoffPackage\b/);
assert.match(docText, /\bdata-handoff-shell\b/);
assert.match(docText, /\bdata-handoff-status\b/);
assert.match(docText, /\bdata-handoff-rows\b/);
assert.match(docText, /\bdata-external-shell-mount\b/);
assert.match(docText, /\brenderIniPanelShellSessionHandoffMountState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.renderShellSessionHandoffMountState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffMountDomContract\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffMountDomReadiness\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.mountShellSessionHandoff\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.mountShellSessionHandoffFromControlPage\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.readShellSessionHandoffStatusFromControlPage\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffWorkflowSummary\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffWorkflowDisplayViewModel\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffWorkflowRenderState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffWorkflowDomContract\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getShellSessionHandoffWorkflowDomReadiness\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.renderShellSessionHandoffWorkflowState\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.mountShellSessionHandoffWorkflow\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getControlPageApiMethods\b/);
assert.match(docText, /\bini_panel_shell_integration_workflow_smoke\.html\b/);
assert.match(browserIniPanelText, /\bini_panel_shell_integration_workflow_smoke\.html\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellIntegrationReadiness\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffSummary\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bisSupportedShellSessionHandoffSummary\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffCompatibilityReport\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffDisplayViewModel\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffSnapshot\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffRenderState\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffActionPlan\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffChecklist\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffPackageSchema\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffPackage\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffPackageReport\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffPackageMountRenderState\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffMountDomContract\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffMountDomReadiness\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bmountShellSessionHandoff\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bmountShellSessionHandoffFromControlPage\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\breadShellSessionHandoffStatusFromControlPage\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffWorkflowSummary\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffWorkflowDisplayViewModel\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffWorkflowRenderState\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffWorkflowDomContract\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetShellSessionHandoffWorkflowDomReadiness\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\brenderShellSessionHandoffWorkflowState\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bmountShellSessionHandoffWorkflow\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bgetWorkflowOverviewEmbeddingReport\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\brenderShellSessionHandoffMountState\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bdata-external-shell-mount\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bdata-external-mount-value\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bisSupportedShellSessionHandoffPackage\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bhandoffSummary\.handoffMethods\.readStatus\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\breadControlPageStatus\b/);
assert.match(shellIntegrationWorkflowSmokeText, /\bbrowser_ini_shell_integration_workflow_smoke=ok\b/);
assert.match(docText, /\bOPFS\/session persistence capabilities\b/);
assert.match(docText, /\bmachine files\b/);
assert.match(docText, /\bsession snapshots\b/);
assert.match(docText, /\bread-only status\b/);

for (const entry of INI_PANEL_ENTRIES) {
  const escapedHref = entry.href.replace(".", "\\.");
  assert.match(docText, new RegExp(`\\| \`${entry.id}\` \\| \`${escapedHref}\` \\| ${entry.title} \\|`));
}

console.log("ini_panel_entry_docs_node_smoke=ok");
