@@ -6,8 +6,7 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
66import { upsertSessionEntry } from "openclaw/plugin-sdk/session-store-runtime" ;
77import { closeOpenClawAgentDatabasesForTest } from "openclaw/plugin-sdk/sqlite-runtime-testing" ;
88import { afterEach , describe , expect , it } from "vitest" ;
9- import { resolveSlackApprovalKind } from "./approval-native-gates.js" ;
10- import { slackApprovalCapability , testing } from "./approval-native.js" ;
9+ import { slackApprovalCapability } from "./approval-native.js" ;
1110
1211function buildConfig (
1312 overrides ?: Partial < NonNullable < NonNullable < OpenClawConfig [ "channels" ] > [ "slack" ] > > ,
@@ -98,26 +97,6 @@ async function resolvePluginOriginTarget(sessionKey: string) {
9897}
9998
10099describe ( "slack native approval adapter" , ( ) => {
101- it ( "derives approval ownership from payload shape instead of id spelling" , ( ) => {
102- expect (
103- resolveSlackApprovalKind ( {
104- ...createExecApprovalRequest ( ) ,
105- id : "plugin:misleading-exec-id" ,
106- } ) ,
107- ) . toBe ( "exec" ) ;
108- expect (
109- resolveSlackApprovalKind ( {
110- id : "opaque-plugin-id" ,
111- request : {
112- title : "Plugin approval" ,
113- description : "Allow access" ,
114- } ,
115- createdAtMs : 0 ,
116- expiresAtMs : 1000 ,
117- } ) ,
118- ) . toBe ( "plugin" ) ;
119- } ) ;
120-
121100 it ( "subscribes the native runtime to exec and plugin approval events" , ( ) => {
122101 expect ( slackApprovalCapability . nativeRuntime ?. eventKinds ) . toEqual ( [ "exec" , "plugin" ] ) ;
123102 } ) ;
@@ -235,15 +214,6 @@ describe("slack native approval adapter", () => {
235214 } ) ;
236215 } ) ;
237216
238- it ( "rejects origin delivery when Slack thread ids differ in the fractional timestamp" , ( ) => {
239- expect (
240- testing . slackTargetsMatch (
241- { to : "channel:C123" , threadId : "1712345678.123456" } ,
242- { to : "channel:C123" , threadId : "1712345678.1234567" } ,
243- ) ,
244- ) . toBe ( false ) ;
245- } ) ;
246-
247217 it ( "resolves approver dm targets" , async ( ) => {
248218 const targets = await slackApprovalCapability . native ?. resolveApproverDmTargets ?.( {
249219 cfg : buildConfig ( ) ,
@@ -749,18 +719,6 @@ describe("slack native approval adapter", () => {
749719 ) . toBe ( true ) ;
750720 } ) ;
751721
752- it ( "falls back to the session-bound origin target for plugin approvals" , ( ) => {
753- expect (
754- testing . resolveSessionSlackOriginTarget ( {
755- to : "channel:C123" ,
756- threadId : "1712345678.123456" ,
757- } ) ,
758- ) . toEqual ( {
759- to : "channel:C123" ,
760- threadId : "1712345678.123456" ,
761- } ) ;
762- } ) ;
763-
764722 it ( "resolves Slack app conversation plugin approvals to the live D-channel thread" , async ( ) => {
765723 const target = await slackApprovalCapability . native ?. resolveOriginTarget ?.( {
766724 cfg : buildConfig ( { allowFrom : [ "U123OWNER" ] } ) ,
@@ -788,55 +746,6 @@ describe("slack native approval adapter", () => {
788746 } ) ;
789747 } ) ;
790748
791- it ( "prefers Slack app conversation D-channel turn source over user-scoped session route" , ( ) => {
792- expect (
793- testing . resolveTurnSourceSlackOriginTarget ( {
794- id : "plugin:req-1" ,
795- request : {
796- title : "Plugin approval" ,
797- description : "Allow access" ,
798- sessionKey : "agent:main:slack:direct:u123owner:thread:1712345678.123456" ,
799- turnSourceChannel : "slack" ,
800- turnSourceTo : "D0ACP6B1T8V" ,
801- turnSourceAccountId : "default" ,
802- turnSourceThreadId : "1712345678.123456" ,
803- } ,
804- createdAtMs : 0 ,
805- expiresAtMs : 1000 ,
806- } ) ,
807- ) . toEqual ( {
808- to : "channel:D0ACP6B1T8V" ,
809- threadId : "1712345678.123456" ,
810- } ) ;
811- } ) ;
812-
813- it ( "does not treat Slack D-channel and user route targets as matching across threads" , ( ) => {
814- expect (
815- testing . slackTargetsMatch (
816- { to : "channel:D0ACP6B1T8V" , threadId : "1712349999.123456" } ,
817- { to : "user:U123OWNER" , threadId : "1712345678.123456" } ,
818- ) ,
819- ) . toBe ( false ) ;
820- } ) ;
821-
822- it ( "does not treat same-second Slack D-channel and user route targets as the same thread" , ( ) => {
823- expect (
824- testing . slackTargetsMatch (
825- { to : "channel:D0ACP6B1T8V" , threadId : "1712345678.999999" } ,
826- { to : "user:U123OWNER" , threadId : "1712345678.123456" } ,
827- ) ,
828- ) . toBe ( false ) ;
829- } ) ;
830-
831- it ( "does not treat same-second Slack channel route targets as the same thread" , ( ) => {
832- expect (
833- testing . slackTargetsMatch (
834- { to : "channel:C123ROOM" , threadId : "1712345678.999999" } ,
835- { to : "channel:C123ROOM" , threadId : "1712345678.123456" } ,
836- ) ,
837- ) . toBe ( false ) ;
838- } ) ;
839-
840749 it ( "falls back to the session-key origin target for plugin approvals when the store is missing" , async ( ) => {
841750 const target = await resolvePluginOriginTarget (
842751 "agent:main:slack:channel:c08gqh53ejm:thread:1712345678.123456" ,
@@ -1094,16 +1003,44 @@ describe("slack native approval adapter", () => {
10941003 ) . toBe ( true ) ;
10951004 } ) ;
10961005
1097- it ( "suppresses plugin forwarding fallback for the persisted native origin target" , ( ) => {
1006+ it ( "keeps plugin forwarding fallback when the native origin thread timestamp differs" , ( ) => {
1007+ const shouldSuppress = slackApprovalCapability . delivery ?. shouldSuppressForwardingFallback ;
1008+ if ( ! shouldSuppress ) {
1009+ throw new Error ( "slack native delivery suppression unavailable" ) ;
1010+ }
1011+
10981012 expect (
1099- testing . slackTargetsMatch (
1100- { to : "channel:CSTORED" , threadId : "1712345678.123456" } ,
1101- testing . resolveSessionSlackOriginTarget ( {
1102- to : "channel:CSTORED" ,
1103- threadId : "1712345678.123456" ,
1013+ shouldSuppress ( {
1014+ cfg : buildConfig ( {
1015+ allowFrom : [ "U123OWNER" ] ,
1016+ execApprovals : {
1017+ enabled : true ,
1018+ approvers : [ "U999EXEC" ] ,
1019+ target : "dm" ,
1020+ } ,
11041021 } ) ,
1105- ) ,
1106- ) . toBe ( true ) ;
1022+ approvalKind : "plugin" ,
1023+ target : {
1024+ channel : "slack" ,
1025+ to : "channel:C123ROOM" ,
1026+ accountId : "default" ,
1027+ threadId : "1712345678.1234567" ,
1028+ } ,
1029+ request : {
1030+ id : "plugin:approval-1" ,
1031+ request : {
1032+ title : "Plugin approval" ,
1033+ description : "Allow access" ,
1034+ turnSourceChannel : "slack" ,
1035+ turnSourceTo : "channel:C123ROOM" ,
1036+ turnSourceAccountId : "default" ,
1037+ turnSourceThreadId : "1712345678.123456" ,
1038+ } ,
1039+ createdAtMs : 0 ,
1040+ expiresAtMs : 1_000 ,
1041+ } ,
1042+ } ) ,
1043+ ) . toBe ( false ) ;
11071044 } ) ;
11081045
11091046 it ( "suppresses explicit plugin forwarding targets when native Slack plugin delivery is active" , ( ) => {
0 commit comments