11import '@sim/testing/mocks/executor'
22
33import { beforeEach , describe , expect , it , type Mock , vi } from 'vitest'
4+ import { executeBufferTool } from '@/lib/internal/buffer/execute-tool'
5+ import { BufferBlock } from '@/blocks/blocks/buffer'
46import { HarmonicBlock } from '@/blocks/blocks/harmonic'
57import { McpBlock } from '@/blocks/blocks/mcp'
68import { getBlock } from '@/blocks/index'
@@ -9,6 +11,8 @@ import type { ExecutionContext } from '@/executor/types'
911import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
1012import type { SerializedBlock } from '@/serializer/types'
1113import { executeTool } from '@/tools'
14+ import { bufferEditPostTool } from '@/tools/buffer/edit_post'
15+ import type { BufferEditPostParams } from '@/tools/buffer/types'
1216import { mcpRunOperationTool } from '@/tools/mcp/run-operation'
1317import type { ToolConfig } from '@/tools/types'
1418import { getTool } from '@/tools/utils'
@@ -76,6 +80,50 @@ describe('GenericBlockHandler', () => {
7680 mockExecuteTool . mockResolvedValue ( { success : true , output : { customResult : 'OK' } } )
7781 } )
7882
83+ it ( 'preserves the current Buffer schedule and approval state when editing only text' , async ( ) => {
84+ mockGetBlock . mockReturnValue ( BufferBlock )
85+ mockGetTool . mockReturnValue ( bufferEditPostTool )
86+ const providerInputs : Record < string , unknown > [ ] = [ ]
87+ vi . spyOn ( globalThis , 'fetch' ) . mockImplementation ( async ( _input , init ) => {
88+ const body : { variables : { input : Record < string , unknown > } } = JSON . parse ( String ( init ?. body ) )
89+ providerInputs . push ( body . variables . input )
90+ return Response . json ( {
91+ data : { editPost : { __typename : 'PostActionSuccess' , post : { id : 'post-1' } } } ,
92+ } )
93+ } )
94+ mockExecuteTool . mockImplementation ( async ( toolId : string , params : BufferEditPostParams ) => {
95+ const response = await executeBufferTool ( {
96+ toolId,
97+ input : bufferEditPostTool . operation . input ( params ) ,
98+ headers : new Headers ( ) ,
99+ context : { workflowId : mockContext . workflowId , userId : 'user-1' } ,
100+ requestId : 'request-1' ,
101+ } )
102+ if ( ! bufferEditPostTool . transformResponse ) throw new Error ( 'Missing response transformer' )
103+ return bufferEditPostTool . transformResponse ( response )
104+ } )
105+
106+ await handler . execute (
107+ mockContext ,
108+ {
109+ ...mockBlock ,
110+ metadata : { id : 'buffer' , name : 'Buffer' } ,
111+ config : { tool : 'buffer_edit_post' , params : { } } ,
112+ } ,
113+ {
114+ operation : 'edit_post' ,
115+ apiKey : 'buffer-key' ,
116+ postId : 'post-1' ,
117+ text : 'Updated caption' ,
118+ mode : 'default' ,
119+ schedulingType : 'default' ,
120+ approvalChange : 'default' ,
121+ }
122+ )
123+
124+ expect ( providerInputs ) . toEqual ( [ { id : 'post-1' , text : 'Updated caption' } ] )
125+ } )
126+
79127 it ( 'executes the standalone stable MCP action after argument resolution with trusted block scope' , async ( ) => {
80128 mockGetBlock . mockReturnValue ( McpBlock )
81129 mockGetTool . mockReturnValue ( mcpRunOperationTool )
0 commit comments