@@ -107,7 +107,7 @@ describeWithEnvironment('PerformanceAgent', () => {
107
107
model_id : 'test model' ,
108
108
temperature : undefined ,
109
109
} ,
110
- client_feature : 8 ,
110
+ client_feature : Host . AidaClient . ClientFeature . CHROME_PERFORMANCE_FULL_AGENT ,
111
111
functionality_type : 1 ,
112
112
} ,
113
113
) ;
@@ -117,34 +117,6 @@ describeWithEnvironment('PerformanceAgent', () => {
117
117
} ) ;
118
118
119
119
describeWithEnvironment ( '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
-
148
120
describe ( 'run' , function ( ) {
149
121
it ( 'generates an answer' , async function ( ) {
150
122
const parsedTrace = await TraceLoader . traceEngine ( this , 'web-dev-outermost-frames.json.gz' ) ;
@@ -205,7 +177,8 @@ describeWithEnvironment('PerformanceAgent – call tree focus', () => {
205
177
assert . deepEqual ( agent . buildRequest ( { text : '' } , Host . AidaClient . Role . USER ) . historical_contexts , [
206
178
{
207
179
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` } ] ,
209
182
} ,
210
183
{
211
184
role : 2 ,
@@ -225,14 +198,17 @@ describeWithEnvironment('PerformanceAgent – call tree focus', () => {
225
198
226
199
const mockAiCallTree = {
227
200
serialize : ( ) => 'Mock call tree' ,
201
+ parsedTrace : FAKE_PARSED_TRACE ,
202
+ rootNode : { event : { ts : 0 , dur : 0 } } ,
228
203
} as unknown as TimelineUtils . AICallTree . AICallTree ;
229
204
230
205
const context1 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
231
206
const context2 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
232
207
const context3 = PerformanceTraceContext . fromCallTree ( mockAiCallTree ) ;
233
208
234
209
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?' ) ;
236
212
237
213
const query2 = 'But what about this follow-up question?' ;
238
214
const enhancedQuery2 = await agent . enhanceQuery ( query2 , context2 ) ;
@@ -269,8 +245,17 @@ const FAKE_INP_MODEL = {
269
245
const FAKE_HANDLER_DATA = {
270
246
Meta : { traceBounds : { min : 0 , max : 10 } , mainFrameURL : 'https://www.example.com' } ,
271
247
} 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 ;
274
259
const FAKE_METADATA = { } as unknown as Trace . Types . File . MetaData ;
275
260
const FAKE_PARSED_TRACE = {
276
261
data : FAKE_HANDLER_DATA ,
@@ -283,15 +268,6 @@ function createAgentForInsightConversation(opts: {aidaClient?: Host.AidaClient.A
283
268
}
284
269
285
270
describeWithEnvironment ( '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
-
295
271
it ( 'outputs the right title for the selected insight' , async ( ) => {
296
272
const context = PerformanceTraceContext . fromInsight ( FAKE_PARSED_TRACE , FAKE_LCP_MODEL ) ;
297
273
assert . strictEqual ( context . getTitle ( ) , 'Trace: www.example.com' ) ;
397
373
398
374
const context = PerformanceTraceContext . fromInsight ( FAKE_PARSED_TRACE , FAKE_LCP_MODEL ) ;
399
375
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?` ;
402
377
403
378
assert . strictEqual ( finalQuery , expected ) ;
404
379
} ) ;
412
387
413
388
await agent . enhanceQuery ( 'What is this?' , context ) ;
414
389
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?` ;
417
391
418
392
assert . strictEqual ( finalQuery , expected ) ;
419
393
} ) ;
@@ -427,9 +401,9 @@ Help me understand?`;
427
401
const firstQuery = await agent . enhanceQuery ( 'Q1' , context1 ) ;
428
402
const secondQuery = await agent . enhanceQuery ( 'Q2' , context1 ) ;
429
403
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' ) ;
433
407
} ) ;
434
408
} ) ;
435
409
0 commit comments