Skip to content

fix: 消除 Sonar CRITICAL 问题(合服 CLI S3776 / 四子棋 Bot S4487) - #989

Merged
AlianBlank merged 2 commits into
mainfrom
feature/GFX-1226
Nov 3, 2026
Merged

AlianBlank merged 2 commits into
mainfrom
feature/GFX-1226

Conversation

@AlianBlank

@AlianBlank AlianBlank commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes GFX-1226
Fixes GFX-1220
Closes #986
Closes #979

本 PR 合并两项 Sonar CRITICAL 修复:

  • GFX-1226:复用现有提交拆分合服 CLI 参数解析,降低 ParseArgumentsAsync 的认知复杂度。
  • GFX-1220:删除四子棋 Bot 中只写不读的房间与对局字段及其赋值,清理相关空锁块和冗余跳转。

验证结果:dotnet build Server.slnx --nologo 通过,0 errors(28 warnings);指定合服相关测试 34/34 通过;git diff --check 通过。

Summary by CodeRabbit

  • 错误修复
    • 在线服务器合并命令遇到未知参数、无效目标值或无效源服务器 ID 时,会报告错误并立即终止,返回退出码 2。
    • 修正无效源服务器列表的处理:解析失败时不再继续处理后续参数。

提取单参数与源服列表解析私有方法,保持公共接口和解析行为不变。
通过解决方案构建、34 项定向测试及 705 组参数差分验证。
本地 Sonar 分析器复现原始复杂度 23,重构后不再触发 S3776。

Linear: GFX-1226
删除 _connectFourRoomInfo / _connectFourGameInfo 及其赋值,消除 Sonar S4487;连带移除仅剩该赋值的 lock 块与随之冗余的 return,流程行为不变。

Linear: GFX-1220
@linear-code

linear-code Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

GFX-1220

GFX-1226

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

合服 CLI 将参数解析拆分为多个私有方法。四子棋机器人移除了未读取的房间与对局信息缓存字段及相关赋值,保留现有流程操作。

Changes: 合服 CLI 参数解析

Layer / File(s) Summary
拆分参数解析
Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs
参数循环改为调用独立解析方法。该方法处理执行标志、目标值和源服列表;源服 ID 解析另由方法处理。解析失败时返回 null,由 RunAsync 返回退出码 2。

四子棋机器人状态清理

Layer / File(s) Summary
移除未读取的缓存状态
GameFrameX.Client/Bot/BotClient.ConnectFour.cs
移除缓存房间信息和对局信息的私有字段及赋值。房间阶段切换、日志、请求和无进展计数逻辑仍保留。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to c2a8f

No merge-blocking behavior change is identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: 消除 Sonar CRITICAL 问题(合服 CLI S3776 / 四子棋 Bot S4487)”与变更集相关。PR 包含两项修复:重构 OnlineServerMergeCli.cs 的参数解析以降低认知复杂度(S3776),以及删除 BotClient.ConnectFour.cs 中只写不读的 _connectFourRoomInfo 和 _connectFourGame…
Linked Issues check Passed 已核对 whole-PR diff(mergeBase d407707 至 currentHead c2a8f3b)。

[#986] 要求降低 OnlineServerMergeCli.cs 中 ParseArgumentsAsync 的认知复杂度(23 降至 15 以内)。
- 变更将参数解析拆分为 ParseArgumentAsync(单参数)和 ParseSourceServerIdsAs…
Out of Scope Changes check Passed 变更仅涉及两个文件:OnlineServerMergeCli.cs 和 BotClient.ConnectFour.cs。
- OnlineServerMergeCli.cs:仅重构参数解析为私有辅助方法,行为等价,直接服务于 #986。
- BotClient.ConnectFour.cs:仅删除两个未读字段、其赋值、仅服务于赋值的空锁块及冗余 return,直接服务于 #979。
未发现与两个…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

标题“fix: 消除 Sonar CRITICAL 问题(合服 CLI S3776 / 四子棋 Bot S4487)”与变更集相关。PR 包含两项修复:重构 OnlineServerMergeCli.cs 的参数解析以降低认知复杂度(S3776),以及删除 BotClient.ConnectFour.cs 中只写不读的 _connectFourRoomInfo 和 _connectFourGameInfo 字段(S4487)。标题点明了两项主要改动和对应的 Sonar 规则编号。标题未逐一说明具体做法,但这属于可接受的范围。

Full details: Linked Issues check

Explanation

已核对 whole-PR diff(mergeBase d407707 至 currentHead c2a8f3b)。

[#986] 要求降低 OnlineServerMergeCli.cs 中 ParseArgumentsAsync 的认知复杂度(23 降至 15 以内)。

  • 变更将参数解析拆分为 ParseArgumentAsync(单参数)和 ParseSourceServerIdsAsync(源服列表)。
  • ParseArgumentsAsync 循环仅调用 ParseArgumentAsync,失败时返回 null。
  • 错误文本、退出路径(返回 null,RunAsync 返回码 2)和 --execute 行为保持不变。
  • 公共 API 无变更(diff 中无公共声明修改)。
  • 按分支数估算,新方法的认知复杂度明显低于 15。

[#979] 要求移除 BotClient.ConnectFour.cs 中未读取的 _connectFourRoomInfo 和 _connectFourGameInfo 字段(S4487)。

  • 两个字段声明及其全部赋值已删除。
  • 删除的空 lock 块和冗余 return 仅服务于这些赋值,删除后房间状态切换、日志、请求发送和无进展计数逻辑保持不变。
  • 公共 API 无变更。

非编码验收项(重跑质量工作流、确认 Sonar 不再报告)属于验证流程,不计入编码要求。作者报告 dotnet build 通过(0 errors)。本次未独立执行构建或 Sonar 扫描。

Full details: Out of Scope Changes check

Explanation

变更仅涉及两个文件:OnlineServerMergeCli.cs 和 BotClient.ConnectFour.cs。

  • OnlineServerMergeCli.cs:仅重构参数解析为私有辅助方法,行为等价,直接服务于 #986。
  • BotClient.ConnectFour.cs:仅删除两个未读字段、其赋值、仅服务于赋值的空锁块及冗余 return,直接服务于 #979。
    未发现与两个关联 issue 无关的修改。PR 描述中提到的 705 组差分验证无法在此次检查中独立核实,但它不影响范围判断。
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 1 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b0b5eb24-3c47-405e-8959-8bd5ac9ac05f
Commits

Reviewing files that changed from the base of the PR and between 92eb84c and c2a8f3b.

Files selected for processing: 2
  • Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs
  • GameFrameX.Client/Bot/BotClient.ConnectFour.cs
Files with no reviewable changes: 1
  • GameFrameX.Client/Bot/BotClient.ConnectFour.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@AlianBlank
AlianBlank merged commit ddb7440 into main Nov 3, 2026
4 checks passed
@AlianBlank
AlianBlank deleted the feature/GFX-1226 branch November 3, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant