| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- // Independent, read-only S3 v2 acceptance. Never calls start/save/import.
- import fs from 'node:fs';
- import crypto from 'node:crypto';
- import assert from 'node:assert/strict';
- import {invoke,classRows} from '../server/scripts/platform-client.mjs';
- import {loadPublicBoard} from '../src/services/workshop-data.js';
- const sessionId='btrFqkz0yw',artifactId='ZW1FB5zeHr',outputSourceId='G1Gzu0_sQV';
- const s1Id='G8IrkkDG7X',s2Id='b7NOby5ys0',s3v1Id='oiNxX7o27j';
- const templateBytes=fs.readFileSync('work/first-live-S3-v2-template.json');
- const template=JSON.parse(templateBytes);
- const s3v1Template=JSON.parse(fs.readFileSync('work/first-live-S3-template.json','utf8'));
- const s1Template=JSON.parse(fs.readFileSync('work/first-live-S1-v2-template.json','utf8'));
- const s2Template=JSON.parse(fs.readFileSync('work/first-live-S2-template.json','utf8'));
- const outputFile='work/live-S3-v2-readback-20261103.json';
- const saveRequestId='KSF-真实资料-20261102-01:S3:save:v2';
- const pointer=(className,objectId)=>({__type:'Pointer',className,objectId});
- const canonical=x=>x&&typeof x==='object'?Array.isArray(x)?'['+x.map(canonical).join(',')+']':'{'+Object.keys(x).sort().map(k=>JSON.stringify(k)+':'+canonical(x[k])).join(',')+'}':JSON.stringify(x);
- const sha=x=>crypto.createHash('sha256').update(x).digest('hex');
- const read=async(className,objectId)=>{
- const r=await invoke('ksfGetRecord',{className,objectId});
- assert.equal(r.http,200);assert.equal(r.body?.result?.ok,true);
- const row=r.body.result.data.record;assert.equal(row?.objectId,objectId);return row;
- };
- assert.equal(fs.existsSync(outputFile),false,'Preserve earlier acceptance');
- let check='template fingerprint and fixed scope';
- try{
- assert.equal(template.sessionId,null);assert.equal(template.taskKey,'KSF-真实资料-20261102-01:S3');
- assert.equal(sha(templateBytes),'41c32974519799103709fb124115ecd79a1ed2ef1b3b343c129e23cb2be9ca49');
- assert.equal(template.stageCode,'S3');assert.equal(template.version,2);assert.equal(template.artifactType,'opportunity_card');
- assert.equal('opportunity' in template,false);assert.equal('projectId' in template,false);
- assert.deepEqual(template.sourceIds,['2mzBadmvws','Pi04eTwTQ3','m1OQx9aynA','QdeMcyTTjX']);
- assert.equal(Object.keys(template.report.evidence).length,4);assert.equal(template.pendingQuestions.length,8);
- assert.equal(template.rawText.length,2554);
- assert.equal(template.rawText,s3v1Template.rawText);
- assert.deepEqual(template.report.chapters[2].sections[3],{kind:'table',title:'待补问题',data:{cols:['序号','待核实问题'],rows:template.pendingQuestions.map((q,i)=>[String(i+1),q])}});
- check='read saved records and operation history';
- const settled=await Promise.allSettled([
- read('KfSession',sessionId),read('KfArtifact',artifactId),read('KfArtifact',s1Id),read('KfArtifact',s2Id),
- read('KfSource',outputSourceId),
- classRows('KfArtifact',{workshopKey:'KSF-真实资料-20261102-01'}),
- classRows('KsfOperation',{operation:'workshop-task',requestId:saveRequestId}),
- classRows('KfOpportunity',{sessionRef:pointer('KfSession',sessionId)}),
- classRows('KfProject',{sessionRef:pointer('KfSession',sessionId)}),
- read('KfArtifact',s3v1Id)
- ]);
- const failures=settled.flatMap((r,i)=>r.status==='rejected'?[i]:[]);
- assert.deepEqual(failures,[],'Read group failure indexes');
- const [session,artifact,s1,s2,generated,history,operations,opportunities,projects,s3v1]=settled.map(r=>r.value);
- check='artifact fields and template';
- assert.equal(artifact.title,template.title);assert.equal(artifact.rawText,template.rawText);
- assert.equal(artifact.version,2);assert.equal(artifact.stageCode,'S3');assert.equal(artifact.artifactType,'opportunity_card');
- assert.equal(artifact.reportSeriesKey,template.taskKey);assert.equal(artifact.reportType,'workshop_auxiliary');
- assert.equal(artifact.schemaVersion,'ksf.v0.7');assert.equal(artifact.dataMode,'live');assert.equal(artifact.recordState,'active');
- assert.equal(artifact.dashboardState,'workshop');assert.equal(artifact.ownerSession,sessionId);
- assert.deepEqual(artifact.sessionRef,pointer('KfSession',sessionId));assert.deepEqual(artifact.sourceRef,pointer('KfSource',outputSourceId));
- assert.equal(artifact.projectRef??null,null);assert.equal(artifact.previousVersionRef??null,null);
- assert.equal(artifact.category??null,null);
- assert.deepEqual(artifact.tags,['拌面','课堂过程成果']);
- assert.equal(artifact.report.title,template.title);assert.ok(Number.isFinite(Date.parse(artifact.report.generatedAt)));
- assert.deepEqual(artifact.report.executive,[ '课堂过程成果,未经员工正式确认;待验证项不作为市场结论。',...template.report.executive ]);
- for(const field of ['chapters','evidence','subtitle','method','sources'])assert.deepEqual(artifact.report[field],template.report[field],field);
- assert.deepEqual(artifact.meta.workshop.sourceIds,template.sourceIds);
- assert.deepEqual(artifact.meta.workshop.pendingQuestions,template.pendingQuestions);
- assert.equal(artifact.meta.workshop.formalConfirmation,false);
- assert.equal(artifact.dashboardPublishedAt??null,null);assert.equal(artifact.contentConfirmedAt??null,null);
- assert.equal(generated.rawText,template.rawText);assert.equal(generated.dataMode,'live');
- check='inherited source evidence and quotes';
- assert.equal(artifact.evidenceCount,4);assert.equal(artifact.sources.length,4);
- const evidenceIds={'consumer-cq-01':'FO47R0yR8D','consumer-cq-02':'rD8XZgV1Xo','consumer-cq-03':'_9mUml0wmh','consumer-cq-04':'2bFGP7axMo'};
- for(const [key,entry]of Object.entries(template.report.evidence)){
- const [origin,evidence]=await Promise.all([read('KfSource',entry.sourceId),read('KfEvidence',evidenceIds[key])]);
- assert.equal(origin.dataMode,'live');assert.equal(origin.sourceKind,'social');assert.equal(origin.platform,'smzdm');
- assert.equal(evidence.quote,entry.quotes[0].text);
- assert.deepEqual(evidence.sourceRef,pointer('KfSource',entry.sourceId));assert.equal(evidence.productRef??null,null);
- assert.equal(evidence.evidenceKind,'public_user_experience_self_report');
- assert.equal(evidence.verificationState,'archived_text_and_screenshot_checked');
- assert.ok(origin.rawText.includes(entry.quotes[0].text),key+' quote exists in source');
- assert.ok(template.rawText.includes(entry.quotes[0].text),key+' quote exists in report text');
- assert.equal(entry.quotes.length,1,key+' quote count');
- }
- check='session ownership and version history';
- assert.equal(session.objectId,sessionId);assert.equal(session.stageCode,'S3');assert.equal(session.step,'submitted');
- assert.deepEqual(session.meta.attribution,artifact.meta.attribution);
- assert.equal(artifact.agentName,'王刚001');assert.equal(artifact.agentId,session.meta.attribution.agentKey);
- for(const [row,prior]of [[s1,s1Template],[s2,s2Template],[s3v1,s3v1Template]]){
- assert.deepEqual(row.meta.attribution,session.meta.attribution);
- for(const field of ['title','rawText','version','stageCode'])assert.deepEqual(row[field],prior[field]);
- assert.deepEqual(row.report.chapters,prior.report.chapters);assert.deepEqual(row.report.evidence,prior.report.evidence);
- assert.deepEqual(row.meta.workshop.sourceIds,prior.sourceIds);
- }
- assert.equal(s1.dashboardState,'workshop');assert.equal(s2.dashboardState,'workshop');assert.equal(s3v1.dashboardState,'workshop');
- const series=history.filter(x=>x.reportSeriesKey===template.taskKey);
- assert.equal(series.length,2);assert.deepEqual(series.map(x=>[x.objectId,x.version]).sort((a,b)=>a[1]-b[1]),[[s3v1Id,1],[artifactId,2]]);
- assert.equal(history.filter(x=>x.stageCode==='S3'&&x.sessionRef?.objectId===sessionId).length,2);
- assert.equal(operations.length,1);assert.equal(operations[0].receipt.artifactId,artifactId);
- assert.equal(operations[0].receipt.sourceId,outputSourceId);
- assert.equal(operations[0].receipt.opportunityId,null);assert.equal(operations[0].receipt.projectId,null);
- assert.equal(opportunities.length,0);assert.equal(projects.length,0);
- check='anonymous public board projection';
- const board=await loadPublicBoard({url:'https://kangshifu.fmode.cn/api/functions',appId:'FKieRbIoGt_main'});
- const projected=board.artifact.find(x=>x.objectId===artifactId);assert.ok(projected);
- assert.equal(projected.dashboardState,'workshop');assert.equal(projected.dataMode,'live');
- assert.equal(projected.category??null,null);assert.deepEqual(projected.tags,artifact.tags);
- assert.deepEqual(projected.report.evidence,template.report.evidence);
- assert.deepEqual(projected.report.chapters,template.report.chapters);
- assert.ok(board.artifact.some(x=>x.objectId===s1Id));assert.ok(board.artifact.some(x=>x.objectId===s2Id));
- assert.ok(board.artifact.some(x=>x.objectId===s3v1Id));
- for(const value of [session.meta.attribution.participantAccount?.accountId,session.meta.attribution.agentAccount?.accountId,session.meta.attribution.conversationKey].filter(Boolean)){
- assert.equal(JSON.stringify(board).includes(value),false);
- }
- const result={
- ok:true,operation:'live-S3-v2-independently-verified',at:new Date().toISOString(),readOnly:true,businessWrites:0,
- sessionId,artifactId,outputSourceId,reportUrl:'https://kangshifu.fmode.cn/report/'+artifactId,
- version:2,stageCode:'S3',dataMode:'live',dashboardState:'workshop',reportSeriesKey:template.taskKey,
- sourceIds:template.sourceIds,evidenceCount:artifact.evidenceCount,quoteCount:4,pendingQuestionCount:8,
- templateMatched:true,categoryPersistedAsTag:projected.tags.includes('拌面'),formalReportPublished:false,
- dashboardPublishedAt:null,employeeConfirmed:false,sessionOwnerMatched:true,s1AndS2Preserved:true,s3v1Preserved:true,
- pendingQuestionsInStructuredReport:8,templateSha256:sha(templateBytes),
- artifactSeriesCount:series.length,s3ArtifactCount:2,saveOperationCount:operations.length,opportunityCount:opportunities.length,projectCount:projects.length,
- publicBoardProjectionVerified:true,browserVerified:false
- };
- fs.writeFileSync(outputFile,JSON.stringify(result,null,2)+'\n',{flag:'wx'});
- console.log(JSON.stringify(result,null,2));
- }catch(error){
- const result={ok:false,operation:'live-S3-v2-independent-readback-stopped',check,
- checkLine:error.stack?.match(/verify-live-S3-v2-readback\.mjs:(\d+):/)?.[1]??null,readOnly:true,businessWrites:0};
- fs.writeFileSync(outputFile,JSON.stringify(result,null,2)+'\n',{flag:'wx'});
- console.error(JSON.stringify(result,null,2));process.exitCode=1;
- }
|