Skip to content

Feat/config schema generator and validation#198

Merged
GeWuYou merged 8 commits into
mainfrom
feat/config-schema-generator-and-validation
Apr 9, 2026
Merged

Feat/config schema generator and validation#198
GeWuYou merged 8 commits into
mainfrom
feat/config-schema-generator-and-validation

Conversation

@GeWuYou

@GeWuYou GeWuYou commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • 新功能

    • 配置系统运行时与工具新增 multipleOf 与 uniqueItems 校验;编辑器/导出元数据与生成器文档同步支持这两项提示。
  • 文档

    • 更新文档与生成器注释,说明 multipleOf 与 uniqueItems 行为、十进制精确判断与浮点容差、基于 schema 的归一化比较及本地化提示字段。
  • 测试

    • 增补大量单元/集成测试,覆盖通过/失败、重复项诊断、科学计数法与大数/边界情况,并新增测试用桩类型。

GeWuYou added 3 commits April 9, 2026 17:06
- 实现了SchemaConfigGenerator源代码生成器
- 支持根据JSON schema文件自动生成配置类型
- 生成强类型的配置表包装类
- 支持嵌套对象和对象数组的类型生成
- 生成配置表的查询和索引功能
- 添加了跨表引用的元数据支持
- 生成运行时注册和访问辅助代码
- 支持默认值、枚举和约束的文档生成
- 实现了配置模式解析器,支持递归对象/数组/标量树结构
- 添加了可编辑字段收集功能,支持批量编辑标量和数组类型
- 实现了YAML解析器,支持嵌套对象、标量数组和对象数组
- 添加了YAML注释提取功能,将注释映射到逻辑字段路径
- 实现了基于模式的示例YAML配置生成功能
- 添加了扩展端验证诊断功能,支持中英文错误消息
- 实现了表单更新应用功能,支持标量、数组和对象数组更新
- 添加了批处理数组值解析和模式枚举值标准化功能
- 实现了YAML标量格式化和引号移除功能
- 添加了完整的模式节点验证,支持数值约束、长度限制和模式匹配
- 实现了多语言验证消息本地化功能
- 添加了YAML标记化和块解析功能
- 实现了唯一性检查和比较键构建功能
- 介绍面向静态游戏内容的 AI-First 配表方案
- 详细说明 YAML 配置源文件和 JSON Schema 结构描述功能
- 提供推荐目录结构和 Schema 示例配置指南
- 说明 VS Code 插件提供的配置浏览和编辑功能
- 提供运行时接入模板和强类型查询辅助使用方法
- 说明跨表引用和运行时校验行为规范
- 介绍开发期热重载功能和性能优化建议
- 说明当前限制和独立 Config Studio 评估结论

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @GeWuYou, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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: e0d3d0b2-c946-455a-ae78-de349752677f

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec3429 and d263a43.

📒 Files selected for processing (5)
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
  • docs/zh-CN/game/config-system.md
  • tools/gframework-config-tool/src/configValidation.js
  • tools/gframework-config-tool/test/configValidation.test.js
✅ Files skipped from review due to trivial changes (1)
  • tools/gframework-config-tool/test/configValidation.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. 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 (6)
**/*.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

All public, protected, and internal types and members MUST include XML documentation comments (///) with <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable.

XML documentation comments must explain intent, contract, and usage constraints instead of restating syntax.

Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds, compatibility constraints, edge cases, registration order, lifecycle sequencing, or generated code assumptions.

Core framework components (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.

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.

Do not rely on implicit imports. Declare every required using explicitly.

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 constants use PascalCase; Interfaces...

Files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
**/*.Tests/**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

Mirror the source structure in test projects whenever practical.

Reuse existing architecture test infrastructure when relevant: ArchitectureTestsBase<T>, SyncTestArchitecture, AsyncTestArchitecture.

Keep tests focused on observable behavior, not implementation trivia.

Files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
docs/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Documentation must be located in docs/ directory with Chinese content in docs/zh-CN/

Files:

  • docs/zh-CN/game/config-system.md
{README.md,docs/**}

📄 CodeRabbit inference engine (AGENTS.md)

Update the relevant README.md or docs/ page when behavior, setup steps, architecture guidance, or user-facing examples change.

Files:

  • docs/zh-CN/game/config-system.md
docs/**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

Keep code samples, package names, and command examples in documentation aligned with the current repository state.

Prefer documenting behavior and design intent, not only API surface.

For integration-oriented features such as the AI-First config system, documentation MUST cover: project directory layout and file conventions, required project or package wiring, minimal working usage example, and migration or compatibility notes when behavior changes.

Do not rely on "the code is self-explanatory" for framework features that consumers need to adopt; write the adoption path down in user-facing documentation so future users do not need to rediscover it from source.

Files:

  • docs/zh-CN/game/config-system.md
docs/zh-CN/**

📄 CodeRabbit inference engine (AGENTS.md)

When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create the corresponding user-facing integration documentation in docs/zh-CN/ in the same change.

Files:

  • docs/zh-CN/game/config-system.md
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Before choosing runtimes or CLI tools, read `@.ai/environment/tools.ai.yaml`. Prefer project-relevant tools listed there instead of assuming every installed system tool is available.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: When working in WSL against a Windows-backed worktree, prefer Windows Git from WSL (for example `git.exe`) instead of the Linux `git` binary.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Keep abstractions projects free of implementation details and engine-specific dependencies.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Preserve existing module boundaries. Do not introduce new cross-module dependencies without clear architectural need.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Treat `Meziantou.Analyzer` feedback as part of the coding standard.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Treat SonarQube maintainability rules as part of the coding standard, especially cognitive complexity and oversized parameter list findings.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Public API changes must be covered by unit or integration tests.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: 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.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Regression fixes should include a test that fails before the fix and passes after it.
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T12:27:21.256Z
Learning: Minimize new package dependencies. Add them only when necessary and keep scope narrow.
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : 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.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
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.Game.Tests/Config/YamlConfigLoaderTests.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.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to docs/zh-CN/**/*.md : When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create the corresponding user-facing integration documentation in `docs/zh-CN/` in the same change

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : For integration-oriented features such as the AI-First config system, documentation MUST cover project directory layout and file conventions, required project or package wiring, minimal working usage example, and migration or compatibility notes when behavior changes

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : Prefer documenting behavior and design intent in documentation, not only API surface

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : Keep code samples, package names, and command examples in documentation aligned with the current repository state

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : Update the relevant `README.md` or `docs/` page when behavior, setup steps, architecture guidance, or user-facing examples change

Applied to files:

  • docs/zh-CN/game/config-system.md
🪛 LanguageTool
docs/zh-CN/game/config-system.md

[uncategorized] ~709-~709: 数词与名词之间一般应存在量词,可能缺少量词。
Context: ...int 和生成代码 XML 文档复用;当前优先按运行时与 JS 共用的十进制精确整倍数判定处理常见十进制步进,并在必要时退回浮点容差兜底 - minLength ...

(wa5)


