fix(小宝预警): 合并远端风险缓存
This commit is contained in:
@@ -3,6 +3,8 @@ import test from 'node:test';
|
||||
import type { XiaobaoRiskSnapshot } from './xiaobao-risk-trend';
|
||||
import {
|
||||
findCachedInsight,
|
||||
mergeDailySnapshotCacheForSave,
|
||||
mergeInsightCacheForSave,
|
||||
upsertDailySnapshot,
|
||||
upsertInsight,
|
||||
type XiaobaoRiskInsightCacheItem,
|
||||
@@ -68,3 +70,34 @@ test('upsertInsight replaces existing version signature pair', () => {
|
||||
|
||||
assert.deepEqual(result, [replacement, otherSignature, otherVersion]);
|
||||
});
|
||||
|
||||
test('mergeDailySnapshotCacheForSave preserves remote rows and local-only rows', () => {
|
||||
const remoteOnly: XiaobaoRiskSnapshot = {
|
||||
versionId: 'remote-version',
|
||||
date: '2026-06-29',
|
||||
riskScore: 30,
|
||||
riskLevel: 'attention',
|
||||
openBugCount: 0,
|
||||
failedTestCount: 0,
|
||||
blockedCount: 0,
|
||||
silentRiskCount: 0,
|
||||
confidence: 90,
|
||||
createdAt: '2026-06-29T08:00:00.000Z',
|
||||
};
|
||||
const localOnly: XiaobaoRiskSnapshot = { ...remoteOnly, versionId: 'local-version', riskScore: 50 };
|
||||
const item: XiaobaoRiskSnapshot = { ...remoteOnly, versionId: 'current-version', riskScore: 70 };
|
||||
|
||||
const result = mergeDailySnapshotCacheForSave([localOnly], [remoteOnly], item);
|
||||
|
||||
assert.deepEqual(result, [item, remoteOnly, localOnly]);
|
||||
});
|
||||
|
||||
test('mergeInsightCacheForSave preserves remote rows and local-only rows', () => {
|
||||
const remoteOnly: XiaobaoRiskInsightCacheItem = { ...insightA, versionId: 'remote-version' };
|
||||
const localOnly: XiaobaoRiskInsightCacheItem = { ...insightA, versionId: 'local-version' };
|
||||
const item: XiaobaoRiskInsightCacheItem = { ...insightA, versionId: 'current-version' };
|
||||
|
||||
const result = mergeInsightCacheForSave([localOnly], [remoteOnly], item);
|
||||
|
||||
assert.deepEqual(result, [item, remoteOnly, localOnly]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user