import assert from "node:assert/strict";
import test from "node:test";

import { artifactInfo, assistantSegments } from "./assistant-artifacts.js";

test("splits projected inline HTML directives from surrounding Markdown", () => {
  assert.deepEqual(assistantSegments([
    "Before",
    "::codex-inline-artifact{id=\"artifact-a1\" name=\"preview.html\" url=\"/api/sessions/session-1/artifacts/artifact-a1/preview.html\"}",
    "After"
  ].join("\n")), [
    { kind: "markdown", text: "Before\n" },
    {
      kind: "html",
      id: "artifact-a1",
      name: "preview.html",
      url: "/api/sessions/session-1/artifacts/artifact-a1/preview.html"
    },
    { kind: "markdown", text: "\nAfter" }
  ]);
});

test("recognizes only backend-issued artifact URLs and safe metadata", () => {
  assert.deepEqual(artifactInfo("/api/sessions/session-1/artifacts/artifact-a1?name=README.md&mime=text%2Fmarkdown&size=42&line=7"), {
    url: "/api/sessions/session-1/artifacts/artifact-a1?name=README.md&mime=text%2Fmarkdown&size=42&line=7",
    name: "README.md",
    mimeType: "text/markdown",
    size: 42,
    line: 7
  });
  assert.equal(artifactInfo("https://example.com/file.pdf"), null);
  assert.equal(artifactInfo("/api/sessions/session-1/attachments/image-1"), null);
});
