11import { describe , it , expect } from "vitest" ;
2+ import { createHash } from "node:crypto" ;
3+
24import {
35 buildBeginnerChecklist ,
46 buildBeginnerDoctorFindings ,
@@ -238,11 +240,15 @@ describe("formatPromptCacheKey", () => {
238240 } ) ;
239241
240242 it ( "redacts short values too" , ( ) => {
241- expect ( formatPromptCacheKey ( "ses_1234" ) ) . toBe ( "ses_1234..." ) ;
243+ expect ( formatPromptCacheKey ( "ses_1234" ) ) . toBe (
244+ `masked-${ createHash ( "sha256" ) . update ( "ses_1234" ) . digest ( "hex" ) . slice ( 0 , 12 ) } ` ,
245+ ) ;
242246 } ) ;
243247
244- it ( "redacts longer values to an 8-char prefix" , ( ) => {
245- expect ( formatPromptCacheKey ( "ses_prompt_cache_key_123" ) ) . toBe ( "ses_prom..." ) ;
248+ it ( "redacts longer values to a stable masked fingerprint" , ( ) => {
249+ expect ( formatPromptCacheKey ( "ses_prompt_cache_key_123" ) ) . toBe (
250+ `masked-${ createHash ( "sha256" ) . update ( "ses_prompt_cache_key_123" ) . digest ( "hex" ) . slice ( 0 , 12 ) } ` ,
251+ ) ;
246252 } ) ;
247253} ) ;
248254
@@ -254,7 +260,9 @@ describe("formatPromptCacheSnapshot", () => {
254260 lastPromptCacheKey : "ses_prompt_cache_key_123" ,
255261 } ) ;
256262
257- expect ( rendered ) . toBe ( "enabled=4, missing=1, lastKey=ses_prom..." ) ;
263+ expect ( rendered ) . toBe (
264+ `enabled=4, missing=1, lastKey=masked-${ createHash ( "sha256" ) . update ( "ses_prompt_cache_key_123" ) . digest ( "hex" ) . slice ( 0 , 12 ) } ` ,
265+ ) ;
258266 expect ( rendered ) . not . toContain ( "ses_prompt_cache_key_123" ) ;
259267 } ) ;
260268} ) ;
0 commit comments