Skip to content

Commit d486cae

Browse files
committed
fix(buffer): accept media when edit assets are null
1 parent 9997999 commit d486cae

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎apps/sim/lib/internal/buffer/input.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function validateDueAt(
5656
message: 'dueAt is required when mode is customScheduled',
5757
})
5858
}
59-
if (body.media != null && body.assets !== undefined)
59+
if (body.media != null && body.assets != null)
6060
ctx.addIssue({
6161
code: z.ZodIssueCode.custom,
6262
path: ['assets'],

‎apps/sim/lib/internal/buffer/operations.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ describe('Buffer operations', () => {
8282
expect(providerInputs).toEqual([{ id: 'post-1', text: 'Updated caption', ...expected }])
8383
})
8484

85+
it.each([
86+
{ assets: null, status: 200 },
87+
{ assets: [], status: 400 },
88+
])(
89+
'attaches edit media with absent assets but rejects explicit assets: $assets',
90+
async ({ assets, status }) => {
91+
mockResolveFileInputToUrl.mockResolvedValueOnce({
92+
fileUrl: 'https://files.example/image.png',
93+
})
94+
const providerInputs: Record<string, unknown>[] = []
95+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (_input, init) => {
96+
const body: { variables: { input: Record<string, unknown> } } = JSON.parse(
97+
String(init?.body)
98+
)
99+
providerInputs.push(body.variables.input)
100+
return Response.json({
101+
data: { editPost: { __typename: 'PostActionSuccess', post: { id: 'post-1' } } },
102+
})
103+
})
104+
105+
const response = await executeBufferTool({
106+
toolId: 'buffer_edit_post',
107+
input: {
108+
apiKey: 'buffer-key',
109+
postId: 'post-1',
110+
media: { key: 'workspace/ws/file-1', name: 'image.png', size: 1, type: 'image/png' },
111+
assets,
112+
},
113+
headers: new Headers(),
114+
context: { workflowId: 'workflow-1', userId: 'user-1' },
115+
requestId: 'request-1',
116+
})
117+
118+
expect(response.status).toBe(status)
119+
expect(providerInputs).toEqual(
120+
status === 200
121+
? [{ id: 'post-1', assets: [{ image: { url: 'https://files.example/image.png' } }] }]
122+
: []
123+
)
124+
}
125+
)
126+
85127
it('resolves stored media with trusted user context before the provider call', async () => {
86128
mockResolveFileInputToUrl.mockResolvedValue({ fileUrl: 'https://files.example/image.png' })
87129
const fetchMock = vi.fn().mockResolvedValue(

0 commit comments

Comments
 (0)