-
Notifications
You must be signed in to change notification settings - Fork 21
refactor: make IntoParameters trait more test friendly #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduce TaskContext. Implement into_parameters_no_context for all presets and merge defaults automatically in trait impl. Add comprehensive copilot tests for default merging and CLI override behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:
- 让
CopilotParams::into_parameters_no_context调用unreachable!比较脆弱,因为任何对IntoParameters的泛型使用(或未来的重构)都可能在运行时触发它;建议实现一个真正的无上下文版本,并把自定义合并逻辑抽取到一个辅助函数中,而不是依赖unreachable!。 - 在 Copilot 参数构建路径里有一处
// TODO: insert unused parameters from default;最好现在就处理这个 TODO,或者明确 default 传播的预期语义,这样在后续依赖这次重构之前,行为就是定义清晰的。
给 AI 代理的提示词
Please address the comments from this code review:
## Overall Comments
- Having `CopilotParams::into_parameters_no_context` call `unreachable!` is brittle, since any generic use of `IntoParameters` (or future refactors) could hit this at runtime; consider implementing the no-context variant and factoring the custom merging logic into a helper instead of relying on `unreachable!`.
- There is a `// TODO: insert unused parameters from default` in the copilot parameter construction path; it would be good to either address this now or clarify the intended semantics of default propagation so the behavior is well-defined before this refactor is relied upon.
## Individual Comments
### Comment 1
<location> `crates/maa-cli/src/run/preset/mod.rs:30-34` </location>
<code_context>
trait IntoParameters {
- fn into_parameters(self, config: &AsstConfig) -> Result<MAAValue>;
+ #[allow(unused_variables)]
+ fn into_parameters(self, mut context: TaskContext<'_>) -> Result<MAAValue>
+ where
+ Self: Sized,
+ {
+ context.default.merge(self.into_parameters_no_context()?);
+ Ok(context.default)
+ }
</code_context>
<issue_to_address>
**question (bug_risk):** The new default `into_parameters` implementation may change precedence semantics compared to the previous `merge_from` usage.
Previously, `IntoTaskConfig::into_task_config` called `default.merge_from(¶ms)`, but the new path uses `context.default.merge(self.into_parameters_no_context()?)`. Depending on how `MAAValue::merge` vs `merge_from` are defined, this might flip which side wins on key conflicts or otherwise change merge behavior for all default `IntoParameters` implementors. Please confirm that `merge` here still applies CLI/task parameters over file defaults and is equivalent in effect to the old `merge_from` call.
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进后续的 Review。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- Having
CopilotParams::into_parameters_no_contextcallunreachable!is brittle, since any generic use ofIntoParameters(or future refactors) could hit this at runtime; consider implementing the no-context variant and factoring the custom merging logic into a helper instead of relying onunreachable!. - There is a
// TODO: insert unused parameters from defaultin the copilot parameter construction path; it would be good to either address this now or clarify the intended semantics of default propagation so the behavior is well-defined before this refactor is relied upon.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Having `CopilotParams::into_parameters_no_context` call `unreachable!` is brittle, since any generic use of `IntoParameters` (or future refactors) could hit this at runtime; consider implementing the no-context variant and factoring the custom merging logic into a helper instead of relying on `unreachable!`.
- There is a `// TODO: insert unused parameters from default` in the copilot parameter construction path; it would be good to either address this now or clarify the intended semantics of default propagation so the behavior is well-defined before this refactor is relied upon.
## Individual Comments
### Comment 1
<location> `crates/maa-cli/src/run/preset/mod.rs:30-34` </location>
<code_context>
trait IntoParameters {
- fn into_parameters(self, config: &AsstConfig) -> Result<MAAValue>;
+ #[allow(unused_variables)]
+ fn into_parameters(self, mut context: TaskContext<'_>) -> Result<MAAValue>
+ where
+ Self: Sized,
+ {
+ context.default.merge(self.into_parameters_no_context()?);
+ Ok(context.default)
+ }
</code_context>
<issue_to_address>
**question (bug_risk):** The new default `into_parameters` implementation may change precedence semantics compared to the previous `merge_from` usage.
Previously, `IntoTaskConfig::into_task_config` called `default.merge_from(¶ms)`, but the new path uses `context.default.merge(self.into_parameters_no_context()?)`. Depending on how `MAAValue::merge` vs `merge_from` are defined, this might flip which side wins on key conflicts or otherwise change merge behavior for all default `IntoParameters` implementors. Please confirm that `merge` here still applies CLI/task parameters over file defaults and is equivalent in effect to the old `merge_from` call.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #473 +/- ##
==========================================
+ Coverage 69.34% 69.40% +0.05%
==========================================
Files 56 56
Lines 5598 5608 +10
Branches 5598 5608 +10
==========================================
+ Hits 3882 3892 +10
Misses 1425 1425
Partials 291 291 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗨——我已经审查了你的修改,看起来非常棒!
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的代码审查。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@sourcery-ai title |
Introduce TaskContext. Implement into_parameters_no_context for all presets and merge defaults automatically in trait impl. Add comprehensive copilot tests for default merging and CLI override behavior.
Summary by Sourcery
引入一个基于 TaskContext 的参数构建流程,用于集中处理默认任务配置的加载与合并,并重构预设与测试以使用新的 API。
Enhancements:
IntoParameterstrait,使其接收一个TaskContext,并通过新增的into_parameters_no_context方法提供一个负责默认值合并的into_parameters默认实现。StartUp、CloseDown、Copilot、SSSCopilot、Fight、Roguelike、Reclamation),以符合新的IntoParameters/into_parameters_no_context模型。TaskConfig的构建方式,改为通过new_with_tasks构造函数创建,而不是增量式 push,从而简化任务列表的创建以及与IntoTaskConfig的集成。test_context辅助方法,用于在测试中构建TaskContext,并更新现有预设测试以使用该方法。Tests:
parse_with_default辅助方法,覆盖默认参数合并、CLI 覆盖优先级以及多任务行为。Original summary in English
Summary by Sourcery
Introduce a TaskContext-based parameter construction flow that centralizes default task config loading and merging, and refactor presets and tests to use the new API.
Enhancements:
Tests:
增强内容:
TaskContext结构体,并更新IntoParameterstrait,使其支持基于上下文的参数构建以及自动默认配置合并。TaskConfig::new_with_tasks并在IntoTaskConfig的实现中使用它,简化TaskConfig的构造流程。StartUp、CloseDown、Copilot、SSSCopilot、Fight、Roguelike、Reclamation),使其适配新的IntoParameters/IntoParameters_no_context模型,并新增可复用的test_context辅助函数。测试:
IntoParametersAPI。Original summary in English
Summary by Sourcery
引入一个基于 TaskContext 的参数构建流程,用于集中处理默认任务配置的加载与合并,并重构预设与测试以使用新的 API。
Enhancements:
IntoParameterstrait,使其接收一个TaskContext,并通过新增的into_parameters_no_context方法提供一个负责默认值合并的into_parameters默认实现。StartUp、CloseDown、Copilot、SSSCopilot、Fight、Roguelike、Reclamation),以符合新的IntoParameters/into_parameters_no_context模型。TaskConfig的构建方式,改为通过new_with_tasks构造函数创建,而不是增量式 push,从而简化任务列表的创建以及与IntoTaskConfig的集成。test_context辅助方法,用于在测试中构建TaskContext,并更新现有预设测试以使用该方法。Tests:
parse_with_default辅助方法,覆盖默认参数合并、CLI 覆盖优先级以及多任务行为。Original summary in English
Summary by Sourcery
Introduce a TaskContext-based parameter construction flow that centralizes default task config loading and merging, and refactor presets and tests to use the new API.
Enhancements:
Tests: