Skip to content

Commit d545479

Browse files
committed
mothership tasks: resolve the pill by task id (jsonb text spacing broke the exact-key match)
1 parent b892a50 commit d545479

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

apps/sim/lib/mothership/tasks/wake.test.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/**
22
* @vitest-environment node
33
*/
4-
import { dbChainMock, queueTableRows, resetDbChainMock, schemaMock } from '@sim/testing'
4+
import {
5+
dbChainMock,
6+
dbChainMockFns,
7+
queueTableRows,
8+
resetDbChainMock,
9+
schemaMock,
10+
} from '@sim/testing'
511
import { beforeEach, describe, expect, it, vi } from 'vitest'
612

713
const {
@@ -47,7 +53,7 @@ vi.mock('@/lib/workspaces/permissions/utils', () => ({
4753
checkWorkspaceAccess: mockCheckWorkspaceAccess,
4854
}))
4955

50-
import { runWakeTurn, validateWake } from './wake'
56+
import { resolveTaskPill, runWakeTurn, validateWake } from './wake'
5157

5258
const WAKE = {
5359
taskId: '22222222-2222-4222-8222-222222222222',
@@ -120,6 +126,44 @@ describe('copilot task wake', () => {
120126
)
121127
})
122128

129+
it('resolves the pill in the arming message before the wake turn lands', async () => {
130+
queueTableRows(schemaMock.copilotMessages, [
131+
{
132+
id: 'row-1',
133+
content: {
134+
id: 'assistant-1',
135+
role: 'assistant',
136+
contentBlocks: [
137+
{ type: 'text', content: 'armed' },
138+
{
139+
type: 'task',
140+
task: {
141+
taskId: WAKE.taskId,
142+
kind: 'timer',
143+
target: {},
144+
note: 'n',
145+
status: 'pending',
146+
},
147+
},
148+
],
149+
},
150+
},
151+
])
152+
await resolveTaskPill('chat-1', WAKE.taskId, 'completed', 'Timer elapsed')
153+
expect(dbChainMockFns.update).toHaveBeenCalledWith(schemaMock.copilotMessages)
154+
const [setArg] = dbChainMockFns.set.mock.calls[0] as [
155+
{
156+
content: {
157+
contentBlocks: Array<{ type: string; task?: { status?: string; summary?: string } }>
158+
}
159+
},
160+
]
161+
expect(setArg.content.contentBlocks[1]?.task).toMatchObject({
162+
status: 'completed',
163+
summary: 'Timer elapsed',
164+
})
165+
})
166+
123167
it('skips the turn when another stream holds the chat', async () => {
124168
mockAcquirePendingChatStream.mockResolvedValue(false)
125169
await runWakeTurn(WAKE)

apps/sim/lib/mothership/tasks/wake.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export async function resolveTaskPill(
5858
.where(
5959
and(
6060
eq(copilotMessages.chatId, chatId),
61-
sql`${copilotMessages.content}::text LIKE ${`%"taskId":"${taskId}"%`}`
61+
// The id alone is the filter — jsonb text puts a space after every colon, so a
62+
// `"taskId":"…"` pattern never matches; the block walk below is the real check.
63+
sql`${copilotMessages.content}::text LIKE ${`%${taskId}%`}`
6264
)
6365
)
6466
for (const row of rows) {

0 commit comments

Comments
 (0)