Skip to content

Commit 9d06cff

Browse files
committed
test(mothership): assert the claim admits a first execution or an interrupted re-run
1 parent 6401695 commit 9d06cff

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎apps/sim/lib/mothership/async-runs/repository.test.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
copilotRequestStops,
66
copilotRuns,
77
} from '@sim/db/schema'
8-
import { dbChainMockFns, hasMockCondition, queueTableRows, resetDbChainMock } from '@sim/testing'
8+
import {
9+
dbChainMockFns,
10+
flattenMockConditions,
11+
hasMockCondition,
12+
queueTableRows,
13+
resetDbChainMock,
14+
} from '@sim/testing'
915
import { beforeEach, describe, expect, it } from 'vitest'
1016
import {
1117
areStreamToolExecutionsSettled,
@@ -240,14 +246,26 @@ describe('durable Sim tool ownership', () => {
240246
(condition) => condition.type === 'eq' && condition.right === input.userId
241247
)
242248
).toBe(true)
249+
/** A first execution, or a re-run of one whose owner died before it recorded a result. */
250+
const claimable = flattenMockConditions(dbChainMockFns.where.mock.calls[1]?.[0]).find(
251+
(condition) => condition.type === 'or'
252+
)
253+
const [firstExecution, interruptedExecution] = (claimable?.conditions ?? []) as unknown[]
243254
expect(
244255
hasMockCondition(
245-
dbChainMockFns.where.mock.calls[1]?.[0],
256+
firstExecution,
246257
(condition) =>
247258
condition.type === 'isNull' &&
248259
condition.column === copilotAsyncToolCalls.executionStartedAt
249260
)
250261
).toBe(true)
262+
expect(
263+
hasMockCondition(
264+
interruptedExecution,
265+
(condition) =>
266+
condition.type === 'lt' && condition.left === copilotAsyncToolCalls.executionAttempts
267+
)
268+
).toBe(true)
251269
expect(dbChainMockFns.set).toHaveBeenCalledWith(
252270
expect.objectContaining({ executionStartedAt: expect.any(Date), status: 'running' })
253271
)

0 commit comments

Comments
 (0)