// #region ReportPageContractTest:Module [TYPE Function]
// @SEMANTICS: llm-report, svelte-effect, screenshot-loading, regression-test
// @PURPOSE: Protect the LLM report page from self-triggering screenshot load effects.
// @LAYER UI (Tests)
// @RELATION BINDS_TO -> [LlmReportPage]

import { describe, it, expect } from "vitest";
import fs from "node:fs";
import path from "node:path";

const PAGE_PATH = path.resolve(
  process.cwd(),
  "src/routes/reports/llm/[taskId]/+page.svelte",
);

// #region llm_report_screenshot_effect_contract:Function [TYPE Function]
// @RELATION USES -> [EXT:frontend:App]
// @PURPOSE: Ensure screenshot loading stays untracked from blob-url mutation state.
// @PRE: Report page source exists.
// @POST: Contract fails if screenshot loading effect can subscribe to screenshotBlobUrls updates.
describe("LLM report screenshot effect contract", () => {
  it("uses untrack around screenshot blob loading side effect", () => {
    const source = fs.readFileSync(PAGE_PATH, "utf-8");

    expect(source).toContain('import { onDestroy, onMount, untrack } from "svelte";');
    expect(source).toContain("untrack(() => {");
    expect(source).toContain("void loadScreenshotBlobUrls(paths);");
  });
});
// #endregion llm_report_screenshot_effect_contract:Function
// #endregion ReportPageContractTest:Module
