@@ -164,6 +164,91 @@ describe("pools", () => {
164164 } ) ;
165165 } ) ;
166166
167+ it ( "keeps a workspace-less hub credential apart from a different workspace credential" , ( ) => {
168+ const accounts = [
169+ {
170+ id : "workspace.json" ,
171+ driver : claude ,
172+ 173+ workspaceId : "workspace-a" ,
174+ usageLimits : {
175+ checkedAt,
176+ windows : [ { ...window , usedPercent : 20 } ] ,
177+ } ,
178+ } ,
179+ {
180+ id : "personal.json" ,
181+ driver : claude ,
182+ 183+ usageLimits : {
184+ checkedAt,
185+ windows : [ { ...window , usedPercent : 70 } ] ,
186+ } ,
187+ } ,
188+ ] ;
189+ const input = new Map ( [
190+ [
191+ EnvironmentId . make ( "env-a" ) ,
192+ {
193+ ...laptop ,
194+ serverConfig : { providers : [ ] , usageLimitSources : [ { ...source , accounts } ] } ,
195+ } ,
196+ ] ,
197+ ] ) ;
198+
199+ const limitAccounts = collectLimitAccounts ( input ) ;
200+ expect ( limitAccounts . map ( ( account ) => account . key ) ) . toEqual ( [
201+ "hub:workspace.json:workspace-a" ,
202+ "hub:personal.json" ,
203+ ] ) ;
204+ expect ( limitAccounts . map ( ( account ) => account . limits . windows [ 0 ] ?. usedPercent ) ) . toEqual ( [
205+ 20 , 70 ,
206+ ] ) ;
207+ } ) ;
208+
209+ it ( "deduplicates native reports without joining source credentials" , ( ) => {
210+ const native = provider ( {
211+ driver : claude ,
212+ instanceId : ProviderInstanceId . make ( "claude" ) ,
213+ auth :
{ status :
"authenticated" , email :
"[email protected] " } , 214+ usageLimits : { checkedAt, windows : [ { ...window , usedPercent : 30 } ] } ,
215+ } ) ;
216+ const accounts = [ "first.json" , "second.json" ] . map ( ( id , index ) => ( {
217+ id,
218+ driver : claude ,
219+ 220+ usageLimits : { checkedAt, windows : [ { ...window , usedPercent : index === 0 ? 10 : 90 } ] } ,
221+ } ) ) ;
222+ const input = new Map ( [
223+ [
224+ EnvironmentId . make ( "env-a" ) ,
225+ {
226+ ...laptop ,
227+ serverConfig : { providers : [ native ] , usageLimitSources : [ { ...source , accounts } ] } ,
228+ } ,
229+ ] ,
230+ [
231+ EnvironmentId . make ( "env-b" ) ,
232+ {
233+ entry : { target : { label : "Desktop" } } ,
234+ serverConfig : {
235+ providers : [ { ...native , instanceId : ProviderInstanceId . make ( "codex-2" ) } ] ,
236+ } ,
237+ } ,
238+ ] ,
239+ ] ) ;
240+
241+ expect ( collectLimitAccounts ( input ) . map ( ( account ) => account . key ) ) . toEqual ( [
242+ "env-a:claude" ,
243+ "hub:first.json" ,
244+ "hub:second.json" ,
245+ ] ) ;
246+ expect ( collectLimitAccounts ( input ) [ 0 ] ?. environments ) . toEqual ( [
247+ { environmentId : "env-a" , label : "Laptop" } ,
248+ { environmentId : "env-b" , label : "Desktop" } ,
249+ ] ) ;
250+ } ) ;
251+
167252 it ( "merges OpenCode Go limits from machines with the same API key" , ( ) => {
168253 const go = provider ( {
169254 driver : ProviderDriverKind . make ( "opencode" ) ,
0 commit comments