Skip to content

[CI] Add unittest Claude skill and supplement unit test coverage#7888

Open
EmmonsCurse wants to merge 1 commit into
PaddlePaddle:developfrom
EmmonsCurse:add_unittest_with_skill
Open

[CI] Add unittest Claude skill and supplement unit test coverage#7888
EmmonsCurse wants to merge 1 commit into
PaddlePaddle:developfrom
EmmonsCurse:add_unittest_with_skill

Conversation

@EmmonsCurse
Copy link
Copy Markdown
Collaborator

Motivation

To improve unit test development efficiency and standardization, a dedicated Claude skill for FastDeploy unittest generation is introduced. In addition, related unit tests need to be supplemented to improve test coverage and validation completeness.

Modifications

  • Added unittest Claude skill documentation and related configurations.
  • Supplemented missing unit test cases.
  • Improved unit test coverage and development workflow consistency.

Usage or Command

N/A

Accuracy Tests

N/A

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 21, 2026

Thanks for your contribution!

@EmmonsCurse
Copy link
Copy Markdown
Collaborator Author

/skip-ci ci_iluvatar
/skip-ci ci_hpu
/skip-ci build_xpu
/skip-ci gpu_4cards_test
/skip-ci pre_ce_test
/skip-ci stable_test
/skip-ci base_test
/skip-ci logprob_test

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 Paddle-CI-Agent | pr_review | 2026-05-22 00:10:01

📋 Review 摘要

PR 概述:新增 FastDeploy 单测生成 Claude Skill,清理 entrypoints 下的临时测试脚本,并为 33+ 个模块补充 unit test 覆盖。
变更范围.claude/skills/(新增 skill 文档)、fastdeploy/entrypoints/(删除临时脚本)、tests/(新增测试)
影响面 Tag[CI]

问题

级别 文件 概述
🟡 建议 tests/cache_manager/test_file_store.py test_clear_refuses_dangerous_paths 方法内存在冗余的 with patch(logger)
❓ 疑问 tests/cache_manager/test_file_store.py 纯逻辑测试类中直接调用 paddle.to_tensor() 未标记 @pytest.mark.gpu

🟡 建议 — 冗余 patch

TestFileStoreClear.test_clear_refuses_dangerous_paths 方法已通过 @patch("...logger") 装饰器注入 mock_logger,但方法体内部又嵌套了一个 with patch("...logger"): 上下文管理器,对同一目标重复 patch,冗余代码建议删除。

❓ 疑问 — paddle.to_tensor 未标注 GPU

TestFileStoreOperations.test_get_invalid_target_sizetest_get_success 两个方法在 mock 路径内调用了 paddle.to_tensor(...)。该调用在没有 GPU 的环境下可能触发 CUDA 初始化异常。由于这两个方法所在的测试类属于 Pattern 1(纯逻辑),建议确认:是否可用 MagicMock() 替代 paddle.to_tensor() 的返回值,避免引入隐式 GPU 依赖?若确认 CI 始终有 GPU 可跳过此项。

📝 PR 规范检查

PR 标题包含官方 Tag [CI] ✓;描述含 ## Motivation## Modifications## Usage or Command(N/A)、## Accuracy Tests(N/A)、## Checklist 五个必填段落,结构完整 ✓;Checklist 勾选状态与 diff 实际情况吻合(新增测试 ✓、pre-commit ✓,精度测试 N/A)✓。PR 规范合规,无需修改。

总体评价

变更整体质量较高:Skill 文档完善(覆盖 4 种测试模式、CI 分类规则、端口管理等),新增测试结构规范、mocking 合理、setUp/tearDown 资源清理完善;删除 test_openai.py 脚本也是正确做法(该文件硬编码了 IP 和端口,属于手动验证脚本不宜放在源码目录)。两处建议均不阻塞合入。

@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 21, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-22 02:07:12

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

当前 Required CI 未通过:存在 1 个 required 失败任务,0 个 required 运行中/等待中任务。需优先处理单测失败后再合入。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
41(0) 41 28 2 0 0 11

