d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*
|
|
* Lock-order regression guard: `updateDocument` must lock the document's
|
|
* embedding rows BEFORE the document row when cascading tag updates, matching
|
|
* the embedding → document order every chunk-mutation path uses
|
|
* (chunks/service.ts). The opposite order deadlocks a document tag edit against
|
|
* a concurrent chunk edit of the same document.
|
|
*/
|
|
import { document, embedding } from '@sim/db/schema'
|
|
import { dbChainMock, dbChainMockFns, resetDbChainMock } from '@sim/testing'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { updateDocument } from '@/lib/knowledge/documents/service'
|
|
|
|
vi.mock('@sim/db', () => dbChainMock)
|
|
|
|
/** invocationCallOrder of the first `tx.update(table)` call. */
|
|
function updateOrderForTable(table: unknown): number {
|
|
const { calls, invocationCallOrder } = dbChainMockFns.update.mock
|
|
for (let i = 0; i < calls.length; i++) {
|
|
if (calls[i][0] === table) return invocationCallOrder[i]
|
|
}
|
|
return -1
|
|
}
|
|
|
|
describe('updateDocument lock ordering', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
resetDbChainMock()
|
|
// Post-transaction re-read of the updated document must return a row.
|
|
dbChainMockFns.limit.mockResolvedValue([{ id: 'doc-1', knowledgeBaseId: 'kb-1' }])
|
|
})
|
|
|
|
it('updates embeddings before the document row when cascading tag changes', async () => {
|
|
await updateDocument('doc-1', { tag1: 'priority' }, 'req-1')
|
|
|
|
const embeddingWriteOrder = updateOrderForTable(embedding)
|
|
const documentWriteOrder = updateOrderForTable(document)
|
|
|
|
expect(embeddingWriteOrder).toBeGreaterThan(0)
|
|
expect(documentWriteOrder).toBeGreaterThan(0)
|
|
expect(embeddingWriteOrder).toBeLessThan(documentWriteOrder)
|
|
})
|
|
})
|