Skip to content

Conversation

@wangl-cc
Copy link
Member

@wangl-cc wangl-cc commented Jan 6, 2026

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:

  • 重构 IntoParameters trait,使其接收一个 TaskContext,并通过新增的 into_parameters_no_context 方法提供一个负责默认值合并的 into_parameters 默认实现。
  • 调整所有预设参数类型(StartUpCloseDownCopilotSSSCopilotFightRoguelikeReclamation),以符合新的 IntoParameters / into_parameters_no_context 模型。
  • 更新 TaskConfig 的构建方式,改为通过 new_with_tasks 构造函数创建,而不是增量式 push,从而简化任务列表的创建以及与 IntoTaskConfig 的集成。
  • 添加一个可复用的 test_context 辅助方法,用于在测试中构建 TaskContext,并更新现有预设测试以使用该方法。

Tests:

  • 扩展 Copilot CLI 测试,使用新的 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:

  • Refactor the IntoParameters trait to take a TaskContext and provide a default-melding into_parameters implementation backed by a new into_parameters_no_context method.
  • Adjust all preset parameter types (StartUp, CloseDown, Copilot, SSSCopilot, Fight, Roguelike, Reclamation) to conform to the new IntoParameters/into_parameters_no_context model.
  • Update TaskConfig to be constructed via a new_with_tasks constructor instead of incremental push, simplifying task list creation and integration with IntoTaskConfig.
  • Add a reusable test_context helper for constructing TaskContext in tests and update existing preset tests to use it.

Tests:

  • Extend Copilot CLI tests to cover default parameter merging, CLI override precedence, and multi-task behavior using a new parse_with_default helper.

增强内容:

  • 引入 TaskContext 结构体,并更新 IntoParameters trait,使其支持基于上下文的参数构建以及自动默认配置合并。
  • 通过新增 TaskConfig::new_with_tasks 并在 IntoTaskConfig 的实现中使用它,简化 TaskConfig 的构造流程。
  • 调整预设参数的实现(StartUpCloseDownCopilotSSSCopilotFightRoguelikeReclamation),使其适配新的 IntoParameters / IntoParameters_no_context 模型,并新增可复用的 test_context 辅助函数。

测试:

  • 扩展 Copilot CLI 测试,覆盖默认参数合并、CLI 覆盖优先级以及多任务行为,并将现有预设测试更新为使用新的 IntoParameters API。
Original summary in English

Summary by Sourcery

引入一个基于 TaskContext 的参数构建流程,用于集中处理默认任务配置的加载与合并,并重构预设与测试以使用新的 API。

Enhancements:

  • 重构 IntoParameters trait,使其接收一个 TaskContext,并通过新增的 into_parameters_no_context 方法提供一个负责默认值合并的 into_parameters 默认实现。
  • 调整所有预设参数类型(StartUpCloseDownCopilotSSSCopilotFightRoguelikeReclamation),以符合新的 IntoParameters / into_parameters_no_context 模型。
  • 更新 TaskConfig 的构建方式,改为通过 new_with_tasks 构造函数创建,而不是增量式 push,从而简化任务列表的创建以及与 IntoTaskConfig 的集成。
  • 添加一个可复用的 test_context 辅助方法,用于在测试中构建 TaskContext,并更新现有预设测试以使用该方法。

Tests:

  • 扩展 Copilot CLI 测试,使用新的 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:

  • Refactor the IntoParameters trait to take a TaskContext and provide a default-melding into_parameters implementation backed by a new into_parameters_no_context method.
  • Adjust all preset parameter types (StartUp, CloseDown, Copilot, SSSCopilot, Fight, Roguelike, Reclamation) to conform to the new IntoParameters/into_parameters_no_context model.
  • Update TaskConfig to be constructed via a new_with_tasks constructor instead of incremental push, simplifying task list creation and integration with IntoTaskConfig.
  • Add a reusable test_context helper for constructing TaskContext in tests and update existing preset tests to use it.

Tests:

  • Extend Copilot CLI tests to cover default parameter merging, CLI override precedence, and multi-task behavior using a new parse_with_default helper.

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.
Copy link

@sourcery-ai sourcery-ai bot left a 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(&params)`, 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>

Sourcery 对开源项目是免费的——如果你觉得我们的 Review 有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进后续的 Review。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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(&params)`, 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.40%. Comparing base (c87d15e) to head (8a9f169).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
crates/maa-cli/src/run/preset/mod.rs 89.47% 0 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wangl-cc
Copy link
Member Author

wangl-cc commented Jan 6, 2026

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我已经审查了你的修改,看起来非常棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的代码审查,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wangl-cc wangl-cc changed the title test: Refactor IntoParameters trait to use TaskContext refactor: make IntoParameters trait more test friendly Jan 6, 2026
@wangl-cc
Copy link
Member Author

wangl-cc commented Jan 6, 2026

@sourcery-ai title

@sourcery-ai sourcery-ai bot changed the title refactor: make IntoParameters trait more test friendly Introduce TaskContext for parameter defaults and extend copilot tests Jan 6, 2026
@wangl-cc wangl-cc changed the title Introduce TaskContext for parameter defaults and extend copilot tests refactor: make IntoParameters trait more test friendly Jan 6, 2026
@wangl-cc wangl-cc merged commit a494efb into main Jan 6, 2026
20 checks passed
@wangl-cc wangl-cc deleted the test/task-context branch January 6, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants