mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
`bsk session start --no-focus` opens the Agent Window in the background without stealing focus. The flag threads focused=false through CLI -> daemon IPC -> tool.session_start -> chrome.windows.create; an omitted `focused` keeps the extension default (true) so older clients are unaffected. Reworked onto current main so it composes with #52 window sizing: AgentWindowApi.create / SessionManager.start (extension), start_session (CLI) and the daemon's session start now take options objects/structs ({ size, focused }) instead of colliding positional params. Co-authored-by: alectimison-maker <alec.timison@gmail.com>
97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { AGENT_WINDOW_HOME, chromeAgentWindowApi } from "../agent-window";
|
|
|
|
describe("chromeAgentWindowApi.ensureActiveTab", () => {
|
|
const query = vi.fn();
|
|
const update = vi.fn();
|
|
const create = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
vi.stubGlobal("chrome", {
|
|
tabs: { query, update, create },
|
|
});
|
|
query.mockReset();
|
|
update.mockReset();
|
|
create.mockReset();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("activates an existing tab when the window already has one", async () => {
|
|
query.mockResolvedValue([{ id: 7, active: false }]);
|
|
update.mockResolvedValue({});
|
|
|
|
await chromeAgentWindowApi.ensureActiveTab(100, AGENT_WINDOW_HOME);
|
|
|
|
expect(query).toHaveBeenCalledWith({ windowId: 100 });
|
|
expect(update).toHaveBeenCalledWith(7, { active: true });
|
|
expect(create).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("creates about:blank when the Agent Window has no tabs", async () => {
|
|
query.mockResolvedValue([]);
|
|
create.mockResolvedValue({ id: 8 });
|
|
|
|
await chromeAgentWindowApi.ensureActiveTab(100, AGENT_WINDOW_HOME);
|
|
|
|
expect(create).toHaveBeenCalledWith({
|
|
windowId: 100,
|
|
url: AGENT_WINDOW_HOME,
|
|
active: true,
|
|
});
|
|
expect(update).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("chromeAgentWindowApi.create", () => {
|
|
const create = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
vi.stubGlobal("chrome", {
|
|
windows: { create },
|
|
});
|
|
create.mockReset();
|
|
create.mockResolvedValue({ id: 100 });
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("focuses Agent Windows by default", async () => {
|
|
await chromeAgentWindowApi.create(AGENT_WINDOW_HOME);
|
|
|
|
expect(create).toHaveBeenCalledWith({
|
|
type: "normal",
|
|
focused: true,
|
|
url: AGENT_WINDOW_HOME,
|
|
});
|
|
});
|
|
|
|
it("can create an Agent Window without stealing focus", async () => {
|
|
await chromeAgentWindowApi.create(AGENT_WINDOW_HOME, { focused: false });
|
|
|
|
expect(create).toHaveBeenCalledWith({
|
|
type: "normal",
|
|
focused: false,
|
|
url: AGENT_WINDOW_HOME,
|
|
});
|
|
});
|
|
|
|
it("passes an optional window size through the options object", async () => {
|
|
await chromeAgentWindowApi.create(AGENT_WINDOW_HOME, {
|
|
size: { width: 1280, height: 800 },
|
|
});
|
|
|
|
expect(create).toHaveBeenCalledWith({
|
|
type: "normal",
|
|
focused: true,
|
|
url: AGENT_WINDOW_HOME,
|
|
width: 1280,
|
|
height: 800,
|
|
});
|
|
});
|
|
});
|