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

const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, "../../..");

const docText = readFileSync(resolve(root, "docs/opfs-session-persistence.md"), "utf8");
const readmeText = readFileSync(resolve(root, "README.md"), "utf8");
const sdkReadmeText = readFileSync(resolve(root, "runtime/sdk/README.md"), "utf8");
const hostSmokeText = readFileSync(resolve(root, "tests/host/verify_host_smokes.sh"), "utf8");
const browserSmokeText = readFileSync(resolve(root, "tests/browser/verify_ini_panel_browser.sh"), "utf8");
const trackerText = readFileSync(resolve(root, "../PROJECT_COMPLETION_TRACKER.md"), "utf8");

for (const phrase of [
  "OPFS/session persistence and release gate",
  "runtime/sdk/src/index.js",
  "createMachineSessionSnapshotPayload",
  "readMachineSessionReadiness",
  "loadMachineSessionFromOpfs",
  "restoreMachineParametersFromOpfs",
  "loadMachineToolTableFromOpfs",
  "browser_ini_opfs_smoke=ok",
  "sdk_surface_node_smoke=ok",
  "host_wasm_opfs_browser_smokes=ok",
  "verify_no_standalone_cnc_semantics.sh",
  "L4-USER-M-PROCESS",
  "L4-TOOL-DB",
  "L4-PYTHON-REMAP",
]) {
  assert.match(docText, new RegExp(phrase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
}

assert.match(readmeText, /docs\/opfs-session-persistence\.md/);
assert.match(sdkReadmeText, /OPFS\/session persistence exports/);
assert.match(sdkReadmeText, /readMachineSessionReadiness/);
assert.match(hostSmokeText, /verify_sdk_surface\.sh/);
assert.match(hostSmokeText, /verify_file_service\.sh/);
assert.match(browserSmokeText, /browser_ini_opfs_smoke=ok/);
assert.match(trackerText, /OPFS\/session persistence/);

console.log("opfs_session_docs_node_smoke=ok");
