fix(小宝预警): 稳定风险证据与建议更新

关键改动:

- 优化风险证据的日报工时与静默风险计算

- 稳定 AI 触发签名,避免证据细节变化造成重复请求

- 调整预警建议更新状态与相关测试

Co-Authored-By: Codex GPT-5 <codex@openai.com>
This commit is contained in:
Script Generator
2026-07-01 11:26:16 +08:00
parent 8947aeaac7
commit e5ef9ee28b
7 changed files with 421 additions and 43 deletions

View File

@@ -103,6 +103,23 @@ test('attachXiaobaoRiskSuggestion keeps previous AI suggestion while a new one i
assert.equal(result.aiInsight?.summary, '旧的小宝建议');
});
test('attachXiaobaoRiskSuggestion hides stale pending update notices', () => {
const previous = risk({ riskScore: 52, riskLevel: 'attention' });
const current = risk({ riskScore: 82, riskLevel: 'at_risk', delayDays: 1 });
const pendingKey = buildXiaobaoRiskInsightPendingKey(current);
const result = attachXiaobaoRiskSuggestion(current, {
insights: [insight(previous)],
pendingInsightKeys: [pendingKey],
pendingInsightAttempts: { [pendingKey]: '2026-06-30T10:00:00.000Z' },
now: new Date('2026-06-30T10:04:00.000Z'),
});
assert.equal(result.aiInsightSource, 'previous_ai');
assert.equal(result.aiInsightUpdating, false);
assert.equal(result.aiInsight?.summary, insight(previous).insight.summary);
});
test('attachXiaobaoRiskSuggestion uses the current AI suggestion when the signature matches', () => {
const current = risk({ riskScore: 82, riskLevel: 'at_risk', delayDays: 1 });
@@ -172,3 +189,49 @@ test('buildXiaobaoRiskInsightPendingKey stays stable for refresh-only risk drift
assert.equal(buildXiaobaoRiskInsightPendingKey(before), buildXiaobaoRiskInsightPendingKey(after));
});
test('buildXiaobaoRiskInsightPendingKey stays stable when only daily report evidence details change', () => {
const before = risk({
riskLevel: 'at_risk',
riskScore: 82,
confidence: 70,
dailyEvidence: {
todayDeliveries: [],
todayProgress: [
{ id: 'ev-old', title: 'Progress', summary: 'Worked on checkout flow.', occurredAt: '2026-06-30T03:00:00.000Z' },
],
todayCreations: [],
todayRisks: [],
progressNotes: [],
needsProgressItems: [],
recentActivityCount: 2,
totalActivityCount: 1,
todayActualHours: 1,
lastActivityAt: '2026-06-30T03:00:00.000Z',
},
});
const after = risk({
riskLevel: 'at_risk',
riskScore: 82,
confidence: 70,
dailyEvidence: {
todayDeliveries: [],
todayProgress: [
{ id: 'ev-new', title: 'Progress', summary: 'Updated checkout flow and added handoff notes.', occurredAt: '2026-07-01T04:00:00.000Z' },
{ id: 'ev-new-2', title: 'Progress', summary: 'Confirmed QA scope.', occurredAt: '2026-07-01T05:00:00.000Z' },
],
todayCreations: [],
todayRisks: [],
progressNotes: [
{ id: 'note-new', title: 'Note', summary: 'Next work starts tomorrow morning.', occurredAt: '2026-07-01T06:00:00.000Z' },
],
needsProgressItems: [],
recentActivityCount: 6,
totalActivityCount: 3,
todayActualHours: 4,
lastActivityAt: '2026-07-01T06:00:00.000Z',
},
});
assert.equal(buildXiaobaoRiskInsightPendingKey(before), buildXiaobaoRiskInsightPendingKey(after));
});