Skip to content

Refactor/重构CQRS处理程序注册生成器以支持反射回退属性#244

Merged
GeWuYou merged 8 commits intomainfrom
refactor/cqrs-and-config-system
Apr 17, 2026
Merged

Refactor/重构CQRS处理程序注册生成器以支持反射回退属性#244
GeWuYou merged 8 commits intomainfrom
refactor/cqrs-and-config-system

Conversation

@GeWuYou
Copy link
Copy Markdown
Owner

@GeWuYou GeWuYou commented Apr 17, 2026

Summary by CodeRabbit

  • 新功能

    • CQRS 注册器支持基于运行时回退元数据的反射回退,并在回退需要但运行时合同缺失时报告错误(新增诊断 GF_Cqrs_001)。
  • 改进

    • 精简并重构生成器输出,移除旧的运行时发现帮助器并改进注册发射流程。
    • 增强生成代码的 XML 文档注释;改进上下文访问的线程同步与惰性初始化。
    • 统一并加固快照路径解析与验证以防止路径逃逸。
  • 测试

    • 新增/更新大量生成器快照与安全单元测试,改进生成器测试执行及诊断捕获。
  • 杂项

    • 更新脚本以跳过测试快照目录的命名校验;添加分析器发布说明文件。

GeWuYou added 2 commits April 17, 2026 07:40
- 在 EnumExtensionsGeneratorSnapshotTests.cs 中补充 snapshotFileNameSelector 的 null 分支覆盖,新增默认快照文件名选择器用例及对应快照资产

- 强化 GeneratorSnapshotTest.cs 的快照路径校验,拒绝空白文件名、绝对路径和目录遍历攻击;将辅助器改为通过 Roslyn GeneratorDriver 读取真实生成结果并验证编译,消除仅依赖 TestState.GeneratedSources 导致的空跑风险

- 新增 GeneratorSnapshotTestSecurityTests.cs 安全回归测试,覆盖绝对路径拒绝和目录逃逸防护两个分支

- 将 Priority、Logger、ContextAware 三组生成器测试统一指向仓库内快照目录,并补齐缺失的快照资产以支持现在强制执行的生成验证
- 实现了 CqrsHandlerRegistryGenerator 源代码生成器
- 减少运行时程序集反射扫描成本提高性能
- 支持 IRequestHandler、INotificationHandler 和 IStreamRequestHandler 接口
- 生成静态注册代码避免运行时动态发现处理器
- 实现精确的运行时类型引用解析机制
- 支持跨程序集类型的反射查找功能
- 添加了日志记录和错误处理机制
- 实现了类型安全的依赖注入注册过程
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 387d2aa3-37fe-435b-a75a-330c2dfcc53f

📥 Commits

Reviewing files that changed from the base of the PR and between 57a006c and b7a4764.

📒 Files selected for processing (5)
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Core/Rule/ContextAwareBase.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
✅ Files skipped from review due to trivial changes (2)
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.Core/Rule/ContextAwareBase.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.cs: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable
XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and edge cases, and registration order or lifecycle sequencing
Avoid obvious comments such as // increment i
Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives
Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what
Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Missing required documentation is a coding standards violation. Code that does not meet the documentation rules is considered incomplete
Do not rely on implicit imports. Declare every required using explicitly in C# files
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and con...

Files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🧠 Learnings (16)
📓 Common learnings
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Preserve snapshot-based verification patterns already used in the repository for source generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : Keep source generators deterministic and free of hidden environment or network dependencies

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : When a public API defines multiple contract branches, tests MUST cover the meaningful variants, including null, empty, default, and filtered inputs when those branches change behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T13:25:59.124Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 235
File: GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs:1-3
Timestamp: 2026-04-16T13:25:59.124Z
Learning: In the GeWuYou/GFramework repo, treat `global using NUnit.Framework;` as provided project-wide by `GFramework.SourceGenerators.Tests/GlobalUsings.cs` (via GlobalUsings.cs). Do not require or flag missing per-file `using NUnit.Framework;` directives in test `.cs` files under `GFramework.SourceGenerators.Tests/`, since the project-wide global usings already include NUnit (along with other common namespaces).

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🔇 Additional comments (7)
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs (3)

158-223: Execute 方法的契约级文档与边界守护设计良好。

本次变更为 Execute 方法补充了详尽的 XML 文档,清晰说明了:

  • 生成目标(CqrsHandlerRegistry.g.cs 及程序集级 fallback 元数据)
  • 语义前提(基础合同齐备 + fallback 契约存在时才允许输出)
  • 诊断边界(GF_Cqrs_001 在缺少 fallback 契约时报告并停止生成)

CanEmitGeneratedRegistry 的提取使得边界条件可测试、可复用,符合 SOLID 原则。


595-648: GenerateSource 的程序集级 fallback 元数据发射逻辑正确。

方法文档明确了调用方职责(必须先确保 fallback 契约可用),且 handler 类型名称在 Execute 中已按字母序排序,确保输出确定性。Based on learnings: "Keep source generators deterministic and free of hidden environment or network dependencies" 和 "Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs"。


250-262: 诊断报告实现合理。

Location.None 对于此类无法指向特定源位置的生成器级诊断是可接受的选择。消息中包含了需要 fallback 的 handler 类型名称和缺失的契约名称,为用户提供了足够的定位信息。

GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs (4)

1171-1268: 回归测试覆盖了 fallback 元数据必需但契约缺失的边界场景。

测试通过 unsafe 指针类型构造了一个生成器无法直接引用的 handler 合同,有效触发了 ReflectionFallbackHandlerTypeMetadataName 路径。断言覆盖了:

  • 无生成源输出
  • 无生成代码编译错误
  • 存在 GF_Cqrs_001 诊断且消息内容正确

这符合 "Source generator changes MUST be covered by generator tests" 和 "Keep tests focused on observable behavior, not implementation trivia" 的要求。


1270-1387: 正向测试验证了 fallback 契约可用时的程序集级元数据发射。

测试使用两个 handler(AlphaHandlerBetaHandler)验证了输出中 handler 类型名称按字母序排列。断言覆盖了:

  • 无编译错误
  • 无生成器错误
  • 生成源包含正确的 CqrsReflectionFallbackAttributeCqrsHandlerRegistryAttribute

这补全了之前缺失的正向分支覆盖。Based on learnings: "When a public API defines multiple contract branches, tests MUST cover the meaningful variants"。


1451-1506: 测试基础设施重构得当。

ExecuteGenerator 通过 GeneratedCompilationDiagnostics 将生成代码的编译诊断与输入代码的编译诊断分离(lines 1483-1487),避免了因输入源本身的诊断(如 unsafe 代码警告)干扰对生成结果的断言。

GeneratorExecutionResult record 结构清晰,文档说明了各字段的语义,便于后续测试复用。


1004-1012: 对遗留运行时辅助逻辑的负向断言有助于防止回归。

新增的 Does.Not.Contain 断言确保生成输出中不再包含已移除的 RegisterRemainingReflectedHandlerInterfaces 和相关日志标记,与 generator 实现的变更保持一致。Based on learnings: "When generator behavior changes intentionally, update snapshots together with the implementation"。


📝 Walkthrough

Walkthrough

将 CQRS 处理器注册生成器从运行时接口发现改为编译期收集反射回退元数据;在缺失运行时回退属性契约时报告错误并跳过生成;移除运行时反射发现 helper;同时更新生成器模型、测试、快照与快照路径安全校验(≤50 字)。

Changes

