refactor: extract iMessage echo cache and unify suppression guards

This commit is contained in:
Peter Steinberger
2026-02-25 00:53:39 +00:00
parent 196a7dbd24
commit 5c6b2cbc8e
9 changed files with 116 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { __testing } from "./monitor-provider.js";
import { createSentMessageCache } from "./echo-cache.js";
describe("iMessage sent-message echo cache", () => {
afterEach(() => {
@@ -9,7 +9,7 @@ describe("iMessage sent-message echo cache", () => {
it("matches recent text within the same scope", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
const cache = __testing.createSentMessageCache();
const cache = createSentMessageCache();
cache.remember("acct:imessage:+1555", { text: " Reasoning:\r\n_step_ " });
@@ -20,7 +20,7 @@ describe("iMessage sent-message echo cache", () => {
it("matches by outbound message id and ignores placeholder ids", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
const cache = __testing.createSentMessageCache();
const cache = createSentMessageCache();
cache.remember("acct:imessage:+1555", { messageId: "abc-123" });
cache.remember("acct:imessage:+1555", { messageId: "ok" });
@@ -32,7 +32,7 @@ describe("iMessage sent-message echo cache", () => {
it("keeps message-id lookups longer than text fallback", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
const cache = __testing.createSentMessageCache();
const cache = createSentMessageCache();
cache.remember("acct:imessage:+1555", { text: "hello", messageId: "m-1" });
vi.advanceTimersByTime(6000);