@@ -82,6 +82,8 @@ describe('agent workspace runtime behavior', () => {
8282 ? '/api/knowledge/path'
8383 : operationId === 'build_study_session'
8484 ? '/api/knowledge/session/plan'
85+ : operationId === 'query_knowledge'
86+ ? '/api/knowledge/query'
8587 : operationId === 'query_session_history'
8688 ? '/api/knowledge/session/history'
8789 : operationId === 'query_mastery_misconceptions'
@@ -111,6 +113,18 @@ describe('agent workspace runtime behavior', () => {
111113 } ,
112114 } ;
113115 }
116+ if ( operationId === 'query_knowledge' ) {
117+ return {
118+ operationId,
119+ endpoint,
120+ method : 'POST' ,
121+ resultPresentation : capability . execution . resultPresentation ,
122+ body : {
123+ query : request . query || request . message || '' ,
124+ topK : Number . isFinite ( Number ( request . topK ) ) ? Number ( request . topK ) : 4 ,
125+ } ,
126+ } ;
127+ }
114128 if ( operationId === 'query_mastery_misconceptions' ) {
115129 return {
116130 operationId,
@@ -373,6 +387,92 @@ describe('agent workspace runtime behavior', () => {
373387 expect ( messages . textContent || '' ) . toContain ( 'Study session built' ) ;
374388 } ) ;
375389
390+ test ( 'executes query trace capability and renders retrieval summary' , async ( ) => {
391+ const fetchMock = jest
392+ . fn ( )
393+ . mockResolvedValueOnce ( {
394+ ok : true ,
395+ status : 200 ,
396+ json : async ( ) => ( {
397+ success : true ,
398+ result : {
399+ userId : 'agent_user_default' ,
400+ message : 'Found 1 local knowledge point(s).' ,
401+ knowledgePoints : [
402+ {
403+ atomId : 'atom-query-1' ,
404+ title : 'Query Candidate' ,
405+ snippet : 'Inspect retrieval trace.' ,
406+ score : 0.79 ,
407+ capabilities : [
408+ {
409+ actionId : 'inspect_query_trace' ,
410+ label : 'Query Trace' ,
411+ request : {
412+ userId : 'agent_user_default' ,
413+ atomId : 'atom-query-1' ,
414+ query : 'retrieval loop' ,
415+ topK : 5 ,
416+ } ,
417+ execution : {
418+ kind : 'knowledge_operation' ,
419+ operationId : 'query_knowledge' ,
420+ resultPresentation : 'query_trace_card' ,
421+ } ,
422+ } ,
423+ ] ,
424+ } ,
425+ ] ,
426+ } ,
427+ } ) ,
428+ } )
429+ . mockResolvedValueOnce ( {
430+ ok : true ,
431+ status : 200 ,
432+ json : async ( ) => ( {
433+ success : true ,
434+ result : {
435+ items : [ { atom : { id : 'a1' } } , { atom : { id : 'a2' } } ] ,
436+ trace : {
437+ retrievalModes : [ 'keyword' , 'graph_traversal' ] ,
438+ latencyMs : 17 ,
439+ evidenceCoverageRatio : 0.75 ,
440+ } ,
441+ } ,
442+ } ) ,
443+ } ) ;
444+ ( global as unknown as Record < string , unknown > ) . fetch = fetchMock ;
445+
446+ const runtime = runtimeModule . createAgentWorkspaceRuntime ( { defaultUserId : 'agent_user_default' } ) ;
447+ runtime . init ( ) ;
448+
449+ const input = document . getElementById ( 'agent-workspace-input' ) as HTMLTextAreaElement ;
450+ const form = document . getElementById ( 'agent-workspace-form' ) as HTMLFormElement ;
451+ input . value = 'inspect query trace' ;
452+ form . dispatchEvent ( new dom ! . window . Event ( 'submit' , { bubbles : true , cancelable : true } ) ) ;
453+ await flushAsync ( ) ;
454+
455+ const actionButton = document . querySelector ( '.agent-workspace-action-button' ) as HTMLButtonElement ;
456+ expect ( actionButton ) . not . toBeNull ( ) ;
457+ actionButton . click ( ) ;
458+ await flushAsync ( ) ;
459+
460+ expect ( fetchMock ) . toHaveBeenNthCalledWith (
461+ 2 ,
462+ '/api/knowledge/query' ,
463+ expect . objectContaining ( { method : 'POST' } )
464+ ) ;
465+ const payload = JSON . parse ( String ( fetchMock . mock . calls [ 1 ] ?. [ 1 ] ?. body || '{}' ) ) as {
466+ query ?: string ;
467+ topK ?: number ;
468+ } ;
469+ expect ( payload . query ) . toBe ( 'retrieval loop' ) ;
470+ expect ( payload . topK ) . toBe ( 5 ) ;
471+
472+ const messages = document . getElementById ( 'agent-workspace-messages' ) as HTMLElement ;
473+ expect ( messages . textContent || '' ) . toContain ( 'Query trace loaded' ) ;
474+ } ) ;
475+
376476 test ( 'executes mastery misconceptions capability and renders summary message' , async ( ) => {
377477 const fetchMock = jest
378478 . fn ( )
0 commit comments