@@ -150,40 +150,16 @@ describe("echo cache — backward compat for channels without messageId", () =>
150150 // Proves text-fallback echo detection still works when no messageId is present
151151 // on either side. Critical for backward compat with channels that don't
152152 // populate messageId.
153- it ( "text-only remember/has works within TTL" , async ( ) => {
153+ it . each ( [
154+ { label : "within TTL" , elapsed : 2000 , text : "no id message" , expected : true } ,
155+ { label : "after TTL expiry" , elapsed : 5000 , text : "no id message" , expected : false } ,
156+ { label : "for different text" , elapsed : 1000 , text : "totally different text" , expected : false } ,
157+ ] ) ( "matches text-only echoes $label: $expected" , ( { elapsed, text, expected } ) => {
154158 useFakeTimersAt ( ) ;
155-
156159 const echoCache = createSentMessageCache ( ) ;
157- const scope = "default:imessage:+15555550123" ;
158-
159- echoCache . remember ( scope , { text : "no id message" } ) ;
160-
161- vi . advanceTimersByTime ( 2000 ) ;
162- expect ( echoCache . has ( scope , { text : "no id message" } ) ) . toBe ( true ) ;
163- } ) ;
164-
165- it ( "text-only has returns false after TTL expiry" , async ( ) => {
166- useFakeTimersAt ( ) ;
167-
168- const echoCache = createSentMessageCache ( ) ;
169- const scope = "default:imessage:+15555550123" ;
170-
171- echoCache . remember ( scope , { text : "no id message" } ) ;
172-
173- vi . advanceTimersByTime ( 5000 ) ;
174- expect ( echoCache . has ( scope , { text : "no id message" } ) ) . toBe ( false ) ;
175- } ) ;
176-
177- it ( "text-only has returns false for different text" , async ( ) => {
178- useFakeTimersAt ( ) ;
179-
180- const echoCache = createSentMessageCache ( ) ;
181- const scope = "default:imessage:+15555550123" ;
182-
183- echoCache . remember ( scope , { text : "no id message" } ) ;
184-
185- vi . advanceTimersByTime ( 1000 ) ;
186- expect ( echoCache . has ( scope , { text : "totally different text" } ) ) . toBe ( false ) ;
160+ echoCache . remember ( SELF_CHAT_SCOPE , { text : "no id message" } ) ;
161+ vi . advanceTimersByTime ( elapsed ) ;
162+ expect ( echoCache . has ( SELF_CHAT_SCOPE , { text } ) ) . toBe ( expected ) ;
187163 } ) ;
188164} ) ;
189165
@@ -285,56 +261,21 @@ describe("self-chat dedupe — #47830", () => {
285261 expect ( decision . kind ) . toBe ( "dispatch" ) ;
286262 } ) ;
287263
288- it ( "drops echo after text TTL expiry (4s TTL: expired at 5s)" , async ( ) => {
289- useFakeTimersAt ( ) ;
290-
291- const echoCache = createSentMessageCache ( ) ;
292- const scope = "default:imessage:+15555550123" ;
293-
294- // Agent sends text (no message id available)
295- echoCache . remember ( scope , { text : "Hello there" } ) ;
296-
297- // After 5 seconds — beyond the 4s TTL, should NOT match
298- vi . advanceTimersByTime ( 5000 ) ;
299-
300- const result = echoCache . has ( scope , { text : "Hello there" } ) ;
301- expect ( result ) . toBe ( false ) ;
302- } ) ;
303-
304- // Safe failure mode: TTL expiry causes duplicate delivery (noisy), never message loss (lossy)
305- it ( "does NOT catch echo after TTL expiry — safe failure mode is duplicate delivery" , async ( ) => {
306- useFakeTimersAt ( ) ;
307-
308- const echoCache = createSentMessageCache ( ) ;
309- const scope = SELF_CHAT_SCOPE ;
310-
311- // Agent sends "Delayed echo test"
312- echoCache . remember ( scope , { text : "Delayed echo test" , messageId : "agent-msg-delayed" } ) ;
313-
314- // 4.5 seconds later — beyond 4s TTL
315- vi . advanceTimersByTime ( 4500 ) ;
316-
317- // Echo arrives with no messageId (text-only fallback path)
318- const result = echoCache . has ( scope , { text : "Delayed echo test" } ) ;
319-
320- // TTL expired → not caught → duplicate delivery (noisy but safe, not lossy)
321- expect ( result ) . toBe ( false ) ;
322- } ) ;
323-
324- it ( "still drops text echo within 4s TTL window" , async ( ) => {
325- useFakeTimersAt ( ) ;
326-
327- const echoCache = createSentMessageCache ( ) ;
328- const scope = "default:imessage:+15555550123" ;
329-
330- echoCache . remember ( scope , { text : "Hello there" } ) ;
331-
332- // After 3 seconds — within the 4s TTL, should still match
333- vi . advanceTimersByTime ( 3000 ) ;
334-
335- const result = echoCache . has ( scope , { text : "Hello there" } ) ;
336- expect ( result ) . toBe ( true ) ;
337- } ) ;
264+ // Late text-only matches must expire even when the original send had an ID.
265+ it . each ( [
266+ { elapsed : 5000 , messageId : undefined , expected : false } ,
267+ { elapsed : 4500 , messageId : "agent-msg-delayed" , expected : false } ,
268+ { elapsed : 3000 , messageId : undefined , expected : true } ,
269+ ] ) (
270+ "matches a text-only lookup after $elapsed ms (send ID $messageId): $expected" ,
271+ ( { elapsed, messageId, expected } ) => {
272+ useFakeTimersAt ( ) ;
273+ const echoCache = createSentMessageCache ( ) ;
274+ echoCache . remember ( SELF_CHAT_SCOPE , { text : "Hello there" , messageId } ) ;
275+ vi . advanceTimersByTime ( elapsed ) ;
276+ expect ( echoCache . has ( SELF_CHAT_SCOPE , { text : "Hello there" } ) ) . toBe ( expected ) ;
277+ } ,
278+ ) ;
338279} ) ;
339280
340281describe ( "self-chat is_from_me=true handling (Bruce Phase 2 fix)" , ( ) => {
0 commit comments