@@ -331,10 +331,7 @@ pub(crate) fn run_statusline(args: StatuslineArgs) -> Result<()> {
331331
332332 let hook: StatuslineHook =
333333 serde_json:: from_str ( stdin. trim ( ) ) . context ( "Invalid input format" ) ?;
334- let shared = SharedArgs {
335- offline : args. offline && !args. no_offline ,
336- ..SharedArgs :: default ( )
337- } ;
334+ let shared = statusline_shared ( & args) ;
338335 let cache_enabled = args. cache && !args. no_cache ;
339336 let cache_path = statusline_cache_path ( & hook. session_id ) ;
340337 let transcript_path = Path :: new ( & hook. transcript_path ) ;
@@ -386,6 +383,14 @@ pub(crate) fn run_statusline(args: StatuslineArgs) -> Result<()> {
386383 Ok ( ( ) )
387384}
388385
386+ fn statusline_shared ( args : & StatuslineArgs ) -> SharedArgs {
387+ SharedArgs {
388+ offline : args. offline && !args. no_offline ,
389+ pricing_overrides : args. pricing_overrides . clone ( ) ,
390+ ..SharedArgs :: default ( )
391+ }
392+ }
393+
389394/// Resolve the model label shown in the statusline.
390395///
391396/// Looks up the model's `display_name` in the user-configured alias map and
@@ -842,9 +847,92 @@ struct HookContext {
842847
843848#[ cfg( test) ]
844849mod tests {
845- use ccusage_test_support:: fs_fixture;
850+ use std:: ffi:: OsString ;
851+
852+ use ccusage_config:: ConfigContext ;
853+ use ccusage_test_support:: { EnvVarGuard , fs_fixture} ;
846854
847855 use super :: * ;
856+ use crate :: cli:: { Cli , Command } ;
857+
858+ #[ test]
859+ fn statusline_invocation_passes_config_pricing_overrides_to_cost_loading ( ) {
860+ let fixture = fs_fixture ! ( {
861+ "ccusage.json" : r#"{
862+ "defaults": {
863+ "pricingOverrides": {
864+ "third-party-model": {
865+ "inputCostPerToken": 0.000001,
866+ "outputCostPerToken": 0.000002
867+ }
868+ }
869+ },
870+ "commands": {
871+ "statusline": {
872+ "pricingOverrides": {
873+ "third-party-model": {
874+ "outputCostPerToken": 0.000003
875+ }
876+ }
877+ }
878+ }
879+ }"# ,
880+ "projects/project/session.jsonl" : r#"{"timestamp":"2020-01-01T00:00:00.000Z","sessionId":"session","message":{"id":"message","model":"third-party-model","usage":{"input_tokens":100000,"output_tokens":100000}}}"# ,
881+ } ) ;
882+ let _env = EnvVarGuard :: set ( "CLAUDE_CONFIG_DIR" , fixture. root ( ) ) ;
883+ let config_path = fixture. path ( "ccusage.json" ) ;
884+ let config_path = config_path. to_string_lossy ( ) . into_owned ( ) ;
885+ let config_args = vec ! [
886+ "statusline" . to_string( ) ,
887+ "--config" . to_string( ) ,
888+ config_path. clone( ) ,
889+ ] ;
890+ let config = ConfigContext :: from_args ( & config_args) ;
891+ let cli = Cli :: parse_from_with_config (
892+ [
893+ "ccusage" ,
894+ "statusline" ,
895+ "--config" ,
896+ config_path. as_str ( ) ,
897+ "--cost-source" ,
898+ "ccusage" ,
899+ ]
900+ . into_iter ( )
901+ . map ( OsString :: from) ,
902+ & config,
903+ DEFAULT_SESSION_DURATION_HOURS ,
904+ env ! ( "CCUSAGE_VERSION" ) ,
905+ )
906+ . unwrap ( ) ;
907+ let Some ( Command :: Statusline ( args) ) = cli. command else {
908+ panic ! ( "expected statusline command" ) ;
909+ } ;
910+
911+ let shared = statusline_shared ( & args) ;
912+ let pricing = & shared. pricing_overrides [ "third-party-model" ] ;
913+ assert_eq ! ( pricing. input_cost_per_token, Some ( 0.000001 ) ) ;
914+ assert_eq ! ( pricing. output_cost_per_token, Some ( 0.000003 ) ) ;
915+
916+ let hook = StatuslineHook {
917+ session_id : "session" . to_string ( ) ,
918+ transcript_path : fixture
919+ . path ( "transcript.jsonl" )
920+ . to_string_lossy ( )
921+ . into_owned ( ) ,
922+ model : HookModel {
923+ id : Some ( "third-party-model" . to_string ( ) ) ,
924+ display_name : "Third-party model" . to_string ( ) ,
925+ } ,
926+ cost : None ,
927+ context_window : Some ( HookContext {
928+ total_input_tokens : 100_000 ,
929+ context_window_size : 200_000 ,
930+ } ) ,
931+ effort : None ,
932+ } ;
933+ let output = render_statusline ( & hook, & args, & shared) . unwrap ( ) ;
934+ assert ! ( output. contains( "💰 $0.40 session" ) , "{output}" ) ;
935+ }
848936
849937 #[ test]
850938 fn calculates_context_tokens_from_latest_assistant_transcript_line ( ) {
0 commit comments