Skip to content

Commit e06eecd

Browse files
committed
fix(tools): dry-run placeholders drop guessed defaults and report partial write lists
- Mothership tests tool returns unmockedWrites as sites plus omittedCalls/omittedRuns - GitHub create_issue echoes labels/assignees from the same helper as the request body; no guessed state, closed_at or null body - Asana, Trello, ClickUp and HubSpot placeholders stop asserting completed/closed/archived defaults or empty notes/desc - Zendesk create_ticket echoes the assignee, group and requester ids it sets - Teams rewrite check shares the send path's mention parser, so blank mentions are not rewrites - Sheets placeholder trims the spreadsheet id, skips empty rows in counts and avoids a spread over every row - HubSpot update placeholders stringify a numeric record id before trimming
1 parent 88c0785 commit e06eecd

15 files changed

Lines changed: 111 additions & 89 deletions

File tree

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
/** An `<at>` mention, which a send resolves into Graph's mention markup. */
2-
const MENTION_PATTERN = /<at>[^<]+<\/at>/i
1+
/** Each `<at>` mention in `content` with a non-blank name, which a send tries to resolve to a member. */
2+
export function parseMentionNames(
3+
content: string
4+
): Array<{ name: string; tag: string; id: number }> {
5+
const parsed: Array<{ name: string; tag: string; id: number }> = []
6+
const pattern = /<at>([^<]+)<\/at>/gi
7+
let match: RegExpExecArray | null
8+
while ((match = pattern.exec(content)) !== null) {
9+
const name = match[1].trim()
10+
if (name) parsed.push({ name, tag: match[0], id: parsed.length })
11+
}
12+
return parsed
13+
}
314

415
/**
5-
* Whether sending `content` rewrites it (attaching files or resolving mentions) rather than
6-
* posting it as given. Dependency-free, so a tool's dry-run placeholder can ask too.
16+
* Whether sending `content` may rewrite it rather than post it as given: files attach, or a
17+
* mention resolves into Graph's mention markup when its name matches a member, which the request
18+
* alone cannot tell. Dependency-free, so a tool's dry-run placeholder can ask too.
719
*/
820
export function rewritesTeamsMessage(
921
content: string,
1022
files: readonly unknown[] | null | undefined
1123
): boolean {
12-
return Boolean(files?.length) || MENTION_PATTERN.test(content)
24+
return Boolean(files?.length) || parseMentionNames(content).length > 0
1325
}

‎apps/sim/lib/internal/microsoft-teams/operations.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
type MicrosoftTeamsGraphObject,
99
} from '@/lib/internal/microsoft-teams/client'
1010
import { MicrosoftTeamsOperationError } from '@/lib/internal/microsoft-teams/errors'
11-
import { rewritesTeamsMessage } from '@/lib/internal/microsoft-teams/message-rewrite'
11+
import {
12+
parseMentionNames,
13+
rewritesTeamsMessage,
14+
} from '@/lib/internal/microsoft-teams/message-rewrite'
1215
import type {
1316
MicrosoftTeamsWriteChannelInput,
1417
MicrosoftTeamsWriteChatInput,
@@ -198,17 +201,6 @@ async function uploadFilesForMessage(
198201
return { attachments, files }
199202
}
200203

201-
function parseMentionNames(content: string): Array<{ name: string; tag: string; id: number }> {
202-
const parsed: Array<{ name: string; tag: string; id: number }> = []
203-
const pattern = /<at>([^<]+)<\/at>/gi
204-
let match: RegExpExecArray | null
205-
while ((match = pattern.exec(content)) !== null) {
206-
const name = match[1].trim()
207-
if (name) parsed.push({ name, tag: match[0], id: parsed.length })
208-
}
209-
return parsed
210-
}
211-
212204
async function resolveMentions(
213205
content: string,
214206
membersPath: string,

‎apps/sim/lib/mothership/tools/server/tests.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@ function failures(report: StoredTestReport | null) {
4848

4949
/**
5050
* Each write a run stubbed because no mock answered it, once, as `block → tool` (a block answered
51-
* whole by its name alone): a test that passes may still lean on a placeholder.
51+
* whole by its name alone): a test that passes may still lean on a placeholder. The list is partial
52+
* when `omittedCalls` (stubbed calls a run's full list left out) or `omittedRuns` (runs past the
53+
* per-file cap, whose writes went unrecorded) is nonzero.
5254
*/
53-
function unmockedWrites(report: StoredTestReport | null): string[] {
55+
function unmockedWrites(report: StoredTestReport | null) {
5456
const executions = Object.values(report?.sideEffects?.executions ?? {})
55-
const writes = executions.flatMap((execution) =>
57+
const sites = executions.flatMap((execution) =>
5658
execution.stubbed.map(({ block, blockId, tool }) => {
5759
const site = block ?? blockId ?? 'unnamed block'
5860
return tool ? `${site} → ${tool}` : site
5961
})
6062
)
61-
return [...new Set(writes)]
63+
return {
64+
sites: [...new Set(sites)],
65+
omittedCalls: executions.reduce((total, execution) => total + execution.omitted.stubbed, 0),
66+
omittedRuns: report?.sideEffects?.omittedExecutions ?? 0,
67+
}
6268
}
6369

6470
const TEST_READ_ACTIONS = new Set(['list', 'get'])

‎apps/sim/tools/asana/create_task.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ export const asanaCreateTaskTool: InternalToolConfig<
6767
}),
6868
},
6969

70-
/** A dry run's placeholder holds the open task the call creates; its gid is a placeholder. */
70+
/** A dry run's placeholder holds the name and notes the call sets; its gid is a placeholder. */
7171
dryRunOutput: (params) => ({
7272
gid: dryRunId('task'),
7373
name: params.name,
74-
notes: params.notes || '',
75-
completed: false,
74+
...(params.notes ? { notes: params.notes } : {}),
7675
}),
7776

7877
transformResponse: async (response: Response) => {

‎apps/sim/tools/clickup/create_task.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const clickupCreateTaskTool: ToolConfig<ClickUpCreateTaskParams, ClickUpT
167167
},
168168

169169
/**
170-
* A dry run's placeholder holds the unarchived task the call creates, named as it asks, with the
170+
* A dry run's placeholder holds the task the call creates, named as it asks, with the
171171
* plain description it sends (ClickUp derives one from markdown) and the parent it names; its id
172172
* is a placeholder.
173173
*/
@@ -176,7 +176,6 @@ export const clickupCreateTaskTool: ToolConfig<ClickUpCreateTaskParams, ClickUpT
176176
id: dryRunId('task'),
177177
name: params.name,
178178
...(params.description && !params.markdownContent ? { description: params.description } : {}),
179-
archived: false,
180179
...(params.parent ? { parent: params.parent } : {}),
181180
},
182181
}),

