Skip to content

feat(generator): 添加运行时发现处理器接口的日志名称记录功能#233

Merged
GeWuYou merged 1 commit into
refactor/cqrs-architecture-decouplingfrom
refactor/cqrs-architecture-decoupling-todo-11
Apr 16, 2026
Merged

feat(generator): 添加运行时发现处理器接口的日志名称记录功能#233
GeWuYou merged 1 commit into
refactor/cqrs-architecture-decouplingfrom
refactor/cqrs-architecture-decoupling-todo-11

Conversation

@GeWuYou

@GeWuYou GeWuYou commented Apr 16, 2026

Copy link
Copy Markdown
Owner
  • 在 HandlerCandidateAnalysis 结构中新增 RuntimeDiscoveredHandlerInterfaceLogNames 字段
  • 为运行时发现的处理器接口创建日志名称收集器并存储显示名称
  • 修改构造函数和属性以支持新的日志名称数组字段
  • 更新相等性比较逻辑以包含运行时发现接口日志名称的比较
  • 在生成的代码中添加注释显示剩余的运行时接口发现目标
  • 更新单元测试验证生成的注释内容是否正确包含接口名称

Summary by CodeRabbit

  • 测试

    • 增强了 CQRS 处理程序注册表生成器的测试断言,完善了运行时接口发现目标的覆盖验证。
  • 重构

    • 改进了内部代码生成器的处理程序接口跟踪机制,优化了元数据管理与注册逻辑中的相等性比较。

注: 本次更新仅涉及内部实现改进,无公共 API 变更或用户可见功能更新。

- 在 HandlerCandidateAnalysis 结构中新增 RuntimeDiscoveredHandlerInterfaceLogNames 字段
- 为运行时发现的处理器接口创建日志名称收集器并存储显示名称
- 修改构造函数和属性以支持新的日志名称数组字段
- 更新相等性比较逻辑以包含运行时发现接口日志名称的比较
- 在生成的代码中添加注释显示剩余的运行时接口发现目标
- 更新单元测试验证生成的注释内容是否正确包含接口名称
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

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: f8e40f01-28dc-45cc-89fc-1ac7d38aaf68

📥 Commits

Reviewing files that changed from the base of the PR and between e96623b and 823be21.

