From 2da38a85a50277ec7d29e40dc333a167e1783c94 Mon Sep 17 00:00:00 2001 From: gewuyou <95328647+GeWuYou@users.noreply.github.com> Date: Thu, 23 Apr 2026 20:21:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(sourcegenerators-tests):=20=E6=94=B6?= =?UTF-8?q?=E6=95=9B=20Cqrs=20=E7=9B=B4=E6=8E=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=B5=8B=E8=AF=95=E9=95=BF=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 HiddenImplementationDirectInterfaceRegistration 场景的共享 source fixture,清理当前 MA0051 位点 - 更新 analyzer-warning-reduction 的 tracking 与 trace,记录第三个有效 subagent 写集和基线降至 12 条 --- .../Cqrs/CqrsHandlerRegistryGeneratorTests.cs | 120 +++++++++--------- .../analyzer-warning-reduction-tracking.md | 20 ++- .../analyzer-warning-reduction-trace.md | 23 ++++ 3 files changed, 100 insertions(+), 63 deletions(-) diff --git a/GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs b/GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs index 0f178b15..abf286df 100644 --- a/GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs +++ b/GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs @@ -122,6 +122,65 @@ public class CqrsHandlerRegistryGeneratorTests """; + private const string HiddenImplementationDirectInterfaceRegistrationSource = """ + using System; + + namespace Microsoft.Extensions.DependencyInjection + { + public interface IServiceCollection { } + + public static class ServiceCollectionServiceExtensions + { + public static void AddTransient(IServiceCollection services, Type serviceType, Type implementationType) { } + } + } + + namespace GFramework.Core.Abstractions.Logging + { + public interface ILogger + { + void Debug(string msg); + } + } + + namespace GFramework.Cqrs.Abstractions.Cqrs + { + public interface IRequest { } + public interface INotification { } + public interface IStreamRequest { } + + public interface IRequestHandler where TRequest : IRequest { } + public interface INotificationHandler where TNotification : INotification { } + public interface IStreamRequestHandler where TRequest : IStreamRequest { } + } + + namespace GFramework.Cqrs + { + public interface ICqrsHandlerRegistry + { + void Register(Microsoft.Extensions.DependencyInjection.IServiceCollection services, GFramework.Core.Abstractions.Logging.ILogger logger); + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class CqrsHandlerRegistryAttribute : Attribute + { + public CqrsHandlerRegistryAttribute(Type registryType) { } + } + } + + namespace TestApp + { + using GFramework.Cqrs.Abstractions.Cqrs; + + public sealed record VisibleRequest() : IRequest; + + public sealed class Container + { + private sealed class HiddenHandler : IRequestHandler { } + } + } + """; + private const string HiddenImplementationDirectInterfaceRegistrationExpected = """ // #nullable enable @@ -535,67 +594,8 @@ public class CqrsHandlerRegistryGeneratorTests public async Task Generates_Direct_Interface_Registrations_For_Hidden_Implementation_When_Handler_Interface_Is_Public() { - const string source = """ - using System; - - namespace Microsoft.Extensions.DependencyInjection - { - public interface IServiceCollection { } - - public static class ServiceCollectionServiceExtensions - { - public static void AddTransient(IServiceCollection services, Type serviceType, Type implementationType) { } - } - } - - namespace GFramework.Core.Abstractions.Logging - { - public interface ILogger - { - void Debug(string msg); - } - } - - namespace GFramework.Cqrs.Abstractions.Cqrs - { - public interface IRequest { } - public interface INotification { } - public interface IStreamRequest { } - - public interface IRequestHandler where TRequest : IRequest { } - public interface INotificationHandler where TNotification : INotification { } - public interface IStreamRequestHandler where TRequest : IStreamRequest { } - } - - namespace GFramework.Cqrs - { - public interface ICqrsHandlerRegistry - { - void Register(Microsoft.Extensions.DependencyInjection.IServiceCollection services, GFramework.Core.Abstractions.Logging.ILogger logger); - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class CqrsHandlerRegistryAttribute : Attribute - { - public CqrsHandlerRegistryAttribute(Type registryType) { } - } - } - - namespace TestApp - { - using GFramework.Cqrs.Abstractions.Cqrs; - - public sealed record VisibleRequest() : IRequest; - - public sealed class Container - { - private sealed class HiddenHandler : IRequestHandler { } - } - } - """; - await GeneratorTest.RunAsync( - source, + HiddenImplementationDirectInterfaceRegistrationSource, ("CqrsHandlerRegistry.g.cs", HiddenImplementationDirectInterfaceRegistrationExpected)); } diff --git a/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md b/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md index c5f2c91a..c88ae546 100644 --- a/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md +++ b/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md @@ -7,9 +7,16 @@ ## 当前恢复点 -- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-038` -- 当前阶段:`Phase 38` +- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-039` +- 当前阶段:`Phase 39` - 当前焦点: + - 已通过第三个有效 subagent 切片完成 + `CqrsHandlerRegistryGeneratorTests.cs` + `Generates_Direct_Interface_Registrations_For_Hidden_Implementation_When_Handler_Interface_Is_Public()` + 的 `MA0051` 收口:将内联 `source` 文本提取为类级常量,保持既有 expected 常量和断言语义不变 + - 当前 `GFramework.SourceGenerators.Tests` Release warnings-only 基线已从 `13` 条降到 `12` 条; + 行号 `536` 已从 `MA0051` 输出中消失,剩余热点继续集中在 + `CqrsHandlerRegistryGeneratorTests.cs` - 已通过第二个有效 subagent 切片完成 `CqrsHandlerRegistryGeneratorTests.cs` `Generates_Visible_Handlers_And_Self_Registers_Private_Nested_Handler_When_Assembly_Contains_Hidden_Handler()` @@ -167,6 +174,8 @@ `Generates_Assembly_Level_Cqrs_Handler_Registry()` 已抽出类级 fixture,当前测试项目基线进一步降到 `14` 条 - 已完成 `RP-038` 的第二个 subagent 接收:`HiddenNestedHandlerSelfRegistrationSource` 已提取到类级常量, 当前测试项目基线进一步降到 `13` 条 +- 已完成 `RP-039` 的第三个 subagent 接收:`HiddenImplementationDirectInterfaceRegistrationSource` + 已提取到类级常量,当前测试项目基线进一步降到 `12` 条 ## 当前活跃事实 @@ -221,6 +230,8 @@ 若继续按“唯一变更文件数接近 `75`”推进,需要接受很多轮单文件、单方法级切片 - `RP-038` 继续验证了“单方法 + 主线程记录恢复点”的 subagent 节奏可稳定复用,但按当前速度离 “接近 `75` 个唯一变更文件”仍然非常远 +- `RP-039` 进一步确认:只要 subagent 继续在同一热点文件内逐点消除 warning,唯一变更文件数会基本停留在 `4` + 左右,不会因为重复修改同一文件快速逼近 `75` - `RP-021` 使用 `$gframework-pr-review` 复核当前分支 PR #269 后,修复仍在本地成立的 4 个项:将 `CqrsHandlerRegistryGenerator` 拆分为职责清晰的 partial 文件、为 `ContextAwareGenerator` 生成字段增加稳定前缀并补上 `SetContextProvider` 的运行时 null 校验、为 `Option` 补齐 ``,并新增字段重名场景的生成器快照测试 @@ -462,13 +473,16 @@ - `RP-038` 的验证结果: - `dotnet build GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj -c Release -t:Rebuild --no-restore --disable-build-servers -m:1 -p:UseSharedCompilation=false -p:RestoreFallbackFolders="" -nologo -clp:"Summary;WarningsOnly"` - 结果:`13 Warning(s)`,`0 Error(s)`;`CqrsHandlerRegistryGeneratorTests.cs` 的行号 `454` 已不再出现在 `MA0051` 列表中 +- `RP-039` 的验证结果: + - `dotnet build GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj -c Release -t:Rebuild --no-restore --disable-build-servers -m:1 -p:UseSharedCompilation=false -p:RestoreFallbackFolders="" -nologo -clp:"Summary;WarningsOnly"` + - 结果:`12 Warning(s)`,`0 Error(s)`;`CqrsHandlerRegistryGeneratorTests.cs` 的行号 `536` 已不再出现在 `MA0051` 列表中 - active 跟踪文件只保留当前恢复点、活跃事实、风险与下一步,不再重复保存已完成阶段的长篇历史 ## 下一步 1. 若要继续该主题,先读 active tracking,再按需展开历史归档中的 warning 热点与验证记录 2. 下一轮优先继续 `GFramework.SourceGenerators.Tests` 的 `MA0051` 收口,并直接进入唯一剩余热点 - `CqrsHandlerRegistryGeneratorTests.cs`;优先把行号 `536`、`607`、`680` 对应的前半段长方法继续拆小 + `CqrsHandlerRegistryGeneratorTests.cs`;优先把行号 `607`、`680` 对应的前半段长方法继续拆小 3. 若改回推进 `MA0158`,先设计 `net8.0` / `net9.0` / `net10.0` 多 target 条件编译方案,不直接批量替换共享源码中的 `object` lock 4. 若后续继续改动 `GFramework.Godot`,先修复该项目的 Linux 侧 restore 资产,再补跑独立 build diff --git a/ai-plan/public/analyzer-warning-reduction/traces/analyzer-warning-reduction-trace.md b/ai-plan/public/analyzer-warning-reduction/traces/analyzer-warning-reduction-trace.md index 12265bfb..7289a47e 100644 --- a/ai-plan/public/analyzer-warning-reduction/traces/analyzer-warning-reduction-trace.md +++ b/ai-plan/public/analyzer-warning-reduction/traces/analyzer-warning-reduction-trace.md @@ -1,5 +1,28 @@ # Analyzer Warning Reduction 追踪 +## 2026-04-23 — RP-039 + +### 阶段:subagent 循环第三个有效写集(RP-039) + +- 启动复核: + - 在 `RP-038` 成功后,继续按单方法级 subagent 推进同一热点文件 + - 本轮目标收敛到 `Generates_Direct_Interface_Registrations_For_Hidden_Implementation_When_Handler_Interface_Is_Public()` +- 决策: + - 仅提取该方法的内联 `source` 文本,继续复用现有 + `HiddenImplementationDirectInterfaceRegistrationExpected` + - 不改变 method name、expected 常量、生成文件名与断言语义 +- 实施调整: + - 新增类级常量 `HiddenImplementationDirectInterfaceRegistrationSource` + - 将目标测试方法改为复用该常量调用 `GeneratorTest.RunAsync(...)` +- 验证结果: + - `dotnet build GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj -c Release -t:Rebuild --no-restore --disable-build-servers -m:1 -p:UseSharedCompilation=false -p:RestoreFallbackFolders="" -nologo -clp:"Summary;WarningsOnly"` + - 结果:`12 Warning(s)`,`0 Error(s)`;原先位于行号 `536` 的 `MA0051` 已消失 +- 当前结论: + - subagent 循环在当前热点文件内已经连续三轮产出 patch,但唯一变更文件数仍停留在 `4` + - 若用户坚持以“接近 `75` 个唯一变更文件”为停止条件,后续需要尽快从单文件热点转向新的文件写集 +- 下一步建议: + - 继续处理 `CqrsHandlerRegistryGeneratorTests.cs` 的下一处前半段热点:行号 `607` + ## 2026-04-23 — RP-038 ### 阶段:subagent 循环第二个有效写集(RP-038)