@@ -4395,6 +4395,75 @@ describe("QmdMemoryManager", () => {
43954395 await manager . close ( ) ;
43964396 } ) ;
43974397
4398+ it ( "keeps per-result and aggregate QMD snippet limits UTF-16 safe" , async ( ) => {
4399+ const expectedDocId = "unicode-boundary" ;
4400+ const snippet = "@@ -1,1\nabc😀tail" ;
4401+ spawnMock . mockImplementation ( ( cmd : string , args : string [ ] ) => {
4402+ const child = createMockChild ( { autoClose : false } ) ;
4403+ if ( isMcporterCommand ( cmd ) && args [ 0 ] === "call" ) {
4404+ emitAndClose (
4405+ child ,
4406+ "stdout" ,
4407+ JSON . stringify ( {
4408+ results : [
4409+ {
4410+ docid : expectedDocId ,
4411+ score : 0.91 ,
4412+ collection : "workspace-main" ,
4413+ snippet,
4414+ } ,
4415+ ] ,
4416+ } ) ,
4417+ ) ;
4418+ return child ;
4419+ }
4420+ emitAndClose ( child , "stdout" , "[]" ) ;
4421+ return child ;
4422+ } ) ;
4423+
4424+ const searchWithLimits = async ( limits : {
4425+ maxSnippetChars : number ;
4426+ maxInjectedChars : number ;
4427+ } ) => {
4428+ const testConfig = {
4429+ ...cfg ,
4430+ memory : {
4431+ backend : "qmd" ,
4432+ qmd : {
4433+ includeDefaultMemory : false ,
4434+ searchMode : "query" ,
4435+ update : { interval : "0s" , debounceMs : 60_000 , onBoot : false } ,
4436+ paths : [ { path : workspaceDir , pattern : "**/*.md" , name : "workspace" } ] ,
4437+ limits,
4438+ mcporter : { enabled : true , serverName : "qmd" , startDaemon : false } ,
4439+ } ,
4440+ } ,
4441+ } as OpenClawConfig ;
4442+ const { manager } = await createManager ( { cfg : testConfig } ) ;
4443+ const inner = manager as unknown as {
4444+ db : { prepare : ( ) => { all : ( ) => unknown } ; close : ( ) => void } ;
4445+ } ;
4446+ inner . db = {
4447+ prepare : ( ) => ( {
4448+ all : ( ) => [ { collection : "workspace-main" , path : "notes/unicode.md" } ] ,
4449+ } ) ,
4450+ close : ( ) => { } ,
4451+ } ;
4452+ const results = await manager . search ( "unicode" , {
4453+ sessionKey : "agent:main:slack:dm:u123" ,
4454+ } ) ;
4455+ await manager . close ( ) ;
4456+ return results ;
4457+ } ;
4458+
4459+ await expect ( searchWithLimits ( { maxSnippetChars : 12 , maxInjectedChars : 100 } ) ) . resolves . toEqual (
4460+ [ expect . objectContaining ( { snippet : "@@ -1,1\nabc" } ) ] ,
4461+ ) ;
4462+ await expect ( searchWithLimits ( { maxSnippetChars : 100 , maxInjectedChars : 12 } ) ) . resolves . toEqual (
4463+ [ expect . objectContaining ( { snippet : "@@ -1,1\nabc" } ) ] ,
4464+ ) ;
4465+ } ) ;
4466+
43984467 it ( "uses snippet header width when mcporter only returns a start line" , async ( ) => {
43994468 const expectedDocId = "line-456" ;
44004469 cfg = {
0 commit comments