| 1234567891011121314151617181920212223242526 |
- import { test } from 'node:test';
- import assert from 'node:assert/strict';
- import { opportunityReportArtifact, opportunitiesForReport, reportOpportunity } from '../src/core/opportunity/report.js';
- const structured = { id:'report', report:{ chapters:[{ sections:[{kind:'para',text:'已保存的报告正文'}] }] } };
- const text = { id:'text', rawText:'已保存的来源原文,保留原有内容,不补造分析。' };
- const empty = { id:'empty', title:'只有标题' };
- const o1 = { id:'o1', linkedArtifactIds:['missing','empty','text','report'] };
- const o2 = { id:'o2', linkedArtifactIds:['report'] };
- const db = { artifactById:{ report:structured,text,empty }, opportunities:[o1,o2], opportunityById:{o1,o2} };
- test('机会报告只按显式关系找正文,优先结构化报告,再用已保存原文', () => {
- assert.equal(opportunityReportArtifact(db,'o1'),structured);
- assert.equal(opportunityReportArtifact({...db,artifactById:{text,empty}},'o1'),text);
- assert.equal(opportunityReportArtifact({...db,artifactById:{empty}},'o1'),null);
- assert.equal(opportunityReportArtifact(db,'不存在'),null);
- });
- test('共用报告必须明确评分对象,错误绑定不能误落到另一张机会卡', () => {
- assert.deepEqual(opportunitiesForReport(db,'report'),[o1,o2]);
- assert.equal(reportOpportunity(db,'report'),null);
- assert.equal(reportOpportunity(db,'report','o2'),o2);
- assert.equal(reportOpportunity(db,'text'),o1);
- assert.equal(reportOpportunity(db,'text','o2'),null);
- assert.deepEqual(opportunitiesForReport(db,'missing'),[]);
- });
|