import { expect, gotoWorkbench, saveScreenshot, test } from "../fixtures/test";
import { selectors, sessionTab } from "../fixtures/selectors";

test.use({ scenarioId: "deleted-session-deeplink" });

test("fresh deep link does not restore an archived session as active", async ({ page }, testInfo) => {
  const detail = await page.request.get("/v1/workbench/sessions/ses_deleted");
  expect(detail.status()).toBe(200);
  expect((await detail.json()).session.status).toBe("archived");

  const list = await page.request.get("/v1/workbench/sessions?includeSessionId=ses_deleted");
  expect(list.status()).toBe(200);
  expect(((await list.json()).sessions as Array<{ sessionId: string; status?: string }>).some((item) => item.sessionId === "ses_deleted" && item.status === "archived")).toBe(true);

  await gotoWorkbench(page, "/workbench/sessions/ses_deleted");
  await expect(page.locator(sessionTab("ses_deleted"))).toHaveCount(0);
  await expect(page.locator(sessionTab("ses_completed"))).toHaveCount(1);
  await expect(page.locator(".conversation-error-hint")).toContainText(/archived|归档|session/u);
  await expect(page.locator(selectors.commandSend)).toBeDisabled();
  await saveScreenshot(page, testInfo, "deleted-session-deeplink");
});