[uncategorized] ~709-~709: 您的意思是“"不"进”?
Context: ...L 文档复用;当前优先按运行时与 JS 共用的十进制精确整倍数判定处理常见十进制步进,并在必要时退回浮点容差兜底 - minLength / `maxLeng...

(BU)

🔇 Additional comments (16)
docs/zh-CN/game/config-system.md (4)

15-15: 文档更新与代码变更保持一致。

multipleOfuniqueItems 已正确添加到支持的约束列表中,与运行时校验器、源生成器和工具端的实现保持同步。


56-67: Schema 示例更新正确反映新约束。

hp 字段新增 multipleOf: 5dropItems 新增 uniqueItems: true,与生成器快照和测试用例中的 schema 变更一致。


709-714: 元数据约束说明清晰完整。

multipleOf 的十进制精确整倍数判定与浮点容差兜底机制、uniqueItems 的 schema 归一化结构比较行为均与 YamlConfigSchemaValidator.cs 实现保持一致。pattern 说明更新为 JS Unicode u 模式也与工具端 configValidation.js 的正则编译方式对齐。


810-810: 表单入口与批量编辑入口的元数据范围描述已修正。

现在明确 multipleOf / uniqueItems 仅在表单入口中显示,批量编辑入口只暴露顶层可批量改写字段所需的基础信息,与 extension.jsrenderFieldHint 实现对齐。

tools/gframework-config-tool/src/configValidation.js (6)

9-11: 预编译正则模式提升性能。

将重复使用的标量类型匹配正则提取为模块级常量,避免在 isScalarCompatibleformatYamlScalar 中多次编译,符合性能最佳实践。


484-521: multipleOf 精确十进制算法与运行时保持一致。

matchesSchemaMultipleOftryMatchesExactDecimalMultiple 的实现与 C# 端 YamlConfigSchemaValidator.IsMultipleOf 逻辑对齐:优先尝试精确十进制整倍数判定,失败时退回浮点容差兜底。这能正确处理 10000000.2 % 0.1 等大数场景。


530-565: 十进制解析器覆盖常见 YAML/JSON 数值格式。

tryParseExactDecimal 支持整数、小数、科学计数法以及正负号,并通过 BigInt 保留精度。需注意一个边界情况:

当输入为纯指数形式如 1e20 时,scale 会变成负数(0 - 20 = -20),后续 scale < 0 分支会正确补零并重置 scale = 0,逻辑正确。


770-805: uniqueItems 校验正确跳过已报错元素。

通过在子项校验前后比较 diagnostics.length,只将未产生新诊断的元素加入 comparableItems,避免了 shape/type 错误元素被误报为重复项。此实现与之前 review 建议一致。


1010-1052: 可比较键编码已修复碰撞问题。

对象字段值、数组元素和标量均采用 ${valueKey.length}:${valueKey} 格式编码,与 C# 端 BuildComparableNodeValue 保持一致,避免 { a: "x|1:b=string:yz" }{ a: "x", b: "yz" } 等边界情况被误判为相同。


1089-1098: 新增本地化消息与诊断键对齐。

multipleOfViolationuniqueItemsViolation 的中英文消息格式与 localizationKeys.js 中的键定义及运行时错误消息保持一致。

Also applies to: 1131-1140

GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs (6)

513-559: multipleOf 基础拒绝场景测试完备。

验证整数字段违反 multipleOf: 5 约束时抛出 ConstraintViolation,断言覆盖 FailureKindDisplayPathRawValue 和消息内容。


561-603: 大数十进制步进接受测试验证精确算法。

10000000.2 配合 multipleOf: 0.1 测试确保精确十进制判定路径正常工作,避免浮点舍入导致误拒。


605-647: 大数量级非整倍数回归测试已补充。

1000000000000.4 配合 multipleOf: 1 测试覆盖了之前 review 指出的回归风险分支,确保精确十进制判定能正确拒绝看似接近但实际不满足约束的大数值。


942-994: uniqueItems 标量数组重复拒绝测试完备。

验证重复整数元素被正确检测,断言覆盖 DisplayPath 指向第二个重复项 dropRates[2],与运行时 ValidateArrayUniqueItemsConstraint 的诊断路径逻辑一致。


996-1056: 可比较键碰撞回归测试覆盖边界情况。

测试用例中 { a: "x|1:b=string:yz" }{ a: "x", b: "yz" } 两个对象看似可能生成相同比较键,但因长度前缀编码而被正确区分,验证了运行时 BuildComparableNodeValue 的碰撞防护。


1995-2009: 测试桩类型定义规范。

MonsterNumberConfigStubMonsterComparableEntryArrayConfigStubComparableEntryConfigStub 均包含完整的 XML 文档注释,符合 **/*.cs 编码规范对类型和成员文档的要求。

Also applies to: 2090-2136


📝 Walkthrough

Walkthrough

为配置系统在运行时与工具链中新增对 JSON Schema 关键字 multipleOfuniqueItems 的支持,覆盖 .NET 验证器、源生成器元数据、JS 工具/VS Code 扩展、文档、以及新增/扩展的单元测试和测试桩类型。

Changes

Cohort / File(s) Summary
运行时验证器 / 测试
GFramework.Game/Config/YamlConfigSchemaValidator.cs, GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
解析并在运行时校验 multipleOf(正数、有限、精确十进制/容差两阶段判定)与 uniqueItems,引入数组唯一性基于 schema 的归一化比较键;添加多项测试和若干测试桩类型。
源生成器与快照
GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs, GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs, GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfig.g.txt
生成器文档/注释输出现在包含 multipleOfuniqueItems 描述;测试 schema 与快照更新以反映新增约束元数据。
JS 工具链实现 & 测试
tools/gframework-config-tool/src/configValidation.js, tools/gframework-config-tool/test/configValidation.test.js
工具端解析并存储 multipleOf/uniqueItems(及编译后正则),实现精确十进制与容差的 multipleOf 校验及基于归一化键的 uniqueItems 检测;补充对应单元测试与本地化诊断项。
VS Code 扩展 & 本地化
tools/gframework-config-tool/src/extension.js, tools/gframework-config-tool/src/localization.js, tools/gframework-config-tool/src/localizationKeys.js
字段提示增加 multipleOf/uniqueItems/itemMultipleOf 显示;新增本地化键与验证消息 multipleOfViolationuniqueItemsViolation(中/英)。
文档与指南
docs/zh-CN/game/config-system.md, AGENTS.md
中文文档补充 multipleOfuniqueItems 的描述与判定说明;AGENTS.md 增补 WSL Git 使用建议与代码质量/文件大小规范。

Sequence Diagram(s)

sequenceDiagram
    rect rgba(220,220,235,0.5)
    participant User as 用户
    participant Loader as YAML 加载器
    participant Schema as Schema 解析器
    participant Validator as 验证器
    participant Reporter as 错误报告
    end

    User->>Loader: 提交 YAML 配置文件
    Loader->>Schema: 解析 schema 元数据(含 multipleOf/uniqueItems/pattern)
    Schema->>Validator: 传入节点与约束
    Validator->>Validator: 标量验证(pattern, multipleOf 精确/容差路径)
    Validator->>Validator: 数组项验证 -> 若项无错则构建归一化可比较键
    Validator->>Validator: uniqueItems 检测(发现重复 -> 记录首个与当前索引)
    alt multipleOf 违例
        Validator->>Reporter: 生成 multipleOf ConstraintViolation (路径/原始值)
        Reporter->>User: 返回验证错误
    end
    alt uniqueItems 违例
        Validator->>Reporter: 生成 uniqueItems ConstraintViolation (当前/先前索引)
        Reporter->>User: 返回验证错误
    end
    alt 验证通过
        Validator->>Reporter: 返回加载并注册的配置表
        Reporter->>User: 加载成功
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 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 PR标题「Feat/config schema generator and validation」涵盖了PR的核心变更内容:添加multipleOf和uniqueItems两个JSON Schema约束的运行时支持和代码生成器支持。标题准确反映了主要改动方向。
Docstring Coverage ✅ Passed Docstring coverage is 94.94% which is sufficient. The required threshold is 80.00%.

✏️ 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 feat/config-schema-generator-and-validation

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

@greptile-apps

greptile-apps Bot commented Apr 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR extends the shared configuration schema subset in GFramework's config system to include multipleOf (numeric step constraints) and uniqueItems (array deduplication) across three layers: the C# runtime validator (YamlConfigSchemaValidator), the VS Code extension tool (configValidation.js), and the Roslyn source generator (SchemaConfigGenerator). Both previous review thread concerns — the JS break vs continue in the uniqueItems loop and the C# tolerance formula using divisor instead of quotient — are addressed in this PR.

Key changes:

  • C# IsMultipleOf: Uses exact BigInteger decimal arithmetic for common decimal literals, falling back to a quotient-based floating-point tolerance (1e-9 × max(1, |quotient|)) that now matches the JS implementation.
  • JS uniqueItems: Uses continue (not break) when a duplicate is found, accumulating all duplicate diagnostics in a single pass.
  • buildComparableNodeValue / BuildComparableNodeValue: Both sides use length-prefixed encoding to avoid separator collisions in the comparable key for uniqueItems checks.
  • Source generator: Emits multipleOf and uniqueItems into XML doc remarks on generated properties so constraints are visible in the strongly-typed API.
  • Tests: C# runtime and JS tooling tests cover violation, pass, scientific notation, large decimal, and collision-resistance scenarios.

Confidence Score: 5/5

This PR is safe to merge — both previously flagged issues are resolved and no new bugs were found.

Both prior review concerns are addressed: the C# tolerance formula now matches JS by using Math.Max(1d, Math.Abs(quotient)), and the JS uniqueItems loop uses continue rather than break to accumulate all duplicates. The BigInteger exact-decimal path correctly handles the zero edge case. Test coverage is thorough across violation, pass, scientific notation, large-decimal precision, and key-collision scenarios. No security issues or data-loss risks identified.

No files require special attention.

Vulnerabilities

No security concerns identified. The BigInteger arithmetic paths in TryParseExactDecimal handle zero and empty-digit edge cases correctly before any parse operations. Input is bounded by double-precision schema values, preventing unbounded memory allocation in ScaleDecimalSignificand.

Important Files Changed

Filename Overview
GFramework.Game/Config/YamlConfigSchemaValidator.cs Adds multipleOf (BigInteger exact + quotient-tolerance fallback) and uniqueItems (length-prefixed comparable key + throw-on-first-duplicate) runtime validation. Zero-value edge case in TryParseExactDecimal is correctly guarded. Tolerance formula now matches JS implementation.
tools/gframework-config-tool/src/configValidation.js Adds multipleOf (exact BigInt decimal path + quotient-tolerance fallback) and uniqueItems (accumulates all duplicates via continue) validation. Both exact decimal paths and the tolerance formula are aligned with the C# runtime.
GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs Emits multipleOf and uniqueItems constraints into XML doc remarks for generated config properties; multipleOf only added when value > 0, consistent with schema validation rules.
GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs Adds comprehensive runtime tests for multipleOf violation, large decimal exact step, large non-multiple rejection, uniqueItems violation, and comparable-key collision resistance for nested objects.
tools/gframework-config-tool/test/configValidation.test.js Adds tests for multipleOf and uniqueItems parsing and validation, including multi-duplicate accumulation and comparable-key collision resistance for objects with separator characters.
tools/gframework-config-tool/src/extension.js Adds multipleOf and uniqueItems hint rendering in the form preview panel for both scalar fields and array item fields.
tools/gframework-config-tool/src/localization.js Adds localized strings for multipleOfViolation, uniqueItemsViolation, webview.hint.multipleOf, webview.hint.uniqueItems, and webview.hint.itemMultipleOf in both English and Simplified Chinese.
docs/zh-CN/game/config-system.md Updates documentation to include multipleOf and uniqueItems in the supported schema subset list and error detection list, with a working schema example.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[YAML Config File] --> B[YamlConfigSchemaValidator]
    S[JSON Schema File] --> B
    B --> C{Array Node?}
    C -- Yes --> D[ValidateArrayConstraints minItems / maxItems]
    D --> E[ValidateNode per item]
    E --> F[ValidateArrayUniqueItemsConstraint BuildComparableNodeValue per item]
    C -- No --> G{Scalar Node?}
    G -- Yes --> H[ValidateScalarConstraints]
    H --> I{multipleOf?}
    I -- Yes --> J[TryIsExactDecimalMultiple BigInteger exact path]
    J -- fails --> K[Quotient tolerance path 1e-9 x max1 quotient]
    J -- succeeds --> L[Return exact result]
    F --> M{Duplicate found?}
    M -- Yes --> N[throw ConstraintViolation]
    M -- No --> O[Add to seenItems map]
Loading

Reviews (5): Last reviewed commit: "docs(config): 添加游戏内容配置系统文档和验证工具" | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
tools/gframework-config-tool/test/configValidation.test.js (1)

422-446: 建议再补一条 items.multipleOf 的运行时校验断言。

当前这段只覆盖了 metadata 解析;建议再加 validateParsedConfig 的失败用例,避免元素级步进约束回归时漏检。

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

In `@tools/gframework-config-tool/test/configValidation.test.js` around lines 422
- 446, Add a runtime validation negative test that ensures the parsed schema's
items.multipleOf constraint is enforced by validateParsedConfig: after using
parseSchemaContent (parseSchemaContent) to produce schema with
properties.dropRates.items.multipleOf = 0.5, call validateParsedConfig with a
config containing a dropRates array containing a value that violates the 0.5
step (e.g., 0.3) and assert that validateParsedConfig throws or returns an
error; this complements the existing metadata assertions
(schema.properties.hp.multipleOf, schema.properties.dropRates.uniqueItems,
schema.properties.dropRates.items.multipleOf) by verifying the runtime
enforcement path (validateParsedConfig).
tools/gframework-config-tool/src/extension.js (1)

1617-1619: 建议把 multipleOf hint 条件收紧为“有限且大于 0”。

现在只判断 number,会让无效值也进入 UI hint;建议与其他层统一约束语义。

♻️ 建议修改
-    if (!isArrayField && typeof propertySchema.multipleOf === "number") {
+    if (!isArrayField &&
+        Number.isFinite(propertySchema.multipleOf) &&
+        propertySchema.multipleOf > 0) {
         hints.push(escapeHtml(localizer.t("webview.hint.multipleOf", {value: propertySchema.multipleOf})));
     }
@@
-    if (isArrayField && propertySchema.items && typeof propertySchema.items.multipleOf === "number") {
+    if (isArrayField &&
+        propertySchema.items &&
+        Number.isFinite(propertySchema.items.multipleOf) &&
+        propertySchema.items.multipleOf > 0) {
         hints.push(escapeHtml(localizer.t("webview.hint.itemMultipleOf", {value: propertySchema.items.multipleOf})));
     }

Also applies to: 1661-1663

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

In `@tools/gframework-config-tool/src/extension.js` around lines 1617 - 1619, The
current check that pushes the multipleOf hint uses only typeof
propertySchema.multipleOf === "number", which allows NaN/Infinity/<=0; update
the condition around the hints.push call (the block using isArrayField and
propertySchema.multipleOf) to require Number.isFinite(propertySchema.multipleOf)
&& propertySchema.multipleOf > 0 before calling
hints.push(escapeHtml(localizer.t(...))); apply the same tightened condition to
the duplicate block that also handles multipleOf at the other occurrence
referenced (lines ~1661-1663).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/zh-CN/game/config-system.md`:
- Line 810: The doc currently overclaims that `multipleOf / uniqueItems` are
shown in both 表单入口 and 批量编辑入口; update the sentence that lists `title /
description / default / enum / ref-table / multipleOf / uniqueItems` to restrict
`multipleOf` and `uniqueItems` to only the 表单入口 (or explicitly state what subset
is shown in 批量编辑入口), replacing the ambiguous "表单和批量编辑入口中显示" phrasing with a
clear statement that the form entry shows all listed metadata while the
batch-edit entry shows only the specific fields you want to support.