2 任务状态汇总

日志列说明:失败任务直接使用 CI 日志链接;可选任务失败不阻塞合并,仅供参考。

2.1 Required任务 : 2/10 通过

必选任务阻塞合并,失败需优先处理。

状态 任务 耗时 根因 修复建议 日志 重跑
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage 1h21m PR问题:Mock 未实现 create_kv_cache 返回为空 补齐 create_kv_cache mock 返回 Job -
⏭️ 其余 7 个必选任务跳过/未执行 - 跳过 - - -
其余 2 个必选任务通过 - - - - -

2.2 可选任务 — 26/31 通过

可选任务不阻塞合并,失败仅供参考;按流程不做深度分析。

状态 任务 耗时 日志 重跑
Trigger Jenkins for PR 8m1s Job -
⏭️ 其余 4 个可选任务跳过/未执行 - - -
其余 26 个可选任务通过 - - -

3 失败详情(仅 required)

Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — 测试失败(置信度: 高)

Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage

  • 状态: ❌ 失败
  • 错误类型: 测试失败
  • 置信度: 高
  • 根因摘要: Mock 未实现 create_kv_cache 返回为空
  • 分析器: ci_analyze_unittest_fastdeploy

失败用例:

测试 错误 根因
tests/cache_manager/v1/test_cache_controller.py::TestInitializeKVCacheDtype::test_initialize_kv_cache_null_value_cache_shape AssertionError: 0 != 2 测试 helper 只 mock 了 get_kv_cache_shape,但 CacheController.initialize_kv_cache() 实际依赖 attn_backend.create_kv_cache() 返回 cache dict

根因详情:
fastdeploy/cache_manager/v1/cache_controller.py L298-L303 中,initialize_kv_cache() 已将 KV cache 分配委托给 attn_backend.create_kv_cache(...),随后只遍历返回的 caches.items() 注册 tensor。失败用例使用的 make_mock_attn_backend(val_shape_is_none=True)tests/cache_manager/v1/test_cache_controller.py L731-L742)仅设置 get_kv_cache_shape.return_value,没有给 MagicMock.create_kv_cache 配置符合接口约定的返回 dict,因此遍历结果为空,最终 cache_list 长度为 0。该问题来自本 PR 新增/修改的单测 mock 与现有被测接口不匹配,不是环境问题。

关键日志:

Case name: cache_manager/v1/test_cache_controller.py::TestInitializeKVCacheDtype::test_initialize_kv_cache_null_value_cache_shape
>       self.assertEqual(len(cache_list), 2)  # 2 layers * key only
E       AssertionError: 0 != 2
tests/cache_manager/v1/test_cache_controller.py:851: AssertionError
Failed test cases:
tests/cache_manager/v1/test_cache_controller.py

修复建议:

  1. tests/cache_manager/v1/test_cache_controller.py L731-L742 的 make_mock_attn_backend() 中补齐 backend.create_kv_cache.return_value,按 AttentionBackend.create_kv_cache() 约定返回 {("key", layer_idx): tensor, ...}val_shape_is_none=True 时仅返回 key(fp8 场景还需包含 key_scale)。
  2. 或将该 helper 改为使用一个最小 AttentionBackend 子类/复用已有测试中的 concrete backend,让 create_kv_cache() 根据 get_kv_cache_shape() 真实生成 cache,避免 MagicMock 默认返回空迭代结果。

修复建议摘要: 补齐 create_kv_cache mock 返回

关联变更: tests/cache_manager/v1/test_cache_controller.py L731-L742、L843-L851
链接: 查看日志

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@8080a25). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7888   +/-   ##
==========================================
  Coverage           ?   76.46%           
==========================================
  Files              ?      398           
  Lines              ?    56276           
  Branches           ?     8804           
==========================================
  Hits               ?    43032           
  Misses             ?    10450           
  Partials           ?     2794           
Flag Coverage Δ
GPU 76.46% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants