🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
test(database): cover verify evidence, review prediction and document history (#20577)
Arvin Xu99fc3e25ea73
diff --git a/packages/database/src/models/__tests__/documentHistory.test.ts b/packages/database/src/models/__tests__/documentHistory.test.tsindex 1c7d15daf66..173dacda008 100644--- a/packages/database/src/models/__tests__/documentHistory.test.ts+++ b/packages/database/src/models/__tests__/documentHistory.test.ts@@ -273,3 +273,114 @@ describe('DocumentHistoryModel', () => {});});});++describe('DocumentHistoryModel.deleteAll', () => {+ it('should delete only the current user rows', async () => {+ const documentId = await createTestDocument(documentModel, fileModel, 'Initial content');+ const otherDocumentId = await createTestDocument(documentModel2, fileModel2, 'Other content');++ await historyModel.create({+ documentId,+ editorData: { tag: 1 },+ saveSource: 'manual',+ savedAt: new Date('2026-04-11T00:00:01.000Z'),+ });+ await historyModel2.create({+ documentId: otherDocumentId,+ editorData: { tag: 1 },+ saveSource: 'manual',+ savedAt: new Date('2026-04-11T00:00:01.000Z'),+ });++ await historyModel.deleteAll();++ expect(await historyModel.list({ documentId })).toHaveLength(0);+ expect(await historyModel2.list({ documentId: otherDocumentId })).toHaveLength(1);+ });+});++describe('DocumentHistoryModel.query', () => {+ it('should mirror list', async () => {+ const documentId = await createTestDocument(documentModel, fileModel, 'Initial content');++ await historyModel.create({+ documentId,+ editorData: { tag: 1 },+ saveSource: 'manual',+ savedAt: new Date('2026-04-11T00:00:01.000Z'),+ });++ const rows = await historyModel.query({ documentId });+ expect(rows).toHaveLength(1);+ expect(rows[0]).toMatchObject({ documentId });+ });+});++describe('DocumentHistoryModel.listByDocumentId', () => {+ it('should page with the default and an explicit limit', async () => {+ const documentId = await createTestDocument(documentModel, fileModel, 'Initial content');++ for (const i of [1, 2, 3]) {+ await historyModel.create({+ documentId,+ editorData: { tag: i },+ saveSource: 'manual',+ savedAt: new Date(`2026-04-11T00:00:0${i}.000Z`),+ });+ }++ expect(await historyModel.listByDocumentId(documentId)).toHaveLength(3);+ expect(await historyModel.listByDocumentId(documentId, 2)).toHaveLength(2);+ });+});++describe('DocumentHistoryModel.list cursor', () => {+ it('should break a savedAt tie with the beforeId cursor', async () => {+ const documentId = await createTestDocument(documentModel, fileModel, 'Initial content');+ const savedAt = new Date('2026-04-11T00:00:05.000Z');++ const first = await historyModel.create({+ documentId,+ editorData: { tag: 'tie-a' },+ saveSource: 'manual',+ savedAt,+ });+ const second = await historyModel.create({+ documentId,+ editorData: { tag: 'tie-b' },+ saveSource: 'manual',+ savedAt,+ });++ const [lowerId, higherId] = [first.id, second.id].sort();++ const rows = await historyModel.list({+ beforeId: higherId,+ beforeSavedAt: savedAt,+ documentId,+ });++ expect(rows).toHaveLength(1);+ expect(rows[0]?.id).toBe(lowerId);+ });++ it('should ignore beforeId when there is no savedAt anchor', async () => {+ const documentId = await createTestDocument(documentModel, fileModel, 'Initial content');++ for (const i of [1, 2, 3]) {+ await historyModel.create({+ documentId,+ editorData: { tag: i },+ saveSource: 'manual',+ savedAt: new Date(`2026-04-11T00:00:0${i}.000Z`),+ });+ }++ const rows = await historyModel.list({+ beforeId: '00000000-0000-0000-0000-000000000000',+ documentId,+ });++ expect(rows).toHaveLength(3);+ });+});diff --git a/packages/database/src/models/__tests__/verifyEvidence.test.ts b/packages/database/src/models/__tests__/verifyEvidence.test.tsindex f05e8824092..141de8baa5c 100644--- a/packages/database/src/models/__tests__/verifyEvidence.test.ts+++ b/packages/database/src/models/__tests__/verifyEvidence.test.ts@@ -26,12 +26,14 @@ const operationId = 'verify-evidence-test-op';let checkResultId: string;let documentId: string;let fileId: string;+let verifyRunId: string;beforeEach(async () => {await serverDB.delete(users);await serverDB.insert(users).values([{ id: userId }]);await new AgentOperationModel(serverDB, userId).recordStart({ operationId });const run = await new VerifyRunModel(serverDB, userId).ensureForOperation(operationId);+ verifyRunId = run.id;const result = await new VerifyCheckResultModel(serverDB, userId).create({checkItemId: 'item-1',checkItemIndex: 0,@@ -236,3 +238,54 @@ describe('VerifyEvidenceModel', () => {expect(await model.listByCheckResult(checkResultId)).toHaveLength(0);});});++describe('VerifyEvidenceModel.listByRun', () => {+ it('returns the run evidence with its check item id, scoped to the caller', async () => {+ const model = new VerifyEvidenceModel(serverDB, userId);+ await model.createMany([+ { checkResultId, content: 'first', type: 'text' },+ { checkResultId, content: 'second', type: 'dom_snapshot' },+ ]);++ const rows = await model.listByRun(verifyRunId);+ expect(rows).toHaveLength(2);+ expect([...rows.map((r) => r.content)].sort()).toEqual(['first', 'second']);+ expect(rows.every((r) => r.checkItemId === 'item-1')).toBe(true);++ const otherModel = new VerifyEvidenceModel(serverDB, 'someone-else');+ expect(await otherModel.listByRun(verifyRunId)).toEqual([]);+ });++ it('returns nothing for a run with no evidence', async () => {+ const model = new VerifyEvidenceModel(serverDB, userId);+ await model.create({ checkResultId, content: 'x', type: 'text' });++ expect(await model.listByRun('00000000-0000-0000-0000-000000000000')).toEqual([]);+ });+});++describe('VerifyEvidenceModel.listByRuns', () => {+ it('is a no-op for an empty run list', async () => {+ const model = new VerifyEvidenceModel(serverDB, userId);+ expect(await model.listByRuns([])).toEqual([]);+ });++ it('annotates every row with its check item and the round it came from', async () => {+ const model = new VerifyEvidenceModel(serverDB, userId);+ await model.create({ checkResultId, content: 'inline', type: 'text' });++ const rows = await model.listByRuns([verifyRunId]);+ expect(rows).toHaveLength(1);+ expect(rows[0]).toMatchObject({ checkItemId: 'item-1', content: 'inline', verifyRunId });++ const otherModel = new VerifyEvidenceModel(serverDB, 'someone-else');+ expect(await otherModel.listByRuns([verifyRunId])).toEqual([]);+ });++ it('returns nothing for runs without evidence', async () => {+ const model = new VerifyEvidenceModel(serverDB, userId);+ await model.create({ checkResultId, content: 'x', type: 'text' });++ expect(await model.listByRuns(['00000000-0000-0000-0000-000000000000'])).toEqual([]);+ });+});diff --git a/packages/database/src/models/__tests__/verifyReviewPrediction.test.ts b/packages/database/src/models/__tests__/verifyReviewPrediction.test.tsindex 5c27ccf84d3..ff46ee3bc92 100644--- a/packages/database/src/models/__tests__/verifyReviewPrediction.test.ts+++ b/packages/database/src/models/__tests__/verifyReviewPrediction.test.ts@@ -23,12 +23,14 @@ const operationId = 'verify-prediction-test-op';const identity = { model: 'gemini-3.6-flash', promptVersion: 'v1', provider: 'google' };let resultIds: string[];+let runId: string;beforeEach(async () => {await serverDB.delete(users);await serverDB.insert(users).values([{ id: userId }]);await new AgentOperationModel(serverDB, userId).recordStart({ operationId });const run = await new VerifyRunModel(serverDB, userId).ensureForOperation(operationId);+ runId = run.id;const rows = await new VerifyCheckResultModel(serverDB, userId).createMany([{ checkItemId: 'a', checkItemIndex: 0, verifierType: 'llm', verifyRunId: run.id },{ checkItemId: 'b', checkItemIndex: 1, verifierType: 'llm', verifyRunId: run.id },@@ -110,3 +112,177 @@ describe('VerifyReviewPredictionModel.resetUnadjudicated', () => {expect(await model.findById(row.id)).toBeDefined();});});++describe('VerifyReviewPredictionModel.upsert', () => {+ it('replaces the previous opinion in place and clears the stale adjudication', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ const first = await model.upsert({+ action: 'accept',+ checkResultId: resultIds[0],+ comment: 'looks good',+ confidence: 0.9,+ status: 'judged',+ ...identity,+ });+ await model.adjudicate(first.id, { adjudication: 'confirmed', edit: 'verbatim' });++ // A re-run that produced no verdict must land on the same row and drop the previous+ // action / comment / adjudication, instead of stacking a second vote.+ const replacement = await model.upsert({+ checkResultId: resultIds[0],+ status: 'skipped',+ statusReason: 'no frame to look at',+ ...identity,+ });++ expect(replacement.id).toBe(first.id);+ expect(replacement.status).toBe('skipped');+ expect(replacement.action).toBeNull();+ expect(replacement.comment).toBeNull();+ expect(replacement.confidence).toBeNull();+ expect(replacement.adjudication).toBeNull();+ expect(replacement.adjudicatedAt).toBeNull();+ expect(replacement.adjudicationEdit).toBeNull();+ expect(replacement.statusReason).toBe('no frame to look at');+ expect(await model.listByCheckResult(resultIds[0])).toHaveLength(1);+ });+});++describe('VerifyReviewPredictionModel.adjudicate', () => {+ it('does not answer a proposal the caller cannot see', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ const row = await model.upsert({+ action: 'reject',+ checkResultId: resultIds[0],+ status: 'judged',+ ...identity,+ });++ const otherModel = new VerifyReviewPredictionModel(serverDB, 'someone-else');+ expect(await otherModel.adjudicate(row.id, { adjudication: 'confirmed' })).toBeUndefined();++ expect((await model.findById(row.id))?.adjudication).toBeNull();+ });+});++describe('VerifyReviewPredictionModel.findAdjudicated', () => {+ it('returns the answered proposal only for the exact result + model identity', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ const row = await model.upsert({+ action: 'accept',+ checkResultId: resultIds[0],+ status: 'judged',+ ...identity,+ });++ // an unanswered proposal is not a recorded label+ expect(+ await model.findAdjudicated(+ resultIds[0],+ identity.provider,+ identity.model,+ identity.promptVersion,+ ),+ ).toBeUndefined();++ await model.adjudicate(row.id, { adjudication: 'not-an-issue' });++ const found = await model.findAdjudicated(+ resultIds[0],+ identity.provider,+ identity.model,+ identity.promptVersion,+ );+ expect(found?.id).toBe(row.id);++ // any other identity axis misses the label+ expect(+ await model.findAdjudicated(resultIds[0], identity.provider, identity.model, 'v0'),+ ).toBeUndefined();+ expect(+ await model.findAdjudicated(resultIds[0], identity.provider, 'other-model', 'v1'),+ ).toBeUndefined();+ expect(+ await model.findAdjudicated(resultIds[0], 'openai', identity.model, 'v1'),+ ).toBeUndefined();+ expect(+ await model.findAdjudicated(resultIds[1], identity.provider, identity.model, 'v1'),+ ).toBeUndefined();++ // ownership: another user never sees the label+ const otherModel = new VerifyReviewPredictionModel(serverDB, 'someone-else');+ expect(+ await otherModel.findAdjudicated(+ resultIds[0],+ identity.provider,+ identity.model,+ identity.promptVersion,+ ),+ ).toBeUndefined();+ });+});++describe('VerifyReviewPredictionModel.listByRuns', () => {+ it('is a no-op for an empty run list', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ expect(await model.listByRuns([])).toEqual([]);+ });++ it('annotates every opinion with its check item and run', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ await model.upsert({+ action: 'accept',+ checkResultId: resultIds[0],+ status: 'judged',+ ...identity,+ });+ await model.upsert({+ action: 'reject',+ checkResultId: resultIds[1],+ status: 'judged',+ ...identity,+ model: 'deepseek-v4-pro',+ });++ const rows = await model.listByRuns([runId]);+ expect(rows).toHaveLength(2);+ expect([...rows.map((r) => r.checkItemId)].sort()).toEqual(['a', 'b']);+ expect(rows.every((r) => r.verifyRunId === runId)).toBe(true);++ const otherModel = new VerifyReviewPredictionModel(serverDB, 'someone-else');+ expect(await otherModel.listByRuns([runId])).toEqual([]);+ });++ it('returns nothing for a run that has no predictions', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ expect(await model.listByRuns(['00000000-0000-0000-0000-000000000000'])).toEqual([]);+ });+});++describe('VerifyReviewPredictionModel.listByCheckResult', () => {+ it('returns every opinion recorded on a result, scoped to the caller', async () => {+ const model = new VerifyReviewPredictionModel(serverDB, userId);+ await model.upsert({+ action: 'accept',+ checkResultId: resultIds[0],+ status: 'judged',+ ...identity,+ });+ await model.upsert({+ action: 'unjudgeable',+ checkResultId: resultIds[0],+ status: 'judged',+ ...identity,+ model: 'deepseek-v4-pro',+ });++ const rows = await model.listByCheckResult(resultIds[0]);+ expect(rows).toHaveLength(2);+ expect([...rows.map((r) => r.model)].sort()).toEqual(['deepseek-v4-pro', 'gemini-3.6-flash']);++ expect(await model.listByCheckResult(resultIds[1])).toHaveLength(0);++ const otherModel = new VerifyReviewPredictionModel(serverDB, 'someone-else');+ expect(await otherModel.listByCheckResult(resultIds[0])).toHaveLength(0);+ });+});