debug(swap)+test: 平仓利息 otcdebug 埋点 + 修复3个前端红测试

1) otcdebug 埋点(unwindSwapTrade.js, 仅 ?otcdebug=1 开启, 生产零噪音):
   - changeClosePercent: 记录实际发给后端的 closePercent
   - getInterestList: 记录 POST closePercent / 返回逐腿 InterestMode·Principal·Amount·Rate
   - 用途: 未来再遇"改比例利息腿不动", 开 ?otcdebug=1 即可定位前端没传对还是后端没缩放

2) 修复分支上既有3个红测试(均为配置/生产已改、测试未跟上或契约过时):
   - swapPrecisionConfig.test.js: quantityIntegerDigits 对齐配置(16→8, Bond等12);
     expectedQuantityPrecisions 对齐配置(Fund=4, ExRate=4), 与同文件 line87/89 一致
   - bondCalc.integration.test.js: 补 require('fs')/require('path'); 事件契约更新为
     ['keydown','input','input','enter'](onKeydown 回车故意幂等重发一次 input, 修 QA 高优 Bug)
   - markClosePnlShortConsistency.test.js: 空头一致性测试由 RED 转 GREEN(income 已补 longRatio);
     CASE deliveryPrice 105→1.05 与 GOLD 的 105*scale(0.01) 单位对齐

引入溯源: 固定值腿缩放缺陷见 d1badfe4; 精度配置 16→8 来自 0672dbbc(张名锐);
红测试为已知缺口记录(用户 hjhan)。
This commit is contained in:
hjhan
2026-08-08 12:18:45 +08:00
parent d1badfe48f
commit 68a3f0b4fa
4 changed files with 47 additions and 27 deletions
+11 -11
View File
@@ -29,7 +29,7 @@ describe('swap price precision common wiring', () => {
const configured = loadConfiguredPrecision();
expect(configured.common).toEqual({
amount: { precision: 2, grouping: true },
quantity: { integerDigits: 16, precision: 2, grouping: true },
quantity: { integerDigits: 8, precision: 2, grouping: true },
rate: { precision: 4 }
});
@@ -60,7 +60,7 @@ describe('swap price precision common wiring', () => {
AbroadSpot: 2,
AbroadStock: 2,
AbroadStockIndex: 2,
ExRate: 8,
ExRate: 4,
Shibor: 2,
FixingRepoRate: 2,
RateYield: 2,
@@ -72,12 +72,12 @@ describe('swap price precision common wiring', () => {
expect(helper.getCommonInputFormat('quantity', { append: '' }, instrumentType).precision).toBe(precision);
});
const expectedQuantityIntegerDigits = {
Stock: 12, StockIndex: 12, StockIF: 12, CommodityFutures: 12, CommoditySpot: 12,
NewOtcStock: 12, HKStock: 12, HKStockIndex: 12, Fund: 12, TBFutures: 12,
OtherFutures: 12, GoldFutures: 12, GoldSpot: 12, OtherSpot: 12, AbroadFutures: 12,
AbroadSpot: 12, AbroadStock: 12, AbroadStockIndex: 12, Shibor: 12,
FixingRepoRate: 12, RateYield: 12, BondIndex: 12,
Bond: 16, TBonds: 16, CreditBonds: 16, OtherBonds: 16, ExRate: 16
Stock: 8, StockIndex: 8, StockIF: 8, CommodityFutures: 8, CommoditySpot: 8,
NewOtcStock: 8, HKStock: 8, HKStockIndex: 8, Fund: 8, TBFutures: 8,
OtherFutures: 8, GoldFutures: 8, GoldSpot: 8, OtherSpot: 8, AbroadFutures: 8,
AbroadSpot: 8, AbroadStock: 8, AbroadStockIndex: 8, Shibor: 8,
FixingRepoRate: 8, RateYield: 8, BondIndex: 8,
Bond: 12, TBonds: 12, CreditBonds: 12, OtherBonds: 12, ExRate: 8
};
Object.entries(expectedQuantityIntegerDigits).forEach(([instrumentType, integerDigits]) => {
expect(configured[instrumentType].quantityIntegerDigits).toBe(integerDigits);
@@ -87,7 +87,7 @@ describe('swap price precision common wiring', () => {
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'Fund').precision).toBe(4);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'Fund').stringMode).toBe(true);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'Bond').precision).toBe(0);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'OtherRate').integerDigits).toBe(16);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'OtherRate').integerDigits).toBe(8);
const input = helper.getCommonInputFormat('amount', { append: '', trimTailZeros: true });
expect(input).toEqual(expect.objectContaining({ precision: 2, grouping: true, trimTailZeros: false }));
@@ -151,11 +151,11 @@ describe('swap price precision common wiring', () => {
expect(helper.getCommonPrecision('quantity', 'Stock')).toBe(3);
expect(helper.getCommonPrecision('quantity', 'Bond')).toBe(3);
expect(helper.getCommonPrecision('quantity', 'OtherRate')).toBe(3);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'Stock').integerDigits).toBe(16);
expect(helper.getCommonInputFormat('quantity', { append: '' }, 'Stock').integerDigits).toBe(8);
expect(loadHelper({
common: { quantity: { integerDigits: 0, precision: 3 } },
Stock: { quantityIntegerDigits: 'invalid' }
}).getCommonInputFormat('quantity', { append: '' }, 'Stock').integerDigits).toBe(16);
}).getCommonInputFormat('quantity', { append: '' }, 'Stock').integerDigits).toBe(8);
});
test('SwapTrade2 common fields use the price helper without changing price responsibilities', () => {