From 7d738e97f0316d0bc9ada848605407621dc44daf Mon Sep 17 00:00:00 2001 From: baobao Date: Thu, 19 Nov 2026 10:33:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=88=B6=E6=8C=87=E4=BB=A4=E6=89=80?= =?UTF-8?q?=E5=B1=9E=E7=AD=96=E7=95=A5=E8=B4=A6=E6=9C=AC=E7=99=BB=E8=AE=B0?= =?UTF-8?q?=E6=92=A4=E6=8D=A2=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/execution_orders.py | 8 ++++++-- scripts/run_tests.py | 2 +- scripts/test_intraday_rotation.py | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/services/execution_orders.py b/app/services/execution_orders.py index 80cbe76..50f8d09 100644 --- a/app/services/execution_orders.py +++ b/app/services/execution_orders.py @@ -216,8 +216,12 @@ def request_replace(parent_id, reason, now=None): progress = dict(parent.get('progress') or {}) if not progress.get('replacement_requested'): progress['replacement_requested'] = {'at': policy.local_now(now).isoformat(), 'reason': reason} - if not pms_repo.update_instruction(parent_id, progress=progress): - raise RuntimeError('撤换请求没有写入父指令') + book = parent.get('book_id') if settings.INFRA_STRATEGY_BOOK_SCHEMA else books.ORIGINAL + if book not in (books.MICRO, books.ORIGINAL): + raise ValueError('父指令所属策略无法核实') + with books.scope(book): + if not pms_repo.update_instruction(parent_id, progress=progress): + raise RuntimeError('撤换请求没有写入父指令') result = dispatcher.cancel(instruction_id=parent_id, dispatch_ref=parent.get('dispatch_ref')) if not result.get('ok'): raise RuntimeError('撤换请求未成功落表:'+str(result.get('error'))) diff --git a/scripts/run_tests.py b/scripts/run_tests.py index 6714a44..6988e8d 100644 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -207,7 +207,7 @@ HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) # 退出纪律专项:两次独立清仓信号、评级下降、事务、双策略隔离及撤单收尾。 SUITES = [ - 'test_intraday_rotation.py', # 单日轮动授权、50个席位和委托出口(7例) + 'test_intraday_rotation.py', # 单日轮动授权、50个席位、撤换和委托出口(8例) "test_business_evidence.py", # 历史准备覆盖与嵌套业务失败(21例) "test_signal_health.py", # 资金监测可用性与交易员提示,7例 "test_proposal_trader_view.py", # 当前分析、数据库读数保存及旧确认保护(21例) diff --git a/scripts/test_intraday_rotation.py b/scripts/test_intraday_rotation.py index 86a9d06..77fa999 100644 --- a/scripts/test_intraday_rotation.py +++ b/scripts/test_intraday_rotation.py @@ -111,6 +111,29 @@ class IntradayEntry(TestCase): self.order['qty']=40 self.assertFalse(entry.blocker(self.parent,self.order,self.now)) + def test_replace_writes_only_own_book_before_cancel(self): + from app.core import strategy_book as books + from app.services import dispatcher + self.mock(eo,'account_guard',side_effect=nullcontext) + self.mock(eo.pms_repo,'get_instruction',return_value=self.parent) + writes=[] + def save(iid,progress): + sql = books.scoped_sql("UPDATE pms_instruction SET progress_json=:progress WHERE instruction_id=:iid") + writes.append(sql) + self.assertIn('replacement_requested',progress) + return 1 + self.mock(eo.pms_repo,'update_instruction',side_effect=save) + cancel=self.mock(dispatcher,'cancel',return_value={'ok':True}) + self.mock(eo,'replacement_state',return_value={'ready':False}) + result=eo.request_replace('p','报价过期',self.now) + self.assertFalse(result['ready']) + self.assertIn("book_id = 'micro30'",writes[0]) + cancel.assert_called_once() + self.parent['book_id']='unknown' + with self.assertRaises(ValueError): + eo.request_replace('p','报价过期',self.now) + self.assertEqual(cancel.call_count,1) + def test_ban_removal_does_not_remove_other_ban(self): rows=self.mock(entry.repo.db,'fetch_all',return_value=[{'cmd_type':t} for t in ('UNFREEZE_STOCK','BLACKLIST_ADD','FREEZE_STOCK')])