assistant/tests/check_preflight_cards_d44.mjs

52 lines
4.1 KiB
JavaScript

// Pure server-rendered card checks. No desktop, browser, backend or model.
import { build } from 'esbuild';
import { mkdtemp, rm } from 'node:fs/promises';
import { createRequire } from 'node:module';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../', import.meta.url));
const directory = await mkdtemp(path.join(os.tmpdir(), 'juzi-preflight-cards-'));
try {
const output = path.join(directory, 'cards.cjs');
await build({ stdin: { resolveDir: root, sourcefile: 'preflight-card-check.tsx', loader: 'tsx', contents: `
import assert from 'node:assert/strict';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { DeliveryStatusCard, LeadResults } from './renderer/components/SceneCards';
const summary = { version:1, completed:true, run_available:true, recorded:true, visited_known:true,
inspected_notes:1, visited_notes:1, checked_count:0, eligible_count:0,
classification_counts:{ unique_dom_deep_reply:0, needs_native_identity:0, ambiguous:0, unknown:0 },
not_in_view_notes:0, unknown_notes:0, folded_notes:1, folded_unknown_notes:0, scope_passed:true,
history_truncated:false, max_notes:2, unknown_click_blocked_count:0,
headline:'预检已完成,可见范围未发现合格样本', detail:'仅代表当前可见范围,折叠及未加载部分未知。',
notes:[{ ordinal:1, inspected:true, status:'inspected', checked_count:0, eligible_count:0, has_unexpanded_replies:true }] };
const delivery = { version:1, status:'fulfilled', headline:summary.headline,
runtime:{status:'completed'}, fulfillment:{scope_met:true,requirements_met:true,complete:true,assessment_current:true,target:null,current:0,remaining:null},
artifacts:{list_available:false,file_required:false,file_available:false,delivered:true,export_count:0},
counts:{eligible:0,known_identity:0,supplemental:0,unresolved:0,signals:0,verified_accounts:0},conditions:[],people:[],preflight:summary };
const complete = renderToStaticMarkup(<DeliveryStatusCard delivery={delivery} />);
assert.ok(complete.includes('data-delivery-kind="preflight"'));
assert.ok(complete.includes('预检已完成') && complete.includes('仍有折叠回复未展开'));
assert.ok(!complete.includes('位满足本次条件') && !complete.includes('尚无可交付名单'));
assert.ok(!complete.includes('unique_dom_deep_reply') && !complete.includes('run_id') && !complete.includes('locator'));
const unknownSummary = {...summary,completed:false,recorded:false,visited_known:false,inspected_notes:0,visited_notes:0,notes:[]};
const unknown = renderToStaticMarkup(<DeliveryStatusCard delivery={{...delivery,status:'no_evidence',preflight:unknownSummary,fulfillment:{...delivery.fulfillment,complete:false}}} />);
assert.ok(unknown.includes('实际访问数量未记录') && unknown.includes('尚无独立预检记录'));
assert.ok(!unknown.includes('0 篇已记录访问'));
const task = {id:'local-card-fixture',inputs:{},artifacts:{},ui:{delivery_status:delivery}};
const results = renderToStaticMarkup(<LeadResults task={task} leads={[]} busy={false} onCorrect={async()=>{}} onBusinessOutcome={async()=>{}} />);
assert.ok(results.includes('preflight-no-candidate-list'));
assert.ok(!results.includes('尚无候选名单') && !results.includes('未读取或未保存到有效来源'));
const normal = renderToStaticMarkup(<DeliveryStatusCard delivery={{...delivery,preflight:undefined,counts:{...delivery.counts,eligible:1}}} />);
assert.ok(normal.includes('1 位满足本次条件'));
assert.ok(!normal.includes('data-delivery-kind="preflight"'));
process.stdout.write(JSON.stringify({kind:'pure SSR preflight card checks',passed:4,externalActions:0})+'\\n');
` }, bundle: true, platform: 'node', target: 'node22', format: 'cjs', outfile: output,
loader: { '.css': 'empty' }, define: { 'process.env.NODE_ENV': '"production"' }, logLevel: 'silent' });
createRequire(import.meta.url)(output);
} finally {
await rm(directory, { recursive: true, force: true });
}