---

Nitpick comments:
In `@tools/gframework-config-tool/src/extension.js`:
- Around line 1617-1619: The current check that pushes the multipleOf hint uses
only typeof propertySchema.multipleOf === "number", which allows
NaN/Infinity/<=0; update the condition around the hints.push call (the block
using isArrayField and propertySchema.multipleOf) to require
Number.isFinite(propertySchema.multipleOf) && propertySchema.multipleOf > 0
before calling hints.push(escapeHtml(localizer.t(...))); apply the same
tightened condition to the duplicate block that also handles multipleOf at the
other occurrence referenced (lines ~1661-1663).

In `@tools/gframework-config-tool/test/configValidation.test.js`:
- Around line 422-446: Add a runtime validation negative test that ensures the
parsed schema's items.multipleOf constraint is enforced by validateParsedConfig:
after using parseSchemaContent (parseSchemaContent) to produce schema with
properties.dropRates.items.multipleOf = 0.5, call validateParsedConfig with a
config containing a dropRates array containing a value that violates the 0.5
step (e.g., 0.3) and assert that validateParsedConfig throws or returns an
error; this complements the existing metadata assertions
(schema.properties.hp.multipleOf, schema.properties.dropRates.uniqueItems,
schema.properties.dropRates.items.multipleOf) by verifying the runtime
enforcement path (validateParsedConfig).
🪄 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: 07ec0ab1-1554-48cd-80a6-4de288a7de19

📥 Commits

Reviewing files that changed from the base of the PR and between 73d2577 and f5317ed.

