@@ -5,7 +5,11 @@ import os from "node:os";
55import path from "node:path" ;
66import { afterEach , describe , expect , it , vi } from "vitest" ;
77import type { OpenClawConfig } from "../../config/config.js" ;
8- import { buildSessionStartupContextPrelude , shouldApplyStartupContext } from "./startup-context.js" ;
8+ import {
9+ buildSessionStartupContextPrelude ,
10+ shouldApplyStartupContext ,
11+ trimStartupMemoryContent ,
12+ } from "./startup-context.js" ;
913
1014const tmpDirs : string [ ] = [ ] ;
1115
@@ -493,3 +497,22 @@ describe("shouldApplyStartupContext", () => {
493497 expect ( shouldApplyStartupContext ( { cfg : applyOnCfg , action : "reset" } ) ) . toBe ( false ) ;
494498 } ) ;
495499} ) ;
500+
501+ describe ( "trimStartupMemoryContent" , ( ) => {
502+ it ( "returns the original text when it fits within maxChars" , ( ) => {
503+ expect ( trimStartupMemoryContent ( "hello" , 100 ) ) . toBe ( "hello" ) ;
504+ } ) ;
505+
506+ it ( "trims whitespace and truncates long content" , ( ) => {
507+ const input = ` ${ "x" . repeat ( 200 ) } ` ;
508+ const result = trimStartupMemoryContent ( input , 100 ) ;
509+ expect ( result . length ) . toBeLessThan ( input . length ) ;
510+ expect ( result ) . toContain ( "[truncated]" ) ;
511+ } ) ;
512+
513+ it ( "does not split a surrogate pair at the boundary" , ( ) => {
514+ const input = `aa🚀${ "b" . repeat ( 200 ) } ` ;
515+ const result = trimStartupMemoryContent ( input , 80 ) ;
516+ expect ( result ) . not . toContain ( "�" ) ;
517+ } ) ;
518+ } ) ;
0 commit comments