mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
fix(extension): classify the home tab by id, not a racy boot flag (issue #57)
SessionManager.classifyNewTab's `initializing` branch relied on a windowInitializing flag that start() cleared *before* the home tab's chrome.tabs.onCreated event was dispatched (the event is asynchronous), so the branch never ran in production and the home tab's classification was subject to a timing race. Match the home tab by its tab id instead — the id is already returned by ensureActiveTab and is reliable regardless of event ordering. Also refresh the overlay-bridge docstring: overlay.ready now makes the background *push* the per-tab overlay state (and the Agent Window also pushes on tab create / control-mode change), rather than a request/reply.
This commit is contained in:
@@ -152,19 +152,17 @@ describe("SessionManager", () => {
|
||||
});
|
||||
|
||||
describe("classifyNewTab (user vs agent tab freedom)", () => {
|
||||
it("classifies a tab born during window init as agent (home tab)", async () => {
|
||||
const aw = fakeAgentWindow();
|
||||
const sm = new SessionManager({ agentWindow: aw });
|
||||
it("classifies the home tab as agent", async () => {
|
||||
const sm = new SessionManager({ agentWindow: fakeAgentWindow() });
|
||||
const ctx = await sm.start("aa11");
|
||||
// Simulate the onCreated event for the home tab while still initializing.
|
||||
// (start() already clears the flag, so re-add to emulate the race.)
|
||||
(sm as unknown as { windowInitializing: Set<number> }).windowInitializing.add(
|
||||
ctx.agentWindowId,
|
||||
);
|
||||
const kind = sm.classifyNewTab(0, ctx.agentWindowId);
|
||||
expect(kind).toBe("initializing");
|
||||
expect(ctx.agentCreatedTabs.has(0)).toBe(true);
|
||||
expect(ctx.userTabs.has(0)).toBe(false);
|
||||
// The home tab is agent-owned and matched by home tab id. The prior
|
||||
// windowInitializing flag was cleared before the home tab's onCreated
|
||||
// arrived, so matching it by boot timing was never reliable.
|
||||
const homeTabId = ctx.homeTabId as number;
|
||||
const kind = sm.classifyNewTab(homeTabId, ctx.agentWindowId);
|
||||
expect(kind).toBe("agent");
|
||||
expect(ctx.agentCreatedTabs.has(homeTabId)).toBe(true);
|
||||
expect(ctx.userTabs.has(homeTabId)).toBe(false);
|
||||
});
|
||||
|
||||
it("classifies a pending tab_create tab as agent", async () => {
|
||||
|
||||
Reference in New Issue
Block a user