mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
refactor(sourcegenerators-tests): 收敛 Cqrs 隐藏泛型定义测试长方法
- 重构 HiddenGenericEnvelopeResponse 场景的共享 source fixture,清理当前 MA0051 位点 - 更新 analyzer-warning-reduction 的 tracking 与 trace,记录第五个有效 subagent 写集和基线降至 10 条
This commit is contained in:
parent
b1c8dccf9a
commit
1a9e8f64bd
@ -314,6 +314,67 @@ public class CqrsHandlerRegistryGeneratorTests
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
private const string HiddenGenericEnvelopeResponseSource = """
|
||||||
|
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<TResponse> { }
|
||||||
|
public interface INotification { }
|
||||||
|
public interface IStreamRequest<TResponse> { }
|
||||||
|
|
||||||
|
public interface IRequestHandler<in TRequest, TResponse> where TRequest : IRequest<TResponse> { }
|
||||||
|
public interface INotificationHandler<in TNotification> where TNotification : INotification { }
|
||||||
|
public interface IStreamRequestHandler<in TRequest, out TResponse> where TRequest : IStreamRequest<TResponse> { }
|
||||||
|
}
|
||||||
|
|
||||||
|
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 class Container
|
||||||
|
{
|
||||||
|
private sealed class HiddenEnvelope<T> { }
|
||||||
|
|
||||||
|
private sealed record HiddenRequest() : IRequest<HiddenEnvelope<string>>;
|
||||||
|
|
||||||
|
private sealed class HiddenHandler : IRequestHandler<HiddenRequest, HiddenEnvelope<string>> { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
private const string HiddenGenericEnvelopeResponseExpected = """
|
private const string HiddenGenericEnvelopeResponseExpected = """
|
||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
#nullable enable
|
#nullable enable
|
||||||
@ -679,69 +740,8 @@ public class CqrsHandlerRegistryGeneratorTests
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task Generates_Precise_Service_Type_For_Hidden_Generic_Type_Definitions()
|
public async Task Generates_Precise_Service_Type_For_Hidden_Generic_Type_Definitions()
|
||||||
{
|
{
|
||||||
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<TResponse> { }
|
|
||||||
public interface INotification { }
|
|
||||||
public interface IStreamRequest<TResponse> { }
|
|
||||||
|
|
||||||
public interface IRequestHandler<in TRequest, TResponse> where TRequest : IRequest<TResponse> { }
|
|
||||||
public interface INotificationHandler<in TNotification> where TNotification : INotification { }
|
|
||||||
public interface IStreamRequestHandler<in TRequest, out TResponse> where TRequest : IStreamRequest<TResponse> { }
|
|
||||||
}
|
|
||||||
|
|
||||||
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 class Container
|
|
||||||
{
|
|
||||||
private sealed class HiddenEnvelope<T> { }
|
|
||||||
|
|
||||||
private sealed record HiddenRequest() : IRequest<HiddenEnvelope<string>>;
|
|
||||||
|
|
||||||
private sealed class HiddenHandler : IRequestHandler<HiddenRequest, HiddenEnvelope<string>> { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""";
|
|
||||||
|
|
||||||
await GeneratorTest<CqrsHandlerRegistryGenerator>.RunAsync(
|
await GeneratorTest<CqrsHandlerRegistryGenerator>.RunAsync(
|
||||||
source,
|
HiddenGenericEnvelopeResponseSource,
|
||||||
("CqrsHandlerRegistry.g.cs", HiddenGenericEnvelopeResponseExpected));
|
("CqrsHandlerRegistry.g.cs", HiddenGenericEnvelopeResponseExpected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,9 +7,16 @@
|
|||||||
|
|
||||||
## 当前恢复点
|
## 当前恢复点
|
||||||
|
|
||||||
- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-040`
|
- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-041`
|
||||||
- 当前阶段:`Phase 40`
|
- 当前阶段:`Phase 41`
|
||||||
- 当前焦点:
|
- 当前焦点:
|
||||||
|
- 已通过第五个有效 subagent 切片完成
|
||||||
|
`CqrsHandlerRegistryGeneratorTests.cs`
|
||||||
|
`Generates_Precise_Service_Type_For_Hidden_Generic_Type_Definitions()` 的 `MA0051` 收口:
|
||||||
|
将内联 `source` 文本提取为类级常量,保持既有 expected 常量和断言语义不变
|
||||||
|
- 当前 `GFramework.SourceGenerators.Tests` Release warnings-only 基线已从 `11` 条降到 `10` 条;
|
||||||
|
行号 `680` 已从 `MA0051` 输出中消失,剩余热点继续集中在
|
||||||
|
`CqrsHandlerRegistryGeneratorTests.cs`
|
||||||
- 已通过第四个有效 subagent 切片完成
|
- 已通过第四个有效 subagent 切片完成
|
||||||
`CqrsHandlerRegistryGeneratorTests.cs`
|
`CqrsHandlerRegistryGeneratorTests.cs`
|
||||||
`Generates_Precise_Service_Type_For_Hidden_Array_Type_Arguments()` 的 `MA0051` 收口:
|
`Generates_Precise_Service_Type_For_Hidden_Array_Type_Arguments()` 的 `MA0051` 收口:
|
||||||
@ -185,6 +192,8 @@
|
|||||||
已提取到类级常量,当前测试项目基线进一步降到 `12` 条
|
已提取到类级常量,当前测试项目基线进一步降到 `12` 条
|
||||||
- 已完成 `RP-040` 的第四个 subagent 接收:`HiddenArrayResponseFallbackSource`
|
- 已完成 `RP-040` 的第四个 subagent 接收:`HiddenArrayResponseFallbackSource`
|
||||||
已提取到类级常量,当前测试项目基线进一步降到 `11` 条
|
已提取到类级常量,当前测试项目基线进一步降到 `11` 条
|
||||||
|
- 已完成 `RP-041` 的第五个 subagent 接收:`HiddenGenericEnvelopeResponseSource`
|
||||||
|
已提取到类级常量,当前测试项目基线进一步降到 `10` 条
|
||||||
|
|
||||||
## 当前活跃事实
|
## 当前活跃事实
|
||||||
|
|
||||||
@ -242,6 +251,8 @@
|
|||||||
- `RP-039` 进一步确认:只要 subagent 继续在同一热点文件内逐点消除 warning,唯一变更文件数会基本停留在 `4`
|
- `RP-039` 进一步确认:只要 subagent 继续在同一热点文件内逐点消除 warning,唯一变更文件数会基本停留在 `4`
|
||||||
左右,不会因为重复修改同一文件快速逼近 `75`
|
左右,不会因为重复修改同一文件快速逼近 `75`
|
||||||
- `RP-040` 延续了这一趋势:当前吞吐稳定,但按“唯一变更文件数接近 `75`”作为停止条件并不匹配当前单文件收口节奏
|
- `RP-040` 延续了这一趋势:当前吞吐稳定,但按“唯一变更文件数接近 `75`”作为停止条件并不匹配当前单文件收口节奏
|
||||||
|
- `RP-041` 再次确认当前分支相对 `origin/main` 的唯一变更文件数仍是 `4`;若继续只收口同一文件的 warning,
|
||||||
|
该计数基本不会上涨
|
||||||
- `RP-021` 使用 `$gframework-pr-review` 复核当前分支 PR #269 后,修复仍在本地成立的 4 个项:将
|
- `RP-021` 使用 `$gframework-pr-review` 复核当前分支 PR #269 后,修复仍在本地成立的 4 个项:将
|
||||||
`CqrsHandlerRegistryGenerator` 拆分为职责清晰的 partial 文件、为 `ContextAwareGenerator` 生成字段增加稳定前缀并补上
|
`CqrsHandlerRegistryGenerator` 拆分为职责清晰的 partial 文件、为 `ContextAwareGenerator` 生成字段增加稳定前缀并补上
|
||||||
`SetContextProvider` 的运行时 null 校验、为 `Option<T>` 补齐 `<remarks>`,并新增字段重名场景的生成器快照测试
|
`SetContextProvider` 的运行时 null 校验、为 `Option<T>` 补齐 `<remarks>`,并新增字段重名场景的生成器快照测试
|
||||||
@ -489,13 +500,17 @@
|
|||||||
- `RP-040` 的验证结果:
|
- `RP-040` 的验证结果:
|
||||||
- `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"`
|
- `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"`
|
||||||
- 结果:`11 Warning(s)`,`0 Error(s)`;`CqrsHandlerRegistryGeneratorTests.cs` 的行号 `607` 已不再出现在 `MA0051` 列表中
|
- 结果:`11 Warning(s)`,`0 Error(s)`;`CqrsHandlerRegistryGeneratorTests.cs` 的行号 `607` 已不再出现在 `MA0051` 列表中
|
||||||
|
- `RP-041` 的验证结果:
|
||||||
|
- `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"`
|
||||||
|
- 结果:`10 Warning(s)`,`0 Error(s)`;`CqrsHandlerRegistryGeneratorTests.cs` 的行号 `680` 已不再出现在 `MA0051` 列表中
|
||||||
- active 跟踪文件只保留当前恢复点、活跃事实、风险与下一步,不再重复保存已完成阶段的长篇历史
|
- active 跟踪文件只保留当前恢复点、活跃事实、风险与下一步,不再重复保存已完成阶段的长篇历史
|
||||||
|
|
||||||
## 下一步
|
## 下一步
|
||||||
|
|
||||||
1. 若要继续该主题,先读 active tracking,再按需展开历史归档中的 warning 热点与验证记录
|
1. 若要继续该主题,先读 active tracking,再按需展开历史归档中的 warning 热点与验证记录
|
||||||
2. 下一轮优先继续 `GFramework.SourceGenerators.Tests` 的 `MA0051` 收口,并直接进入唯一剩余热点
|
2. 下一轮优先继续 `GFramework.SourceGenerators.Tests` 的 `MA0051` 收口,并直接进入唯一剩余热点
|
||||||
`CqrsHandlerRegistryGeneratorTests.cs`;优先把行号 `680` 对应的前半段长方法继续拆小
|
`CqrsHandlerRegistryGeneratorTests.cs`;但若用户真正关心“唯一变更文件数接近 `75`”,下一轮应改为选择新的文件写集,
|
||||||
|
而不是继续停留在当前同一文件
|
||||||
3. 若改回推进 `MA0158`,先设计 `net8.0` / `net9.0` / `net10.0` 多 target 条件编译方案,不直接批量替换共享源码中的
|
3. 若改回推进 `MA0158`,先设计 `net8.0` / `net9.0` / `net10.0` 多 target 条件编译方案,不直接批量替换共享源码中的
|
||||||
`object` lock
|
`object` lock
|
||||||
4. 若后续继续改动 `GFramework.Godot`,先修复该项目的 Linux 侧 restore 资产,再补跑独立 build
|
4. 若后续继续改动 `GFramework.Godot`,先修复该项目的 Linux 侧 restore 资产,再补跑独立 build
|
||||||
|
|||||||
@ -1,5 +1,28 @@
|
|||||||
# Analyzer Warning Reduction 追踪
|
# Analyzer Warning Reduction 追踪
|
||||||
|
|
||||||
|
## 2026-04-23 — RP-041
|
||||||
|
|
||||||
|
### 阶段:subagent 循环第五个有效写集(RP-041)
|
||||||
|
|
||||||
|
- 启动复核:
|
||||||
|
- 在 `RP-040` 成功后,继续按单方法级 subagent 推进同一热点文件
|
||||||
|
- 本轮目标收敛到 `Generates_Precise_Service_Type_For_Hidden_Generic_Type_Definitions()`
|
||||||
|
- 决策:
|
||||||
|
- 仅提取该方法的内联 `source` 文本,继续复用现有
|
||||||
|
`HiddenGenericEnvelopeResponseExpected`
|
||||||
|
- 不改变 method name、expected 常量、生成文件名与断言语义
|
||||||
|
- 实施调整:
|
||||||
|
- 新增类级常量 `HiddenGenericEnvelopeResponseSource`
|
||||||
|
- 将目标测试方法改为复用该常量调用 `GeneratorTest<CqrsHandlerRegistryGenerator>.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"`
|
||||||
|
- 结果:`10 Warning(s)`,`0 Error(s)`;原先位于行号 `680` 的 `MA0051` 已消失
|
||||||
|
- 当前结论:
|
||||||
|
- subagent 循环已连续五轮产出 patch,但当前分支相对 `origin/main` 的唯一变更文件数依旧只有 `4`
|
||||||
|
- 若用户坚持把“接近 `75` 个唯一变更文件”作为停止条件,后续策略必须从“继续收口同一文件”切换到“优先进入新文件写集”
|
||||||
|
- 下一步建议:
|
||||||
|
- 主线程需要决定:继续按 warning 热点清理同一文件,还是切到新的文件写集以增加唯一变更文件数
|
||||||
|
|
||||||
## 2026-04-23 — RP-040
|
## 2026-04-23 — RP-040
|
||||||
|
|
||||||
### 阶段:subagent 循环第四个有效写集(RP-040)
|
### 阶段:subagent 循环第四个有效写集(RP-040)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user