Files
one_divine_lot/scripts/verify-real-attribution.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

49 lines
2.3 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.
/**
* 真实库归属闭环验证(写操作测试):设置归属 → 过滤 → UPSERT 保留 → 还原
* 注意:插件进程持锁时外部写会失败;若失败说明插件在运行(正常),跳过写操作
*/
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); }
}
try {
// 1. 设置归属:博纳影业 001330.SZ → grid-supermarket(候选 holdingId=13
const ok = await storage.setTradeOrderAttribution('645009273', 'grid-supermarket', 13);
assert(ok, '手动设置归属成功(grid-supermarket / holding 13');
// 2. 读取确认持久化
const row = storage.sqlite.db.prepare('SELECT strategy_id, holding_id FROM trade_orders WHERE order_id=?').get('645009273');
assert(row.strategy_id === 'grid-supermarket' && row.holding_id === 13, '归属已持久化');
// 3. 按策略过滤命中
const byGrid = await storage.getTradeOrderHistory({ start: '20260901', end: '20260901', strategyId: 'grid-supermarket' });
assert(byGrid.length === 1 && byGrid[0].orderId === '645009273', '按 grid-supermarket 过滤命中');
// 4. 未关联过滤为空(该委托已设归属)
const unassigned = await storage.getTradeOrderHistory({ start: '20260901', end: '20260901', strategyId: '__unassigned__' });
assert(unassigned.length === 0, '未关联过滤为空');
// 5. 成交按委托归属过滤
const fills = await storage.getTradeFillHistory({ start: '20260901', end: '20260901', strategyId: 'grid-supermarket' });
assert(fills.length === 1, '成交按 grid-supermarket 过滤命中');
// 6. 还原为未关联(不污染真实数据)
await storage.setTradeOrderAttribution('645009273', null, null);
const restored = storage.sqlite.db.prepare('SELECT strategy_id FROM trade_orders WHERE order_id=?').get('645009273');
assert(restored.strategy_id === null, '归属已还原(未关联)');
} catch (e) {
console.log(' ⚠️ 写操作被锁(插件持锁中,正常):' + (e?.message ?? e));
fail++;
}
storage.close();
console.log('\n结果: ' + pass + ' 通过, ' + fail + ' 失败');
process.exit(fail > 0 ? 1 : 0);