Files
one_divine_lot/scripts/verify-real-r009.mjs
T
kyugao 859938c4f1 test(交易记录): 迭代 07/08 回归测试(独立数据目录)
- test-r009: 手动归属核心(建表/幂等/UPSERT 不覆盖归属/候选/持久化过滤)
- test-r009-sync: TradeSync 同步集成
- test-r009-normalize: QMT code 归一化
- test-r009-api: API 层端点集成
- verify-real-r009: 真实数据只读验证
- verify-real-attribution: 归属写闭环(被插件锁时跳过)
2026-09-02 01:21:04 +08:00

54 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 真实数据完整链路验证 v3(只读,技术约束-011:真实库不做写操作)
* 手动归属模型:验证归属列(若已迁移)、历史查询、候选列表
* 注:归属列 ALTER 迁移由插件重启后自动执行(当前运行中的旧构建未含迁移逻辑)
*/
import { DataStore } from '../src/component/DataStore.js';
const storage = new DataStore({ dataDir: process.env.HOME + '/.dsh/one-divine-lot' });
await storage._ensure();
let pass = 0, fail = 0;
function assert(cond, msg) {
if (cond) { pass++; console.log(' ✅ ' + msg); }
else { fail++; console.log(' ❌ ' + msg); }
}
// 1. 历史查询
const hist = await storage.getTradeOrderHistory({ start: '20260901', end: '20260901' });
console.log(' 历史委托条数:', hist.length);
const o = hist[0];
assert(o && o.orderId === '645009273', '查到真实委托 645009273');
assert(o.code === '001330.SZ', 'code 归一化正确: ' + o.code);
// 2. 归属候选列表(只读)
const cands = await storage.getTradeAttributionCandidates('001330.SZ');
console.log(' 001330.SZ 候选:', JSON.stringify(cands));
assert(cands.some(c => c.strategyId === 'grid-supermarket'), '候选含 grid-supermarket(当前持仓)');
const cands2 = await storage.getTradeAttributionCandidates('300057.SZ');
console.log(' 300057.SZ 候选:', JSON.stringify(cands2));
assert(cands2.length >= 2, '一票多策略候选 ≥2grid + manual');
// 3. 归属列状态(只读 PRAGMA
let cols = [];
try {
cols = storage.sqlite.db.prepare('PRAGMA table_info(trade_orders)').all().map(c => c.name);
} catch { cols = []; }
console.log(' trade_orders 归属列存在:', cols.includes('strategy_id'), cols.includes('holding_id'));
if (cols.includes('strategy_id') && cols.includes('holding_id')) {
// 委托 645009273 已由用户手动设置归属(grid-supermarket)→ 未关联应为 0,按策略过滤应命中
const unassigned = await storage.getTradeOrderHistory({ start: '20260901', end: '20260901', strategyId: '__unassigned__' });
const byGrid = await storage.getTradeOrderHistory({ start: '20260901', end: '20260901', strategyId: 'grid-supermarket' });
const o = hist[0];
if (o && o.strategyId) {
assert(byGrid.length >= 1 && byGrid.some((x) => x.orderId === o.orderId), '已设置归属的委托按策略过滤命中');
assert(unassigned.length === 0, '已设置归属的委托不在「未关联」中');
} else {
assert(unassigned.length === hist.length, '未设置归属的委托都在「未关联」过滤中');
}
}
storage.close();
console.log('\n结果: ' + pass + ' 通过, ' + fail + ' 失败');
process.exit(fail > 0 ? 1 : 0);