📒 Files selected for processing (11)
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfig.g.txt
  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
  • docs/zh-CN/game/config-system.md
  • tools/gframework-config-tool/src/configValidation.js
  • tools/gframework-config-tool/src/extension.js
  • tools/gframework-config-tool/src/localization.js
  • tools/gframework-config-tool/src/localizationKeys.js
  • tools/gframework-config-tool/test/configValidation.test.js
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. 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 (6)
**/*.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 in C# code
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 comments
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds, compatibility constraints, edge cases, registration order, lifecycle sequencing, or generated code assumptions
Avoid obvious comments such as // increment i in C# code
Generated logic and source 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 in C# code
Comments MUST NOT be trivial, redundant, or misleading; prefer explaining why and when, not just what
Missing required documentation is a coding standards violation in C# code
Do not rely on implicit imports in C# code; declare every required using explicitly
Write null-safe C# code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase ...

Files:

  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
**/*SourceGenerators.Tests/**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*SourceGenerators.Tests/**/*.cs: Source generator changes MUST be covered by generator tests
Preserve snapshot-based verification patterns already used in the repository for source generator tests

Files:

  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
**/*SourceGenerators/**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

**/*SourceGenerators/**/*.cs: When source generator behavior changes intentionally, update snapshots together with the implementation
Keep source generators deterministic and free of hidden environment or network dependencies

Files:

  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
docs/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Documentation must be located in docs/ directory with Chinese content in docs/zh-CN/

Files:

  • docs/zh-CN/game/config-system.md
{README.md,docs/**/*.md,docs/zh-CN/**/*.md}

📄 CodeRabbit inference engine (AGENTS.md)

{README.md,docs/**/*.md,docs/zh-CN/**/*.md}: Update the relevant README.md or docs/ page when behavior, setup steps, architecture guidance, or user-facing examples change
Keep code samples, package names, and command examples in documentation aligned with the current repository state
Prefer documenting behavior and design intent in documentation, not only API surface
For integration-oriented features such as the AI-First config system, documentation MUST cover project directory layout and file conventions, required project or package wiring, minimal working usage example, and migration or compatibility notes when behavior changes

Files:

  • docs/zh-CN/game/config-system.md
docs/zh-CN/**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create the corresponding user-facing integration documentation in docs/zh-CN/ in the same change

Files:

  • docs/zh-CN/game/config-system.md
🧠 Learnings (11)
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
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/Config/SchemaConfigGeneratorSnapshotTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*SourceGenerators.Tests/**/*.cs : Source generator changes MUST be covered by generator tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*SourceGenerators/**/*.cs : When source generator behavior changes intentionally, update snapshots together with the implementation

Applied to files:

  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfig.g.txt
  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
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/Config/SchemaConfigGeneratorSnapshotTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : 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/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.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/Config/SchemaConfigGeneratorSnapshotTests.cs
  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Any change to public API, lifecycle semantics, module behavior, or extension points MUST update the related XML docs in C#

Applied to files:

  • GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Generated logic and source 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/Config/SchemaConfigGenerator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to docs/zh-CN/**/*.md : When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create the corresponding user-facing integration documentation in `docs/zh-CN/` in the same change

Applied to files:

  • docs/zh-CN/game/config-system.md
🪛 LanguageTool
docs/zh-CN/game/config-system.md

[uncategorized] ~709-~709: 您的意思是“"不"进”?
Context: ...和生成代码 XML 文档复用;当前按运行时与 JS 共用的浮点容差策略判断十进制步进 - minLength / maxLength:供运行时校验、VS ...

(BU)

🔇 Additional comments (8)
tools/gframework-config-tool/src/localizationKeys.js (1)

13-18: 新增校验键与调用侧保持一致,没问题。

这两个 key 与校验分支和本地化字典的新增项对齐,风险低。

GFramework.SourceGenerators.Tests/Config/SchemaConfigGeneratorSnapshotTests.cs (1)

95-103: 测试样例补充了新约束分支,方向正确。

multipleOf / uniqueItems 放进 schema 样本能有效驱动快照验证。

GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfig.g.txt (1)

37-48: 快照内容与新约束文档输出一致。

HpDropItems 的约束文本更新准确,能覆盖本次生成器改动。

tools/gframework-config-tool/src/localization.js (1)

112-123: 本地化补充完整且中英文对齐。

新增提示文案与诊断文案都已覆盖,参数占位符也匹配调用侧。

Also applies to: 138-142, 216-227, 242-246

GFramework.SourceGenerators/Config/SchemaConfigGenerator.cs (1)

9-10: 约束文档生成逻辑更新合理,和快照结果一致。

multipleOfuniqueItems 的输出条件明确,生成侧行为可预期。

Also applies to: 2435-2435, 2468-2473, 2506-2511

GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs (1)

513-559: 新增回归测试覆盖点完整。

这两组测试不仅验证了异常抛出,还把 FailureKindDisplayPathRawValue 和注册表不变性一起锁住了,能比较稳地防住 multipleOf / uniqueItems 的回归。

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

Also applies to: 813-865

GFramework.Game/Config/YamlConfigSchemaValidator.cs (2)

928-960: multipleOf 的解析、校验和诊断串起来了。

这里把 schema 解析、容差比较和 ConstraintViolation 诊断闭环补齐了,和现有运行时错误模型衔接得比较干净。

Also applies to: 1317-1329, 1575-1589, 2003-2067


609-609: uniqueItems 的运行时比较模型设计合理。

去重检查放在元素递归校验之后,并且比较键显式规避了对象字段顺序与标量格式差异,这个方向和运行时一致性目标是对的。

Also applies to: 1438-1573, 2089-2121

Comment thread docs/zh-CN/game/config-system.md Outdated
Comment thread tools/gframework-config-tool/src/configValidation.js
Comment thread tools/gframework-config-tool/src/configValidation.js Outdated
Comment thread tools/gframework-config-tool/src/configValidation.js
GeWuYou added 2 commits April 9, 2026 19:23
- 新增游戏内容配置系统完整文档,涵盖 YAML 配置、JSON Schema 结构、目录组织等
- 添加 Schema 示例和 YAML 示例,说明怪物、物品等静态数据配置方式
- 提供推荐接入模板,包括目录结构、csproj 配置和启动代码模板
- 实现官方启动帮助器 GameConfigBootstrap 与 GameConfigModule 集成
- 添加运行时读取模板,提供强类型配置访问入口
- 实现生成查询辅助功能,支持 FindBy* 和 TryFindFirstBy* 查询接口
- 提供 Architecture 推荐接入模板,支持模块化配置管理
- 添加热重载模板,支持开发期配置文件自动刷新
- 实现运行时接入方案,提供只读表形式的配置访问
- 添加运行时校验行为说明,支持跨表引用和数据完整性检查
- 实现开发期热重载功能,支持配置变更自动重载
- 添加生成器接入约定,自动生成配置类型和表包装代码
- 提供 VS Code 工具支持,包括配置浏览、表单编辑和批量更新功能
- 实现配置验证工具,支持 JSON Schema 子集解析和 YAML 校验功能
- 定义了环境能力清单和工具选择规则
- 规定了XML文档注释、内联注释和架构级注释要求
- 明确了代码风格包括命名约定、格式化和C#惯例
- 设立了测试覆盖范围、组织结构和验证命令标准
- 制定了安全规则防止输入验证和敏感数据泄露
- 规范了代码文档、任务跟踪和仓库文档更新流程
- 建立了审查标准确保代码质量和完整性

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tools/gframework-config-tool/src/configValidation.js (1)

933-940: 对象属性排序使用 localeCompare 与 C# 端存在细微差异。

C# 实现使用 string.CompareOrdinal 进行排序(见 YamlConfigSchemaValidator.cs:1676),而此处使用 localeCompare。对于 ASCII 字符集的属性名,两者行为一致;但对于包含非 ASCII 字符或特殊 Unicode 字符的属性名,排序结果可能不同,从而导致生成的比较键不同。

鉴于 JSON Schema 属性名通常为 ASCII 标识符,此差异在实际使用中不太可能造成问题。

♻️ 可选:改用字节序比较以完全对齐 C# 行为
 return Object.keys(schemaNode.properties)
     .filter((key) => yamlNode.map.has(key))
