@@ -13,6 +13,11 @@ import fs from "node:fs/promises";
1313import path from "node:path" ;
1414import { expectDefined } from "@openclaw/normalization-core" ;
1515import { Command } from "commander" ;
16+ import { isToolResultError } from "openclaw/plugin-sdk/agent-harness-runtime" ;
17+ import {
18+ buildContractReplyPayloads ,
19+ createContractToolTerminalObserver ,
20+ } from "openclaw/plugin-sdk/agent-runtime-test-contracts" ;
1621import {
1722 clearMemoryPluginState ,
1823 getMemoryCapabilityRegistration ,
@@ -3620,19 +3625,82 @@ describe("memory plugin e2e", () => {
36203625 expectToolExecute ( forgetTool , "memory_forget" ) ;
36213626
36223627 const directAbsent = await forgetTool . execute ( "forget-direct-absent" , { memoryId } ) ;
3623- expect ( directAbsent . details ) . toEqual ( { action : "not_found" , id : memoryId } ) ;
3628+ const notDeletedError = `Memory ${ memoryId } was not deleted because it was not found.` ;
3629+ expect ( directAbsent . details ) . toEqual ( {
3630+ action : "not_found" ,
3631+ error : notDeletedError ,
3632+ id : memoryId ,
3633+ status : "error" ,
3634+ } ) ;
3635+ expect ( directAbsent . content ?. [ 0 ] ?. text ) . toBe ( notDeletedError ) ;
36243636
36253637 const queryAbsent = await forgetTool . execute ( "forget-query-absent" , {
36263638 query : "concise replies" ,
36273639 } ) ;
3628- expect ( queryAbsent . details ) . toEqual ( { action : "not_found" , id : memoryId } ) ;
3640+ expect ( queryAbsent . details ) . toEqual ( {
3641+ action : "not_found" ,
3642+ error : notDeletedError ,
3643+ id : memoryId ,
3644+ status : "error" ,
3645+ } ) ;
3646+ expect ( queryAbsent . content ?. [ 0 ] ?. text ) . toBe ( notDeletedError ) ;
36293647 expect ( queryAbsent . content ?. [ 0 ] ?. text ) . not . toContain ( "Forgotten" ) ;
36303648
3649+ for ( const [ label , args , result ] of [
3650+ [ "direct" , { memoryId } , directAbsent ] ,
3651+ [ "query" , { query : "concise replies" } , queryAbsent ] ,
3652+ ] as const ) {
3653+ expect ( isToolResultError ( result ) , `${ label } zero-row receipt` ) . toBe ( true ) ;
3654+ const terminal = createContractToolTerminalObserver ( `forget-${ label } -zero` ) ( {
3655+ toolName : "memory_forget" ,
3656+ arguments : args ,
3657+ outcome : "failure" ,
3658+ failure : { error : result . content ?. [ 0 ] ?. text } ,
3659+ ownerMutation : { ownerKey : '["memory-lancedb","memory_forget"]' } ,
3660+ } ) ;
3661+ const payloads = buildContractReplyPayloads ( {
3662+ assistantText : "Done — I forgot that memory." ,
3663+ lastToolError : terminal . lastToolError ,
3664+ } ) ;
3665+ expect ( payloads ) . toEqual ( [
3666+ expect . objectContaining ( { text : "Done — I forgot that memory." } ) ,
3667+ expect . objectContaining ( { isError : true } ) ,
3668+ ] ) ;
3669+ expect ( JSON . stringify ( payloads ) ) . not . toContain ( "memory-lancedb" ) ;
3670+ }
3671+
36313672 const queryDeleted = await forgetTool . execute ( "forget-query-deleted" , {
36323673 query : "concise replies" ,
36333674 } ) ;
36343675 expect ( queryDeleted . details ) . toEqual ( { action : "deleted" , id : memoryId } ) ;
36353676 expect ( queryDeleted . content ?. [ 0 ] ?. text ) . toContain ( "Forgotten" ) ;
3677+ expect ( isToolResultError ( queryDeleted ) ) . toBe ( false ) ;
3678+ const successTerminal = createContractToolTerminalObserver ( "forget-query-positive" ) ( {
3679+ toolName : "memory_forget" ,
3680+ arguments : { query : "concise replies" } ,
3681+ outcome : "success" ,
3682+ ownerMutation : { ownerKey : '["memory-lancedb","memory_forget"]' } ,
3683+ } ) ;
3684+ expect (
3685+ buildContractReplyPayloads ( {
3686+ assistantText : "Done — I forgot that memory." ,
3687+ lastToolError : successTerminal . lastToolError ,
3688+ } ) ,
3689+ ) . toEqual ( [ expect . objectContaining ( { text : "Done — I forgot that memory." } ) ] ) ;
3690+
3691+ const unrelatedNotFound = { details : { action : "not_found" } } ;
3692+ expect ( isToolResultError ( unrelatedNotFound ) ) . toBe ( false ) ;
3693+ const recallTerminal = createContractToolTerminalObserver ( "recall-not-found" ) ( {
3694+ toolName : "memory_recall" ,
3695+ arguments : { query : "concise replies" } ,
3696+ outcome : "success" ,
3697+ } ) ;
3698+ expect (
3699+ buildContractReplyPayloads ( {
3700+ assistantText : "No matching memory was found." ,
3701+ lastToolError : recallTerminal . lastToolError ,
3702+ } ) ,
3703+ ) . toEqual ( [ expect . objectContaining ( { text : "No matching memory was found." } ) ] ) ;
36363704 expect ( deleteRows ) . toHaveBeenCalledTimes ( 3 ) ;
36373705 } ,
36383706 } ) ;
0 commit comments