import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Saved notebook error preview strips colon SGR and preserves frames", WEB, async ({ t3, app, screen }) => {
  const notebook = { nbformat: 4, nbformat_minor: 5, metadata: {}, cells: [{ cell_type: "code", execution_count: 3, metadata: {}, source: ["fail()"], outputs: [{ output_type: "error", ename: "ValueError", evalue: "preview proof", traceback: ["\u001b[31mTraceback (most recent call last):\n\u001b[0m", "\u001b[38:2::255:0:0mCell In[3], line 1\n----> 1 fail()\n\u001b[0m\u001b[39m", "\u001b[31mValueError: preview proof\u001b[0m", "final entry"] }] }] };
  const project = await t3.project("notebook-proof", { "colon-sgr.ipynb": JSON.stringify(notebook) });
  const thread = await t3.thread({ project, title: "Notebook error preview", messages: ["Inspect the saved notebook"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel", { exact: true }).tap();
  await screen.getByRole("button", "Files F", { exact: true }).tap();
  await screen.getByRole("treeitem", "colon-sgr.ipynb", { exact: true }).tap();
  const traceback = screen.getByText("Traceback (most recent call last):", { exact: false });
  await traceback.waitFor({ state: "visible" });
  await screen.getByText("Loading code...", { exact: true }).waitFor({ state: "hidden" });
  await screen.getByRole("button", "Maximize panel", { exact: true }).tap();
  await app.screenshot("notebook-error-preview");
  await expect(traceback).toHaveText("Traceback (most recent call last): Cell In[3], line 1 ----> 1 fail() ValueError: preview proof final entry");
});
