




























@@ -122,6 +122,30 @@ describe("thread-ownership plugin", () => {
122122);
123123});
124124125+it("canonicalizes non-canonical Slack targets when shared conversationId is missing", async () => {
126+vi.mocked(globalThis.fetch).mockResolvedValue(
127+new Response(JSON.stringify({ owner: "test-agent" }), { status: 200 }),
128+);
129+130+const result = await hooks.message_sending(
131+{
132+content: "hello",
133+replyToId: "1234.5678",
134+to: "channel:C123",
135+},
136+{ channelId: "slack", conversationId: "" },
137+);
138+139+expect(result).toBeUndefined();
140+expect(globalThis.fetch).toHaveBeenCalledWith(
141+"http://localhost:8750/api/v1/ownership/C123/1234.5678",
142+expect.objectContaining({
143+method: "POST",
144+body: JSON.stringify({ agent_id: "test-agent" }),
145+}),
146+);
147+});
148+125149it("cancels when thread owned by another agent", async () => {
126150vi.mocked(globalThis.fetch).mockResolvedValue(
127151new Response(JSON.stringify({ owner: "other-agent" }), { status: 409 }),
@@ -194,6 +218,29 @@ describe("thread-ownership plugin", () => {
194218expect(globalThis.fetch).not.toHaveBeenCalled();
195219});
196220221+it("canonicalizes inbound non-canonical metadata without shared conversation context", async () => {
222+await hooks.message_received(
223+{
224+content: "Hey @TestBot help me",
225+threadId: "9999.0003",
226+metadata: { channelId: "channel:C456" },
227+},
228+{ channelId: "slack", conversationId: "" },
229+);
230+231+const result = await hooks.message_sending(
232+{
233+content: "Sure!",
234+replyToId: "9999.0003",
235+to: "C456",
236+},
237+{ channelId: "slack", conversationId: "C456" },
238+);
239+240+expect(result).toBeUndefined();
241+expect(globalThis.fetch).not.toHaveBeenCalled();
242+});
243+197244it("ignores @-mentions on non-slack channels", async () => {
198245// Use a unique thread key so module-level state from other tests doesn't interfere.
199246await hooks.message_received(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。