22 * @vitest -environment node
33 */
44import { describe , expect , it } from 'vitest'
5+ import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility'
56import {
67 getSlackV2ActionSubBlocks ,
78 getSlackV2OperationSentences ,
@@ -11,7 +12,7 @@ import {
1112} from '@/blocks/blocks/slack'
1213
1314const AGENT_OPERATION_IDS = [
14- 'set_suggested_prompts ' ,
15+ 'set_agent_suggested_prompts ' ,
1516 'set_agent_session_status' ,
1617 'rename_agent_session' ,
1718]
@@ -20,6 +21,8 @@ const AGENT_TOOL_IDS = [
2021 'slack_set_agent_session_status_v2' ,
2122 'slack_rename_agent_session_v2' ,
2223]
24+ const ASSISTANT_OPERATION_IDS = [ 'set_status' , 'set_title' , 'set_suggested_prompts' ]
25+ const ASSISTANT_TOOL_IDS = [ 'slack_set_status' , 'slack_set_title' ]
2326
2427function operationIds ( ) : string [ ] {
2528 const operation = SlackV2Block . subBlocks . find ( ( subBlock ) => subBlock . id === 'operation' )
@@ -32,6 +35,12 @@ function mapSlackV2Params(params: Record<string, unknown>): Record<string, unkno
3235 return mapParams ( params )
3336}
3437
38+ function isSlackV2SubBlockVisible ( subBlockId : string , values : Record < string , unknown > ) : boolean {
39+ const subBlock = SlackV2Block . subBlocks . find ( ( candidate ) => candidate . id === subBlockId )
40+ if ( ! subBlock ) throw new Error ( `Slack v2 subblock not found: ${ subBlockId } ` )
41+ return evaluateSubBlockCondition ( subBlock . condition , values )
42+ }
43+
3544describe ( 'Slack block release' , ( ) => {
3645 it ( 'releases slack_v2 and keeps the legacy block executable but hidden' , ( ) => {
3746 expect ( SlackBlock . hideFromToolbar ) . toBe ( true )
@@ -41,21 +50,27 @@ describe('Slack block release', () => {
4150 expect ( SlackV2Block . sunset ) . toBeUndefined ( )
4251 } )
4352
44- it ( 'replaces legacy assistant operations with custom-bot Agent Sessions operations' , ( ) => {
45- expect ( operationIds ( ) ) . toEqual ( expect . arrayContaining ( AGENT_OPERATION_IDS ) )
46- for ( const id of [ 'set_status' , 'set_title' ] ) {
47- expect ( operationIds ( ) ) . not . toContain ( id )
48- }
49- expect ( getSlackV2ToolAccess ( ) ) . toEqual ( expect . arrayContaining ( AGENT_TOOL_IDS ) )
53+ it ( 'adds custom-bot Agent Sessions operations without removing assistant operations' , ( ) => {
54+ expect ( operationIds ( ) ) . toEqual (
55+ expect . arrayContaining ( [ ...ASSISTANT_OPERATION_IDS , ...AGENT_OPERATION_IDS ] )
56+ )
57+ expect ( getSlackV2ToolAccess ( ) ) . toEqual (
58+ expect . arrayContaining ( [ ...ASSISTANT_TOOL_IDS , ...AGENT_TOOL_IDS ] )
59+ )
5060 expect ( getSlackV2ToolAccess ( ) ) . toContain ( 'slack_set_suggested_prompts' )
51- for ( const id of [ 'slack_set_status' , 'slack_set_title' ] ) {
52- expect ( getSlackV2ToolAccess ( ) ) . not . toContain ( id )
53- }
5461 expect ( Object . keys ( getSlackV2OperationSentences ( ) ) ) . toEqual (
55- expect . arrayContaining ( AGENT_OPERATION_IDS )
62+ expect . arrayContaining ( [ ... ASSISTANT_OPERATION_IDS , ... AGENT_OPERATION_IDS ] )
5663 )
5764 } )
5865
66+ it ( 'keeps assistant operations routed to their original tools' , ( ) => {
67+ const selectTool = SlackV2Block . tools . config ?. tool
68+ if ( ! selectTool ) throw new Error ( 'Slack v2 tool selector is required' )
69+
70+ expect ( selectTool ( { operation : 'set_status' } ) ) . toBe ( 'slack_set_status' )
71+ expect ( selectTool ( { operation : 'set_title' } ) ) . toBe ( 'slack_set_title' )
72+ } )
73+
5974 it ( 'uses a service-account-only picker for Agent Sessions operations' , ( ) => {
6075 const credential = getSlackV2ActionSubBlocks ( ) . find (
6176 ( subBlock ) => subBlock . id === 'agentBotCredential'
@@ -67,7 +82,7 @@ describe('Slack block release', () => {
6782 } )
6883 } )
6984
70- it ( 'keeps persisted OAuth suggested prompts on the compatibility tool' , ( ) => {
85+ it ( 'keeps assistant suggested prompts on the original fields and tool' , ( ) => {
7186 const selectTool = SlackV2Block . tools . config ?. tool
7287 if ( ! selectTool ) throw new Error ( 'Slack v2 tool selector is required' )
7388
@@ -90,14 +105,28 @@ describe('Slack block release', () => {
90105 prompts : '[{"title":"Summarize","message":"Summarize this thread"}]' ,
91106 promptsTitle : 'Try asking' ,
92107 } )
108+
109+ const assistantValues = {
110+ operation : 'set_suggested_prompts' ,
111+ credential : 'oauth-credential' ,
112+ channel : 'C123' ,
113+ getThreadTimestamp : '1700000000.000001' ,
114+ }
115+ expect ( isSlackV2SubBlockVisible ( 'credential' , assistantValues ) ) . toBe ( true )
116+ expect ( isSlackV2SubBlockVisible ( 'channel' , assistantValues ) ) . toBe ( true )
117+ expect ( isSlackV2SubBlockVisible ( 'getThreadTimestamp' , assistantValues ) ) . toBe ( true )
118+ expect ( isSlackV2SubBlockVisible ( 'suggestedPrompts' , assistantValues ) ) . toBe ( true )
119+ expect ( isSlackV2SubBlockVisible ( 'agentBotCredential' , assistantValues ) ) . toBe ( false )
120+ expect ( isSlackV2SubBlockVisible ( 'agentChannel' , assistantValues ) ) . toBe ( false )
121+ expect ( isSlackV2SubBlockVisible ( 'agentThreadTs' , assistantValues ) ) . toBe ( false )
93122 } )
94123
95124 it ( 'uses service-account tools for new agent operations' , ( ) => {
96125 const selectTool = SlackV2Block . tools . config ?. tool
97126 if ( ! selectTool ) throw new Error ( 'Slack v2 tool selector is required' )
98127
99128 expect (
100- selectTool ( { operation : 'set_suggested_prompts ' , agentCredentialId : 'custom-bot' } )
129+ selectTool ( { operation : 'set_agent_suggested_prompts ' , agentCredentialId : 'custom-bot' } )
101130 ) . toBe ( 'slack_set_suggested_prompts_v2' )
102131 expect ( selectTool ( { operation : 'set_agent_session_status' } ) ) . toBe (
103132 'slack_set_agent_session_status_v2'
@@ -116,5 +145,48 @@ describe('Slack block release', () => {
116145 threadTs : '1700000000.000001' ,
117146 status : 'processing' ,
118147 } )
148+
149+ const agentPromptValues = {
150+ operation : 'set_agent_suggested_prompts' ,
151+ agentBotCredential : 'custom-bot' ,
152+ agentChannel : 'D123' ,
153+ agentThreadTs : '1700000000.000001' ,
154+ }
155+ expect ( isSlackV2SubBlockVisible ( 'credential' , agentPromptValues ) ) . toBe ( false )
156+ expect ( isSlackV2SubBlockVisible ( 'channel' , agentPromptValues ) ) . toBe ( false )
157+ expect ( isSlackV2SubBlockVisible ( 'getThreadTimestamp' , agentPromptValues ) ) . toBe ( false )
158+ expect ( isSlackV2SubBlockVisible ( 'suggestedPrompts' , agentPromptValues ) ) . toBe ( true )
159+ expect ( isSlackV2SubBlockVisible ( 'agentBotCredential' , agentPromptValues ) ) . toBe ( true )
160+ expect ( isSlackV2SubBlockVisible ( 'agentChannel' , agentPromptValues ) ) . toBe ( true )
161+ expect ( isSlackV2SubBlockVisible ( 'agentThreadTs' , agentPromptValues ) ) . toBe ( true )
162+
163+ expect (
164+ mapSlackV2Params ( {
165+ operation : 'set_agent_suggested_prompts' ,
166+ agentCredentialId : 'custom-bot' ,
167+ agentChannelId : 'D123' ,
168+ agentThreadTs : '1700000000.000001' ,
169+ suggestedPrompts : '[{"title":"Summarize","message":"Summarize this thread"}]' ,
170+ promptsTitle : 'Try asking' ,
171+ } )
172+ ) . toMatchObject ( {
173+ credential : 'custom-bot' ,
174+ channel : 'D123' ,
175+ threadTs : '1700000000.000001' ,
176+ prompts : '[{"title":"Summarize","message":"Summarize this thread"}]' ,
177+ promptsTitle : 'Try asking' ,
178+ } )
179+
180+ const repurposedValues = {
181+ operation : 'set_agent_suggested_prompts' ,
182+ credential : 'stale-credential' ,
183+ channel : 'C123' ,
184+ suggestedPrompts : '[{"title":"Summarize","message":"Summarize this thread"}]' ,
185+ }
186+ expect ( isSlackV2SubBlockVisible ( 'credential' , repurposedValues ) ) . toBe ( false )
187+ expect ( isSlackV2SubBlockVisible ( 'channel' , repurposedValues ) ) . toBe ( false )
188+ expect ( isSlackV2SubBlockVisible ( 'agentBotCredential' , repurposedValues ) ) . toBe ( true )
189+ expect ( isSlackV2SubBlockVisible ( 'agentChannel' , repurposedValues ) ) . toBe ( true )
190+ expect ( selectTool ( repurposedValues ) ) . toBe ( 'slack_set_suggested_prompts_v2' )
119191 } )
120192} )
0 commit comments