@@ -2598,6 +2598,7 @@ mod tests {
25982598 unlimited : false ,
25992599 balance : Some ( "10.00" . to_string ( ) ) ,
26002600 } ) ,
2601+ plan_type : Some ( codex_protocol:: account:: PlanType :: Plus ) ,
26012602 } ;
26022603 state. set_rate_limits ( initial. clone ( ) ) ;
26032604
@@ -2613,6 +2614,7 @@ mod tests {
26132614 resets_at : Some ( 1_900 ) ,
26142615 } ) ,
26152616 credits : None ,
2617+ plan_type : None ,
26162618 } ;
26172619 state. set_rate_limits ( update. clone ( ) ) ;
26182620
@@ -2622,6 +2624,78 @@ mod tests {
26222624 primary: update. primary. clone( ) ,
26232625 secondary: update. secondary,
26242626 credits: initial. credits,
2627+ plan_type: initial. plan_type,
2628+ } )
2629+ ) ;
2630+ }
2631+
2632+ #[ test]
2633+ fn set_rate_limits_updates_plan_type_when_present ( ) {
2634+ let codex_home = tempfile:: tempdir ( ) . expect ( "create temp dir" ) ;
2635+ let config = Config :: load_from_base_config_with_overrides (
2636+ ConfigToml :: default ( ) ,
2637+ ConfigOverrides :: default ( ) ,
2638+ codex_home. path ( ) . to_path_buf ( ) ,
2639+ )
2640+ . expect ( "load default test config" ) ;
2641+ let config = Arc :: new ( config) ;
2642+ let session_configuration = SessionConfiguration {
2643+ provider : config. model_provider . clone ( ) ,
2644+ model : config. model . clone ( ) ,
2645+ model_reasoning_effort : config. model_reasoning_effort ,
2646+ model_reasoning_summary : config. model_reasoning_summary ,
2647+ developer_instructions : config. developer_instructions . clone ( ) ,
2648+ user_instructions : config. user_instructions . clone ( ) ,
2649+ base_instructions : config. base_instructions . clone ( ) ,
2650+ compact_prompt : config. compact_prompt . clone ( ) ,
2651+ approval_policy : config. approval_policy ,
2652+ sandbox_policy : config. sandbox_policy . clone ( ) ,
2653+ cwd : config. cwd . clone ( ) ,
2654+ original_config_do_not_use : Arc :: clone ( & config) ,
2655+ exec_policy : Arc :: new ( RwLock :: new ( ExecPolicy :: empty ( ) ) ) ,
2656+ session_source : SessionSource :: Exec ,
2657+ } ;
2658+
2659+ let mut state = SessionState :: new ( session_configuration) ;
2660+ let initial = RateLimitSnapshot {
2661+ primary : Some ( RateLimitWindow {
2662+ used_percent : 15.0 ,
2663+ window_minutes : Some ( 20 ) ,
2664+ resets_at : Some ( 1_600 ) ,
2665+ } ) ,
2666+ secondary : Some ( RateLimitWindow {
2667+ used_percent : 5.0 ,
2668+ window_minutes : Some ( 45 ) ,
2669+ resets_at : Some ( 1_650 ) ,
2670+ } ) ,
2671+ credits : Some ( CreditsSnapshot {
2672+ has_credits : true ,
2673+ unlimited : false ,
2674+ balance : Some ( "15.00" . to_string ( ) ) ,
2675+ } ) ,
2676+ plan_type : Some ( codex_protocol:: account:: PlanType :: Plus ) ,
2677+ } ;
2678+ state. set_rate_limits ( initial. clone ( ) ) ;
2679+
2680+ let update = RateLimitSnapshot {
2681+ primary : Some ( RateLimitWindow {
2682+ used_percent : 35.0 ,
2683+ window_minutes : Some ( 25 ) ,
2684+ resets_at : Some ( 1_700 ) ,
2685+ } ) ,
2686+ secondary : None ,
2687+ credits : None ,
2688+ plan_type : Some ( codex_protocol:: account:: PlanType :: Pro ) ,
2689+ } ;
2690+ state. set_rate_limits ( update. clone ( ) ) ;
2691+
2692+ assert_eq ! (
2693+ state. latest_rate_limits,
2694+ Some ( RateLimitSnapshot {
2695+ primary: update. primary,
2696+ secondary: update. secondary,
2697+ credits: initial. credits,
2698+ plan_type: update. plan_type,
26252699 } )
26262700 ) ;
26272701 }
0 commit comments