Skip to content

Commit 5e20663

Browse files
committed
refactor(dry-run): name the executor-injected params a recorded request drops, and tighten the new tests
describeToolRequest drops _context, _credentialId and _workflowId by name rather than every underscore key, so an operation field like _id survives. The check-tool-effects justification rule is one decision chain with an accurate header; placeholder tests assert positively without dead columns.
1 parent f3e377a commit 5e20663

4 files changed

Lines changed: 35 additions & 53 deletions

File tree

‎apps/sim/tools/dry-run.test.ts‎

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,24 @@ describe('a dry run’s placeholder for an unsent write', () => {
141141
toolId: 'hubspot_update_deal',
142142
params: { accessToken: SECRET, dealId: 'deal-key', idProperty: 'deal_key', properties: {} },
143143
read: (returned: Record<string, unknown>) => returned.dealId,
144-
not: 'deal-key',
145144
},
146145
{
147146
case: 'an upsert names the document it replaces as previous, never as its own',
148147
toolId: 'knowledge_upsert_document',
149148
params: { knowledgeBaseId: 'kb1', name: 'Runbook', content: 'steps', documentId: 'doc-old' },
150149
read: (returned: Record<string, unknown>) => toRecord(returned.data).documentId,
151-
not: 'doc-old',
152150
},
153151
{
154152
case: 'a Slack DM reports the channel Slack opens, not the user it names',
155153
toolId: 'slack_message',
156154
params: { accessToken: SECRET, destinationType: 'dm', dmUserId: 'U123', text: 'hi' },
157155
read: (returned: Record<string, unknown>) => returned.channel,
158-
not: 'U123',
159156
},
160157
{
161158
case: 'Slack text that Slack returns escaped is not echoed as sent',
162159
toolId: 'slack_message',
163160
params: { accessToken: SECRET, channel: 'C1', text: 'Q&A <today>' },
164161
read: (returned: Record<string, unknown>) => toRecord(returned.message).text,
165-
not: 'Q&A <today>',
166162
},
167163
{
168164
case: 'a Confluence page created in a space named by key reports the id Confluence resolves',
@@ -175,7 +171,6 @@ describe('a dry run’s placeholder for an unsent write', () => {
175171
content: '<p>x</p>',
176172
},
177173
read: (returned: Record<string, unknown>) => returned.spaceId,
178-
not: 'ENG',
179174
},
180175
{
181176
case: 'a zero-padded Confluence space id is a key Confluence resolves, not an id it echoes',
@@ -188,59 +183,36 @@ describe('a dry run’s placeholder for an unsent write', () => {
188183
content: '<p>x</p>',
189184
},
190185
read: (returned: Record<string, unknown>) => returned.spaceId,
191-
not: '007',
192186
},
193-
])('$case', async ({ toolId, params, read, not }) => {
187+
])('$case', async ({ toolId, params, read }) => {
194188
const returned = await placeholderFor(toolId, params)
195189

196190
expect(read(returned)).toEqual(expect.stringMatching(/^dry_run_/))
197-
expect(read(returned)).not.toBe(not)
198191
})
199192

200193
it.each([
201194
{
202195
toolId: 'knowledge_upsert_document',
203196
params: { knowledgeBaseId: 'kb1', name: 'Runbook', content: 'steps' },
204-
pairs: [
205-
[
206-
(r: Record<string, unknown>) => toRecord(r.data).documentId,
207-
(r: Record<string, unknown>) => r.documentId,
208-
],
209-
],
197+
repeats: (r: Record<string, unknown>) => ({ data: { documentId: r.documentId } }),
210198
},
211199
{
212200
toolId: 'zendesk_create_ticket',
213201
params: { accessToken: SECRET, subdomain: 'acme', subject: 'Help', description: 'x' },
214-
pairs: [
215-
[
216-
(r: Record<string, unknown>) => toRecord(r.ticket).id,
217-
(r: Record<string, unknown>) => r.ticket_id,
218-
],
219-
],
202+
repeats: (r: Record<string, unknown>) => ({ ticket: { id: r.ticket_id } }),
220203
},
221204
{
222205
toolId: 'slack_message',
223206
params: { accessToken: SECRET, channel: 'C1', text: 'hi' },
224-
pairs: [
225-
[
226-
(r: Record<string, unknown>) => toRecord(r.message).ts,
227-
(r: Record<string, unknown>) => r.ts,
228-
],
229-
[
230-
(r: Record<string, unknown>) => toRecord(r.message).channel,
231-
(r: Record<string, unknown>) => r.channel,
232-
],
233-
],
207+
repeats: (r: Record<string, unknown>) => ({ message: { ts: r.ts, channel: r.channel } }),
234208
},
235209
])(
236210
'$toolId reports one placeholder id wherever its output repeats it',
237-
async ({ toolId, params, pairs }) => {
211+
async ({ toolId, params, repeats }) => {
238212
const returned = await placeholderFor(toolId, params)
239213

240-
for (const [nested, topLevel] of pairs) {
241-
expect(nested(returned)).toBeDefined()
242-
expect(nested(returned)).toBe(topLevel(returned))
243-
}
214+
expect(JSON.stringify(repeats(returned))).toMatch(/dry_run_|9000000/)
215+
expect(returned).toMatchObject(repeats(returned))
244216
}
245217
)
246218

‎apps/sim/tools/side-effects.test.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
describeToolRequest,
1919
unsentWriteFor,
2020
} from '@/tools/side-effects'
21+
import { terminateWorkerTool } from '@/tools/workday/terminate_worker'
2122

2223
vi.mock('@/lib/guardrails/mask-client', () => maskClientMock)
2324

@@ -167,13 +168,8 @@ describe('a write a dry run does not send', () => {
167168
})
168169

169170
it('records an in-process operation without the run context it reads but never sends', () => {
170-
const tool = {
171-
id: 'workday_terminate_worker',
172-
operation: { input: (params: Record<string, unknown>) => params },
173-
} as unknown as Parameters<typeof describeToolRequest>[0]
174-
175171
expect(
176-
describeToolRequest(tool, {
172+
describeToolRequest(terminateWorkerTool, {
177173
workerId: 'w-1',
178174
_context: { billingAttribution: { payerId: 'org-1' } },
179175
_credentialId: 'cred-1',

‎apps/sim/tools/side-effects.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ function readBody(body: string | undefined): unknown {
128128
}
129129
}
130130

131+
/**
132+
* Params the executor adds to every tool call for its own use. An in-process operation that
133+
* forwards its params whole reads them in process and never sends them, so its recorded request
134+
* leaves them out.
135+
*/
136+
const EXECUTOR_INJECTED_PARAMS: ReadonlySet<string> = new Set([
137+
'_context',
138+
'_credentialId',
139+
'_workflowId',
140+
])
141+
131142
/** What an MCP tool call would send its server: only the arguments it was given. */
132143
export function describeMcpToolRequest(params: Record<string, unknown>): unknown {
133144
return { arguments: parseMcpToolArguments(params) }
@@ -152,10 +163,10 @@ export function describeToolRequest(
152163
}
153164
if (isInternalToolConfig(tool)) {
154165
const input = tool.operation.input(params)
155-
// An operation that forwards its params whole carries the run's `_context` and credential id,
156-
// which it reads in process and never sends.
157166
return isPlainRecord(input)
158-
? Object.fromEntries(Object.entries(input).filter(([key]) => !key.startsWith('_')))
167+
? Object.fromEntries(
168+
Object.entries(input).filter(([key]) => !EXECUTOR_INJECTED_PARAMS.has(key))
169+
)
159170
: input
160171
}
161172
const prepared = prepareToolRequest(tool, params)

‎scripts/check-tool-effects.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* it back in `transformResponse` or `postProcess`), so that contradiction passes when the
1515
* tool's `effect` property carries `// tool-effect: <reason>` on one of the two lines above it.
1616
* A `read` sent by a write verb never does: when unsure, the label is `write`;
17-
* - a `// tool-effect:` annotation sits on a tool whose verb agrees with its label, or on a
18-
* definition whose id is not a string literal, so stale or unattributable justifications do
19-
* not accumulate.
17+
* - a `// tool-effect:` annotation sits on a `read` tool, on a `write` whose verb agrees with
18+
* its label, or on a definition whose id is not a string literal, so stale or unattributable
19+
* justifications do not accumulate.
2020
*
2121
* POST, the rest of function-valued verbs, and in-process operations are not judged here: their
2222
* effect comes from the tool's documented semantics. The `add-tools` skill lists the rules.
@@ -135,14 +135,17 @@ export function findToolEffectViolations(
135135

136136
for (const justification of justifications) {
137137
const tool = justification.toolId ? tools[justification.toolId] : undefined
138-
if (!tool || tool.effect !== 'write' || !contradictsVerb(tool)) {
138+
const reason = !tool
139+
? `${ANNOTATION} annotation is not on the effect of a registered tool with a literal id`
140+
: tool.effect !== 'write'
141+
? `has a ${ANNOTATION} annotation, which only justifies a 'write'; remove it`
142+
: !contradictsVerb(tool)
143+
? `has a ${ANNOTATION} annotation but its verb agrees with its effect; remove it`
144+
: undefined
145+
if (reason) {
139146
violations.push({
140147
toolId: justification.toolId ?? `${justification.file}:${justification.line}`,
141-
reason: !tool
142-
? `${ANNOTATION} annotation is not on the effect of a registered tool with a literal id`
143-
: tool.effect === 'write'
144-
? `has a ${ANNOTATION} annotation but its verb agrees with its effect; remove it`
145-
: `has a ${ANNOTATION} annotation, which only justifies a 'write'; remove it`,
148+
reason,
146149
})
147150
}
148151
}

0 commit comments

Comments
 (0)