fix: 区分用户停止与自然结束 (fixes #1358, #1790)#2223
Conversation
📝 WalkthroughWalkthrough本PR为OneDragon运行框架添加了用户主动停止与自然完成的区分机制。通过在 Changes用户停止追踪与结束后动作控制流
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as App UI
participant RunCtx as ApplicationRunContext
participant Config as one_dragon_config
participant OneDragon as OneDragonRunInterface
User->>UI: Click Stop Button / Press Hotkey
UI->>RunCtx: stop_running(by_user=True)
RunCtx->>RunCtx: _last_stop_by_user = True
rect rgba(200, 150, 100, 0.5)
Note over RunCtx,OneDragon: Natural App Completion
RunCtx->>RunCtx: _last_stop_by_user = False (reset on start)
RunCtx->>OneDragon: context_state_changed(stopped)
OneDragon->>Config: should_execute_after_done(after_done, is_last_stop_by_user=False)
Config-->>OneDragon: True (if CLOSE_GAME or SHUTDOWN)
OneDragon->>OneDragon: Execute close/shutdown action
end
rect rgba(100, 150, 200, 0.5)
Note over RunCtx,OneDragon: User-Initiated Stop
RunCtx->>OneDragon: context_state_changed(stopped)
OneDragon->>Config: should_execute_after_done(after_done, is_last_stop_by_user=True)
Config-->>OneDragon: False (skip close/shutdown)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/one_dragon/base/operation/application/application_run_context/test_stop_running.py (1)
72-93: ⚡ Quick win建议补一条
AfterDoneOpEnum.NONE的断言覆盖。当前参数化已覆盖“应执行”的两种动作;再补
NONE可以更稳地防止误回归。可选补丁
@@ `@pytest.mark.parametrize`( "after_done", [ + AfterDoneOpEnum.NONE.value.value, AfterDoneOpEnum.CLOSE_GAME.value.value, AfterDoneOpEnum.SHUTDOWN.value.value, ], ) def test_after_done_action_skips_user_stop(self, after_done: str) -> None: @@ `@pytest.mark.parametrize`( "after_done", [ + AfterDoneOpEnum.NONE.value.value, AfterDoneOpEnum.CLOSE_GAME.value.value, AfterDoneOpEnum.SHUTDOWN.value.value, ], ) def test_after_done_action_runs_after_natural_stop(self, after_done: str) -> None: """测试自然结束时会执行结束后动作。""" - assert should_execute_after_done(after_done, is_last_stop_by_user=False) + expected = after_done != AfterDoneOpEnum.NONE.value.value + assert should_execute_after_done(after_done, is_last_stop_by_user=False) is expected🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/one_dragon/base/operation/application/application_run_context/test_stop_running.py` around lines 72 - 93, Add a dedicated test to cover AfterDoneOpEnum.NONE: create a new test (e.g., test_after_done_none_never_runs) that calls should_execute_after_done(AfterDoneOpEnum.NONE.value.value, is_last_stop_by_user=True) and should_execute_after_done(AfterDoneOpEnum.NONE.value.value, is_last_stop_by_user=False) and asserts both return False; reference AfterDoneOpEnum and should_execute_after_done so the NONE case is explicitly covered and prevents regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@tests/one_dragon/base/operation/application/application_run_context/test_stop_running.py`:
- Around line 72-93: Add a dedicated test to cover AfterDoneOpEnum.NONE: create
a new test (e.g., test_after_done_none_never_runs) that calls
should_execute_after_done(AfterDoneOpEnum.NONE.value.value,
is_last_stop_by_user=True) and
should_execute_after_done(AfterDoneOpEnum.NONE.value.value,
is_last_stop_by_user=False) and asserts both return False; reference
AfterDoneOpEnum and should_execute_after_done so the NONE case is explicitly
covered and prevents regressions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d20014a1-cbb9-493c-87da-55957e076642
📒 Files selected for processing (11)
assets/text/output/en/LC_MESSAGES/ui.moassets/text/output/zh/LC_MESSAGES/ui.moassets/text/ui/en.poassets/text/ui/zh.podocs/develop/one_dragon/one_dragon_architecture.mdsrc/one_dragon/base/config/one_dragon_config.pysrc/one_dragon/base/operation/application/application_run_context.pysrc/one_dragon/base/operation/one_dragon_context.pysrc/one_dragon_qt/view/app_run_interface.pysrc/one_dragon_qt/view/one_dragon/one_dragon_run_interface.pytests/one_dragon/base/operation/application/application_run_context/test_stop_running.py
| SHUTDOWN = ConfigItem('关机') | ||
|
|
||
|
|
||
| def should_execute_after_done(after_done: str, is_last_stop_by_user: bool) -> bool: |




This pull request adds support for configuring "after completion" actions (such as closing the game or shutting down) in the one-dragon run interface, and ensures these actions are only executed when the application ends naturally (not when stopped by the user). It introduces logic to track whether the last stop was user-initiated, updates the UI and configuration accordingly, and adds comprehensive tests for these behaviors.
After Completion Actions & User Stop Tracking:
en.po,zh.po) and documented the intended behavior in the architecture docs. [1] [2] [3]should_execute_after_done) and state tracking inApplicationRunContextto distinguish between user-initiated stops and natural application completion, ensuring "after completion" actions only run on natural completion. [1] [2] [3] [4] [5] [6] [7]Testing:
Miscellaneous Improvements:
run_application(removed unused variable).Summary by CodeRabbit
发布说明
新功能
文档
测试