📒 Files selected for processing (2)
  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📜 Recent 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: Analyze (C#)
  • GitHub Check: Build and Test
  • GitHub Check: Code Quality & Security
🧰 Additional context used
📓 Path-based instructions (3)
**/*.cs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.cs: LoggerGenerator must automatically generate log fields and logging helper methods for classes decorated with [Log] attribute
PriorityGenerator must generate priority comparison implementations for classes decorated with [Priority] attribute
EnumExtensionsGenerator must generate enum extension capabilities for enums decorated with [GenerateEnumExtensions] attribute
ContextAwareGenerator must automatically implement IContextAware boilerplate logic for classes decorated with [ContextAware] attribute

**/*.cs: All public, protected, and internal types and members MUST include XML documentation comments (///) with <summary>, <param>, <returns>, <exception>, and <remarks> where applicable
Add inline comments for non-trivial logic, concurrency/threading behavior, performance-sensitive paths, workarounds, compatibility constraints, and edge cases
Core framework components (Architecture, Module, System, Context, Registry, Service Module, Lifecycle types) MUST include high-level explanations of responsibilities, lifecycle, interactions, and design rationale
Generated logic and source generator pipelines MUST explain what is generated, why it is generated, semantic assumptions, and diagnostic or fallback behavior
Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling
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, constants use PascalCase; interfaces use I prefix; parameters and locals use camelCase; private fields use _camelCase
Use 4 spaces for indentation (not tabs), use Allman braces, and keep using directives at the top of the file sorted consistently
Prefer one primary type per file unless the surrounding project alread...

Files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
**/*.{cs,csproj}

📄 CodeRabbit inference engine (AGENTS.md)

Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical

Files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
**/*SourceGenerators/**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

Keep source generators deterministic and free of hidden environment or network dependencies

Files:

  • GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🧠 Learnings (8)
📚 Learning: 2026-04-14T01:59:40.041Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T01:59:40.041Z
Learning: Applies to **/*.Tests/*.cs : Source generator changes MUST be covered by generator tests; preserve snapshot-based verification patterns already used in the repository

Applied to files:

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

Applied to files:

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

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
📚 Learning: 2026-04-14T01:59:40.041Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T01:59:40.041Z
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.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-14T01:59:40.041Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T01:59:40.041Z
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-14T01:59:40.041Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T01:59:40.041Z
Learning: Applies to **/*.cs : Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs

Applied to files:

  • GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
  • GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
📚 Learning: 2026-04-14T01:59:40.041Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-14T01:59:40.041Z
Learning: Applies to **/*.Tests/*.cs : When a public API defines multiple contract branches, tests MUST cover 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-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.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
🔇 Additional comments (4)
GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs (3)

95-144: 运行时发现接口名的采集与透传链路是完整的。

这里沿用已排序的 handlerInterfaces 迭代结果收集并下传显示名,后续生成出来的注释顺序会保持稳定,可读性和可重复性都不错。

Based on learnings: Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs.

Also applies to: 189-190


663-669: 把剩余运行时发现目标直接写进生成注释很有帮助。

这能让 fallback 目标在生成源码里一眼可见,排查为什么还需要运行时接口发现时会直观很多。

As per coding guidelines: Generated logic and source generator pipelines MUST explain what is generated, why it is generated, semantic assumptions, and diagnostic or fallback behavior.


1117-1232: 新字段已同步纳入相等性与哈希,增量失效条件补齐了。

如果后续只有这组日志名发生变化,增量生成也会正确识别候选项变更,不会残留旧的注释输出。

Based on learnings: Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs.

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

935-938: 新增断言覆盖到了这次生成输出的新增可观察行为。

这里直接验证“剩余运行时发现目标”注释是否带出接口名,和这次实现改动是对齐的。

Based on learnings: Keep tests focused on observable behavior, not implementation trivia.


📝 Walkthrough

概述

该 PR 扩展了 CQRS 处理程序注册生成器,为每个处理程序实现候选项追踪额外的运行时接口发现目标元数据,并在生成的代码中发出相应的注释标记。生成器的相等性和哈希逻辑也随之更新。

变更内容

内聚组 / 文件 摘要
生成器运行时发现元数据追踪
GFramework.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
添加 ImmutableArray<string> 字段用于追踪待运行时发现的处理程序接口日志名称;扩展 HandlerCandidateAnalysisImplementationRegistrationSpec 以传播该元数据;更新相等性和哈希逻辑以支持新数组的序数比较和哈希计算;在源代码生成期间为注册代码块发出包含剩余运行时发现目标的注释行。
测试断言扩展
GFramework.SourceGenerators.Tests/Cqrs/CqrsHandlerRegistryGeneratorTests.cs
Generates_Partial_Runtime_Interface_Discovery_For_Inaccessible_External_Protected_Types 测试中添加额外的断言,验证生成的注册表源代码包含对受保护请求处理程序接口的运行时发现目标注释标记。

代码审查工作量估算

🎯 3 (中等) | ⏱️ ~20 分钟

可能相关的 PR

  • PR #230:修改相同的处理程序候选项分析和注册发出代码路径,通过扩展数据结构元数据和更新相等性/哈希逻辑来支持运行时/反射接口目标追踪。
  • PR #232:修改 CqrsHandlerRegistryGenerator 的运行时接口发现处理,涉及相同的每实现元数据传播、注册发出和相等性逻辑更新。
  • PR #228:修改 CQRS 处理程序注册表源生成器中的处理程序候选项/实现规范数据、相等性/哈希逻辑及反射/运行时处理程序注册的发出元数据。
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题使用中文,且明确反映了主要变更:为处理器接口的运行时发现过程添加日志名称记录功能,与代码变更内容一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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-architecture-decoupling-todo-11

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

@GeWuYou GeWuYou merged commit 52e40a1 into refactor/cqrs-architecture-decoupling Apr 16, 2026
7 checks passed
@GeWuYou GeWuYou deleted the refactor/cqrs-architecture-decoupling-todo-11 branch April 16, 2026 11:47
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