惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
I
InfoQ
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
Y
Y Combinator Blog
博客园_首页
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
C
Check Point Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Engineering at Meta
Engineering at Meta
B
Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
F
Fortinet All Blogs
月光博客
月光博客
GbyAI
GbyAI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: repair anchorless iMessage watch payloads · openclaw...
omarshahine · 2026-05-25 · via Recent Commits to openclaw:main
1+

import { describe, expect, it, vi } from "vitest";

2+

import { isIMessageAnchorless, repairIMessageConversationAnchor } from "./conversation-repair.js";

3+

import type { IMessagePayload } from "./types.js";

4+5+

function anchorlessMessage(overrides: Partial<IMessagePayload> = {}): IMessagePayload {

6+

return {

7+

id: 9500,

8+

guid: "ANCHORLESS-GUID-1",

9+

chat_id: 0,

10+

sender: "+15550001111",

11+

is_from_me: false,

12+

text: "https://example.com",

13+

chat_guid: "",

14+

chat_identifier: "",

15+

chat_name: "",

16+

participants: null,

17+

is_group: false,

18+

...overrides,

19+

};

20+

}

21+22+

function mockClient(chats: Array<{ id: number; messages: Record<string, unknown>[] }>) {

23+

const request = vi.fn(async (method: string, params?: Record<string, unknown>) => {

24+

if (method === "chats.list") {

25+

return { chats: chats.map((chat) => ({ id: chat.id })) };

26+

}

27+

if (method === "messages.history") {

28+

return {

29+

messages: chats.find((chat) => chat.id === params?.chat_id)?.messages ?? [],

30+

};

31+

}

32+

throw new Error(`unexpected method ${method}`);

33+

});

34+

return { request };

35+

}

36+37+

describe("isIMessageAnchorless", () => {

38+

it("detects explicit broken conversation anchors", () => {

39+

expect(isIMessageAnchorless(anchorlessMessage())).toBe(true);

40+

expect(isIMessageAnchorless(anchorlessMessage({ chat_guid: undefined }))).toBe(true);

41+

expect(isIMessageAnchorless(anchorlessMessage({ chat_identifier: undefined }))).toBe(true);

42+

expect(

43+

isIMessageAnchorless(

44+

anchorlessMessage({ chat_id: undefined, chat_guid: "", chat_identifier: "" }),

45+

),

46+

).toBe(true);

47+

});

48+49+

it("does not classify sender-only direct messages as anchorless", () => {

50+

expect(

51+

isIMessageAnchorless({

52+

guid: "DM-GUID",

53+

sender: "+15550001111",

54+

is_from_me: false,

55+

text: "hello",

56+

}),

57+

).toBe(false);

58+

});

59+60+

it("does not classify messages with any usable conversation anchor", () => {

61+

expect(isIMessageAnchorless(anchorlessMessage({ chat_id: 349 }))).toBe(false);

62+

expect(isIMessageAnchorless(anchorlessMessage({ chat_guid: "iMessage;+;chat349" }))).toBe(

63+

false,

64+

);

65+

expect(isIMessageAnchorless(anchorlessMessage({ chat_identifier: "chat349" }))).toBe(false);

66+

});

67+

});

68+69+

describe("repairIMessageConversationAnchor", () => {

70+

it("passes through non-anchorless messages without recovery RPCs", async () => {

71+

const message = anchorlessMessage({ chat_id: 349, is_group: true });

72+

const client = mockClient([]);

73+74+

await expect(

75+

repairIMessageConversationAnchor({ client: client as never, message }),

76+

).resolves.toBe(message);

77+

expect(client.request).not.toHaveBeenCalled();

78+

});

79+80+

it("recovers the conversation from recent history by GUID", async () => {

81+

const message = anchorlessMessage();

82+

const client = mockClient([

83+

{ id: 100, messages: [{ guid: "OTHER-GUID", chat_id: 100, is_group: true }] },

84+

{

85+

id: 349,

86+

messages: [

87+

{

88+

guid: "ANCHORLESS-GUID-1",

89+

chat_id: 349,

90+

chat_guid: "iMessage;+;chat349",

91+

chat_identifier: "chat349",

92+

chat_name: "Project group",

93+

participants: ["+15550001111", "+15550002222"],

94+

is_group: true,

95+

},

96+

],

97+

},

98+

]);

99+100+

const repaired = await repairIMessageConversationAnchor({

101+

client: client as never,

102+

message,

103+

});

104+105+

expect(repaired).toMatchObject({

106+

chat_id: 349,

107+

chat_guid: "iMessage;+;chat349",

108+

chat_identifier: "chat349",

109+

chat_name: "Project group",

110+

participants: ["+15550001111", "+15550002222"],

111+

is_group: true,

112+

});

113+

});

114+115+

it("drops fail-closed when the GUID cannot be matched", async () => {

116+

const runtime = { error: vi.fn() };

117+

const client = mockClient([{ id: 349, messages: [{ guid: "OTHER-GUID", chat_id: 349 }] }]);

118+119+

await expect(

120+

repairIMessageConversationAnchor({

121+

client: client as never,

122+

message: anchorlessMessage(),

123+

runtime,

124+

}),

125+

).resolves.toBeNull();

126+

expect(runtime.error.mock.calls.at(-1)?.[0]).toContain("no recent chat matched");

127+

});

128+129+

it("drops fail-closed when history finds the GUID but no usable anchor", async () => {

130+

const runtime = { error: vi.fn() };

131+

const client = mockClient([

132+

{

133+

id: 349,

134+

messages: [

135+

{

136+

guid: "ANCHORLESS-GUID-1",

137+

chat_id: 0,

138+

chat_guid: "",

139+

chat_identifier: "",

140+

is_group: false,

141+

},

142+

],

143+

},

144+

]);

145+146+

await expect(

147+

repairIMessageConversationAnchor({

148+

client: client as never,

149+

message: anchorlessMessage(),

150+

runtime,

151+

}),

152+

).resolves.toBeNull();

153+

expect(runtime.error.mock.calls.at(-1)?.[0]).toContain("no usable conversation anchor");

154+

});

155+

});