11// Control UI tests cover agents panels tools skills behavior.
22import { render } from "lit" ;
3- import { describe , expect , it } from "vitest" ;
3+ import { describe , expect , it , vi } from "vitest" ;
44import type { SkillStatusEntry } from "../../api/types.ts" ;
55import { installBrowserHistoryIsolation } from "../../test-helpers/browser-history.ts" ;
66import { 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