‎apps/sim/tools/github/create_issue.ts‎

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ import {
99
import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
1010
import type { ToolConfig } from '@/tools/types'
1111

12+
/** A comma-separated `assignees` or `labels` param as the names the request sends. */
13+
function nameList(value: string | undefined): string[] {
14+
return (value ?? '')
15+
.split(',')
16+
.map((name) => name.trim())
17+
.filter(Boolean)
18+
}
19+
20+
/** The issue fields a create request sends: its title, and the body, labels and assignees it sets. */
21+
function requestedIssue(params: CreateIssueParams) {
22+
const labels = nameList(params.labels)
23+
const assignees = nameList(params.assignees)
24+
return {
25+
title: params.title,
26+
...(params.body ? { body: params.body } : {}),
27+
...(labels.length > 0 ? { labels } : {}),
28+
...(assignees.length > 0 ? { assignees } : {}),
29+
}
30+
}
31+
1232
export const createIssueTool: ToolConfig<CreateIssueParams, IssueResponse> = {
1333
id: 'github_create_issue',
1434
name: 'GitHub Create Issue',
@@ -77,37 +97,17 @@ export const createIssueTool: ToolConfig<CreateIssueParams, IssueResponse> = {
7797
Authorization: `Bearer ${params.apiKey}`,
7898
'X-GitHub-Api-Version': '2022-11-28',
7999
}),
80-
body: (params) => {
81-
const body: any = {
82-
title: params.title,
83-
}
84-
if (params.body) body.body = params.body
85-
if (params.assignees) {
86-
const assigneesArray = params.assignees
87-
.split(',')
88-
.map((a) => a.trim())
89-
.filter((a) => a)
90-
if (assigneesArray.length > 0) body.assignees = assigneesArray
91-
}
92-
if (params.labels) {
93-
const labelsArray = params.labels
94-
.split(',')
95-
.map((l) => l.trim())
96-
.filter((l) => l)
97-
if (labelsArray.length > 0) body.labels = labelsArray
98-
}
99-
if (params.milestone) body.milestone = params.milestone
100-
return body
101-
},
100+
body: (params) => ({
101+
...requestedIssue(params),
102+
...(params.milestone ? { milestone: params.milestone } : {}),
103+
}),
102104
},
103105

