@@ -31,8 +31,6 @@ import {
3131 removeGroundedShortTermCandidates ,
3232 repairShortTermPromotionArtifacts ,
3333 testing ,
34- truncatePromotedSnippet ,
35- truncateShortTermSnippet ,
3634} from "./short-term-promotion.js" ;
3735
3836describe ( "short-term promotion" , ( ) => {
@@ -3590,41 +3588,70 @@ describe("short-term promotion", () => {
35903588 } ) ;
35913589 } ) ;
35923590 } ) ;
3593- } ) ;
3594-
3595- describe ( "truncateShortTermSnippet" , ( ) => {
3596- it ( "returns the original snippet when within the char limit" , ( ) => {
3597- expect ( truncateShortTermSnippet ( "short" ) ) . toBe ( "short" ) ;
3598- } ) ;
3599-
3600- it ( "truncates oversize snippets to the cap" , ( ) => {
3601- const input = "x" . repeat ( 900 ) ;
3602- const result = truncateShortTermSnippet ( input ) ;
3603- expect ( result . length ) . toBeLessThanOrEqual ( 800 ) ;
3604- } ) ;
3591+ describe ( "UTF-16 snippet bounds" , ( ) => {
3592+ it ( "stores a complete-code-point short-term recall snippet" , async ( ) => {
3593+ await withTempWorkspace ( async ( workspaceDir ) => {
3594+ const prefix = "y" . repeat ( testing . SHORT_TERM_RECALL_MAX_SNIPPET_CHARS - 1 ) ;
3595+ await recordShortTermRecalls ( {
3596+ workspaceDir,
3597+ query : "utf16 recall" ,
3598+ results : [
3599+ {
3600+ path : "memory/2026-04-03.md" ,
3601+ source : "memory" ,
3602+ startLine : 1 ,
3603+ endLine : 1 ,
3604+ score : 0.9 ,
3605+ snippet : `${ prefix } 🚀tail` ,
3606+ } ,
3607+ ] ,
3608+ } ) ;
36053609
3606- it ( "does not split a surrogate pair at the cap boundary" , ( ) => {
3607- const input = `${ "y" . repeat ( 799 ) } 🚀` ;
3608- const result = truncateShortTermSnippet ( input ) ;
3609- expect ( result ) . not . toContain ( "�" ) ;
3610- } ) ;
3611- } ) ;
3610+ const entries = Object . values ( await readRecallStoreEntries ( workspaceDir ) ) ;
3611+ expect ( entries ) . toHaveLength ( 1 ) ;
3612+ expect ( readEntrySnippet ( entries [ 0 ] ) ) . toBe ( prefix ) ;
3613+ } ) ;
3614+ } ) ;
36123615
3613- describe ( "truncatePromotedSnippet" , ( ) => {
3614- it ( "returns the original snippet when within token limit" , ( ) => {
3615- const result = truncatePromotedSnippet ( "short snippet" , 100 ) ;
3616- expect ( result ) . toBe ( "short snippet" ) ;
3617- } ) ;
3616+ it ( "writes a complete-code-point promoted MEMORY.md snippet" , async ( ) => {
3617+ await withTempWorkspace ( async ( workspaceDir ) => {
3618+ const prefix = "a" . repeat ( 7 ) ;
3619+ const snippet = `${ prefix } 🚀tail` ;
3620+ await writeDailyMemoryNote ( workspaceDir , "2026-04-03" , [ snippet ] ) ;
3621+ await recordShortTermRecalls ( {
3622+ workspaceDir,
3623+ query : "utf16 promotion" ,
3624+ results : [
3625+ {
3626+ path : "memory/2026-04-03.md" ,
3627+ source : "memory" ,
3628+ startLine : 1 ,
3629+ endLine : 1 ,
3630+ score : 0.9 ,
3631+ snippet,
3632+ } ,
3633+ ] ,
3634+ } ) ;
3635+ const ranked = await rankShortTermPromotionCandidates ( {
3636+ workspaceDir,
3637+ minScore : 0 ,
3638+ minRecallCount : 0 ,
3639+ minUniqueQueries : 0 ,
3640+ } ) ;
36183641
3619- it ( "truncates and appends ellipsis" , ( ) => {
3620- const input = "x" . repeat ( 500 ) ;
3621- const result = truncatePromotedSnippet ( input , 10 ) ;
3622- expect ( result . endsWith ( "..." ) ) . toBe ( true ) ;
3623- } ) ;
3642+ await applyShortTermPromotions ( {
3643+ workspaceDir,
3644+ candidates : ranked ,
3645+ minScore : 0 ,
3646+ minRecallCount : 0 ,
3647+ minUniqueQueries : 0 ,
3648+ maxPromotedSnippetTokens : 2 ,
3649+ } ) ;
36243650
3625- it ( "does not split a surrogate pair at the boundary" , ( ) => {
3626- const input = `aa🚀. ${ "b" . repeat ( 300 ) } ` ;
3627- const result = truncatePromotedSnippet ( input , 15 ) ;
3628- expect ( result ) . not . toContain ( "�" ) ;
3651+ const memoryText = await fs . readFile ( path . join ( workspaceDir , "MEMORY.md" ) , "utf-8" ) ;
3652+ expect ( memoryText ) . toContain ( `- ${ prefix } ... [` ) ;
3653+ expect ( memoryText ) . not . toContain ( "🚀" ) ;
3654+ } ) ;
3655+ } ) ;
36293656 } ) ;
36303657} ) ;
0 commit comments