Cohort / File(s) Summary
CQRS Handler Registry Generator
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
添加对 CqrsReflectionFallbackAttribute 的编译期检测与 GenerationEnvironment.SupportsReflectionFallbackAttribute;用每个处理器的可空 ReflectionFallbackHandlerTypeMetadataName 替代旧运行时发现标识;在 Execute 阶段聚合回退元数据、基于可用性决定发出或报告 GF_Cqrs_001 并中止;移除注册剩余反射接口的 runtime helper 与相关注入。
生成器数据模型与相等性
GFramework.Cqrs.SourceGenerators/...
.../HandlerCandidateAnalysis.cs, .../ImplementationRegistrationSpec.cs
移除 RequiresRuntimeInterfaceDiscoveryRuntimeDiscoveredHandlerInterfaceLogNames;引入并在分析→注册规格→收集中传播 ReflectionFallbackHandlerTypeMetadataName,并更新相等性/哈希实现以反映该字段。
生成器发射/辅助代码
GFramework.Cqrs.SourceGenerators/... (AppendReflectionHelpers 等)
删除用于“注册剩余反射接口”的 helper 方法(如 RegisterRemainingReflectedHandlerInterfaces)与已知服务类型跟踪,简化发射路径,仅保留外部程序集精确类型查找相关辅助。
分析器发布说明
GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Shipped.md, ...Unshipped.md
新增/更新发布说明文件;在 Unshipped 中登记新规则 GF_Cqrs_001(Error)。
生成器测试与断言
GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
重构测试执行管线以返回完整执行结果(生成源、生成器诊断、编译诊断);新增断言确保不再包含旧运行时发现标记;新增测试覆盖:缺少运行时回退属性时报错并跳过生成,以及在契约可用时发出程序集级回退属性。
快照路径与测试框架
GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs, GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
将测试执行改为显式 Roslyn 流水线(SyntaxTree→Compilation→CSharpGeneratorDriver);引入 ResolveSnapshotPath 做路径逃逸校验并支持 ISourceGenerator/IIncrementalGenerator;新增安全测试断言对绝对路径或包含 .. 的快照选择器抛出 InvalidOperationException
测试快照路径 helper
GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs, GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs, GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
提取并使用统一 GetSnapshotFolder(string) 帮助方法以规范化/复用快照目录计算,替换多处硬编码路径。
Snapshots(Priority / Logger / Rule / Enum 等)
GFramework.SourceGenerators.Tests/.../snapshots/*
新增或更新大量快照文件以反映生成代码变化:Priority、Logger 字段变体、ContextAware 的锁保护延迟初始化与 Set/ResetProvider 行为、更丰富的枚举扩展 XML 文档等。
生成器注释与行为调整
GFramework.Core.SourceGenerators/...
Bases/PriorityGenerator.cs, Enums/EnumExtensionsGenerator.cs, Logging/LoggerGenerator.cs, Rule/ContextAwareGenerator.cs
增强生成代码中的 XML 注释;ContextAware 生成逻辑由无锁延迟初始化改为锁保护模式,新增 _contextSync 并在 Set/Reset/SetContext 中使用该锁,文档随之更新。
命名校验脚本
scripts/validate-csharp-naming.sh
将测试快照目录 GFramework.SourceGenerators.Tests/*/snapshots 加入排除列表,避免对快照源码执行命名规则校验。
库实现文档微调
GFramework.Core/Rule/ContextAwareBase.cs
更新 XML 文档备注以匹配生成器行为说明(实例缓存、无同步等),并确保文件以换行结尾。

Sequence Diagram(s)

sequenceDiagram
    participant Generator as 源生成器 (CqrsHandlerRegistryGenerator)
    participant Roslyn as Roslyn 编译驱动/语义模型
    participant Analysis as 候选分析 (HandlerCandidateAnalysis)
    participant RuntimeAttr as 运行时回退属性契约 (CqrsReflectionFallbackAttribute)

    Generator->>Roslyn: 读取语法与语义,收集处理器候选
    Roslyn->>Analysis: 对候选执行分析,生成 ImplementationRegistrationSpec(含可选 ReflectionFallbackHandlerTypeMetadataName)
    Analysis-->>Generator: 返回注册规格集合
    Generator->>Generator: 聚合集合化的 ReflectionFallbackHandlerTypeMetadataName
    alt 无回退元数据
        Generator->>Roslyn: 生成精确注册表源码(不含回退属性)
    else 存在回退元数据且 RuntimeAttr 可用
        Generator->>Roslyn: 生成程序集级 [CqrsReflectionFallbackAttribute(...)] 与注册表源码
    else 存在回退元数据但 RuntimeAttr 不可用
        Generator->>Generator: 报告 GF_Cqrs_001 错误诊断并跳过源生成
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地描述了 PR 的主要变化,即重构 CQRS 处理程序注册生成器以支持反射回退属性,是对变更集的准确总结。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/cqrs-and-config-system

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (1)
GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs (1)

38-56: 错误消息语言不一致

第 45 行的编译错误消息使用中文,而第 56 行的断言消息使用英文。建议统一使用同一种语言以保持一致性。

♻️ 建议统一为中文或英文
         Assert.That(
             generated,
             Is.Not.Empty,
-            $"Generator '{typeof(TGenerator).FullName}' did not produce any sources.");
+            $"生成器 '{typeof(TGenerator).FullName}' 未产生任何输出。");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs` around lines
38 - 56, The two assertion messages use different languages—translate and unify
them so both are the same language; specifically update the message built in the
Assert after updatedCompilation.GetDiagnostics() (the interpolation starting
with "编译生成的代码时出现错误") to match the language used in the later Assert for
driver.GetRunResult() (or vice versa), ensuring both Assert.That calls (the one
checking compilationErrors and the one checking generated) use consistent
wording and language.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs`:
- Around line 161-176: The generator currently bails out when any registrations
produce a non-empty ReflectionFallbackHandlerTypeMetadataName but
generationEnvironment.SupportsReflectionFallbackAttribute is false, which
prevents generating code when a reflection fallback is actually required; add a
unit test that constructs registrations with at least one
ReflectionFallbackHandlerTypeMetadataName (use the same setup as where
ReflectionFallbackHandlerTypeMetadataName is set) and asserts that the generator
returns early (no source added) when
generationEnvironment.SupportsReflectionFallbackAttribute is false, and then
either (A) document this defensive behavior in the Execute/GenerateSource
contract (mentioning that GenerateSource/HintName will not be produced if
reflection fallback is required but unsupported) or (B) update the Execute logic
to emit a clear diagnostic/error before returning so callers/tests can detect
the unsupported-required-fallback scenario (referencing
generationEnvironment.SupportsReflectionFallbackAttribute, registrations,
fallbackHandlerTypeMetadataNames, GenerateSource, context.AddSource and
HintName).

In
`@GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs`:
- Around line 6-7: The partial type declaration "partial class
HighPrioritySystem : global::GFramework.Core.Abstractions.Bases.IPrioritized" is
missing XML documentation; add a triple-slash XML comment immediately above that
class declaration including at minimum a <summary> describing the class and its
purpose, and include other tags as applicable (e.g., <remarks> for
implementation details or <inheritdoc/> if inheriting docs from an interface) to
satisfy the rule that internal types must have XML comments; update the
generator/template that emits
PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs so the generated partial
class always includes these documentation comments.

In
`@GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs`:
- Around line 37-42: The public async test method
Snapshot_BasicEnum_IsMethods_DefaultSnapshotFileNameSelector is missing an XML
<returns> tag; update its XML documentation to include a <returns> element that
states the method returns a Task representing the asynchronous test operation
(e.g., "A Task that represents the asynchronous test."). Ensure the <returns>
tag is added alongside the existing <summary> so the public method's
documentation meets the project's XML doc requirements.

In
`@GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs`:
- Around line 5-15: Add missing XML documentation for the generated public API:
add a <summary> for the generated partial class StatusExtensions and add <param
name="value"> and <returns> tags for each generated method (IsActive,
IsInactive, IsIn) so all public symbols (StatusExtensions, IsActive, IsInactive,
IsIn) comply with the project's XML-doc rule; update the source generator
template that emits these members to produce the class-level <summary> and for
IsIn include a <param name="values"> description and <returns> for all methods,
then regenerate and commit the updated snapshot file to reflect the new
documentation.

