File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,6 +200,51 @@ describe("runCachedStep", () => {
200200 fallbackElementId : "0-1" ,
201201 } )
202202 ) ;
203+ expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
204+ } finally {
205+ logSpy . mockRestore ( ) ;
206+ }
207+ } ) ;
208+
209+ it ( "logs cached fallback diagnostics only in debug mode" , async ( ) => {
210+ executeReplaySpecialAction . mockResolvedValue ( null ) ;
211+ resolveXPathWithCDP . mockRejectedValue ( new Error ( "xpath resolution failed" ) ) ;
212+ const performFallback = jest . fn ( ) . mockResolvedValue ( {
213+ taskId : "fallback-task" ,
214+ status : TaskStatus . COMPLETED ,
215+ steps : [ ] ,
216+ output : "fallback completed" ,
217+ replayStepMeta : {
218+ usedCachedAction : false ,
219+ fallbackUsed : true ,
220+ retries : 1 ,
221+ fallbackXPath : "/html/body/button[1]" ,
222+ fallbackElementId : "0-1" ,
223+ } ,
224+ } ) ;
225+ const logSpy = jest . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
226+
227+ try {
228+ await runCachedStep ( {
229+ page : createMockPage ( ) ,
230+ instruction : "click login" ,
231+ cachedAction : {
232+ actionType : "actElement" ,
233+ xpath : "//button[1]" ,
234+ method : "click" ,
235+ frameIndex : 0 ,
236+ arguments : [ ] ,
237+ } ,
238+ maxSteps : 1 ,
239+ debug : true ,
240+ tokenLimit : 8000 ,
241+ llm : createMockLLM ( ) ,
242+ mcpClient : undefined ,
243+ variables : [ ] ,
244+ performFallback,
245+ } ) ;
246+
247+ expect ( logSpy ) . toHaveBeenCalledTimes ( 1 ) ;
203248 } finally {
204249 logSpy . mockRestore ( ) ;
205250 }
Original file line number Diff line number Diff line change @@ -139,17 +139,19 @@ export async function runCachedStep(
139139 // All cached attempts failed; optionally fall back to LLM perform
140140 if ( params . performFallback ) {
141141 const fb = await params . performFallback ( instruction ) ;
142- const cachedXPath = cachedAction . xpath || "N/A" ;
143- const resolvedXPath = fb . replayStepMeta ?. fallbackXPath || "N/A" ;
144- // eslint-disable-next-line no-console
145- console . log (
146- `
142+ if ( debug ) {
143+ const cachedXPath = cachedAction . xpath || "N/A" ;
144+ const resolvedXPath = fb . replayStepMeta ?. fallbackXPath || "N/A" ;
145+ // eslint-disable-next-line no-console
146+ console . log (
147+ `
147148⚠️ [runCachedStep] Cached action failed. Falling back to LLM...
148149 Instruction: "${ instruction } "
149150 ❌ Cached XPath Failed: "${ cachedXPath } "
150151 ✅ LLM Resolved New XPath: "${ resolvedXPath } "
151152`
152- ) ;
153+ ) ;
154+ }
153155 return {
154156 ...fb ,
155157 replayStepMeta : {
You can’t perform that action at this time.
0 commit comments