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

test.describe("session authority boundary", () => {
  test.use({ scenarioId: "cross-project-detail-boundary" });

  test("does not expose a cross-project session through Workbench session routes", async ({ page }, testInfo) => {
    const session = await page.request.get("/v1/workbench/sessions/ses_cross_project");
    expect(session.status()).toBe(404);
    await expect((await session.json()).error.code).toBe("session_not_found");

    const messages = await page.request.get("/v1/workbench/sessions/ses_cross_project/messages");
    expect(messages.status()).toBe(404);
    await expect((await messages.json()).error.code).toBe("session_not_found");

    await gotoWorkbench(page, "/workbench/sessions/ses_cross_project");
    await expect(page.locator(sessionTab("ses_cross_project"))).toHaveCount(0);
    await expect(page.locator(selectors.messageCard)).toHaveCount(0);
    await saveScreenshot(page, testInfo, "project-boundary-cross-detail");
  });
});
