@@ -84,6 +84,8 @@ describe('agent workspace runtime behavior', () => {
8484 ? '/api/knowledge/session/plan'
8585 : operationId === 'query_session_history'
8686 ? '/api/knowledge/session/history'
87+ : operationId === 'query_mastery_misconceptions'
88+ ? '/api/knowledge/mastery/misconceptions'
8789 : operationId === 'capture_learning_quality_snapshot'
8890 ? '/api/knowledge/quality/snapshot'
8991 : operationId === 'apply_memory_policy'
@@ -109,6 +111,21 @@ describe('agent workspace runtime behavior', () => {
109111 } ,
110112 } ;
111113 }
114+ if ( operationId === 'query_mastery_misconceptions' ) {
115+ return {
116+ operationId,
117+ endpoint,
118+ method : 'POST' ,
119+ resultPresentation : capability . execution . resultPresentation ,
120+ body : {
121+ userId : request . userId ,
122+ topK : Number . isFinite ( Number ( request . topK ) ) ? Number ( request . topK ) : 5 ,
123+ ...( typeof request . atomId === 'string' && request . atomId . trim ( ) . length > 0
124+ ? { atomIds : [ request . atomId . trim ( ) ] }
125+ : { } ) ,
126+ } ,
127+ } ;
128+ }
112129 return {
113130 operationId,
114131 endpoint,
@@ -356,6 +373,94 @@ describe('agent workspace runtime behavior', () => {
356373 expect ( messages . textContent || '' ) . toContain ( 'Study session built' ) ;
357374 } ) ;
358375
376+ test ( 'executes mastery misconceptions capability and renders summary message' , async ( ) => {
377+ const fetchMock = jest
378+ . fn ( )
379+ . mockResolvedValueOnce ( {
380+ ok : true ,
381+ status : 200 ,
382+ json : async ( ) => ( {
383+ success : true ,
384+ result : {
385+ userId : 'agent_user_default' ,
386+ message : 'Found 1 local knowledge point(s).' ,
387+ knowledgePoints : [
388+ {
389+ atomId : 'atom-misconception-1' ,
390+ title : 'Misconception Candidate' ,
391+ snippet : 'Inspect misconception concentration.' ,
392+ score : 0.72 ,
393+ capabilities : [
394+ {
395+ actionId : 'inspect_mastery_misconceptions' ,
396+ label : 'Mastery Misconceptions' ,
397+ request : {
398+ userId : 'agent_user_default' ,
399+ atomId : 'atom-misconception-1' ,
400+ topK : 6 ,
401+ } ,
402+ execution : {
403+ kind : 'knowledge_operation' ,
404+ operationId : 'query_mastery_misconceptions' ,
405+ resultPresentation : 'mastery_misconceptions_card' ,
406+ } ,
407+ } ,
408+ ] ,
409+ } ,
410+ ] ,
411+ } ,
412+ } ) ,
413+ } )
414+ . mockResolvedValueOnce ( {
415+ ok : true ,
416+ status : 200 ,
417+ json : async ( ) => ( {
418+ success : true ,
419+ result : {
420+ summary : {
421+ trackedTags : 2 ,
422+ totalObservations : 7 ,
423+ } ,
424+ items : [
425+ {
426+ errorTag : 'overgeneralization' ,
427+ } ,
428+ ] ,
429+ } ,
430+ } ) ,
431+ } ) ;
432+ ( global as unknown as Record < string , unknown > ) . fetch = fetchMock ;
433+
434+ const runtime = runtimeModule . createAgentWorkspaceRuntime ( { defaultUserId : 'agent_user_default' } ) ;
435+ runtime . init ( ) ;
436+
437+ const input = document . getElementById ( 'agent-workspace-input' ) as HTMLTextAreaElement ;
438+ const form = document . getElementById ( 'agent-workspace-form' ) as HTMLFormElement ;
439+ input . value = 'inspect misconceptions' ;
440+ form . dispatchEvent ( new dom ! . window . Event ( 'submit' , { bubbles : true , cancelable : true } ) ) ;
441+ await flushAsync ( ) ;
442+
443+ const actionButton = document . querySelector ( '.agent-workspace-action-button' ) as HTMLButtonElement ;
444+ expect ( actionButton ) . not . toBeNull ( ) ;
445+ actionButton . click ( ) ;
446+ await flushAsync ( ) ;
447+
448+ expect ( fetchMock ) . toHaveBeenNthCalledWith (
449+ 2 ,
450+ '/api/knowledge/mastery/misconceptions' ,
451+ expect . objectContaining ( { method : 'POST' } )
452+ ) ;
453+ const payload = JSON . parse ( String ( fetchMock . mock . calls [ 1 ] ?. [ 1 ] ?. body || '{}' ) ) as {
454+ topK ?: number ;
455+ atomIds ?: string [ ] ;
456+ } ;
457+ expect ( payload . topK ) . toBe ( 6 ) ;
458+ expect ( payload . atomIds ) . toEqual ( [ 'atom-misconception-1' ] ) ;
459+
460+ const messages = document . getElementById ( 'agent-workspace-messages' ) as HTMLElement ;
461+ expect ( messages . textContent || '' ) . toContain ( 'Mastery misconceptions loaded' ) ;
462+ } ) ;
463+
359464 test ( 'executes follow-up tutor capability and renders assistant message' , async ( ) => {
360465 const fetchMock = jest
361466 . fn ( )
0 commit comments