@@ -5,7 +5,11 @@ import type {
55import { EnvironmentId , ProjectId , ProviderInstanceId , ThreadId } from "@t3tools/contracts" ;
66import { describe , expect , it } from "vite-plus/test" ;
77
8- import { buildHomeProjectScopes , sortHomeProjectScopes } from "./homeThreadList" ;
8+ import {
9+ buildHomeProjectScopes ,
10+ findHomeProjectScope ,
11+ sortHomeProjectScopes ,
12+ } from "./homeThreadList" ;
913import { makeThreadShellFixture } from "../../test-fixtures" ;
1014
1115function makeProject (
@@ -282,4 +286,35 @@ describe("home project scopes", () => {
282286 } ) ,
283287 ) . toHaveLength ( 2 ) ;
284288 } ) ;
289+
290+ it ( "prefers an exact scope key over a project ID that collides with it" , ( ) => {
291+ const environmentId = EnvironmentId . make ( "environment-local" ) ;
292+ // project.create accepts caller-supplied IDs, so one project's scoped ref
293+ // key can equal another project's normalized workspace-root scope key.
294+ const collidingProject = makeProject ( {
295+ environmentId,
296+ id : ProjectId . make ( "/workspaces/target" ) ,
297+ title : "Colliding" ,
298+ workspaceRoot : "/workspaces/colliding" ,
299+ } ) ;
300+ const targetProject = makeProject ( {
301+ environmentId,
302+ id : ProjectId . make ( "project-target" ) ,
303+ title : "Target" ,
304+ workspaceRoot : "/workspaces/target" ,
305+ } ) ;
306+ const scopes = buildHomeProjectScopes ( {
307+ projects : [ collidingProject , targetProject ] ,
308+ environmentId : null ,
309+ projectGroupingMode : "separate" ,
310+ } ) ;
311+ const targetScope = scopes . find ( ( scope ) => scope . title === "Target" ) ;
312+ expect ( scopes . map ( ( scope ) => scope . title ) ) . toEqual ( [ "Colliding" , "Target" ] ) ;
313+ expect ( targetScope ?. key ) . toBe ( "environment-local:/workspaces/target" ) ;
314+
315+ expect ( findHomeProjectScope ( scopes , "environment-local:/workspaces/target" ) ) . toBe ( targetScope ) ;
316+ expect ( findHomeProjectScope ( scopes , "environment-local:project-target" ) ) . toBe ( targetScope ) ;
317+ expect ( findHomeProjectScope ( scopes , "environment-local:missing" ) ) . toBeNull ( ) ;
318+ expect ( findHomeProjectScope ( scopes , null ) ) . toBeNull ( ) ;
319+ } ) ;
285320} ) ;
0 commit comments