104106
/**
105-
* A dry run's placeholder holds the title and body of the open issue the call creates; its
106-
* number, URL and times stay placeholders.
107+
* A dry run's placeholder holds what the call sets on the issue it creates; its number, state,
108+
* URL and times stay placeholders.
107109
*/
108-
dryRunOutput: (params) => ({
109-
metadata: { title: params.title, state: 'open', body: params.body || null },
110-
}),
110+
dryRunOutput: (params) => ({ metadata: requestedIssue(params) }),
111111

112112
transformResponse: async (response) => {
113113
const issue = await response.json()
@@ -172,15 +172,17 @@ export const createIssueV2Tool: ToolConfig<CreateIssueParams, any> = {
172172
request: createIssueTool.request,
173173

174174
/**
175-
* A dry run's placeholder holds the title and body of the open issue the call creates; its id,
176-
* number, URL and times stay placeholders.
175+
* A dry run's placeholder holds what the call sets on the issue it creates, each label and
176+
* assignee by the name it sends; its id, number, state, URL and times stay placeholders.
177177
*/
178-
dryRunOutput: (params) => ({
179-
title: params.title,
180-
state: 'open',
181-
body: params.body || null,
182-
closed_at: null,
183-
}),
178+
dryRunOutput: (params) => {
179+
const { labels, assignees, ...issue } = requestedIssue(params)
180+
return {
181+
...issue,
182+
...(labels ? { labels: labels.map((name) => ({ name })) } : {}),
183+
...(assignees ? { assignees: assignees.map((login) => ({ login })) } : {}),
184+
}
185+
},
184186

185187
transformResponse: async (response: Response) => {
186188
const issue = await response.json()

‎apps/sim/tools/google_sheets/utils.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,15 @@ interface SheetWriteCounts {
180180

181181
/**
182182
* The counts a write of `values` reports, or null when the request alone cannot say: `values`
183-
* is not a grid, or a null cell leaves the sheet's value in place.
183+
* is not a grid, or a null cell leaves the sheet's value in place. An empty row or column writes
184+
* no cell, so it is not counted as updated.
184185
*/
185186
function sheetWriteCounts(values: unknown, majorDimension: string): SheetWriteCounts | null {
186187
if (!Array.isArray(values) || !values.every(Array.isArray)) return null
187188
const rows: unknown[][] = values
188189
if (rows.some((row) => row.some((cell) => cell === null || cell === undefined))) return null
189-
const lines = rows.length
190-
const width = Math.max(0, ...rows.map((row) => row.length))
190+
const lines = rows.filter((row) => row.length > 0).length
191+
const width = rows.reduce((widest, row) => Math.max(widest, row.length), 0)
191192
const cells = rows.reduce((total, row) => total + row.length, 0)
192193
const byColumns = majorDimension === 'COLUMNS'
193194
return {
@@ -219,11 +220,12 @@ export function sheetWritePlaceholder(
219220
values: unknown
220221
): Record<string, unknown> {
221222
const majorDimension = params.majorDimension || 'ROWS'
223+
const spreadsheetId = String(params.spreadsheetId).trim()
222224
return {
223225
...sheetWriteCounts(values, majorDimension),
224226
metadata: {
225-
spreadsheetId: params.spreadsheetId,
226-
spreadsheetUrl: `https://docs.google.com/spreadsheets/d/${params.spreadsheetId}`,
227+
spreadsheetId,
228+
spreadsheetUrl: `https://docs.google.com/spreadsheets/d/${spreadsheetId}`,
227229
},
228230
updatedData: params.includeValuesInResponse ? { majorDimension, values } : null,
229231
}

‎apps/sim/tools/hubspot/update_company.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const hubspotUpdateCompanyTool: ToolConfig<
8686
placeholderCrmRecord(
8787
'company',
8888
params.properties,
89-
params.idProperty ? undefined : params.companyId.trim()
89+
params.idProperty ? undefined : String(params.companyId).trim()
9090
),
9191

9292
transformResponse: async (response: Response) => {

‎apps/sim/tools/hubspot/update_contact.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const hubspotUpdateContactTool: ToolConfig<
8686
placeholderCrmRecord(
8787
'contact',
8888
params.properties,
89-
params.idProperty ? undefined : params.contactId.trim()
89+
params.idProperty ? undefined : String(params.contactId).trim()
9090
),
9191

9292
transformResponse: async (response: Response) => {

‎apps/sim/tools/hubspot/update_deal.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const hubspotUpdateDealTool: ToolConfig<HubSpotUpdateDealParams, HubSpotU
7676
placeholderCrmRecord(
7777
'deal',
7878
params.properties,
79-
params.idProperty ? undefined : params.dealId.trim()
79+
params.idProperty ? undefined : String(params.dealId).trim()
8080
),
8181

8282
transformResponse: async (response: Response) => {

0 commit comments

Comments
 (0)