@@ -49,7 +49,12 @@ const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
4949
5050function fixture (
5151 options : {
52- accounts ?: Array < ( typeof accounts ) [ number ] & { disabled ?: boolean } > ;
52+ accounts ?: Array <
53+ ( typeof accounts ) [ number ] & {
54+ disabled ?: boolean ;
55+ id_token : { chatgpt_account_id : string ; plan_type ?: string ; chatgpt_plan_type ?: string } ;
56+ }
57+ > ;
5358 upstream ?: ( request : RequestBody ) => { status : number ; body : unknown } ;
5459 cooldownStatus ?: number ;
5560 } = { } ,
@@ -254,6 +259,46 @@ describe("CLIProxyAPI built-in management API", () => {
254259 } ) ,
255260 ) ;
256261
262+ it . effect ( "resolves a missing usage plan from current, then legacy, token plans" , ( ) =>
263+ Effect . gen ( function * ( ) {
264+ const test = fixture ( {
265+ accounts : [
266+ { ...accounts [ 0 ] ! , id_token : { chatgpt_account_id : "account-a" , plan_type : "free" } } ,
267+ {
268+ ...accounts [ 1 ] ! ,
269+ id_token : {
270+ chatgpt_account_id : "account-b" ,
271+ plan_type : "go" ,
272+ chatgpt_plan_type : "plus" ,
273+ } ,
274+ } ,
275+ {
276+ ...accounts [ 1 ] ! ,
277+ id : "third.json" ,
278+ auth_index : "c" ,
279+ id_token : { chatgpt_account_id : "account-c" , chatgpt_plan_type : "free" } ,
280+ } ,
281+ ] ,
282+ upstream : ( request ) => ( {
283+ status : 200 ,
284+ body : {
285+ ...( request . auth_index === "a" ? { plan_type : "plus" } : { } ) ,
286+ rate_limit : { primary_window : { used_percent : 12 } } ,
287+ } ,
288+ } ) ,
289+ } ) ;
290+ const api = yield * test . api ;
291+ const result = yield * api . readAccounts ( config ) ;
292+ expect ( result . map ( ( account ) => [ account . plan , account . usageLimits . windows [ 0 ] ?. kind ] ) ) . toEqual (
293+ [
294+ [ "ChatGPT Plus Subscription" , "session" ] ,
295+ [ "ChatGPT Go Subscription" , "monthly" ] ,
296+ [ "ChatGPT Free Subscription" , "monthly" ] ,
297+ ] ,
298+ ) ;
299+ } ) ,
300+ ) ;
301+
257302 it . effect ( "keeps the path of a hub served under a prefix" , ( ) =>
258303 Effect . gen ( function * ( ) {
259304 const test = fixture ( ) ;
0 commit comments