Skip to content

Commit d935f77

Browse files
author
Peter Steinberger
committed
fix(test/ui): prevent shared history pollution
1 parent aa2a5c9 commit d935f77

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎ui/src/pages/agents/panels-tools-skills.browser.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Control UI tests cover agents panels tools skills behavior.
22
import { render } from "lit";
3-
import { describe, expect, it } from "vitest";
3+
import { describe, expect, it, vi } from "vitest";
44
import type { SkillStatusEntry } from "../../api/types.ts";
55
import { installBrowserHistoryIsolation } from "../../test-helpers/browser-history.ts";
66
import { renderAgentSkills, renderAgentTools } from "./panels-tools-skills.ts";
@@ -420,7 +420,10 @@ describe("agents tools panel (browser)", () => {
420420
expect(group.open).toBe(false);
421421
expect(tool.open).toBe(false);
422422

423-
const previousUrl = `${window.location.pathname}${window.location.search}${window.location.hash}`;
423+
const previousUrl = window.location.href;
424+
// Shared jsdom workers can observe URL changes before finally/afterEach,
425+
// so inspect the intended deep link without mutating browser history.
426+
const replaceState = vi.spyOn(window.history, "replaceState").mockImplementation(() => {});
424427
try {
425428
chip.click();
426429
await new Promise((resolve) => {
@@ -429,10 +432,13 @@ describe("agents tools panel (browser)", () => {
429432

430433
expect(group.open).toBe(true);
431434
expect(tool.open).toBe(true);
435+
expect(replaceState).toHaveBeenCalledOnce();
436+
const requestedUrl = replaceState.mock.calls[0]?.[2];
437+
expect(requestedUrl).toBeInstanceOf(URL);
438+
expect((requestedUrl as URL).hash).toBe("#agent-tool-read");
439+
expect(window.location.href).toBe(previousUrl);
432440
} finally {
433-
// Hash links mutate shared jsdom history; restore the actual prior URL
434-
// so a later Settings route never inherits this tool-card deep link.
435-
window.history.replaceState({}, "", previousUrl);
441+
replaceState.mockRestore();
436442
container.remove();
437443
}
438444
});

0 commit comments

Comments
 (0)