@@ -107,7 +107,7 @@ describeWithEnvironment('PerformanceAgent', () => {
107107 model_id : 'test model' ,
108108 temperature : undefined ,
109109 } ,
110- client_feature : 8 ,
110+ client_feature : Host . AidaClient . ClientFeature . CHROME_PERFORMANCE_FULL_AGENT ,
111111 functionality_type : 1 ,
112112 } ,
113113 ) ;
@@ -117,34 +117,6 @@ describeWithEnvironment('PerformanceAgent', () => {
117117} ) ;
118118
119119describeWithEnvironment ( 'PerformanceAgent – call tree focus' , ( ) => {
120- describe ( 'getOrigin()' , ( ) => {
121- it ( 'calculates the origin of the selected node when it has a URL associated with it' , async function ( ) {
122- const parsedTrace = await TraceLoader . traceEngine ( this , 'web-dev-with-commit.json.gz' ) ;
123- // An Evaluate Script event, picked because it has a URL of googletagmanager.com/...
124- const evalScriptEvent =
125- allThreadEntriesInTrace ( parsedTrace )
126- . find ( event => event . name === Trace . Types . Events . Name . EVALUATE_SCRIPT && event . ts === 122411195649 ) ;
127- assert . exists ( evalScriptEvent ) ;
128- const aiCallTree = TimelineUtils . AICallTree . AICallTree . fromEvent ( evalScriptEvent , parsedTrace ) ;
129- assert . isOk ( aiCallTree ) ;
130- const context = PerformanceTraceContext . fromCallTree ( aiCallTree ) ;
131- assert . strictEqual ( context . getOrigin ( ) , 'https://www.googletagmanager.com' ) ;
132- } ) ;
133-
134- it ( 'returns a random but deterministic "origin" for nodes that have no URL associated' , async function ( ) {
135- const parsedTrace = await TraceLoader . traceEngine ( this , 'web-dev-with-commit.json.gz' ) ;
136- // A random layout event with no URL associated
137- const layoutEvent =
138- allThreadEntriesInTrace ( parsedTrace )
139- . find ( event => event . name === Trace . Types . Events . Name . LAYOUT && event . ts === 122411130078 ) ;
140- assert . exists ( layoutEvent ) ;
141- const aiCallTree = TimelineUtils . AICallTree . AICallTree . fromEvent ( layoutEvent , parsedTrace ) ;
142- assert . isOk ( aiCallTree ) ;
143- const context = PerformanceTraceContext . fromCallTree ( aiCallTree ) ;
144- assert . strictEqual ( context . getOrigin ( ) , 'Layout_90829_259_122411130078' ) ;
145- } ) ;
146- } ) ;
147-
148120 describe ( 'run' , function ( ) {
149121 it ( 'generates an answer' , async function ( ) {
150122 const parsedTrace = await TraceLoader . traceEngine ( this , 'web-dev-outermost-frames.json.gz' ) ;
@@ -205,7 +177,8 @@ describeWithEnvironment('PerformanceAgent – call tree focus', () => {
205177 assert . deepEqual ( agent . buildRequest ( { text : '' } , Host . AidaClient . Role . USER ) . historical_contexts , [
206178 {
207179 role : 1 ,
208- parts : [ { text : `${ aiCallTree . serialize ( ) } \n\n# User request\n\ntest` } ] ,
180+ parts :
181+ [ { text : `User selected the following call tree:\n\n${ aiCallTree . serialize ( ) } \n\n# User query\n\ntest` } ] ,
209182 } ,
210183 {
211184 role : 2 ,
@@ -225,14 +198,17 @@ describeWithEnvironment('PerformanceAgent – call tree focus', () => {
225198
226199 const mockAiCallTree = {
227200 serialize : ( ) => 'Mock call tree' ,
201+ parsedTrace : FAKE_PARSED_TRACE ,
202+ rootNode : { event : { ts : 0 , dur : 0 } } ,
228203 } as unknown as TimelineUtils . AICallTree . AICallTree ;
229204
230205 const context1 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
231206 const context2 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
232207 const context3 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
233208
234209 const enhancedQuery1 = await agent . enhanceQuery ( 'What is this?' , context1 ) ;
235- assert . strictEqual ( enhancedQuery1 , 'Mock call tree\n\n# User request\n\nWhat is this?' ) ;
210+ assert . strictEqual (
211+ enhancedQuery1 , 'User selected the following call tree:\n\nMock call tree\n\n# User query\n\nWhat is this?' ) ;
236212
237213 const query2 = 'But what about this follow-up question?' ;
238214 const enhancedQuery2 = await agent . enhanceQuery ( query2 , context2 ) ;
@@ -269,8 +245,17 @@ const FAKE_INP_MODEL = {
269245const FAKE_HANDLER_DATA = {
270246 Meta : { traceBounds : { min : 0 , max : 10 } , mainFrameURL : 'https://www.example.com' } ,
271247} as unknown as Trace . Handlers . Types . HandlerData ;
272- const FAKE_INSIGHTS = new Map ( [ [ '' , { model : { LCPBreakdown : FAKE_LCP_MODEL , INPBreakdown : FAKE_INP_MODEL } } ] ] ) as
273- unknown as Trace . Insights . Types . TraceInsightSets ;
248+ const FAKE_INSIGHTS = new Map ( [
249+ [
250+ '' , {
251+ model : {
252+ LCPBreakdown : FAKE_LCP_MODEL ,
253+ INPBreakdown : FAKE_INP_MODEL ,
254+ } ,
255+ bounds : { min : 0 , max : 0 , range : 0 } ,
256+ }
257+ ] ,
258+ ] ) as unknown as Trace . Insights . Types . TraceInsightSets ;
274259const FAKE_METADATA = { } as unknown as Trace . Types . File . MetaData ;
275260const FAKE_PARSED_TRACE = {
276261 data : FAKE_HANDLER_DATA ,
@@ -283,15 +268,6 @@ function createAgentForInsightConversation(opts: {aidaClient?: Host.AidaClient.A
283268}
284269
285270describeWithEnvironment ( 'PerformanceAgent – insight focus' , ( ) => {
286- it ( 'uses the min and max bounds of the trace as the origin' , async function ( ) {
287- const parsedTrace = await TraceLoader . traceEngine ( this , 'lcp-images.json.gz' ) ;
288- assert . isOk ( parsedTrace . insights ) ;
289- const [ firstNav ] = parsedTrace . data . Meta . mainFrameNavigations ;
290- const lcpBreakdown = getInsightOrError ( 'LCPBreakdown' , parsedTrace . insights , firstNav ) ;
291- const context = PerformanceTraceContext . fromInsight ( parsedTrace , lcpBreakdown ) ;
292- assert . strictEqual ( context . getOrigin ( ) , 'trace-658799706428-658804825864' ) ;
293- } ) ;
294-
295271 it ( 'outputs the right title for the selected insight' , async ( ) => {
296272 const context = PerformanceTraceContext . fromInsight ( FAKE_PARSED_TRACE , FAKE_LCP_MODEL ) ;
297273 assert . strictEqual ( context . getTitle ( ) , 'Trace: www.example.com' ) ;
397373
398374 const context = PerformanceTraceContext . fromInsight ( FAKE_PARSED_TRACE , FAKE_LCP_MODEL ) ;
399375 const finalQuery = await agent . enhanceQuery ( 'What is this?' , context ) ;
400- const expected =
401- `User clicked on the LCPBreakdown insight, and then asked a question.\n\n# User question for you to answer:\nWhat is this?` ;
376+ const expected = `User selected the LCPBreakdown insight.\n\n# User query\n\nWhat is this?` ;
402377
403378 assert . strictEqual ( finalQuery , expected ) ;
404379 } ) ;
412387
413388 await agent . enhanceQuery ( 'What is this?' , context ) ;
414389 const finalQuery = await agent . enhanceQuery ( 'Help me understand?' , context ) ;
415- const expected = `# User question for you to answer:
416- Help me understand?` ;
390+ const expected = `Help me understand?` ;
417391
418392 assert . strictEqual ( finalQuery , expected ) ;
419393 } ) ;
@@ -427,9 +401,9 @@ Help me understand?`;
427401 const firstQuery = await agent . enhanceQuery ( 'Q1' , context1 ) ;
428402 const secondQuery = await agent . enhanceQuery ( 'Q2' , context1 ) ;
429403 const thirdQuery = await agent . enhanceQuery ( 'Q3' , context2 ) ;
430- assert . include ( firstQuery , 'User clicked on the LCPBreakdown' ) ;
431- assert . notInclude ( secondQuery , 'User clicked on the' ) ;
432- assert . include ( thirdQuery , 'User clicked on the INPBreakdown' ) ;
404+ assert . include ( firstQuery , 'User selected the LCPBreakdown' ) ;
405+ assert . notInclude ( secondQuery , 'User selected the' ) ;
406+ assert . include ( thirdQuery , 'User selected the INPBreakdown' ) ;
433407 } ) ;
434408 } ) ;
435409
0 commit comments