11import "./reply.directive.directive-behavior.e2e-mocks.js" ;
22import { describe , expect , it , vi } from "vitest" ;
3+ import { loadSessionStore } from "../config/sessions.js" ;
34import {
45 installDirectiveBehaviorE2EHooks ,
56 loadModelCatalog ,
@@ -9,6 +10,7 @@ import {
910 replyText ,
1011 replyTexts ,
1112 runEmbeddedPiAgent ,
13+ sessionStorePath ,
1214 withTempHome ,
1315} from "./reply.directive.directive-behavior.e2e-harness.js" ;
1416import { getReplyFromConfig } from "./reply.js" ;
@@ -79,6 +81,70 @@ describe("directive behavior", () => {
7981 expect ( runEmbeddedPiAgent ) . not . toHaveBeenCalled ( ) ;
8082 } ) ;
8183 } ) ;
84+ it ( "persists /reasoning off on discord even when model defaults reasoning on" , async ( ) => {
85+ await withTempHome ( async ( home ) => {
86+ const storePath = sessionStorePath ( home ) ;
87+ mockEmbeddedTextResult ( "done" ) ;
88+ vi . mocked ( loadModelCatalog ) . mockResolvedValue ( [
89+ {
90+ id : "x-ai/grok-4.1-fast" ,
91+ name : "Grok 4.1 Fast" ,
92+ provider : "openrouter" ,
93+ reasoning : true ,
94+ } ,
95+ ] ) ;
96+
97+ const config = makeWhatsAppDirectiveConfig (
98+ home ,
99+ {
100+ model : "openrouter/x-ai/grok-4.1-fast" ,
101+ } ,
102+ {
103+ channels : {
104+ discord : { allowFrom : [ "*" ] } ,
105+ } ,
106+ session : { store : storePath } ,
107+ } ,
108+ ) ;
109+
110+ const offRes = await getReplyFromConfig (
111+ {
112+ Body : "/reasoning off" ,
113+ From : "discord:user:1004" ,
114+ To : "channel:general" ,
115+ Provider : "discord" ,
116+ Surface : "discord" ,
117+ CommandSource : "text" ,
118+ CommandAuthorized : true ,
119+ } ,
120+ { } ,
121+ config ,
122+ ) ;
123+ expect ( replyText ( offRes ) ) . toContain ( "Reasoning visibility disabled." ) ;
124+
125+ const store = loadSessionStore ( storePath ) ;
126+ const entry = Object . values ( store ) [ 0 ] ;
127+ expect ( entry ?. reasoningLevel ) . toBe ( "off" ) ;
128+
129+ await getReplyFromConfig (
130+ {
131+ Body : "hello" ,
132+ From : "discord:user:1004" ,
133+ To : "channel:general" ,
134+ Provider : "discord" ,
135+ Surface : "discord" ,
136+ CommandSource : "text" ,
137+ CommandAuthorized : true ,
138+ } ,
139+ { } ,
140+ config ,
141+ ) ;
142+
143+ expect ( runEmbeddedPiAgent ) . toHaveBeenCalledOnce ( ) ;
144+ const call = vi . mocked ( runEmbeddedPiAgent ) . mock . calls [ 0 ] ?. [ 0 ] ;
145+ expect ( call ?. reasoningLevel ) . toBe ( "off" ) ;
146+ } ) ;
147+ } ) ;
82148 for ( const replyTag of [ "[[reply_to_current]]" , "[[ reply_to_current ]]" ] ) {
83149 it ( `strips ${ replyTag } and maps reply_to_current to MessageSid` , async ( ) => {
84150 await withTempHome ( async ( home ) => {
0 commit comments