@@ -5,6 +5,7 @@ import type { EnvironmentProject } from "./models.ts";
55import { chooseLoadBalancedEnvironment } from "../load-balancing.ts" ;
66import {
77 buildProjectGroups ,
8+ deriveLogicalProjectKeyFromSettings ,
89 derivePhysicalProjectKey ,
910 resolveScratchProjectScopeKey ,
1011 type ProjectGroupingSettings ,
@@ -118,6 +119,43 @@ function settings(
118119}
119120
120121describe ( "buildProjectGroups" , ( ) => {
122+ it . each ( [ "repository" , "repository_path" , "separate" ] as const ) (
123+ "migrates a pre-config %s scratch selection and retains it after the original host is removed" ,
124+ ( mode ) => {
125+ const local = makeProject ( "scratch-local" , "/local/repo/scratch" , {
126+ repositoryIdentity : { ...repositoryIdentity , rootPath : "/local/repo" } ,
127+ } ) ;
128+ const remote = makeProject ( "scratch-remote" , "/remote/scratch" , {
129+ environmentId : EnvironmentId . make ( "remote" ) ,
130+ repositoryIdentity : null ,
131+ isScratch : true ,
132+ } ) ;
133+ const groupingSettings = settings ( mode ) ;
134+ const selectedBeforeConfig = deriveLogicalProjectKeyFromSettings ( local , groupingSettings ) ;
135+ const loaded = [ { ...local , isScratch : true as const } , remote ] ;
136+ const migrated = resolveScratchProjectScopeKey (
137+ selectedBeforeConfig ,
138+ loaded ,
139+ groupingSettings ,
140+ ) ;
141+ const scratchKey = buildProjectGroups ( { projects : loaded , settings : groupingSettings } ) [ 0 ] !
142+ . key ;
143+ expect ( migrated ) . toBe ( scratchKey ) ;
144+ expect ( resolveScratchProjectScopeKey ( migrated , [ remote ] , groupingSettings ) ) . toBe ( scratchKey ) ;
145+ expect (
146+ buildProjectGroups ( { projects : [ remote ] , settings : groupingSettings } ) [ 0 ]
147+ ?. memberProjectRefs ,
148+ ) . toEqual ( [ { environmentId : remote . environmentId , projectId : remote . id } ] ) ;
149+ } ,
150+ ) ;
151+
152+ it ( "retains a repository filter that still belongs to an ordinary project" , ( ) => {
153+ const scratch = makeProject ( "scratch" , "/scratch" , { isScratch : true } ) ;
154+ const ordinary = makeProject ( "ordinary" , "/ordinary" ) ;
155+ const key = deriveLogicalProjectKeyFromSettings ( ordinary , settings ( "repository" ) ) ;
156+ expect ( resolveScratchProjectScopeKey ( key , [ scratch , ordinary ] ) ) . toBe ( key ) ;
157+ } ) ;
158+
121159 it . each ( [ "repository" , "repository_path" , "separate" ] as const ) (
122160 "coalesces scratch homes in %s mode without merging ordinary same-title projects" ,
123161 ( mode ) => {
0 commit comments