// End-to-end verification for the #1403 fix: an HTML artifact whose
// React tree reads `localStorage` / `sessionStorage` during initial
// render used to throw `SecurityError` in the sandboxed preview
// iframe and unmount, because the URL-load path runs raw HTML under
// `sandbox="allow-scripts"` (no `allow-same-origin`) where the
// browser's real Web Storage access is rejected.
//
// PR #1306 landed the narrower fix: artifacts whose source matches
// `htmlNeedsSandboxShim()` are routed through `buildSrcdoc()`, which
// injects a Web Storage polyfill *before* any user script runs. This
// file exists to prove the fix end-to-end by:
//
// 1. Composing a real-shape React artifact that reads localStorage
// from a `useState` initializer (the exact repro in #1403's
// summary).
// 2. Running the produced srcDoc string through a sandboxed VM
// context whose `window` raises `SecurityError` on every
// Web Storage touch — modeling the browser's `allow-scripts`
// iframe behavior, which jsdom's default `window.localStorage`
// does not simulate on its own.
// 3. Asserting (a) the shim takes over `window.localStorage` /
// `window.sessionStorage`, and (b) the user script reads/writes
// without throwing.
//
// Closing the loop on the original report — the routing decision is
// already covered by `file-viewer-render-mode.test.ts`; this file
// covers the runtime payload the routing decision delivers.
import { describe, expect, it } from 'vitest';
import * as vm from 'node:vm';
import { buildSrcdoc } from '../../src/runtime/srcdoc';
// Pull every