-    .sort((left, right) => left.localeCompare(right))
+    .sort((left, right) => {
+        if (left < right) return -1;
+        if (left > right) return 1;
+        return 0;
+    })
     .map((key) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/gframework-config-tool/src/configValidation.js` around lines 933 - 940,
The sorting currently uses localeCompare which can differ from C#'s
string.CompareOrdinal; change the comparator inside the block that builds the
comparison key (the Object.keys(...).sort(...) chain) to use a code-unit
(ordinal) comparison instead of localeCompare — e.g., replace .sort((left,
right) => left.localeCompare(right)) with a comparator that returns left ===
right ? 0 : left < right ? -1 : 1 so the ordering matches C#'s ordinal behavior
when building the string in buildComparableNodeValue/map handling.
GFramework.Game/Config/YamlConfigSchemaValidator.cs (1)

423-429: references 的可空约定补进这些递归方法的 XML 注释。

这里的签名已经允许 referencesnull,但 <param name="references"> 仍然像是在描述一个始终存在的“已收集引用”集合,和 ValidateCore(...) 的契约不一致。后续维护时很容易把它误当成非空参数。

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

Also applies to: 469-475, 565-571, 623-629

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

In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs` around lines 423 - 429,
Update the XML doc comments for the recursive validation methods so the <param
name="references"> clearly states that the references argument is nullable: when
null the method will not collect/populate references, callers must not assume a
non-null collection, and behavior matches the contract of ValidateCore(...);
apply this change to ValidateNode and the other recursive validation overloads
that accept ICollection<YamlConfigReferenceUsage>? references so the
documentation explains intent, usage constraints, and nullability rather than
restating the signature.
🤖 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.Game/Config/YamlConfigSchemaValidator.cs`:
- Around line 1754-1759: IsMultipleOf currently scales tolerance by the
magnitude of the quotient which lets very large values pass; change it to scale
by the divisor (step) or the remainder scale instead. In IsMultipleOf(double
value, double divisor) compute the nearest integer multiple (e.g., quotient and
nearestInteger as you already do), then compute the remainder as value -
nearestInteger * divisor and set tolerance = 1e-9 * Math.Max(1d,
Math.Abs(divisor)); finally return Math.Abs(remainder) <= tolerance (or also
accept Math.Abs(remainder - divisor) <= tolerance to handle sign), so the
tolerance is tied to the step size rather than the quotient magnitude.

---

Nitpick comments:
In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs`:
- Around line 423-429: Update the XML doc comments for the recursive validation
methods so the <param name="references"> clearly states that the references
argument is nullable: when null the method will not collect/populate references,
callers must not assume a non-null collection, and behavior matches the contract
of ValidateCore(...); apply this change to ValidateNode and the other recursive
validation overloads that accept ICollection<YamlConfigReferenceUsage>?
references so the documentation explains intent, usage constraints, and
nullability rather than restating the signature.

In `@tools/gframework-config-tool/src/configValidation.js`:
- Around line 933-940: The sorting currently uses localeCompare which can differ
from C#'s string.CompareOrdinal; change the comparator inside the block that
builds the comparison key (the Object.keys(...).sort(...) chain) to use a
code-unit (ordinal) comparison instead of localeCompare — e.g., replace
.sort((left, right) => left.localeCompare(right)) with a comparator that returns
left === right ? 0 : left < right ? -1 : 1 so the ordering matches C#'s ordinal
behavior when building the string in buildComparableNodeValue/map handling.
🪄 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: 2ce219b7-43d0-47c2-8ddd-1d78fa60d482

📥 Commits

Reviewing files that changed from the base of the PR and between f5317ed and f9f608a.

📒 Files selected for processing (6)
  • AGENTS.md
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
  • docs/zh-CN/game/config-system.md
  • tools/gframework-config-tool/src/configValidation.js
  • tools/gframework-config-tool/test/configValidation.test.js
✅ Files skipped from review due to trivial changes (1)
  • AGENTS.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. 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 (5)
**/*.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

All public, protected, and internal types and members MUST include XML documentation comments (///) with <summary>, <param>, <returns>, <exception>, and <remarks> 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/compatibility constraints, and registration/lifecycle sequencing

Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling

Comments MUST NOT be trivial, redundant, or misleading; prefer explaining why and when, not just what

Do not rely on implicit imports; declare every required using explicitly

Write null-safe code that respects nullable annotations instead of suppressing warnings by default

Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments

Use PascalCase for types, methods, properties, events, and constants in C#

Use I prefix for interface names in C#

Use camelCase for parameters and locals in C#

Use _camelCase for private fields in C#

Use 4 spaces for indentation in C# code; do not use tabs

Use Allman braces in C# code

Keep using directives at the top of the file and sort them consistently in C#

Separate logical b...

Files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
docs/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Documentation must be located in docs/ directory with Chinese content in docs/zh-CN/

Files:

  • docs/zh-CN/game/config-system.md
{README.md,docs/**/*.md,docs/zh-CN/**/*.md}

📄 CodeRabbit inference engine (AGENTS.md)

Update the relevant README.md or docs/ page when behavior, setup steps, architecture guidance, or user-facing examples change

Keep code samples, package names, and command examples aligned with the current repository state in documentation

Prefer documenting behavior and design intent, not only API surface in documentation

Files:

  • docs/zh-CN/game/config-system.md
docs/zh-CN/**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create corresponding user-facing integration documentation in docs/zh-CN/

Files:

  • docs/zh-CN/game/config-system.md
{docs/**/*.md,docs/zh-CN/**/*.md}

📄 CodeRabbit inference engine (AGENTS.md)

For integration-oriented features, documentation MUST cover: project directory layout and file conventions, required project/package wiring, minimal working usage example, and migration/compatibility notes

Do not rely on 'the code is self-explanatory' for framework features that consumers need to adopt; write the adoption path down

Files:

  • docs/zh-CN/game/config-system.md
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Read `@.ai/environment/tools.ai.yaml` before choosing runtimes or CLI tools
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Prefer Windows Git from WSL (for example `git.exe`) instead of the Linux `git` binary when working in WSL against this repository's Windows-backed worktree
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Core framework components (Architecture, Module, System, Context, Registry, Service Module, Lifecycle types) MUST include high-level explanations of responsibilities, lifecycle, component interactions, abstraction rationale, and usage alternatives
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Keep abstractions projects free of implementation details and engine-specific dependencies
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Preserve existing module boundaries; do not introduce new cross-module dependencies without clear architectural need
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Treat Meziantou.Analyzer feedback as part of the coding standard
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Treat SonarQube maintainability rules (especially cognitive complexity and oversized parameter list findings) as part of the coding standard
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Naming must remain compatible with `scripts/validate-csharp-naming.sh`
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Public API changes must be covered by unit or integration tests
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Mirror the source structure in test projects whenever practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: When working from a tracked implementation plan, contributors MUST update the corresponding tracking document under `local-plan/todos/` in the same change
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:24:14.769Z
Learning: Tracking updates MUST reflect completed work, newly discovered issues, validation results, and the next recommended recovery point
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : 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.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Keep tests focused on observable behavior, not implementation trivia

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.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.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to docs/zh-CN/**/*.md : When a feature is added, removed, renamed, or substantially refactored, contributors MUST update or create the corresponding user-facing integration documentation in `docs/zh-CN/` in the same change

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : Prefer documenting behavior and design intent in documentation, not only API surface

Applied to files:

  • docs/zh-CN/game/config-system.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : For integration-oriented features such as the AI-First config system, documentation MUST cover project directory layout and file conventions, required project or package wiring, minimal working usage example, and migration or compatibility notes when behavior changes

Applied to files:

  • docs/zh-CN/game/config-system.md
🪛 LanguageTool
docs/zh-CN/game/config-system.md

[uncategorized] ~709-~709: 您的意思是“"不"进”?
Context: ...和生成代码 XML 文档复用;当前按运行时与 JS 共用的浮点容差策略判断十进制步进 - minLength / maxLength:供运行时校验、VS ...

(BU)

🔇 Additional comments (10)
docs/zh-CN/game/config-system.md (1)

709-714: 文档描述与实现一致,静态分析为误报。

"步进"在此处是正确的技术术语,用于描述 multipleOf 的数值步进校验行为。该词汇与 YamlConfigSchemaValidator.csIsMultipleOf 方法的实现(使用浮点容差判断商是否为整数)相符。

关于 uniqueItems 使用"schema 归一化后的结构比较"的描述,也与 context snippet 3-4 中 BuildComparableObjectValue 的字段排序和长度前缀编码实现一致。

tools/gframework-config-tool/test/configValidation.test.js (3)

311-350: 测试覆盖全面,LGTM。

