1- import { describe , expect , it } from "vite-plus/test" ;
1+ import { EnvironmentId , ProjectId , ThreadId } from "@t3tools/contracts" ;
2+ import { describe , expect , it , vi } from "vite-plus/test" ;
23import { page } from "vite-plus/test/browser" ;
34
45import { render } from "../../test/render" ;
56import { openCommandPalette } from "../commandPaletteBus" ;
67import { useCommandPaletteStore } from "../commandPaletteStore" ;
8+ import { makeThreadFixture } from "../test-fixtures" ;
9+ import type { Project , Thread } from "../types" ;
710import { CommandPalette } from "./CommandPalette" ;
811
9- function setup ( ) {
12+ const entities = vi . hoisted ( ( ) => ( {
13+ projects : [ ] as ReadonlyArray < Project > ,
14+ threads : [ ] as ReadonlyArray < Thread > ,
15+ } ) ) ;
16+ vi . mock ( "../state/entities" , async ( original ) => ( {
17+ ...( await original < typeof import ( "../state/entities" ) > ( ) ) ,
18+ useProjects : ( ) => entities . projects ,
19+ useVisibleThreadShells : ( ) => entities . threads ,
20+ } ) ) ;
21+
22+ function setup ( state : { projects ?: ReadonlyArray < Project > ; threads ?: ReadonlyArray < Thread > } = { } ) {
1023 useCommandPaletteStore . setState ( useCommandPaletteStore . getInitialState ( ) , true ) ;
24+ entities . projects = state . projects ?? [ ] ;
25+ entities . threads = state . threads ?? [ ] ;
1126}
1227
1328describe ( "CommandPalette open intents" , ( ) => {
@@ -30,4 +45,50 @@ describe("CommandPalette open intents", () => {
3045 await expect . element ( input ) . toHaveFocus ( ) ;
3146 await expect . element ( input ) . toHaveValue ( "acme" ) ;
3247 } ) ;
48+
49+ it ( "opens a searched project's latest listed thread, not a newer subagent" , async ( ) => {
50+ const environmentId = EnvironmentId . make ( "local" ) ;
51+ const projectId = ProjectId . make ( "acme" ) ;
52+ const parentId = ThreadId . make ( "parent" ) ;
53+ setup ( {
54+ projects : [
55+ {
56+ id : projectId ,
57+ environmentId,
58+ title : "Acme" ,
59+ workspaceRoot : "/work/acme" ,
60+ repositoryIdentity : null ,
61+ defaultModelSelection : null ,
62+ createdAt : "2026-03-01T00:00:00.000Z" ,
63+ updatedAt : "2026-03-01T00:00:00.000Z" ,
64+ scripts : [ ] ,
65+ } ,
66+ ] ,
67+ threads : [
68+ makeThreadFixture ( {
69+ id : parentId ,
70+ environmentId,
71+ projectId,
72+ latestUserMessageAt : "2026-03-02T00:00:00.000Z" ,
73+ } ) ,
74+ makeThreadFixture ( {
75+ id : ThreadId . make ( "subagent" ) ,
76+ environmentId,
77+ projectId,
78+ updatedAt : "2026-03-03T00:00:00.000Z" ,
79+ lineage : {
80+ rootThreadId : parentId ,
81+ parentThreadId : parentId ,
82+ relationshipToParent : "subagent" ,
83+ } ,
84+ } ) ,
85+ ] ,
86+ } ) ;
87+ await using screen = await render ( < CommandPalette > { null } </ CommandPalette > ) ;
88+
89+ openCommandPalette ( { query : "Acme" } ) ;
90+ await page . getByRole ( "option" , { name : / A c m e / } ) . first ( ) . click ( ) ;
91+
92+ await vi . waitFor ( ( ) => expect ( screen . router ?. state . location . pathname ) . toBe ( "/local/parent" ) ) ;
93+ } ) ;
3394} ) ;
0 commit comments