In
`@GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs`:
- Line 7: 生成的部分类型声明 partial class MyService 缺少类型级别的 XML 文档注释;在代码生成器模板(负责产生
MyService.Logger.g.cs 的生成逻辑)中为内部类型 MyService 添加符合仓库规范的类型注释(例如在 partial class
MyService 声明前增加 /// <summary>...</summary>),确保注释风格与已有字段注释一致并包含必要描述,更新生成快照以反映此更改。

In
`@GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs`:
- Around line 7-8: MyService<T> is an internal partial generic type missing XML
documentation; add a triple-slash XML doc comment above the type declaration for
partial class MyService<T> including at minimum a <summary> describing the class
and a <typeparam name="T"> describing the generic type parameter (and other tags
like <remarks> if applicable) so the internal type complies with the project's
XML documentation guideline.

In
`@GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs`:
- Around line 7-8: The partial class MyService is an internal type without XML
documentation; add a triple-slash XML comment above the declaration for partial
class MyService including at minimum a <summary> describing the class purpose
(and other tags if applicable), so the internal type complies with the rule that
internal types must have XML docs; update the generated file's partial class
MyService declaration to include the appropriate /// <summary>…</summary>
comment.

In
`@GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs`:
- Around line 18-22: The lazy initialization of _context reads _contextProvider
without synchronization and can race with
SetContextProvider/ResetContextProvider causing a null reference when calling
GetContext(); fix by serializing access to _contextProvider and _context: either
(A) introduce a dedicated lock object (e.g., _contextProviderLock) and wrap the
lazy-init block that sets _contextProvider and assigns _context as well as
SetContextProvider and ResetContextProvider in that lock, or (B) use an atomic
snapshot/CompareExchange pattern (capture var provider = _contextProvider; if
provider is null create a new provider and use Interlocked.CompareExchange to
publish it, then call provider.GetContext() on the non-null snapshot) and ensure
a null-check before calling GetContext(); apply the same pattern to the other
locations (lines 32-43) that access _contextProvider/_context.

---

Nitpick comments:
In `@GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs`:
- Around line 38-56: The two assertion messages use different
languages—translate and unify them so both are the same language; specifically
update the message built in the Assert after updatedCompilation.GetDiagnostics()
(the interpolation starting with "编译生成的代码时出现错误") to match the language used in
the later Assert for driver.GetRunResult() (or vice versa), ensuring both
Assert.That calls (the one checking compilationErrors and the one checking
generated) use consistent wording and language.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d08cea62-c3b1-4094-b7bb-50a9ac00db4e

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6ff22 and 35a1634.

📒 Files selected for processing (20)
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Code Quality & Security
  • GitHub Check: Analyze (C#)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.cs: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable
XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and edge cases, and registration order or lifecycle sequencing
Avoid obvious comments such as // increment i
Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives
Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what
Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Missing required documentation is a coding standards violation. Code that does not meet the documentation rules is considered incomplete
Do not rely on implicit imports. Declare every required using explicitly in C# files
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and con...

Files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🧠 Learnings (22)
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: LoggerGenerator source generator with [Log] attribute must automatically generate log fields and logging helper methods

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Preserve snapshot-based verification patterns already used in the repository for source generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : Keep source generators deterministic and free of hidden environment or network dependencies

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T13:25:59.124Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 235
File: GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs:1-3
Timestamp: 2026-04-16T13:25:59.124Z
Learning: In the GeWuYou/GFramework repo, treat `global using NUnit.Framework;` as provided project-wide by `GFramework.SourceGenerators.Tests/GlobalUsings.cs` (via GlobalUsings.cs). Do not require or flag missing per-file `using NUnit.Framework;` directives in test `.cs` files under `GFramework.SourceGenerators.Tests/`, since the project-wide global usings already include NUnit (along with other common namespaces).

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : When a public API defines multiple contract branches, tests MUST cover the meaningful variants, including null, empty, default, and filtered inputs when those branches change behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: PriorityGenerator source generator with [Priority] attribute must automatically generate priority comparison implementations

Applied to files:

  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: ContextAwareGenerator source generator with [ContextAware] attribute must automatically implement IContextAware boilerplate logic

Applied to files:

  • GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Reuse existing architecture test infrastructure when relevant: `ArchitectureTestsBase<T>`, `SyncTestArchitecture`, `AsyncTestArchitecture`

Applied to files:

  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Mirror the source structure in test projects whenever practical

Applied to files:

  • GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: EnumExtensionsGenerator source generator with [GenerateEnumExtensions] attribute must automatically generate enum extension capabilities

Applied to files:

  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: Source Generators must target netstandard2.1 and provide incremental Roslyn code generation capabilities

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: IContextAware must provide unified context access through SetContext(IArchitectureContext) method for all components

Applied to files:

  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
🔇 Additional comments (26)
GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs (1)

6-6: 与前述问题重复:类型级 XML 文档缺失

该快照中的 internal partial class MySystem 同样缺少类型 /// <summary>,建议通过生成器模板统一修复并批量更新快照。

GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs (1)

6-6: 与前述问题重复:类型级 XML 文档缺失

internal partial class GenericSystem<T> 仍缺少类型注释,建议在生成器模板层统一补齐。

GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs (1)

7-7: 与前述问题重复:类型级 XML 文档缺失

internal partial class MyService 依然缺少类型文档注释,建议与其它生成快照一起统一修复。

GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs (1)

6-6: 与前述问题重复:类型级 XML 文档缺失

internal partial class CriticalSystem 缺少 /// <summary>,建议通过生成器统一补齐。

GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs (1)

7-7: 与前述问题重复:类型级 XML 文档缺失

该快照同样缺少类型级 XML 注释,建议在生成器侧一次性修复并重录快照。

GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs (1)

7-7: 与前述问题重复:类型级 XML 文档缺失

internal partial class MyService 仍缺少类型文档注释,建议统一由生成模板输出。

GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs (1)

6-6: 与前述问题重复:类型级 XML 文档缺失

internal partial class MyRule 缺少类型 /// <summary> 注释,建议在 ContextAware 生成模板中统一补齐。

GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs (1)

87-90: 快照目录解析重构实现清晰且可维护

这里把目录定位逻辑收敛到 GetSnapshotFolder(),同时用 Path.GetFullPath 做归一化,和当前测试基建的路径校验策略是匹配的。

Also applies to: 92-107

GFramework.SourceGenerators.Tests/Bases/PriorityGeneratorSnapshotTests.cs (1)

53-54: Priority 快照路径重构一致且稳妥

各场景统一走 GetSnapshotFolder(string scenarioName) 后,可读性和后续维护性都更好。

Also applies to: 96-97, 149-150, 192-193, 195-212

GFramework.SourceGenerators.Tests/Logging/LoggerGeneratorSnapshotTests.cs (1)

99-100: Logger 快照目录重构实现一致

统一的 GetSnapshotFolder 让各测试场景的目录定位逻辑更集中,和同 PR 其他快照测试保持了一致。

Also applies to: 191-192, 283-284, 375-376, 467-468, 559-560, 562-579

GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs (3)

62-64: 安全增强:路径验证

使用 ResolveSnapshotPath 替代直接的 Path.Combine 是很好的安全增强,确保在访问文件系统前验证路径合法性。


95-110: 实现正确:支持经典与增量生成器

CreateGenerator 方法通过模式匹配正确处理了 ISourceGeneratorIIncrementalGenerator 两种类型,并使用 AsSourceGenerator() 扩展方法进行适配。XML 文档完整,异常消息清晰。


112-141: 安全实现完善

ResolveSnapshotPath 方法的路径验证逻辑设计合理:

  1. 拒绝空白和绝对路径(第 123 行)
  2. 规范化路径后进行包含关系判断(第 129-130 行)
  3. 使用平台感知的字符串比较(Windows 不区分大小写)
  4. 通过 snapshotRoot + Path.DirectorySeparatorChar 前缀检查防止前缀攻击(如 /root vs /root2

XML 文档完整,注释说明了规范化的原因。

GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs (3)

1-12: 测试类结构良好

导入声明清晰,命名空间符合规范,XML 文档说明了测试目的。使用常量 EnumAttributeNamespace 避免魔法字符串是良好实践。


14-44: 安全测试覆盖充分

两个测试方法分别验证了:

  1. 绝对路径被拒绝(第 18-28 行)
  2. 路径遍历攻击被拒绝(第 34-44 行)

测试命名遵循 MethodName_Condition_ExpectedResult 模式,XML 文档清晰说明测试意图。使用不存在的目录路径确保了异常在文件系统访问之前抛出。


46-91: 辅助方法设计合理

  • CreateSnapshotRoot 通过组合 Test.IDGuid 确保测试隔离,避免状态共享
  • BuildSource 自包含地定义了触发生成器所需的最小源码,不依赖外部文件
  • 使用 $$ 原始字符串字面量语法正确处理了插值
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs (9)

22-24: LGTM!

新增的常量 CqrsReflectionFallbackAttributeMetadataName 遵循命名规范,与现有的元数据名称常量风格一致。


59-62: LGTM!

正确检测 CqrsReflectionFallbackAttribute 的可用性,并将结果传递到生成环境中,实现了对不同运行时合约版本的兼容。


132-147: LGTM!

当存在无法静态注册的处理器接口时,使用 ??= 确保只记录一次回退元数据名称。注释清晰地解释了这种保守策略的设计意图。


526-543: LGTM!

程序集级别 CqrsReflectionFallbackAttribute 的生成逻辑正确:

  • 仅在支持该属性且存在回退处理器时才生成
  • 使用 EscapeStringLiteral 正确转义类型名称中的特殊字符
  • 生成的字符串字面量语法正确

604-608: LGTM!

简化了 AppendReflectionHelpers 的调用条件,现在仅在存在外部程序集类型查找时才添加辅助方法,与移除运行时接口发现逻辑保持一致。


1071-1078: LGTM!

ImplementationRegistrationSpec 记录结构正确添加了 ReflectionFallbackHandlerTypeMetadataName 字段,与其他字段命名风格一致。


1114-1127: LGTM!

HandlerCandidateAnalysisEquals 方法正确更新,使用 StringComparer.Ordinal 比较新增的 ReflectionFallbackHandlerTypeMetadataName 字段,保持了确定性行为。


1169-1172: LGTM!

GetHashCode 方法正确包含新字段,处理 null 值的方式与现有的 ReflectionTypeMetadataName 字段一致。


1193-1195: LGTM!

GenerationEnvironment 记录结构正确添加了 SupportsReflectionFallbackAttribute 属性。

GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs (1)

1004-1012: LGTM!

新增的负向断言正确验证了生成器不再输出旧版运行时接口发现逻辑的标记。这些断言与 ExternalAssemblyPreciseLookupExpected 的精确匹配验证互补,确保了重构的完整性。

Based on learnings: "Source generator changes MUST be covered by generator tests" - 此测试正确覆盖了生成器行为的变更。

@GeWuYou GeWuYou changed the title Refactor/cqrs and config system Refactor/重构CQRS处理程序注册生成器以支持反射回退属性 Apr 17, 2026
- 新增 PriorityGenerator 为标记 Priority 特性的类自动生成 IPrioritized 接口实现
- 新增 EnumExtensionsGenerator 为枚举自动生成 Is 和 IsIn 扩展方法
- 新增 LoggerGenerator 为标记 Log 特性的类自动生成日志字段
- 新增 ContextAwareGenerator 为标记 ContextAware 特性的类自动生成 IContextAware 接口实现
- 新增 CqrsHandlerRegistryGenerator 为 CQRS 处理器生成编译时注册器减少运行时反射开销
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs (1)

12-18: 🛠️ Refactor suggestion | 🟠 Major

补全 RunAsync 的 XML 契约说明。

RunAsync 现在不只是“运行快照测试”:它会手动构建 Roslyn 编译、在编译报错时失败、在生成结果为空时失败、首跑时落盘快照并中断测试,还会校验快照路径安全。当前注释没有把这些前置条件和失败语义说明清楚,调用方很难从 API 文档理解这个测试基类的真实约束。 As per coding guidelines, "Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling" and "Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs` around lines
12 - 18, 补充 GeneratorSnapshotTest.RunAsync 的 XML 文档以明确方法行为:在 RunAsync 的
<summary> 和 <param> 注释中说明它不只是“运行快照测试”,而是会手动构建 Roslyn
编译并在存在编译错误时抛出/使测试失败(列出可能抛出的异常或诊断聚合),说明当生成器未产出任何结果时会失败,以及首次运行时会将生成结果写入磁盘并中断测试以便手动审查;在
<param> 对 source、snapshotFolder 和 snapshotFileNameSelector 的注释中说明
snapshotFileNameSelector 为空时使用原始生成文件名;在 <returns> 中标注返回 Task
并说明何时完成或失败;并补充边界情况与安全检查(例如对 snapshotFolder
的路径安全校验、文件写入失败的处理、生成器诊断/警告处理策略)以便调用方理解核心决策与失败语义(参照类名 GeneratorSnapshotTest 和方法名
RunAsync 以定位修改位置)。
♻️ Duplicate comments (1)
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs (1)

168-173: ⚠️ Potential issue | 🟠 Major

不要在这里静默放弃整个注册器生成。

这里直接 return 后,消费方只会看到 CqrsHandlerRegistry.g.cs 消失,却看不到是“存在 fallback 需求但 runtime 缺少 CqrsReflectionFallbackAttribute”导致的。这个分支是有意的防御逻辑,但最好在返回前发一个明确 diagnostic,并带上触发的 fallback handler metadata name,否则定位成本会很高。 As per coding guidelines: "Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs` around
lines 168 - 173, Before returning from the CanEmitGeneratedRegistry check, emit
a diagnostic that explains why registry generation is being skipped: create a
Diagnostic (via the generator’s context.ReportDiagnostic) with a clear message
stating that generation is skipped due to missing
CqrsReflectionFallbackAttribute support at runtime and include the entries from
fallbackHandlerTypeMetadataNames so callers know which handlers triggered the
fallback requirement; then return as before. Target the code around
CanEmitGeneratedRegistry,
generationEnvironment.SupportsReflectionFallbackAttribute,
fallbackHandlerTypeMetadataNames and ensure the diagnostic references the
CqrsHandlerRegistry.g.cs generation being omitted.
🧹 Nitpick comments (2)
GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs (1)

204-210: 建议在 IsIn 文档里明确 values == null 的契约。

实现已在 Line 214 定义了 valuesnull 时返回 false,但当前 XML 注释未显式写出该边界行为,调用方不易从文档直接获知。

✏️ 建议修改(文档层)
-        builder.AppendLine("        /// <param name=\"values\">用于匹配的候选枚举值集合。</param>");
+        builder.AppendLine("        /// <param name=\"values\">用于匹配的候选枚举值集合;当为 <see langword=\"null\" /> 时返回 <see langword=\"false\" />。</param>");

As per coding guidelines: XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs` around
lines 204 - 210, Update the XML documentation for the IsIn method to specify the
contract when the values parameter is null: state explicitly that if values ==
null the method returns false, describe that this is intentional boundary
behavior, and clarify expected usage for callers (e.g., pass an empty array for
no matches). Ensure the <param name="values"> and the <returns> summary mention
the null-handling behavior so callers can rely on the contract when calling
IsIn.
GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs (1)

99-101: 补全生成类型的 XML 契约说明。

这段 <summary> 目前只说明“会补充上下文访问实现”,但没有交代关键语义:默认回退到 GameContextProvider、provider 是按类型静态共享、以及 SetContextProvider / ResetContextProvider 的线程与生命周期约束。对框架级生成代码来说,这些都属于调用方需要知道的契约。

As per coding guidelines "Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior" and "If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs` around lines
99 - 101, Update the generated XML <summary> produced by ContextAwareGenerator
(the sb.AppendLine calls that emit the type-level documentation) to fully
describe the contract: state that the generator emits a context-access
implementation that falls back to GameContextProvider when no custom provider is
set, that the provider is stored as a static-per-generated-type shared instance,
and that SetContextProvider and ResetContextProvider are the registration APIs
with their threading and lifecycle constraints (e.g., callers must ensure
thread-safety when swapping providers and providers are expected to live for the
duration needed by consumers unless explicitly reset). Also mention any
diagnostics/fallback behavior the generator emits when no provider is available
and note the semantic assumption that consumer code may rely on the static
per-type provider for cross-instance context access.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs`:
- Around line 143-155: SetContext currently assigns _context without
synchronization while the getter uses lock(_contextSync) to lazily initialize
_context; wrap the assignment in SetContext in the same lock(_contextSync) block
so writes and reads use the same synchronization protocol (i.e., inside
SetContext lock(_contextSync) { _context = context; } and adjust any related
_contextProvider updates under the same lock to avoid races).
- Around line 167-181: The XML docs for SetContextProvider() and
ResetContextProvider() are missing cache/semantics notes: add <remarks> to both
methods explaining that the Context property uses lazy caching via the _context
field (assigned with _context ??= _contextProvider.GetContext()), so calling
SetContextProvider() or ResetContextProvider() does not clear already-cached
_context on existing instances and only affects new or not-yet-initialized
instances; also note that to change/clear an already-cached context one must
call IContextAware.SetContext() on the instance.

In `@GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs`:
- Around line 33-45: The test discards the generator diagnostics by using out _
on RunGeneratorsAndUpdateCompilation; capture the third out parameter (e.g., var
generatorDiagnostics) instead, then inspect it for any DiagnosticSeverity.Error
or other severities you care about and fail the test if non-empty; update the
assertion logic around updatedCompilation/GetDiagnostics (compilationErrors) to
also include generatorDiagnostics in the failure message (or assert
generatorDiagnostics is empty) so generator-reported errors from
RunGeneratorsAndUpdateCompilation are not silently ignored.

In `@GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs`:
- Around line 1179-1194: The test currently calls the private helper
CanEmitGeneratedRegistry via reflection which pins implementation details;
replace this with an observable-behavior test that runs the
CqrsHandlerRegistryGenerator (invoke its Execute path) and asserts on generated
output/diagnostics: when metadata requires fallback but runtime types lack
CqrsReflectionFallbackAttribute, assert that CqrsHandlerRegistry.g.cs is not
produced or a specific diagnostic is emitted. Update the test to feed
appropriate compilation inputs (types/attributes) to the generator, run the
generator, and assert on GeneratedSources and Diagnostics instead of calling
CanEmitGeneratedRegistry by name.

---

Outside diff comments:
In `@GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs`:
- Around line 12-18: 补充 GeneratorSnapshotTest.RunAsync 的 XML 文档以明确方法行为:在
RunAsync 的 <summary> 和 <param> 注释中说明它不只是“运行快照测试”,而是会手动构建 Roslyn
编译并在存在编译错误时抛出/使测试失败(列出可能抛出的异常或诊断聚合),说明当生成器未产出任何结果时会失败,以及首次运行时会将生成结果写入磁盘并中断测试以便手动审查;在
<param> 对 source、snapshotFolder 和 snapshotFileNameSelector 的注释中说明
snapshotFileNameSelector 为空时使用原始生成文件名;在 <returns> 中标注返回 Task
并说明何时完成或失败;并补充边界情况与安全检查(例如对 snapshotFolder
的路径安全校验、文件写入失败的处理、生成器诊断/警告处理策略)以便调用方理解核心决策与失败语义(参照类名 GeneratorSnapshotTest 和方法名
RunAsync 以定位修改位置)。

---

Duplicate comments:
In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs`:
- Around line 168-173: Before returning from the CanEmitGeneratedRegistry check,
emit a diagnostic that explains why registry generation is being skipped: create
a Diagnostic (via the generator’s context.ReportDiagnostic) with a clear message
stating that generation is skipped due to missing
CqrsReflectionFallbackAttribute support at runtime and include the entries from
fallbackHandlerTypeMetadataNames so callers know which handlers triggered the
fallback requirement; then return as before. Target the code around
CanEmitGeneratedRegistry,
generationEnvironment.SupportsReflectionFallbackAttribute,
fallbackHandlerTypeMetadataNames and ensure the diagnostic references the
CqrsHandlerRegistry.g.cs generation being omitted.

---

Nitpick comments:
In `@GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs`:
- Around line 204-210: Update the XML documentation for the IsIn method to
specify the contract when the values parameter is null: state explicitly that if
values == null the method returns false, describe that this is intentional
boundary behavior, and clarify expected usage for callers (e.g., pass an empty
array for no matches). Ensure the <param name="values"> and the <returns>
summary mention the null-handling behavior so callers can rely on the contract
when calling IsIn.

In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs`:
- Around line 99-101: Update the generated XML <summary> produced by
ContextAwareGenerator (the sb.AppendLine calls that emit the type-level
documentation) to fully describe the contract: state that the generator emits a
context-access implementation that falls back to GameContextProvider when no
custom provider is set, that the provider is stored as a
static-per-generated-type shared instance, and that SetContextProvider and
ResetContextProvider are the registration APIs with their threading and
lifecycle constraints (e.g., callers must ensure thread-safety when swapping
providers and providers are expected to live for the duration needed by
consumers unless explicitly reset). Also mention any diagnostics/fallback
behavior the generator emits when no provider is available and note the semantic
assumption that consumer code may rely on the static per-type provider for
cross-instance context access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2558a26c-7b40-48a3-95da-257073073cd1

📥 Commits

Reviewing files that changed from the base of the PR and between 35a1634 and b19877f.

📒 Files selected for processing (26)
  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableAllGeneratedMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/EnumWithFlagValues/Permissions.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
✅ Files skipped from review due to trivial changes (16)
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/GenericClass/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableAllGeneratedMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/DefaultConfiguration_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/PublicField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/CustomFieldName_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Logging/snapshots/LoggerGenerator/InstanceField_Class/MyService.Logger.g.cs
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/EnumWithFlagValues/Permissions.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
🚧 Files skipped from review as they are similar to previous changes (3)
  • GFramework.SourceGenerators.Tests/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
  • GFramework.SourceGenerators.Tests/Enums/EnumExtensionsGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (C#)
  • GitHub Check: Code Quality & Security
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.cs: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable
XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and edge cases, and registration order or lifecycle sequencing
Avoid obvious comments such as // increment i
Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives
Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what
Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Missing required documentation is a coding standards violation. Code that does not meet the documentation rules is considered incomplete
Do not rely on implicit imports. Declare every required using explicitly in C# files
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and con...

Files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🧠 Learnings (27)
📓 Common learnings
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: PriorityGenerator source generator with [Priority] attribute must automatically generate priority comparison implementations

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Any change to public API, lifecycle semantics, module behavior, or extension points MUST update the related XML docs

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : All public, protected, and internal types and members in C# MUST include XML documentation comments (`///`) using `<summary>`, `<param>`, `<returns>`, `<exception>`, and `<remarks>` tags where applicable

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : Keep source generators deterministic and free of hidden environment or network dependencies

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
  • GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: LoggerGenerator source generator with [Log] attribute must automatically generate log fields and logging helper methods

Applied to files:

  • GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: EnumExtensionsGenerator source generator with [GenerateEnumExtensions] attribute must automatically generate enum extension capabilities

Applied to files:

  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Preserve snapshot-based verification patterns already used in the repository for source generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : When a public API defines multiple contract branches, tests MUST cover the meaningful variants, including null, empty, default, and filtered inputs when those branches change behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T13:25:59.124Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 235
File: GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs:1-3
Timestamp: 2026-04-16T13:25:59.124Z
Learning: In the GeWuYou/GFramework repo, treat `global using NUnit.Framework;` as provided project-wide by `GFramework.SourceGenerators.Tests/GlobalUsings.cs` (via GlobalUsings.cs). Do not require or flag missing per-file `using NUnit.Framework;` directives in test `.cs` files under `GFramework.SourceGenerators.Tests/`, since the project-wide global usings already include NUnit (along with other common namespaces).

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: ContextAwareGenerator source generator with [ContextAware] attribute must automatically implement IContextAware boilerplate logic

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : If a framework abstraction changes meaning or intended usage, update the explanatory comments in code as part of the same change

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: IContextAware must provide unified context access through SetContext(IArchitectureContext) method for all components

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: Source Generators must target netstandard2.1 and provide incremental Roslyn code generation capabilities

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Reuse existing architecture test infrastructure when relevant: `ArchitectureTestsBase<T>`, `SyncTestArchitecture`, `AsyncTestArchitecture`

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Mirror the source structure in test projects whenever practical

Applied to files:

  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
🔇 Additional comments (5)
GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs (2)

74-77: 这段生成类型注释补充得很好。

为生成的 partial 类型添加 <summary> 能清晰表达职责,提升生成代码可读性与可维护性。

As per coding guidelines: "All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable".


83-85: 日志字段的 XML 注释完善且准确。

字段级 <summary> 明确了该成员是自动生成产物,便于使用方快速识别来源。

As per coding guidelines: "Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior".

GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs (1)

121-123: 类级 XML 注释补充到位,方向正确。

新增的 <summary> 能清晰表达该生成分部类型的职责,与本次生成行为一致,建议保留。

GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs (2)

98-100: 生成的扩展类文档补充到位。

这里新增的类级 <summary> 能明确生成对象与目标枚举类型,提升了生成代码可读性与 IDE 提示质量。

As per coding guidelines: Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior.


182-188: Is{Member} 扩展方法文档结构完整,方向正确。

补齐 <summary> + <param> + <returns>,并通过 cref 指向具体枚举成员,契约表达比之前清晰。

As per coding guidelines: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable.

Comment thread GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
Comment thread GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
Comment thread GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
Comment thread GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs Outdated
- 实现了CqrsHandlerRegistryGenerator用于自动生成CQRS处理器注册器
- 添加了EnumExtensionsGenerator用于自动生成枚举相关的扩展方法
- 创建了ContextAwareGenerator为标记类自动生成IContextAware接口实现
- 支持运行时类型引用的安全编码和反射回退机制
- 实现了精确的运行时类型引用描述和泛型类型处理
- 添加了完整的诊断报告和错误处理机制
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs (2)

137-176: 建议文档补充与 ContextAwareBase 的行为差异说明。

生成的实现使用 _contextSync 进行同步,而 ContextAwareBase(手动继承基类)的 SetContext/GetContext 没有锁保护。两种实现路径的线程安全保证不同:

  • ContextAwareBase:简单属性赋值,无同步
  • 生成代码:支持静态提供者的惰性初始化,有锁保护

建议在生成代码的类级文档或框架文档中说明这一差异,帮助开发者根据场景选择合适的实现方式。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs` around lines
137 - 176, The generated Context property (created by GenerateContextProperty)
uses a lock on _contextSync for lazy initialization of the static
_contextProvider and caching _context, which differs from the manual
ContextAwareBase implementation whose SetContext/GetContext are not
synchronized; update the XML/class-level doc comments emitted by
GenerateContextProperty (or add a remark block near the protected Context
property) to explicitly state this behavioral and thread-safety difference
versus ContextAwareBase and give guidance when to prefer each approach
(mentioning SetContext/GetContext and _contextSync/_contextProvider to locate
the relevant code).

161-174: 在锁内调用 _contextProvider.GetContext() 存在潜在的锁嵌套风险。

GetContext() 被锁保护(Line 172),但根据 GameContextProvider 的实现,其内部会调用 GameContext.GetFirstArchitectureContext(),后者访问 ArchitectureDictionary。如果 GameContext 内部也使用了同步机制,可能会形成锁嵌套,在高并发场景下增加死锁风险或性能瓶颈。

建议在文档或内联注释中明确 IArchitectureContextProvider.GetContext() 的线程安全契约,确保实现者了解该方法会在持有 _contextSync 锁的情况下被调用。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs` around lines
161 - 174, The code calls _contextProvider.GetContext() while holding
_contextSync which can cause nested-lock/deadlock if implementations (e.g.,
GameContextProvider -> GameContext.GetFirstArchitectureContext()) use their own
synchronization; update the codebase by (1) adding a clear thread-safety
contract to IArchitectureContextProvider.GetContext() XML docs stating that
implementations must be safe to be called while _contextSync is held or must be
non-blocking, (2) add an inline comment above the lock in ContextAwareGenerator
(referencing _contextSync, _contextProvider.GetContext(), and _context)
documenting this contract and warning implementers, and (3) optionally consider
refactoring to initialize _contextProvider under _contextSync but call
GetContext() outside the lock if implementations cannot be guaranteed
non-blocking (adjust logic around _contextProvider ??= and _context ??=
accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs`:
- Around line 561-565: 为 GenerateSource 方法补充完整的契约级 XML 文档,说明该方法生成的源码类型(registry
类/方法/属性等)、生成时机与目的(包括何时会产出程序集级 CqrsReflectionFallbackAttribute
与何时完全跳过产出)、对输入参数的语义假设(GenerationEnvironment、registrations、fallbackHandlerTypeMetadataNames
各自代表什么、fallback
列表如何被使用)、诊断边界(哪些错误会以编译器诊断报告、哪些会作为回退行为记录)以及任何不变条件或线程/性能假设;在文档中引用方法名
GenerateSource 和参数名
GenerationEnvironment、registrations、fallbackHandlerTypeMetadataNames 以便定位。

In `@GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs`:
- Around line 1171-1262: Add a positive test that covers the branch where the
runtime contract includes the CqrsReflectionFallbackAttribute so the generator
emits CqrsHandlerRegistry.g.cs with assembly-level fallback metadata;
specifically, create a new test (parallel to
Reports_Diagnostic_And_Skips_Registry_When_Fallback_Metadata_Is_Required_But_Runtime_Contract_Lacks_Fallback_Attribute)
that supplies a source containing a definition of
GFramework.Cqrs.CqrsReflectionFallbackAttribute at runtime, invokes
ExecuteGenerator, then asserts that no GF_Cqrs_001 error is reported and that
execution.GeneratedSources contains the generated CqrsHandlerRegistry.g.cs and
that its contents reference the assembly-level fallback metadata and the handler
type (e.g., TestApp.Container+HiddenHandler).
- Line 1244: The test call to ExecuteGenerator in
Generates_Registry_For_Hidden_Handler_When_Fallback_Marker_Is_Unavailable must
allow unsafe code; add an optional parameter allowUnsafe = false to
ExecuteGenerator, thread that flag into the compilation/parse options creation
inside ExecuteGenerator so the C# compilation is created with AllowUnsafe = true
when requested, and then change the call at the test (the var execution =
ExecuteGenerator(source);) to var execution = ExecuteGenerator(source,
allowUnsafe: true);; reference ExecuteGenerator and the test
Generates_Registry_For_Hidden_Handler_When_Fallback_Marker_Is_Unavailable so you
change only the generator helper signature and its use in that test.

---

Nitpick comments:
In `@GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs`:
- Around line 137-176: The generated Context property (created by
GenerateContextProperty) uses a lock on _contextSync for lazy initialization of
the static _contextProvider and caching _context, which differs from the manual
ContextAwareBase implementation whose SetContext/GetContext are not
synchronized; update the XML/class-level doc comments emitted by
GenerateContextProperty (or add a remark block near the protected Context
property) to explicitly state this behavioral and thread-safety difference
versus ContextAwareBase and give guidance when to prefer each approach
(mentioning SetContext/GetContext and _contextSync/_contextProvider to locate
the relevant code).
- Around line 161-174: The code calls _contextProvider.GetContext() while
holding _contextSync which can cause nested-lock/deadlock if implementations
(e.g., GameContextProvider -> GameContext.GetFirstArchitectureContext()) use
their own synchronization; update the codebase by (1) adding a clear
thread-safety contract to IArchitectureContextProvider.GetContext() XML docs
stating that implementations must be safe to be called while _contextSync is
held or must be non-blocking, (2) add an inline comment above the lock in
ContextAwareGenerator (referencing _contextSync, _contextProvider.GetContext(),
and _context) documenting this contract and warning implementers, and (3)
optionally consider refactoring to initialize _contextProvider under
_contextSync but call GetContext() outside the lock if implementations cannot be
guaranteed non-blocking (adjust logic around _contextProvider ??= and _context
??= accordingly).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 840347f7-f6db-4ba5-9b9d-6d4753f44cbb

📥 Commits

Reviewing files that changed from the base of the PR and between b19877f and 9ec83fa.

📒 Files selected for processing (13)
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Shipped.md
  • GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Unshipped.md
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/EnumWithFlagValues/Permissions.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
✅ Files skipped from review due to trivial changes (7)
  • GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Shipped.md
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsInMethod/Status.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/EnumWithFlagValues/Permissions.EnumExtensions.g.txt
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
  • GFramework.SourceGenerators.Tests/Enums/snapshots/EnumExtensionsGenerator/DisableIsMethods/Status.EnumExtensions.g.txt
  • GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTest.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Code Quality & Security
  • GitHub Check: Analyze (C#)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.cs: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable
XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and edge cases, and registration order or lifecycle sequencing
Avoid obvious comments such as // increment i
Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives
Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what
Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Missing required documentation is a coding standards violation. Code that does not meet the documentation rules is considered incomplete
Do not rely on implicit imports. Declare every required using explicitly in C# files
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and con...

Files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
🧠 Learnings (24)
📓 Common learnings
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: ContextAwareGenerator source generator with [ContextAware] attribute must automatically implement IContextAware boilerplate logic

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
  • GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Unshipped.md
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : Keep source generators deterministic and free of hidden environment or network dependencies

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : When adding caching, pooling, or shared mutable state, document thread-safety assumptions and failure modes

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: IContextAware must provide unified context access through SetContext(IArchitectureContext) method for all components

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Any change to public API, lifecycle semantics, module behavior, or extension points MUST update the related XML docs

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : If a framework abstraction changes meaning or intended usage, update the explanatory comments in code as part of the same change

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Preserve snapshot-based verification patterns already used in the repository for source generator tests

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : When a public API defines multiple contract branches, tests MUST cover the meaningful variants, including null, empty, default, and filtered inputs when those branches change behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T13:25:59.124Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 235
File: GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs:1-3
Timestamp: 2026-04-16T13:25:59.124Z
Learning: In the GeWuYou/GFramework repo, treat `global using NUnit.Framework;` as provided project-wide by `GFramework.SourceGenerators.Tests/GlobalUsings.cs` (via GlobalUsings.cs). Do not require or flag missing per-file `using NUnit.Framework;` directives in test `.cs` files under `GFramework.SourceGenerators.Tests/`, since the project-wide global usings already include NUnit (along with other common namespaces).

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: IArchitectureContext and Provider types must propagate context capabilities between components enabling unified service access without direct implementation coupling

Applied to files:

  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : The repository uses `Meziantou.Analyzer`; treat analyzer feedback as part of the coding standard

Applied to files:

  • GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Unshipped.md
🪛 LanguageTool
GFramework.Cqrs.SourceGenerators/AnalyzerReleases.Unshipped.md

[grammar] ~8-~8: Ensure spelling is correct
Context: ...------------- GF_Cqrs_001 | GFramework.Cqrs.SourceGenerators | Error | CqrsHandl...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🔇 Additional comments (5)
GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs (4)

99-109: 类级 XML 文档清晰完整。

文档准确解释了生成代码的行为:实例级缓存、默认回退到 GameContextProvider、静态提供者共享语义以及缓存失效的限制。符合编码规范中对生成器管道文档的要求。


178-195: SetContextProvider 同步逻辑与文档完整。

方法使用与 Context getter 相同的锁,XML 备注清晰说明了缓存语义和使用限制。符合之前评审意见的修复要求。


197-212: ResetContextProvider 实现正确。

锁保护和文档说明到位,适用于测试清理场景。


278-286: SetContext 方法体正确添加了锁保护。

Context getter 共享相同的同步协议,避免了显式注入与并发懒加载之间的竞态条件。

GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs (1)

1-96: 快照文件与生成器输出一致。

快照正确反映了生成器的最新更改:

  • 添加了 _contextSync 静态锁对象(Line 18)
  • Context 属性使用双重检查锁定模式(Lines 31-46)
  • SetContextProviderResetContextProviderSetContext 均使用相同的锁保护
  • XML 文档完整描述了缓存语义和线程安全行为

之前评审中指出的并发竞态问题已修复。

Comment thread GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs Outdated
GeWuYou added 2 commits April 17, 2026 10:58
- 实现了 PascalCase 命名规则检查功能
- 集成了 Git 文件遍历和 grep 文本匹配
- 支持排除特定目录如 Godot 模板和测试快照
- 验证命名空间和目录路径的大小写规范
- 提供详细的违规信息报告和错误定位
- 包含字母数字字符和缩写命名规则校验
- 新增 ContextAwareBase 抽象类提供手动继承的上下文感知基础实现
- 实现 IContextAware 接口的简单实例字段缓存上下文功能
- 添加 ContextAwareGenerator 源代码生成器自动生成上下文感知实现
- 生成器支持 partial 类的 ContextAware 特性标记自动实现
- 提供 CqrsHandlerRegistryGenerator 生成 CQRS 处理器注册器减少运行时反射扫描
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs (1)

158-189: 🛠️ Refactor suggestion | 🟠 Major

请给 Execute 补上契约级文档。

这里已经集中承载了 fallback 元数据聚合、GF_Cqrs_001 诊断以及“何时直接跳过 AddSource”的核心语义,但方法本身没有把这些约束说清楚,后续维护只能倒推实现。

As per coding guidelines "Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs` around
lines 158 - 189, Add a contract-level XML doc comment to the Execute method that
explains its responsibilities and semantic assumptions: state that Execute is
the gatekeeper for generation (it returns immediately when
generationEnvironment.GenerationEnabled is false or when CollectRegistrations
yields no registrations), describe that it aggregates fallback handler metadata
into fallbackHandlerTypeMetadataNames (via CollectRegistrations) and that
generation requires SupportsReflectionFallbackAttribute support and at least one
fallback metadata entry (checked by CanEmitGeneratedRegistry) otherwise it
reports the GF_Cqrs_001-style diagnostic using
ReportMissingReflectionFallbackContractDiagnostic; also document that when
checks pass it emits the generated registry source with context.AddSource using
GenerateSource(registration, fallbackHandlerTypeMetadataNames), and note any
invariants callers can rely on (e.g., registrations non-empty,
fallbackHandlerTypeMetadataNames distinct/non-whitespace) and side effects
(diagnostic emission, AddSource). Include references to the symbols Execute,
generationEnvironment.GenerationEnabled, CollectRegistrations,
fallbackHandlerTypeMetadataNames, CanEmitGeneratedRegistry,
ReportMissingReflectionFallbackContractDiagnostic, registrations,
GenerateSource, and context.AddSource in the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs`:
- Around line 1244-1263: The tests call ExecuteGenerator and assert on
GeneratorDiagnostics/GeneratedSources but don't assert that
execution.CompilationDiagnostics is empty, so a non-compilable generated result
can wrongly pass; update the test(s) (the block that creates var execution =
ExecuteGenerator(...), var generatorErrors = ..., and missingContractDiagnostic)
to also Assert that execution.CompilationDiagnostics is empty (or contains no
errors) before asserting generator diagnostics and generated sources, ensuring
compilation errors fail the test; apply the same change to the other similar
test block around the ExecuteGenerator call at the referenced second location.

---

Outside diff comments:
In `@GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs`:
- Around line 158-189: Add a contract-level XML doc comment to the Execute
method that explains its responsibilities and semantic assumptions: state that
Execute is the gatekeeper for generation (it returns immediately when
generationEnvironment.GenerationEnabled is false or when CollectRegistrations
yields no registrations), describe that it aggregates fallback handler metadata
into fallbackHandlerTypeMetadataNames (via CollectRegistrations) and that
generation requires SupportsReflectionFallbackAttribute support and at least one
fallback metadata entry (checked by CanEmitGeneratedRegistry) otherwise it
reports the GF_Cqrs_001-style diagnostic using
ReportMissingReflectionFallbackContractDiagnostic; also document that when
checks pass it emits the generated registry source with context.AddSource using
GenerateSource(registration, fallbackHandlerTypeMetadataNames), and note any
invariants callers can rely on (e.g., registrations non-empty,
fallbackHandlerTypeMetadataNames distinct/non-whitespace) and side effects
(diagnostic emission, AddSource). Include references to the symbols Execute,
generationEnvironment.GenerationEnabled, CollectRegistrations,
fallbackHandlerTypeMetadataNames, CanEmitGeneratedRegistry,
ReportMissingReflectionFallbackContractDiagnostic, registrations,
GenerateSource, and context.AddSource in the comment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0103721c-7fad-484d-959f-1ef3e8b0ff15

📥 Commits

Reviewing files that changed from the base of the PR and between 57a006c and bcde9f6.

📒 Files selected for processing (5)
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.Core/Rule/ContextAwareBase.cs
  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
✅ Files skipped from review due to trivial changes (1)
  • GFramework.Core/Rule/ContextAwareBase.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build and Test
  • GitHub Check: Code Quality & Security
  • GitHub Check: Analyze (C#)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.cs: All public, protected, and internal types and members in C# MUST include XML documentation comments (///) using <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable
XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and edge cases, and registration order or lifecycle sequencing
Avoid obvious comments such as // increment i
Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types MUST include high-level explanations of responsibilities, lifecycle, interaction with other components, why the abstraction exists, and when to use it instead of alternatives
Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what
Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Missing required documentation is a coding standards violation. Code that does not meet the documentation rules is considered incomplete
Do not rely on implicit imports. Declare every required using explicitly in C# files
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and con...

Files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
🧠 Learnings (24)
📓 Common learnings
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: CqrsHandlerRegistryGenerator must generate CQRS handler registries for consuming assemblies with runtime prioritization of generated products and fallback to reflection scanning; non-default assemblies must be explicitly registered via RegisterCqrsHandlersFromAssembly or RegisterCqrsHandlersFromAssemblies

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : When generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.cs : Keep source generators deterministic and free of hidden environment or network dependencies

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: ContextAwareGenerator source generator with [ContextAware] attribute must automatically implement IContextAware boilerplate logic

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Generated logic and generator pipelines MUST explain what is generated, why it is generated, the semantic assumptions the generator relies on, and any diagnostics or fallback behavior

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: Source Generators must target netstandard2.1 and provide incremental Roslyn code generation capabilities

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.SourceGenerators.Tests.cs : Preserve snapshot-based verification patterns already used in the repository for source generator tests

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : Any change to public API, lifecycle semantics, module behavior, or extension points MUST update the related XML docs

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : If a framework abstraction changes meaning or intended usage, update the explanatory comments in code as part of the same change

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.cs : When adding caching, pooling, or shared mutable state, document thread-safety assumptions and failure modes

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T11:55:23.931Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.931Z
Learning: Applies to **/*.cs : XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
📚 Learning: 2026-04-16T14:51:18.170Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-16T14:51:18.170Z
Learning: IContextAware must provide unified context access through SetContext(IArchitectureContext) method for all components

Applied to files:

  • GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : When a public API defines multiple contract branches, tests MUST cover the meaningful variants, including null, empty, default, and filtered inputs when those branches change behavior

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T11:55:23.932Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-16T11:55:23.932Z
Learning: Applies to **/*.Tests.csproj : Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-16T13:25:59.124Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 235
File: GFramework.SourceGenerators.Tests/Rule/ContextAwareGeneratorSnapshotTests.cs:1-3
Timestamp: 2026-04-16T13:25:59.124Z
Learning: In the GeWuYou/GFramework repo, treat `global using NUnit.Framework;` as provided project-wide by `GFramework.SourceGenerators.Tests/GlobalUsings.cs` (via GlobalUsings.cs). Do not require or flag missing per-file `using NUnit.Framework;` directives in test `.cs` files under `GFramework.SourceGenerators.Tests/`, since the project-wide global usings already include NUnit (along with other common namespaces).

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs
🔇 Additional comments (8)
GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs (4)

99-113: 类级别 XML 文档完整,清晰说明了生成实现与手动继承路径的差异。

文档详尽描述了实例级缓存、静态提供者共享、以及与 ContextAwareBase 无锁语义的对比,符合编码规范对生成器管道的文档要求。


146-186: Context 属性的双重检查锁定模式实现正确,文档充分说明了同步语义和潜在的死锁风险。

  • 先读取 _context 并在非空时快速返回,避免不必要的锁获取
  • 锁内使用 ??= 处理竞态条件
  • 文档明确警告自定义 provider 不应在 GetContext() 调用链内重入配置 API 或形成反向锁顺序

这解决了之前审查中提出的线程竞态问题。


188-222: SetContextProviderResetContextProvider 的文档现在明确说明了缓存语义。

文档已补充说明:

  • 切换/重置提供者仅影响尚未初始化上下文的新实例
  • 已缓存的实例上下文不会自动失效
  • 如需覆盖已有实例的上下文,需显式调用 IContextAware.SetContext(...)

这符合编码规范中"生命周期、线程、注册或处置行为必须在 XML 文档中显式记录"的要求,且解决了之前审查中提出的文档缺失问题。


290-296: SetContext 方法体现在使用与 Context getter 相同的同步协议。

生成的 SetContext 实现已在 _contextSync 锁保护下赋值 _context,避免显式注入被并发懒加载覆盖。这解决了之前审查中识别的线程竞态问题。

GFramework.SourceGenerators.Tests/Rule/snapshots/ContextAwareGenerator/MyRule.ContextAware.g.cs (4)

1-20: 快照正确反映了生成器的同步实现。

生成的代码包含:

  • 实例级 _context 字段
  • 静态共享 _contextProvider 字段
  • _contextSync 锁对象用于协调所有共享状态的访问

类级别文档清晰说明了与 ContextAwareBase 的差异,符合 learnings 中"When generator behavior changes intentionally, update snapshots together with the implementation"的要求。


33-52: Context 属性的双重检查锁定模式实现正确。

  • 第 37-41 行:先读取 _context 快照并在非空时快速返回
  • 第 45-50 行:锁内使用 ??= 确保线程安全的懒加载
  • 内联注释准确描述了同步语义和对自定义 provider 的约束

这解决了之前审查中识别的并发竞态问题。


63-85: SetContextProviderResetContextProvider 现在正确同步。

两个方法都在 _contextSync 锁内修改 _contextProvider,与 Context getter 使用相同的同步协议,避免了提供者切换与惰性初始化的交错竞态。


87-99: 显式接口实现完整且线程安全。

  • IContextAware.SetContext 在锁内赋值 _context,与 getter 共享同步协议
  • IContextAware.GetContext 委托到 Context 属性,复用懒加载逻辑

实现符合 IContextAware 接口契约,且保持了线程安全性。

GeWuYou added 2 commits April 17, 2026 12:44
添加了完整的XML文档注释到Execute方法,详细说明了CQRS处理器注册生成器的执行流程、参数含义、实现逻辑和注意事项。同时改进了测试框架,在GeneratorExecutionResult中分离了生成代码的编译诊断,使测试能够更精确地验证生成代码的质量。
@GeWuYou
Copy link
Copy Markdown
Owner Author

GeWuYou commented Apr 17, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@GeWuYou GeWuYou merged commit 59dfb68 into main Apr 17, 2026
7 checks passed
@GeWuYou GeWuYou deleted the refactor/cqrs-and-config-system branch April 17, 2026 05:15
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.

1 participant