新增的测试用例覆盖了关键场景:

  • multipleOf 约束违规检测(hp: 12 不满足 multipleOf: 5
  • uniqueItems 去重检测,且验证了对象字段顺序不影响重复判定(wave: 1, monsterId: slimemonsterId: slime, wave: 1 被正确识别为重复项)

389-418: 元素校验失败时跳过 uniqueItems 检查的逻辑已正确实现。

此测试确保当数组元素本身存在类型错误(如 integer[] 中放入对象)时,不会额外产生误导性的 uniqueItemsViolation 诊断。这与之前的 review 反馈一致。


450-479: 可比较键碰撞回归测试覆盖了边界情况。

测试用例 { a: "x|1:b=string:yz" }{ a: "x", b: "yz" } 验证了长度前缀编码能够正确区分这两个不同的对象,避免误报重复。这与 C# 端 BuildComparableObjectValue 的实现保持一致。

GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs (3)

513-559: multipleOf 约束测试覆盖完整,LGTM。

测试验证了:

  • hp: 12 不满足 multipleOf: 5 时抛出 ConfigLoadException
  • 诊断信息包含正确的 FailureKind.ConstraintViolationDisplayPath: hpRawValue: 12
  • 注册表保持为空,未出现部分加载

854-906: uniqueItems 约束测试验证了关键行为。

测试确认:

  • 重复元素 dropRates: [5, 10, 5] 被正确拒绝
  • DisplayPath 指向第二个重复项 dropRates[2]
  • 错误消息包含 "unique array items" 关键词

908-968: 可比较键归一化回归测试与 JS 端保持一致。

此测试用例验证了包含分隔符字符的字符串值(如 "x|1:b=string:yz")不会与结构不同的对象({ a: "x", b: "yz" })产生键碰撞。这确保了运行时与工具端的 uniqueItems 行为一致。

tools/gframework-config-tool/src/configValidation.js (3)

9-11: 正则表达式常量抽取提升了可维护性。

IntegerScalarPatternNumberScalarPatternBooleanScalarPattern 提取为模块级常量,避免了每次调用 isScalarCompatibleformatYamlScalar 时重复创建正则对象。NumberScalarPattern 正确支持科学计数法格式。


683-717: uniqueItems 校验逻辑已正确实现跳过无效元素的行为。

通过在子项校验后检查 diagnostics.length 是否变化(lines 685-697),只有校验通过的元素才会参与去重比较。这避免了类型错误的元素被压成同一个比较键后误报 uniqueItemsViolation

此实现与之前的 review 反馈一致。


484-494: multipleOf 校验使用与运行时一致的浮点容差策略。

容差公式 1e-9 * Math.max(1, Math.abs(quotient))YamlConfigSchemaValidator.cs:1757-1760 中的 C# 实现完全一致,确保了工具端与运行时对边界情况的判定行为相同。

Comment thread GFramework.Game/Config/YamlConfigSchemaValidator.cs Outdated
- 定义了环境能力清单和工具选择规则
- 规定了XML文档注释、内联注释和架构级注释要求
- 明确了代码风格包括命名规范、格式化和C#约定
- 设立了测试覆盖范围、组织结构和验证命令标准
- 制定了安全输入验证、依赖管理和权限控制规则
- 确立了文档更新、任务跟踪和审查完成标准
- 更新了浮点数比较算法中的容差计算方式
- 优化了数值精度验证逻辑以避免十进制步进误差

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
AGENTS.md (1)

125-133: 详细且可操作的复杂度治理指导

新增的 SonarQube 可维护性规则建立了清晰的重构策略:

  • 按语义阶段(解析、规范化、验证、诊断)提取方法来降低认知复杂度
  • 针对参数数量问题选择合适的重构方式(值对象、参数对象、命名工厂)
  • 严格限制抑制告警,除非有外部约束并记录原因

这些指导具体且实用,适合高质量框架项目的标准。

📋 可选建议:补充 SonarQube 工具使用说明

文档在"Validation Commands"部分(第 164 行起)中可以考虑补充如何在本地检查 SonarQube 合规性的说明,或明确说明 SonarQube 在 CI 中运行,开发者应关注 CI 反馈。这样可以让贡献者更清楚如何验证是否符合新增的可维护性标准。

例如:

# Check SonarQube maintainability rules (if configured locally)
# Note: SonarQube analysis runs in CI; review CI feedback for compliance
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` around lines 125 - 133, Summary: The PR adds detailed, actionable
SonarQube maintainability guidance but also suggests optionally documenting how
to locally verify those rules; update the doc accordingly. Edit the "SonarQube
maintainability rules" section to explicitly list the recommended refactor
strategies (extract helpers by semantic phase:
parsing/normalization/validation/diagnostics; prefer domain value objects or
parameter objects for long parameter lists; use named factory methods for
different creation modes; avoid suppressions unless externally required and
documented) and make the language prescriptive and concise; additionally, under
the "Validation Commands" heading add a short note showing how to check
SonarQube maintainability rules locally (or state that analysis runs in CI and
developers should review CI results) so contributors know how to validate
compliance.
GFramework.Game/Config/YamlConfigSchemaValidator.cs (2)

1307-1325: 建议为正则表达式添加超时保护。

当前 Regex 创建未设置 MatchTimeout,若 schema 中包含恶意或复杂正则模式,可能导致 ReDoS。虽然 schema 文件通常可信,但添加超时是更安全的防御性做法。

♻️ 可选:添加正则超时
 private static YamlConfigStringConstraints? CreateStringScalarConstraints(
     int? minLength,
     int? maxLength,
     string? pattern)
 {
     return !minLength.HasValue &&
            !maxLength.HasValue &&
            pattern is null
         ? null
         : new YamlConfigStringConstraints(
             minLength,
             maxLength,
             pattern,
             pattern is null
                 ? null
                 : new Regex(
                     pattern,
-                    SupportedPatternRegexOptions));
+                    SupportedPatternRegexOptions,
+                    TimeSpan.FromSeconds(1)));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs` around lines 1307 -
1325, The Regex constructed in CreateStringScalarConstraints lacks a match
timeout, risking ReDoS for complex patterns; update
CreateStringScalarConstraints to pass a sensible MatchTimeout when instantiating
new Regex (use the Regex(TimeSpan) overload) and surface that timeout into the
YamlConfigStringConstraints (or add a private constant like PatternMatchTimeout)
so callers use the bounded Regex; update the Regex creation site in
CreateStringScalarConstraints and the YamlConfigStringConstraints
constructor/signature as needed to accept and store the timeout-protected Regex
while keeping SupportedPatternRegexOptions unchanged.

1-13: 文件长度超出建议上限。

当前文件约 2558 行,显著超出编码规范建议的 800-1000 行上限。考虑将模型类(YamlConfigSchemaYamlConfigSchemaNode、约束类等)拆分到独立文件如 YamlConfigSchemaModels.cs,保持验证器逻辑的聚焦。

As per coding guidelines: "Keep a single source file under roughly 800-1000 lines; if it grows beyond that range, stop and check whether responsibilities should be split before continuing."

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

In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs` around lines 1 - 13, The
file YamlConfigSchemaValidator.cs is too large (~2558 lines); split model and
constraint types out of it so the validator stays focused: move classes like
YamlConfigSchema, YamlConfigSchemaNode and any constraint/model types into a new
file (e.g., YamlConfigSchemaModels.cs) or multiple files, keep
YamlConfigSchemaValidator as the logic-only class, preserve namespaces and
internal accessibility, update using/imports and remove duplicate usings, and
ensure all references in methods of YamlConfigSchemaValidator still point to the
moved types and compile (run tests/build to verify).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@AGENTS.md`:
- Around line 125-133: Summary: The PR adds detailed, actionable SonarQube
maintainability guidance but also suggests optionally documenting how to locally
verify those rules; update the doc accordingly. Edit the "SonarQube
maintainability rules" section to explicitly list the recommended refactor
strategies (extract helpers by semantic phase:
parsing/normalization/validation/diagnostics; prefer domain value objects or
parameter objects for long parameter lists; use named factory methods for
different creation modes; avoid suppressions unless externally required and
documented) and make the language prescriptive and concise; additionally, under
the "Validation Commands" heading add a short note showing how to check
SonarQube maintainability rules locally (or state that analysis runs in CI and
developers should review CI results) so contributors know how to validate
compliance.

In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs`:
- Around line 1307-1325: The Regex constructed in CreateStringScalarConstraints
lacks a match timeout, risking ReDoS for complex patterns; update
CreateStringScalarConstraints to pass a sensible MatchTimeout when instantiating
new Regex (use the Regex(TimeSpan) overload) and surface that timeout into the
YamlConfigStringConstraints (or add a private constant like PatternMatchTimeout)
so callers use the bounded Regex; update the Regex creation site in
CreateStringScalarConstraints and the YamlConfigStringConstraints
constructor/signature as needed to accept and store the timeout-protected Regex
while keeping SupportedPatternRegexOptions unchanged.
- Around line 1-13: The file YamlConfigSchemaValidator.cs is too large (~2558
lines); split model and constraint types out of it so the validator stays
focused: move classes like YamlConfigSchema, YamlConfigSchemaNode and any
constraint/model types into a new file (e.g., YamlConfigSchemaModels.cs) or
multiple files, keep YamlConfigSchemaValidator as the logic-only class, preserve
namespaces and internal accessibility, update using/imports and remove duplicate
usings, and ensure all references in methods of YamlConfigSchemaValidator still
point to the moved types and compile (run tests/build to verify).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4399994b-74b4-4340-8d55-eea9d94a3965

📥 Commits

Reviewing files that changed from the base of the PR and between f9f608a and ccb6b5a.

📒 Files selected for processing (2)
  • AGENTS.md
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. 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 (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

All public, protected, and internal types and members MUST include XML documentation comments (///) with <summary>, <param>, <returns>, <exception>, and <remarks> tags where applicable

Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds, compatibility constraints, edge cases, registration order, lifecycle sequencing, and generated code assumptions

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 include comments explaining what is generated, why it is generated, 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

Do not rely on implicit imports; declare every required using explicitly, following the repository defaults of ImplicitUsings disabled

Write null-safe code that respects nullable annotations instead of suppressing warnings by default, following the repository default of Nullable enabled

Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments

Follow standard C# naming: types, methods, properties, events, and consta...

Files:

  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
🧠 Learnings (25)
📓 Common learnings
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Before choosing runtimes or CLI tools, read `@.ai/environment/tools.ai.yaml` to verify tool availability before using them
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Prefer Windows Git from WSL (e.g., `git.exe`) instead of the Linux `git` binary when working in WSL against a Windows-backed worktree
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Public API changes must be covered by unit or integration tests
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: 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
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Regression fixes should include a test that fails before the fix and passes after it
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Mirror the source structure in test projects whenever practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Reuse existing architecture test infrastructure when relevant: `ArchitectureTestsBase<T>`, `SyncTestArchitecture`, `AsyncTestArchitecture`
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Keep tests focused on observable behavior, not implementation trivia
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: When generator behavior changes intentionally, update snapshots together with the implementation
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Validate external or user-controlled input before it reaches file system, serialization, reflection, code generation, or process boundaries
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Do not build command strings, file paths, type names, or generated code from untrusted input without strict validation or allow-listing
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Avoid logging secrets, tokens, credentials, or machine-specific sensitive data
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Keep source generators deterministic and free of hidden environment or network dependencies
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Prefer least-privilege behavior for file, process, and environment access
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Do not introduce unsafe deserialization, broad reflection-based activation, or dynamic code execution unless it is explicitly required and tightly constrained
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Minimize new package dependencies; add them only when necessary and keep scope narrow
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Keep abstractions projects free of implementation details and engine-specific dependencies
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:44:13.350Z
Learning: Preserve existing module boundaries; do not introduce new cross-module dependencies without clear architectural need
📚 Learning: 2026-04-05T15:30:46.211Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-05T15:30:46.211Z
Learning: Follow all coding rules defined in AGENTS.md

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to {README.md,docs/**/*.md,docs/zh-CN/**/*.md} : For integration-oriented features such as the AI-First config system, documentation MUST cover project directory layout and file conventions, required project or package wiring, minimal working usage example, and migration or compatibility notes when behavior changes

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Use `@.ai/environment/tools.raw.yaml` only when needing full collected facts behind AI-facing hints

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Read `@.ai/environment/tools.ai.yaml` before choosing runtimes or CLI tools

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Prefer project-relevant tools listed in environment inventory instead of assuming every installed system tool is available

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Comments MUST NOT be trivial, redundant, or misleading; prefer explaining why and when, not just what

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Keep line length readable in C# code; around 120 characters is the preferred upper bound

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Keep `using` directives at the top of C# files and sort them consistently

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Separate logical blocks with blank lines in C# code when it improves readability

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Prefer one primary type per C# file unless the surrounding project already uses a different local pattern

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Prefer explicit, readable code over clever shorthand in C# framework internals

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds, compatibility constraints, edge cases, registration order, lifecycle sequencing, or generated code assumptions

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Follow standard C# naming: Types, methods, properties, events, constants in PascalCase; interfaces with `I` prefix; parameters and locals in camelCase; private fields in `_camelCase`

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling in C# code

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Missing required documentation is a coding standards violation in C# code

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Do not rely on implicit imports in C# code; declare every required `using` explicitly

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : The repository uses `Meziantou.Analyzer`; treat analyzer feedback as part of the coding standard in C#

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : When adding analyzers or suppressions in C#, keep them minimal and justify them in code comments if the reason is not obvious

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Naming must remain compatible with `scripts/validate-csharp-naming.sh`

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : 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:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Public API changes must be covered by unit or integration tests

Applied to files:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
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:

  • AGENTS.md
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.cs : Generated logic and source 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:

  • AGENTS.md
📚 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.Game/Config/YamlConfigSchemaValidator.cs
🔇 Additional comments (11)
AGENTS.md (2)

13-16: 实用的 WSL Git 配置指导

这条新增的指导清晰地解决了 WSL 环境下使用 Windows 后端工作树的路径转换问题,提供了明确的回退策略。建议合理且可操作。


107-110: 合理的文件大小可维护性指导

新增的 800-1000 行软性限制是合理的可维护性实践。措辞恰当地保持了灵活性("roughly"、"clear and documented reason"),同时明确将超大文件视为设计问题的信号,有助于保持代码库的可维护性。

GFramework.Game/Config/YamlConfigSchemaValidator.cs (9)

10-11: LGTM!

类级别文档更新准确反映了新增的 multipleOfuniqueItems 约束支持。


132-154: 重构合理,避免重复解析。

ValidateCore 抽取为共享入口,Validate 路径传 null 避免不必要的列表分配,ValidateAndCollectReferences 按需收集引用。逻辑清晰,符合 DRY 原则。


919-952: LGTM!

TryParseMultipleOfConstraint 正确校验 multipleOf 必须为正数,符合 JSON Schema 规范。复用 TryParseNumericConstraint 避免代码重复。


1099-1130: LGTM!

TryParseUniqueItemsConstraint 正确解析布尔型 uniqueItems 约束,未声明时返回 false 作为默认值。


1575-1621: LGTM!

ValidateArrayUniqueItemsConstraint 实现正确:

  • 使用字典记录已见元素及其索引,O(n) 时间复杂度
  • 错误信息同时报告重复项索引和先前出现的索引,便于定位问题
  • StringComparer.Ordinal 确保一致的比较行为

1651-1681: 规范化键设计合理。

BuildComparableObjectValue 按属性名排序忽略 YAML 字段顺序,使用长度前缀编码 ({keyLen}:{key}={valueLen}:{value}) 避免分隔符冲突。递归构建确保嵌套对象也能正确比较。


1746-1761: 先前评审问题已修复。

IsMultipleOf 现在正确地将容差绑定到步进量级 (divisor) 而非商值 (quotient),并通过 Math.Abs(value - (nearestInteger * divisor)) 比较实际余数。这避免了大数值误判为合法倍数的问题。


2074-2165: 重构改善了内聚性和参数数量。

YamlConfigSchemaNode 拆分为 NodeChildren(结构信息)和 NodeValidation(校验约束)两个嵌套类:

  • 静态工厂方法 (CreateObject/CreateArray/CreateScalar) 使创建意图更清晰
  • 私有构造函数强制使用工厂方法
  • None 静态实例避免重复分配空状态
  • 符合 SonarQube 参数数量限制的编码规范

2316-2368: LGTM!

YamlConfigNumericConstraints 将数值约束(区间与步进)从标量约束中独立出来,避免字符串字段暴露不相关成员,符合单一职责原则。

coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 9, 2026
Comment thread GFramework.Game/Config/YamlConfigSchemaValidator.cs Outdated
- 验证YAML文件扫描和注册表写入功能
- 测试带schema校验的配置表注册选项对象支持
- 验证空配置表注册选项的异常处理
- 测试配置目录不存在时的错误抛出
- 验证配置表加载失败时注册表状态回滚
- 测试非法YAML文件的反序列化错误处理
- 验证schema校验对必填字段缺失的检查
- 测试schema校验对类型不匹配的检查
- 验证schema校验对枚举值限制的支持
- 测试数值范围约束的校验功能
- 验证数值exclusive min/max约束
- 测试multipleOf约束校验
- 验证大数值和科学计数法支持
- 测试字符串长度和正则模式约束
- 验证数组元素数量和唯一性约束
- 测试未知字段检测和错误处理
- 验证嵌套对象和数组的递归校验
- 测试跨表引用校验功能

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
GFramework.Game/Config/YamlConfigSchemaValidator.cs (1)

1746-1760: ⚠️ Potential issue | 🟠 Major

multipleOf 的容差仍然按商值放大,会把明显非法的大数判成合法。

这里的容差跟 |value / divisor| 绑定,值越大,允许误差就越大。结果是 multipleOf: 1 这类最严格的步进,在大数量级下也会放过诸如 1000000000000.4 这样的非法值。容差应该绑定到“步进/余数”的尺度,而不是绑定到商值本身。

🛠️ 可行修正
 private static bool IsMultipleOf(double value, double divisor)
 {
     var quotient = value / divisor;
     var nearestInteger = Math.Round(quotient);
-    var tolerance = 1e-9 * Math.Max(1d, Math.Abs(quotient));
-    return Math.Abs(quotient - nearestInteger) <= tolerance;
+    var remainder = value - (nearestInteger * divisor);
+    var tolerance = 1e-9 * Math.Max(1d, Math.Abs(divisor));
+    return Math.Abs(remainder) <= tolerance;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs` around lines 1746 -
1760, IsMultipleOf currently scales tolerance with the quotient which allows
large values to slip through; change it to measure remainder against a tolerance
tied to the divisor (step) instead. In IsMultipleOf(double value, double
divisor) compute the nearest integer as now, then compute remainder =
Math.Abs(value - nearestInteger * divisor) and set tolerance = 1e-9 *
Math.Max(1d, Math.Abs(divisor)) (so tolerance scales with step, not quotient),
and return remainder <= tolerance; keep the same rounding logic to find
nearestInteger so behavior for fractional steps remains consistent.
🤖 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.Game.Tests/Config/YamlConfigLoaderTests.cs`:
- Around line 513-644: Add a regression test named like
LoadAsync_Should_Reject_Large_Decimal_Number_When_Not_MultipleOf that mirrors
the other cases but uses a very large non-integer value (e.g. dropRate:
1000000000000.4) with a schema containing "multipleOf": 1; instantiate
YamlConfigLoader, RegisterTable<int, MonsterNumberConfigStub>("monster", ...
"schemas/monster.schema.json", ...), call loader.LoadAsync against a new
ConfigRegistry and Assert.ThrowsAsync<ConfigLoadException>, then verify
exception.Diagnostic.FailureKind == ConfigLoadFailureKind.ConstraintViolation,
Diagnostic.DisplayPath == "dropRate", Diagnostic.RawValue contains the large
value and registry.Count == 0 so this fails before the fix and passes after.

---

Duplicate comments:
In `@GFramework.Game/Config/YamlConfigSchemaValidator.cs`:
- Around line 1746-1760: IsMultipleOf currently scales tolerance with the
quotient which allows large values to slip through; change it to measure
remainder against a tolerance tied to the divisor (step) instead. In
IsMultipleOf(double value, double divisor) compute the nearest integer as now,
then compute remainder = Math.Abs(value - nearestInteger * divisor) and set
tolerance = 1e-9 * Math.Max(1d, Math.Abs(divisor)) (so tolerance scales with
step, not quotient), and return remainder <= tolerance; keep the same rounding
logic to find nearestInteger so behavior for fractional steps remains
consistent.
🪄 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: edfc6bd9-a8e3-4581-8783-ea8e292e7198

📥 Commits

Reviewing files that changed from the base of the PR and between ccb6b5a and 3ec3429.

📒 Files selected for processing (2)
  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. 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 (2)
**/*.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

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, edge cases, and registration order/lifecycle sequencing

Core framework components (Architecture, Module, System, Context, Registry, Service Module, Lifecycle types) MUST include high-level explanations of responsibilities, lifecycle, interactions, why the abstraction exists, and when to use it

Methods with non-trivial logic MUST document the core idea, key decisions, and edge case handling

Declare every required using explicitly; do not rely on implicit imports

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 C# naming conventions: Types/methods/properties/events/constants in PascalCase, interfaces with I prefix, parameters/locals in camelCase, private fields in _camelCase

Use 4 spaces for indentation, not tabs, and use Allman braces

Keep using directives at the top of the file and sort them consistently

Prefer one primary type per file unless the surrounding project already uses a different local pattern

Keep a single source file under roughly 800-1000 lines; if a file grows ...

Files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs
**/*.Tests/**/*.cs

📄 CodeRabbit inference engine (AGENTS.md)

Reuse existing architecture test infrastructure when relevant: ArchitectureTestsBase, SyncTestArchitecture, AsyncTestArchitecture

Files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Keep abstractions projects free of implementation details and engine-specific dependencies
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Preserve existing module boundaries; do not introduce new cross-module dependencies without clear architectural need
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test is not practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Public API changes must be covered by unit or integration tests
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: 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
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Regression fixes should include a test that fails before the fix and passes after it
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Mirror the source structure in test projects whenever practical
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Keep tests focused on observable behavior, not implementation trivia
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Validate external or user-controlled input before it reaches file system, serialization, reflection, code generation, or process boundaries
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Do not build command strings, file paths, type names, or generated code from untrusted input without strict validation or allow-listing
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Avoid logging secrets, tokens, credentials, or machine-specific sensitive data
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Prefer least-privilege behavior for file, process, and environment access
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Do not introduce unsafe deserialization, broad reflection-based activation, or dynamic code execution unless it is explicitly required and tightly constrained
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Minimize new package dependencies and add them only when necessary with narrow scope
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: When working from a tracked implementation plan, contributors MUST update the corresponding tracking document under `local-plan/todos/` in the same change
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Tracking updates MUST reflect completed work, newly discovered issues, validation results, and the next recommended recovery point
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Do not rely on 'the code is self-explanatory' for framework features that consumers need to adopt; write the adoption path down
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: Before choosing runtimes or CLI tools, read `@.ai/environment/tools.ai.yaml` and prefer project-relevant tools listed there
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: When working in WSL against this repository's Windows-backed worktree, prefer Windows Git from WSL (e.g., `git.exe`) instead of the Linux `git` binary
Learnt from: CR
URL: 
File: AGENTS.md:undefined-undefined
Timestamp: 2026-04-09T11:59:42.535Z
Learning: If a Git command in WSL fails with a worktree-style 'not a git repository' path translation error, rerun it with the Windows Git executable
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Regression fixes should include a test that fails before the fix and passes after it

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : 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.Game.Tests/Config/YamlConfigLoaderTests.cs
📚 Learning: 2026-04-06T10:00:34.101Z
Learnt from: CR
Repo: GeWuYou/GFramework PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-06T10:00:34.101Z
Learning: Applies to **/*.Tests.cs : Public API changes must be covered by unit or integration tests

Applied to files:

  • GFramework.Game.Tests/Config/YamlConfigLoaderTests.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.Game.Tests/Config/YamlConfigLoaderTests.cs
  • GFramework.Game/Config/YamlConfigSchemaValidator.cs

Comment thread GFramework.Game.Tests/Config/YamlConfigLoaderTests.cs
- 新增游戏内容配置系统完整文档,涵盖 YAML 配置、JSON Schema 结构、目录组织等
- 实现运行时只读查询、Source Generator 类型生成、VS Code 插件等功能
- 提供配置浏览、raw 编辑、schema 打开、递归校验和嵌套对象表单入口
- 添加配置系统接入模板,包括 csproj 模板、启动帮助器、运行时读取模板
- 实现热重载功能支持开发期配置文件自动刷新
- 提供完整的 schema 示例和 YAML 示例配置
- 添加跨表引用、索引查询辅助、批量编辑等高级功能支持
- 实现配置验证工具,支持类型校验、约束检查、注释提取等特性
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