@@ -1032,6 +1032,9 @@ describe("Discord model picker interactions", () => {
10321032 entry : {
10331033 updatedAt : Date . now ( ) ,
10341034 sessionId : "bound-session" ,
1035+ authProfileOverride : "lmstudio:work" ,
1036+ authProfileOverrideSource : "user" ,
1037+ authProfileOverrideCompactionCount : 2 ,
10351038 } ,
10361039 } ) ;
10371040
@@ -1056,6 +1059,9 @@ describe("Discord model picker interactions", () => {
10561059 expect ( entry ?. providerOverride ) . toBe ( "lmstudio" ) ;
10571060 expect ( entry ?. modelOverride ) . toBe ( "unsloth/gemma-4-26b-a4b-it@iq4_xs" ) ;
10581061 expect ( entry ?. liveModelSwitchPending ) . toBe ( true ) ;
1062+ expect ( entry ?. authProfileOverride ) . toBe ( "lmstudio:work" ) ;
1063+ expect ( entry ?. authProfileOverrideSource ) . toBe ( "user" ) ;
1064+ expect ( entry ?. authProfileOverrideCompactionCount ) . toBe ( 2 ) ;
10591065 expectDispatchedModelSelection ( {
10601066 dispatchSpy,
10611067 model : "lmstudio/unsloth/gemma-4-26b-a4b-it@iq4_xs" ,
@@ -1065,6 +1071,61 @@ describe("Discord model picker interactions", () => {
10651071 ) . toContain ( "✅ Model set to lmstudio/unsloth/gemma-4-26b-a4b-it@iq4_xs." ) ;
10661072 } ) ;
10671073
1074+ it ( "preserves auth profiles through provider aliases in the direct persistence fallback" , async ( ) => {
1075+ const context = createModelPickerContext ( ) ;
1076+ context . cfg . plugins = { allow : [ "byteplus" ] } ;
1077+ context . threadBindings = createBoundThreadBindingManager ( {
1078+ accountId : "default" ,
1079+ threadId : "thread-auth-alias" ,
1080+ targetSessionKey : "agent:worker:subagent:auth-alias" ,
1081+ agentId : "worker" ,
1082+ } ) ;
1083+ const pickerData = createModelsProviderData ( {
1084+ anthropic : [ "claude-sonnet-4-5" ] ,
1085+ "byteplus-plan" : [ "ark-code-latest" ] ,
1086+ } ) ;
1087+ const modelCommand = createModelCommandDefinition ( ) ;
1088+ const storePath = resolveStorePath ( context . cfg . session ?. store , { agentId : "worker" } ) ;
1089+ await upsertSessionEntry ( {
1090+ storePath,
1091+ sessionKey : "agent:worker:subagent:auth-alias" ,
1092+ entry : {
1093+ updatedAt : Date . now ( ) ,
1094+ sessionId : "auth-alias-session" ,
1095+ authProfileOverride : "byteplus:work" ,
1096+ authProfileOverrideSource : "user" ,
1097+ authProfileOverrideCompactionCount : 2 ,
1098+ } ,
1099+ } ) ;
1100+
1101+ vi . spyOn ( modelPickerModule , "loadDiscordModelPickerData" ) . mockResolvedValue ( pickerData ) ;
1102+ mockModelCommandPipeline ( modelCommand ) ;
1103+
1104+ const dispatchSpy = createDispatchSpy ( ) ;
1105+ const button = createModelPickerFallbackButton ( context , dispatchSpy ) ;
1106+ const submitInteraction = createInteraction ( { userId : "owner" } ) ;
1107+ submitInteraction . channel = {
1108+ type : ChannelType . PublicThread ,
1109+ id : "thread-auth-alias" ,
1110+ } ;
1111+
1112+ await button . run ( submitInteraction as unknown as PickerButtonInteraction , {
1113+ ...createModelsViewSubmitData ( ) ,
1114+ p : "byteplus-plan" ,
1115+ mi : "1" ,
1116+ } ) ;
1117+
1118+ const entry = getSessionEntry ( {
1119+ storePath,
1120+ sessionKey : "agent:worker:subagent:auth-alias" ,
1121+ } ) ;
1122+ expect ( entry ?. providerOverride ) . toBe ( "byteplus-plan" ) ;
1123+ expect ( entry ?. modelOverride ) . toBe ( "ark-code-latest" ) ;
1124+ expect ( entry ?. authProfileOverride ) . toBe ( "byteplus:work" ) ;
1125+ expect ( entry ?. authProfileOverrideSource ) . toBe ( "user" ) ;
1126+ expect ( entry ?. authProfileOverrideCompactionCount ) . toBe ( 2 ) ;
1127+ } ) ;
1128+
10681129 it ( "does not write a fallback override when hidden /model dispatch is rejected" , async ( ) => {
10691130 const context = createModelPickerContext ( ) ;
10701131 context . threadBindings = createBoundThreadBindingManager ( {
0 commit comments