@@ -417,14 +417,79 @@ describeWithMockConnection('AccessibilityAgent', () => {
417417 sinon . stub ( domModel , 'existingDocument' ) . returns ( document ) ;
418418
419419 const responses = await Array . fromAsync ( agent . run ( 'test' , { selected : context } ) ) ;
420- const errorResponse = responses . find ( response => response . type === AiAssistance . AiAgent . ResponseType . ERROR ) ;
421- assert . exists ( errorResponse ) ;
422- if ( errorResponse && 'error' in errorResponse ) {
423- assert . strictEqual ( errorResponse . error , AiAssistance . AiAgent . ErrorType . UNKNOWN ) ;
424- }
420+ const actionResponse = responses . find ( response => response . type === AiAssistance . AiAgent . ResponseType . ACTION ) ;
421+ assert . exists ( actionResponse ) ;
422+ assert . strictEqual ( actionResponse . output , 'Cannot use this tool on an imported file.' ) ;
425423 sinon . assert . notCalled ( execJs ) ;
426424 } ) ;
427425
426+ it ( 'cannot call runAccessibilityAudits if the report is imported' , async ( ) => {
427+ const aidaClient = mockAidaClient ( [ [ {
428+ explanation : '' ,
429+ functionCalls : [ { name : 'runAccessibilityAudits' , args : { explanation : 'testing' } } ] ,
430+ } ] ] ) ;
431+ const lighthouseRecording = sinon . stub ( ) . resolves ( mockReport ) ;
432+ const agent = new AiAssistance . AccessibilityAgent . AccessibilityAgent ( {
433+ aidaClient,
434+ lighthouseRecording,
435+ } ) ;
436+
437+ const importedReport : LHModel . ReporterTypes . ReportJSON = {
438+ ...mockReport ,
439+ isImported : true ,
440+ } ;
441+ const context = new AiAssistance . AccessibilityAgent . AccessibilityContext ( importedReport ) ;
442+
443+ const responses = await Array . fromAsync ( agent . run ( 'test' , { selected : context } ) ) ;
444+ const actionResponse = responses . find ( response => response . type === AiAssistance . AiAgent . ResponseType . ACTION ) ;
445+ assert . exists ( actionResponse ) ;
446+ assert . strictEqual ( actionResponse . output , 'Cannot use this tool on an imported file.' ) ;
447+ sinon . assert . notCalled ( lighthouseRecording ) ;
448+ } ) ;
449+
450+ it ( 'cannot call getStyles if the report is imported' , async ( ) => {
451+ const aidaClient = mockAidaClient ( [ [ {
452+ explanation : '' ,
453+ functionCalls :
454+ [ { name : 'getStyles' , args : { path : '1,HTML,1,BODY' , styleProperties : [ 'color' ] , explanation : 'testing' } } ] ,
455+ } ] ] ) ;
456+ const agent = new AiAssistance . AccessibilityAgent . AccessibilityAgent ( {
457+ aidaClient,
458+ } ) ;
459+
460+ const importedReport : LHModel . ReporterTypes . ReportJSON = {
461+ ...mockReport ,
462+ isImported : true ,
463+ } ;
464+ const context = new AiAssistance . AccessibilityAgent . AccessibilityContext ( importedReport ) ;
465+
466+ const responses = await Array . fromAsync ( agent . run ( 'test' , { selected : context } ) ) ;
467+ const actionResponse = responses . find ( response => response . type === AiAssistance . AiAgent . ResponseType . ACTION ) ;
468+ assert . exists ( actionResponse ) ;
469+ assert . strictEqual ( actionResponse . output , 'Cannot use this tool on an imported file.' ) ;
470+ } ) ;
471+
472+ it ( 'cannot call getElementAccessibilityDetails if the report is imported' , async ( ) => {
473+ const aidaClient = mockAidaClient ( [ [ {
474+ explanation : '' ,
475+ functionCalls : [ { name : 'getElementAccessibilityDetails' , args : { path : '1,HTML,1,BODY' , explanation : 'testing' } } ] ,
476+ } ] ] ) ;
477+ const agent = new AiAssistance . AccessibilityAgent . AccessibilityAgent ( {
478+ aidaClient,
479+ } ) ;
480+
481+ const importedReport : LHModel . ReporterTypes . ReportJSON = {
482+ ...mockReport ,
483+ isImported : true ,
484+ } ;
485+ const context = new AiAssistance . AccessibilityAgent . AccessibilityContext ( importedReport ) ;
486+
487+ const responses = await Array . fromAsync ( agent . run ( 'test' , { selected : context } ) ) ;
488+ const actionResponse = responses . find ( response => response . type === AiAssistance . AiAgent . ResponseType . ACTION ) ;
489+ assert . exists ( actionResponse ) ;
490+ assert . strictEqual ( actionResponse . output , 'Cannot use this tool on an imported file.' ) ;
491+ } ) ;
492+
428493 it ( 'can still call getLighthouseAudits if the report is imported' , async ( ) => {
429494 const aidaClient = mockAidaClient ( [ [ {
430495 explanation : '' ,
@@ -453,33 +518,14 @@ describeWithMockConnection('AccessibilityAgent', () => {
453518 } ) ;
454519
455520 describe ( 'enhanceQuery' , ( ) => {
456- it ( 'prepends security warning if the report is imported' , async ( ) => {
457- const agent = new AiAssistance . AccessibilityAgent . AccessibilityAgent ( {
458- aidaClient : mockAidaClient ( [ ] ) ,
459- } ) ;
460-
461- const importedReport : LHModel . ReporterTypes . ReportJSON = {
462- ...mockReport ,
463- isImported : true ,
464- } ;
465- const context = new AiAssistance . AccessibilityAgent . AccessibilityContext ( importedReport ) ;
466-
467- const enhancedQuery = await agent . enhanceQuery ( 'user query' , context ) ;
468-
469- assert . include ( enhancedQuery , 'imported from a file and is static' ) ;
470- assert . include ( enhancedQuery , 'user query' ) ;
471- } ) ;
472-
473- it ( 'does not prepend security warning if the report is not imported' , async ( ) => {
521+ it ( 'adds the context to the query' , async ( ) => {
474522 const agent = new AiAssistance . AccessibilityAgent . AccessibilityAgent ( {
475523 aidaClient : mockAidaClient ( [ ] ) ,
476524 } ) ;
477525
478526 const context = new AiAssistance . AccessibilityAgent . AccessibilityContext ( mockReport ) ;
479-
480527 const enhancedQuery = await agent . enhanceQuery ( 'user query' , context ) ;
481-
482- assert . notInclude ( enhancedQuery , 'imported from a file and is static' ) ;
528+ assert . include ( enhancedQuery , '# Lighthouse Report' ) ;
483529 assert . include ( enhancedQuery , 'user query' ) ;
484530 } ) ;
485531 } ) ;
0 commit comments