






















@@ -74,6 +74,14 @@ function requireMattermostReplyToModeResolver() {
7474return resolveReplyToMode;
7575}
767677+function requireMattermostThreadTargetMatcher() {
78+const matchesToolContextTarget = mattermostPlugin.threading?.matchesToolContextTarget;
79+if (!matchesToolContextTarget) {
80+throw new Error("mattermost threading.matchesToolContextTarget missing");
81+}
82+return matchesToolContextTarget;
83+}
84+7785function requireMattermostSendText() {
7886const sendText = mattermostPlugin.outbound?.sendText;
7987if (!sendText) {
@@ -236,6 +244,27 @@ describe("mattermostPlugin", () => {
236244},
237245);
238246247+it("matches bare Mattermost channel ids against the active channel target", () => {
248+const matchesToolContextTarget = requireMattermostThreadTargetMatcher();
249+250+expect(
251+matchesToolContextTarget({
252+target: "tqfek9psh7fw8mpa5berwyytqw",
253+toolContext: {
254+currentChannelId: "channel:tqfek9psh7fw8mpa5berwyytqw",
255+},
256+}),
257+).toBe(true);
258+expect(
259+matchesToolContextTarget({
260+target: "tqfek9psh7fw8mpa5berwyytqw",
261+toolContext: {
262+currentChannelId: "channel:kqfek9psh7fw8mpa5berwyytqw",
263+},
264+}),
265+).toBe(false);
266+});
267+239268it("exposes the effective reply root as the transport thread", () => {
240269const resolveReplyTransport = mattermostPlugin.threading?.resolveReplyTransport;
241270if (!resolveReplyTransport) {
@@ -249,8 +278,30 @@ describe("mattermostPlugin", () => {
249278threadId: "other-thread",
250279}),
251280).toEqual({
252-replyToId: "post-parent",
253-threadId: "post-parent",
281+replyToId: "other-thread",
282+threadId: "other-thread",
283+});
284+expect(
285+resolveReplyTransport({
286+cfg: {},
287+replyToId: "child-post",
288+replyToIsExplicit: true,
289+threadId: "root-post",
290+}),
291+).toEqual({
292+replyToId: "root-post",
293+threadId: "root-post",
294+});
295+expect(
296+resolveReplyTransport({
297+cfg: {},
298+replyToId: "child-post",
299+replyToIsExplicit: false,
300+threadId: "root-post",
301+}),
302+).toEqual({
303+replyToId: "root-post",
304+threadId: "root-post",
254305});
255306expect(
256307resolveReplyTransport({
@@ -402,6 +453,17 @@ describe("mattermostPlugin", () => {
402453},
403454}),
404455).toBeUndefined();
456+expect(
457+resolveAutoThreadId({
458+cfg: {},
459+to: "tqfek9psh7fw8mpa5berwyytqw",
460+toolContext: {
461+currentChannelId: "channel:tqfek9psh7fw8mpa5berwyytqw",
462+currentThreadTs: "root-1",
463+replyToMode: "all",
464+},
465+}),
466+).toBe("root-1");
405467expect(
406468resolveAutoThreadId({
407469cfg: {},
@@ -714,7 +776,28 @@ describe("mattermostPlugin", () => {
714776expect(options.replyToId).toBe("post-root");
715777});
716778717-it("keeps explicit reply precedence when threadId is also provided", async () => {
779+it("uses threadId as the Mattermost root when generic replyTo names a child post", async () => {
780+const cfg = createMattermostTestConfig();
781+782+await mattermostPlugin.actions?.handleAction?.(
783+createMattermostActionContext({
784+action: "send",
785+params: {
786+to: "channel:CHAN1",
787+message: "hello",
788+threadId: "post-root",
789+replyTo: "child-post",
790+},
791+ cfg,
792+accountId: "default",
793+}),
794+);
795+796+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
797+expect(options.replyToId).toBe("post-root");
798+});
799+800+it("keeps explicit replyToId precedence when threadId is also provided", async () => {
718801const cfg = createMattermostTestConfig();
719802720803await mattermostPlugin.actions?.handleAction?.(
@@ -723,6 +806,7 @@ describe("mattermostPlugin", () => {
723806params: {
724807to: "channel:CHAN1",
725808message: "hello",
809+replyToId: "explicit-root",
726810threadId: "post-root",
727811replyTo: "child-post",
728812},
@@ -732,7 +816,7 @@ describe("mattermostPlugin", () => {
732816);
733817734818const options = expectSingleMattermostSend("channel:CHAN1", "hello");
735-expect(options.replyToId).toBe("child-post");
819+expect(options.replyToId).toBe("explicit-root");
736820});
737821738822it("routes filePath send actions through Mattermost media upload options", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。