import assert from "node:assert/strict";
import { test } from "bun:test";

import { renderWebProbeScriptResult } from "./web-observe-render";

test("web-probe script render warns to promote repeated scripts into commands", () => {
  const rendered = renderWebProbeScriptResult({
    ok: true,
    status: "pass",
    command: "web-probe script --node D601 --lane v03",
    node: "D601",
    lane: "v03",
    url: "https://hwlab.example.test",
    warnings: [{
      code: "web_probe_script_ad_hoc_only",
      severity: "warning",
      message: "web-probe script is for one-off exploration; repeated or high-frequency checks must be promoted to a typed command instead of rerunning temporary scripts.",
    }],
    hints: [
      "Prefer `web-probe observe start` plus `web-probe observe command` for interactive flows.",
    ],
    preferredCommands: {
      startObserver: "bun scripts/cli.ts web-probe observe start --node D601 --lane v03 --target-path /projects/mdtodo",
      mdtodoSummary: "bun scripts/cli.ts web-probe observe collect <observerId> --view project-mdtodo-summary",
    },
    summary: { ok: true, status: "pass" },
    issueEvidence: {},
    probe: { steps: [], script: { result: { ok: true } } },
    reportLoad: { source: "stdout", path: ".state/web-probe-script/run.demo/web-probe-script-report.json" },
    result: { exitCode: 0, timedOut: false },
  });

  const text = String(rendered.renderedText ?? "");
  assert.match(text, /WARNINGS/u);
  assert.match(text, /web_probe_script_ad_hoc_only/u);
  assert.match(text, /HINTS/u);
  assert.match(text, /web-probe observe command/u);
  assert.match(text, /startObserver: bun scripts\/cli\.ts web-probe observe start/u);
  assert.match(text, /mdtodoSummary: bun scripts\/cli\.ts web-probe observe collect/u);
});
