@@ -978,6 +978,98 @@ describe('agent workspace runtime behavior', () => {
978978 expect ( messages . textContent || '' ) . toContain ( 'Memory snapshot loaded' ) ;
979979 } ) ;
980980
981+ test ( 'executes unit memory snapshot capability and forwards unit layer' , async ( ) => {
982+ const fetchMock = jest
983+ . fn ( )
984+ . mockResolvedValueOnce ( {
985+ ok : true ,
986+ status : 200 ,
987+ json : async ( ) => ( {
988+ success : true ,
989+ result : {
990+ userId : 'agent_user_default' ,
991+ message : 'Found 1 local knowledge point(s).' ,
992+ knowledgePoints : [
993+ {
994+ atomId : 'atom-memory-unit-1' ,
995+ title : 'Unit Memory Candidate' ,
996+ snippet : 'Inspect unit memory snapshot.' ,
997+ score : 0.71 ,
998+ capabilities : [
999+ {
1000+ actionId : 'inspect_unit_memory_snapshot' ,
1001+ label : 'Unit Memory Snapshot' ,
1002+ request : {
1003+ userId : 'agent_user_default' ,
1004+ atomId : 'atom-memory-unit-1' ,
1005+ memoryLayer : 'unit' ,
1006+ memoryOperation : 'snapshot' ,
1007+ memoryLimit : 10 ,
1008+ } ,
1009+ execution : {
1010+ kind : 'knowledge_operation' ,
1011+ operationId : 'apply_memory_policy' ,
1012+ resultPresentation : 'memory_policy_card' ,
1013+ } ,
1014+ } ,
1015+ ] ,
1016+ } ,
1017+ ] ,
1018+ } ,
1019+ } ) ,
1020+ } )
1021+ . mockResolvedValueOnce ( {
1022+ ok : true ,
1023+ status : 200 ,
1024+ json : async ( ) => ( {
1025+ success : true ,
1026+ result : {
1027+ layer : 'unit' ,
1028+ operation : 'snapshot' ,
1029+ entries : [
1030+ { key : 'u1' , value : 'unit memory 1' } ,
1031+ ] ,
1032+ evictedCount : 0 ,
1033+ stats : {
1034+ session : 3 ,
1035+ unit : 4 ,
1036+ longTerm : 2 ,
1037+ } ,
1038+ } ,
1039+ } ) ,
1040+ } ) ;
1041+ ( global as unknown as Record < string , unknown > ) . fetch = fetchMock ;
1042+
1043+ const runtime = runtimeModule . createAgentWorkspaceRuntime ( { defaultUserId : 'agent_user_default' } ) ;
1044+ runtime . init ( ) ;
1045+
1046+ const input = document . getElementById ( 'agent-workspace-input' ) as HTMLTextAreaElement ;
1047+ const form = document . getElementById ( 'agent-workspace-form' ) as HTMLFormElement ;
1048+ input . value = 'show unit memory snapshot' ;
1049+ form . dispatchEvent ( new dom ! . window . Event ( 'submit' , { bubbles : true , cancelable : true } ) ) ;
1050+ await flushAsync ( ) ;
1051+
1052+ const actionButton = document . querySelector ( '.agent-workspace-action-button' ) as HTMLButtonElement ;
1053+ expect ( actionButton ) . not . toBeNull ( ) ;
1054+ actionButton . click ( ) ;
1055+ await flushAsync ( ) ;
1056+
1057+ expect ( fetchMock ) . toHaveBeenNthCalledWith (
1058+ 2 ,
1059+ '/api/knowledge/memory/policy' ,
1060+ expect . objectContaining ( { method : 'POST' } )
1061+ ) ;
1062+ const payload = JSON . parse ( String ( fetchMock . mock . calls [ 1 ] ?. [ 1 ] ?. body || '{}' ) ) as {
1063+ layer ?: string ;
1064+ operation ?: string ;
1065+ } ;
1066+ expect ( payload . layer ) . toBe ( 'unit' ) ;
1067+ expect ( payload . operation ) . toBe ( 'snapshot' ) ;
1068+
1069+ const messages = document . getElementById ( 'agent-workspace-messages' ) as HTMLElement ;
1070+ expect ( messages . textContent || '' ) . toContain ( 'unit/snapshot' ) ;
1071+ } ) ;
1072+
9811073 test ( 'executes memory retrain-plan capability and preserves readonly operation' , async ( ) => {
9821074 const fetchMock = jest
9831075 . fn ( )
0 commit comments