Skip to content

Commit e942dd4

Browse files
fix(tests): refresh test tabs after a run, keep saved edits successful
- A finished Mothership run refreshes its tests instead of upserting tabs, so a test deleted mid-run does not come back. - A failed file-tab lookup after a saved edit opens no tab instead of reporting the edit as failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EHGBgHrtePpi7KMrEfy41R
1 parent b5ed03e commit e942dd4

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎apps/sim/lib/mothership/resources/file-tabs.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { db } from '@sim/db'
22
import { workspaceFiles } from '@sim/db/schema'
3+
import { createLogger } from '@sim/logger'
34
import { toStringOrNull } from '@sim/utils/coerce'
45
import { and, inArray, notInArray } from 'drizzle-orm'
56
import type { BaseServerTool } from '@/lib/mothership/tools/server/base-tool'
67

8+
const logger = createLogger('FileTabs')
9+
710
/** Row contexts that open as a file tab: workspace files and chat uploads. */
811
const FILE_TAB_CONTEXTS = ['workspace', 'mothership']
912

@@ -38,8 +41,16 @@ export function withFileTabFlag<TArgs, TResult extends { data?: Record<string, u
3841
async execute(args, context) {
3942
const result = await tool.execute(args, context)
4043
const id = toStringOrNull(result.data?.id)
41-
if (id === null || !(await findNonTabFileIds([id])).has(id)) return result
42-
return { ...result, data: { ...result.data, fileTab: false } }
44+
if (id === null) return result
45+
let isTab: boolean
46+
try {
47+
isTab = !(await findNonTabFileIds([id])).has(id)
48+
} catch (error) {
49+
// The edit already saved, so a failed lookup opens no tab rather than failing it.
50+
logger.error('Could not check whether an edited file is a file tab', { id, error })
51+
isTab = false
52+
}
53+
return isTab ? result : { ...result, data: { ...result.data, fileTab: false } }
4354
},
4455
}
4556
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ export const testsServerTool: BaseServerTool = {
144144
)
145145
if (current.every((run) => run.status !== 'running')) {
146146
const resources: ResourceChange[] = current.map((run) => ({
147-
op: 'upsert',
148-
resource: { type: 'test', workspaceId, id: run.name, title: run.title },
147+
op: 'refresh',
148+
resource: { type: 'test', id: run.name },
149149
}))
150150
return {
151151
resources,

‎apps/sim/lib/workflow-tests/application/tests.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ export const readWorkflowTestRuns = defineAuthorizedWorkspaceUseCase({
390390
runs: rows.map((row) => ({
391391
...presentRun(row, row.testSourceHash, facts),
392392
name: row.testName,
393-
title: row.testTitle,
394393
report: row.report as TestReport | null,
395394
})),
396395
}

‎apps/sim/lib/workflow-tests/repository.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,24 +437,16 @@ export async function getWorkflowTestRunById(
437437
export async function listWorkflowTestRunsById(
438438
runIds: string[],
439439
workspaceId: string
440-
): Promise<
441-
Array<WorkflowTestRunRow & { testName: string; testTitle: string; testSourceHash: string }>
442-
> {
440+
): Promise<Array<WorkflowTestRunRow & { testName: string; testSourceHash: string }>> {
443441
if (runIds.length === 0) return []
444442
const rows = await db
445443
.select({
446444
run: workflowTestRun,
447445
testName: workflowTest.name,
448-
testTitle: workflowTest.title,
449446
testSourceHash: workflowTest.sourceHash,
450447
})
451448
.from(workflowTestRun)
452449
.innerJoin(workflowTest, eq(workflowTest.id, workflowTestRun.testId))
453450
.where(and(inArray(workflowTestRun.id, runIds), eq(workflowTestRun.workspaceId, workspaceId)))
454-
return rows.map(({ run, testName, testTitle, testSourceHash }) => ({
455-
...run,
456-
testName,
457-
testTitle,
458-
testSourceHash,
459-
}))
451+
return rows.map(({ run, testName, testSourceHash }) => ({ ...run, testName, testSourceHash }))
460452
}

0 commit comments

Comments
 (0)