#!/usr/bin/env node const { CORE_FIELDS, REQUIRED_FIELDS, MANUAL_ONLY_FIELDS, PGY_ALIAS, INDEXES, buildDdl, buildQueryMap } = require('../mcp/src/features/tihao-sourcing/media-library-schema'); function main() { // 字段总数与必填数 assert(Object.keys(CORE_FIELDS).length >= 30, '字段总数应覆盖模板表头 35 列'); assert(REQUIRED_FIELDS.length === 8, `必填字段应为 8 个,实际 ${REQUIRED_FIELDS.length}`); // 必填字段(模板「*」标记) ['platform', 'content_type', 'nickname', 'fans_count', 'homepage_url', 'quote_url', 'fans_profile', 'tax_inclusive_price'].forEach(key => { assert(CORE_FIELDS[key] && CORE_FIELDS[key].required === true, `${key} 应为必填字段`); }); // 报价/成本字段 ['tax_inclusive_price', 'picture_price', 'video_price', 'cpv', 'cpe'].forEach(key => { assert(CORE_FIELDS[key] && CORE_FIELDS[key].type === 'number', `${key} 应为数值字段`); }); // 商单交付侧字段应含人工补录项 ['schedule', 'case_url', 'report_form', 'tier', 'verified'].forEach(key => { assert(MANUAL_ONLY_FIELDS.includes(key), `${key} 应属于人工补录字段`); }); // 与蒲公英对账字段 ['blogger_id', 'fans_count', 'picture_price', 'video_price', 'interaction_rate'].forEach(key => { assert(PGY_ALIAS[key], `${key} 应有蒲公英对账别名`); }); // 索引唯一键 assert(INDEXES.some(index => index.name === 'uk_blogger_id' && index.options.unique), '应有 platform+blogger_id 唯一索引'); assert(INDEXES.length >= 5, '应覆盖选号热路径索引'); // DDL 与查询映射生成 const ddl = buildDdl('media_library'); assert(ddl.includes('createCollection'), 'DDL 应包含建表语句'); assert(ddl.includes('uk_blogger_id'), 'DDL 应包含唯一索引'); assert(ddl.includes('tax_inclusive_price'), 'DDL 应包含必填字段说明'); const queryMap = buildQueryMap(); assert(queryMap.includes('公司媒体资源库字段映射'), '查询映射应有标题'); assert(queryMap.includes('必填字段'), '查询映射应包含必填字段节'); assert(queryMap.includes('蒲公英采集库字段对账'), '查询映射应包含对账节'); console.log(JSON.stringify({ ok: true, fieldCount: Object.keys(CORE_FIELDS).length, requiredCount: REQUIRED_FIELDS.length, manualOnlyCount: MANUAL_ONLY_FIELDS.length, pgyAliasCount: Object.keys(PGY_ALIAS).length, indexCount: INDEXES.length }, null, 2)); } function assert(condition, message) { if (!condition) throw new Error(message); } if (require.main === module) main();