d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
66 lines
2.5 KiB
TypeScript
66 lines
2.5 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { mockTransaction, mockSetForkLockTimeout, mockAcquireForkEdgeLock } = vi.hoisted(() => ({
|
|
mockTransaction: vi.fn(),
|
|
mockSetForkLockTimeout: vi.fn(),
|
|
mockAcquireForkEdgeLock: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@sim/db', () => ({ db: { transaction: mockTransaction } }))
|
|
vi.mock('@/ee/workspace-forking/lib/lineage/lineage', () => ({
|
|
setForkLockTimeout: mockSetForkLockTimeout,
|
|
acquireForkEdgeLock: mockAcquireForkEdgeLock,
|
|
}))
|
|
|
|
import { unlinkForkEdge } from '@/ee/workspace-forking/lib/lineage/unlink'
|
|
|
|
/** A fake tx whose update returns `updatedRows` and whose deletes record their calls. */
|
|
function fakeTx(updatedRows: Array<{ id: string }>) {
|
|
const updateWhere = vi.fn(() => ({ returning: vi.fn().mockResolvedValue(updatedRows) }))
|
|
const updateSet = vi.fn(() => ({ where: updateWhere }))
|
|
const update = vi.fn(() => ({ set: updateSet }))
|
|
const deleteWhere = vi.fn().mockResolvedValue(undefined)
|
|
const del = vi.fn(() => ({ where: deleteWhere }))
|
|
return { tx: { update, delete: del }, update, updateSet, del }
|
|
}
|
|
|
|
const EDGE = { childWorkspaceId: 'child-ws', parentWorkspaceId: 'parent-ws' }
|
|
|
|
describe('unlinkForkEdge', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('nulls the child pointer and purges all four edge tables under the edge lock', async () => {
|
|
const { tx, update, updateSet, del } = fakeTx([{ id: 'child-ws' }])
|
|
mockTransaction.mockImplementation(async (cb: (t: unknown) => unknown) => cb(tx))
|
|
|
|
const result = await unlinkForkEdge(EDGE, 'req-1')
|
|
|
|
expect(result).toEqual({ unlinked: true })
|
|
expect(mockSetForkLockTimeout).toHaveBeenCalledTimes(1)
|
|
expect(mockAcquireForkEdgeLock).toHaveBeenCalledWith(tx, 'child-ws')
|
|
expect(update).toHaveBeenCalledTimes(1)
|
|
expect(updateSet).toHaveBeenCalledWith(expect.objectContaining({ forkedFromWorkspaceId: null }))
|
|
expect(del).toHaveBeenCalledTimes(4)
|
|
})
|
|
|
|
it('is an idempotent no-op when the edge was already dissolved', async () => {
|
|
const { tx, del } = fakeTx([])
|
|
mockTransaction.mockImplementation(async (cb: (t: unknown) => unknown) => cb(tx))
|
|
|
|
const result = await unlinkForkEdge(EDGE)
|
|
|
|
expect(result).toEqual({ unlinked: false })
|
|
expect(del).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('propagates a transaction failure without swallowing it', async () => {
|
|
mockTransaction.mockRejectedValue(new Error('lock timeout'))
|
|
await expect(unlinkForkEdge(EDGE)).rejects.toThrow('lock timeout')
|
|
})
|
|
})
|