The platform for continuously improving AI agents.
// @vitest-environment jsdom
// covers: console-logic
import { beforeEach, expect, it } from "vitest";
import {
acknowledgeLaunchedTab,
currentLaunchedTabs,
launchJobTab,
launchRecordedTab,
scopedLaunchedTabs,
withLaunchedTabs,
} from "./launched-tabs";
import type { RunningJobItem } from "./running-jobs";
beforeEach(() => {
for (const tab of currentLaunchedTabs()) acknowledgeLaunchedTab(tab.id);
sessionStorage.clear();
});
const job = (over: Partial<RunningJobItem> = {}): RunningJobItem => ({
id: "job",
key: "ft:group",
kind: "finetuning",
startedAt: "2026-01-01T00:00:00Z",
status: "running",
title: "Train the classifier",
...over,
groupId: "group",
});
it("opens one unseen tab per started job and drops it once viewed", () => {
launchJobTab(job(), "project", "user");
launchJobTab(job(), "project", "user");
const [tab] = currentLaunchedTabs();
expect(currentLaunchedTabs()).toHaveLength(1);
expect(tab.unseen).toBe(true);
expect(tab.href).toContain("groupId=group");
expect(tab.href).toContain(`workspaceTab=${encodeURIComponent(tab.id)}`);
expect(tab.id.startsWith("/training:")).toBe(true);
const open = withLaunchedTabs(
[{ href: "/?projectId=project", id: "home", title: "Home" }],
[tab]
);
expect(open.map((item) => item.id)).toEqual(["home", tab.id]);
acknowledgeLaunchedTab(tab.id);
expect(currentLaunchedTabs()).toEqual([]);
launchJobTab(job(), "project", "user");
expect(currentLaunchedTabs()).toEqual([]);
});
it("records an evaluation on its own tab", () => {
launchRecordedTab({
jobKey: "native:plan",
path: "/evaluations/runs/plan",
search: { format: "decision", projectId: "project" },
section: "/evaluations",
title: "Evaluation",
userId: "user",
});
const [tab] = currentLaunchedTabs();
expect(tab.href).toContain("/evaluations/runs/plan");
expect(tab.href).toContain("format=decision");
expect(tab.id.startsWith("/evaluations:")).toBe(true);
});
it("keeps unviewed job tabs within their project and account", () => {
launchJobTab(job(), "project-a", "alice");
launchJobTab(job(), "project-b", "alice");
launchJobTab(job(), "project-a", "bob");
const stored = currentLaunchedTabs();
expect(stored).toHaveLength(3);
expect(scopedLaunchedTabs(stored, "alice", "project-a").map((tab) => tab.href)).toEqual([
expect.stringContaining("projectId=project-a"),
]);
expect(scopedLaunchedTabs(stored, undefined, "project-a")).toEqual([]);
expect(scopedLaunchedTabs(stored, "alice", "other")).toEqual([]);
});