Skip to content

Commit 47fbefd

Browse files
fix(workflows): bind executor metadata targets
1 parent 4efb0ec commit 47fbefd

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

apps/sim/providers/utils.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ describe('workflow executor metadata delegation', () => {
18861886
vi.unstubAllGlobals()
18871887
})
18881888

1889-
it('binds workflow metadata reads to the target workflow and trusted execution subject', async () => {
1889+
it('binds cross-workflow metadata reads to the target without attaching the parent run', async () => {
18901890
const fetchMock = vi
18911891
.fn()
18921892
.mockResolvedValue(
@@ -1914,7 +1914,6 @@ describe('workflow executor metadata delegation', () => {
19141914
expect(workflowMetadataMocks.buildExecutorDelegationHeaders).toHaveBeenCalledWith({
19151915
subjectUserId: 'user-1',
19161916
workflowId: 'child-workflow',
1917-
executionId: 'execution-1',
19181917
})
19191918
expect(fetchMock).toHaveBeenCalledWith('https://sim.local/api/workflows/child-workflow', {
19201919
headers: {
@@ -1929,6 +1928,38 @@ describe('workflow executor metadata delegation', () => {
19291928
})
19301929
})
19311930

1931+
it('includes the run binding when the metadata target is the executing workflow', async () => {
1932+
vi.stubGlobal(
1933+
'fetch',
1934+
vi.fn().mockResolvedValue(
1935+
new Response(JSON.stringify({ data: { name: 'Current Workflow', description: null } }), {
1936+
status: 200,
1937+
headers: { 'Content-Type': 'application/json' },
1938+
})
1939+
)
1940+
)
1941+
1942+
await transformBlockTool(
1943+
{ type: 'workflow', params: { workflowId: 'current-workflow' } },
1944+
{
1945+
getAllBlocks: () => [workflowBlock],
1946+
getTool: () => workflowTool,
1947+
enrichmentContext: {
1948+
workflowId: 'current-workflow',
1949+
workspaceId: 'workspace-1',
1950+
executionId: 'execution-1',
1951+
userId: 'user-1',
1952+
},
1953+
}
1954+
)
1955+
1956+
expect(workflowMetadataMocks.buildExecutorDelegationHeaders).toHaveBeenCalledWith({
1957+
subjectUserId: 'user-1',
1958+
workflowId: 'current-workflow',
1959+
executionId: 'execution-1',
1960+
})
1961+
})
1962+
19321963
it('does not issue an actorless fallback token without a trusted execution subject', async () => {
19331964
const fetchMock = vi.fn()
19341965
vi.stubGlobal('fetch', fetchMock)

apps/sim/providers/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ async function fetchWorkflowMetadata(
8989
const headers = await buildExecutorDelegationHeaders({
9090
subjectUserId: executionContext.userId,
9191
workflowId,
92-
...(executionContext.executionId ? { executionId: executionContext.executionId } : {}),
92+
...(executionContext.workflowId === workflowId && executionContext.executionId
93+
? { executionId: executionContext.executionId }
94+
: {}),
9395
})
9496
const url = buildAPIUrl(`/api/workflows/${workflowId}`)
9597

0 commit comments

Comments
 (0)