#!/usr/bin/env node const fs = require('fs'); const os = require('os'); const path = require('path'); const { spawnSync } = require('child_process'); const ROOT = path.resolve(__dirname, '..'); function main() { const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'tihao-homepage-readiness-')); const input = path.join(temp, 'homepage-evidence.json'); const output = path.join(temp, 'out'); fs.writeFileSync(input, JSON.stringify({ candidates: [ { platform: 'xiaohongshu', displayName: '高质感生活方式账号', profileUrl: 'https://example.com/profile/a', recentPosts: Array.from({ length: 10 }, (_, index) => ({ title: `近期内容 ${index + 1}`, coverUrl: `https://example.com/cover-${index + 1}.jpg`, publishTime: `2026-06-${String(index + 1).padStart(2, '0')}`, likeCount: 100 + index, commentCount: 10 + index })), homepageEvidence: { source: 'provider', confidence: 'provider', recentContentWindow: 10, visualQualityScore: 88, riskHits: ['无明显下沉风险'], reviewNotes: ['近期封面稳定,标题和场景一致'] } } ] }, null, 2), 'utf8'); const result = run(['scripts/homepage-evidence-readiness-audit.js', '--input', input, '--output', output, '--strict']); assert(result.status === 0, 'ready provider evidence should pass strict'); const summary = readJson(path.join(output, 'homepage-evidence-readiness-summary.json')); assert(summary.ready === true, 'summary.ready should be true'); assert(summary.directCustomerProof === false, 'homepage readiness should not claim customer proof'); assert(summary.counts.providerEvidenceCreators === 1, 'provider evidence should be counted'); assert(summary.counts.creatorsWithEnoughRecentPosts === 1, 'recent 10 posts should be counted'); const weakInput = path.join(temp, 'weak-homepage-evidence.json'); const weakOutput = path.join(temp, 'weak-out'); fs.writeFileSync(weakInput, JSON.stringify({ candidates: [ { platform: 'xiaohongshu', displayName: '只有主页链接的账号', profileUrl: 'https://example.com/profile/b', homepageEvidence: { source: 'fallback', reviewNotes: ['待补主页近期内容证据'] } } ] }, null, 2), 'utf8'); const weak = run(['scripts/homepage-evidence-readiness-audit.js', '--input', weakInput, '--output', weakOutput]); assert(weak.status === 0, 'non-strict weak evidence should still write audit artifacts'); const weakSummary = readJson(path.join(weakOutput, 'homepage-evidence-readiness-summary.json')); assert(weakSummary.ready === false, 'weak evidence should not be ready'); assert(weakSummary.proofLevel === 'not_business_proof', 'weak evidence should stay not business proof'); assert(weakSummary.repairActions.length >= 1, 'weak evidence should produce repair actions'); const strictWeak = run(['scripts/homepage-evidence-readiness-audit.js', '--input', weakInput, '--output', path.join(temp, 'strict-weak'), '--strict']); assert(strictWeak.status === 2, 'strict weak evidence should fail readiness gate'); console.log(JSON.stringify({ ok: true, output, weakOutput, ready: summary.ready, weakReady: weakSummary.ready, weakRepairActions: weakSummary.repairActions.length }, null, 2)); } function run(args) { const result = spawnSync(process.execPath, args, { cwd: ROOT, encoding: 'utf8', shell: false }); if (result.stdout) process.stdout.write(result.stdout); if (result.stderr) process.stderr.write(result.stderr); return result; } function readJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')); } function assert(condition, message) { if (!condition) throw new Error(message); } if (require.main === module) main();