fix(ci): resolve tsgo regressions and target-scoped followup dedupe

This commit is contained in:
KimGLee 2026-03-03 00:37:32 +08:00
parent 5c37d58fff
commit 868d766b9a
2 changed files with 44 additions and 1 deletions

View File

@ -540,6 +540,40 @@ describe("createFollowupRunner messaging tool dedupe", () => {
expect(onBlockReply).toHaveBeenCalled();
});
it("reuses session-level text dedupe when prior run had repeated sends to one target", async () => {
const onBlockReply = vi.fn(async () => {});
const sessionEntry: SessionEntry = {
sessionId: "session",
updatedAt: Date.now(),
lastMessagingToolSessionId: "session",
lastMessagingToolSentAt: Date.now(),
lastMessagingToolSentTexts: ["hello world!"],
lastMessagingToolSentTargets: [
{ tool: "message", provider: "telegram", to: "123" },
{ tool: "message", provider: "telegram", to: "123" },
],
};
const sessionStore: Record<string, SessionEntry> = { main: sessionEntry };
runEmbeddedPiAgentMock.mockResolvedValueOnce({
payloads: [{ text: "hello world!" }],
meta: {},
});
const runner = createMessagingDedupeRunner(onBlockReply, {
sessionEntry,
sessionStore,
sessionKey: "main",
});
await runner({
...baseQueuedRun("telegram"),
originatingTo: "123",
});
expect(onBlockReply).not.toHaveBeenCalled();
});
it("drops media URL from payload when messaging tool already sent it", async () => {
const onBlockReply = vi.fn(async () => {});
runEmbeddedPiAgentMock.mockResolvedValueOnce({

View File

@ -344,8 +344,17 @@ export function createFollowupRunner(params: {
originatingTo,
accountId: originAccountId,
});
const uniquePreviousTargets = new Set(
previousSentTargets.map((target) =>
JSON.stringify({
provider: target.provider,
to: target.to ?? "",
accountId: target.accountId ?? "",
}),
),
);
const canReuseSessionDedupeFingerprints =
recentTargetMatch && previousSentTargets.length <= 1;
recentTargetMatch && uniquePreviousTargets.size <= 1;
const sentTexts = [
...(runResult.messagingToolSentTexts ?? []),