Skip to content

Conversation

@Bainianzzz
Copy link
Collaborator

Description

给OpenApi中较为复杂的功能加上了单元测试,全部使用magicMock和patch模拟请求,包括:

  • run.history() 功能
  • runs 中对分组后实验数据的展开功能
  • projects 分页请求功能(找到bug并修改)
  • user 中权限和参数的校验

- add unit test and fix bugs of getting all projects through OpenApi
- add unit tests for OpenApi runs and run.history()
@Bainianzzz Bainianzzz requested a review from SAKURA-CAT January 18, 2026 16:58
@Bainianzzz Bainianzzz self-assigned this Jan 18, 2026
@Bainianzzz Bainianzzz added 💪 enhancement New feature or request 🔌 api SwanLab OpenAPI labels Jan 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Bainianzzz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过为Open API中一些复杂的核心功能添加全面的单元测试来提高代码的健壮性和可靠性。这些测试利用 MagicMockpatch 技术模拟网络请求,确保了 run.history()、分组实验数据展平、项目分页以及用户权限校验等关键功能的正确性。此外,还修复了项目分页功能中的一个现有bug。

Highlights

  • run.history() 功能测试: 为 run.history() 方法添加了全面的单元测试,覆盖了数据获取、参数处理和错误情况。
  • 分组实验数据展平测试: 新增单元测试,确保 runs 中分组后的实验数据能够正确展平。
  • 项目分页功能测试与修复: 为 projects 分页请求功能添加了单元测试,并修复了 swanlab/api/projects/__init__.py 中一个导致分页数据收集不完整的bug。
  • 用户权限与参数校验测试: 新增单元测试,验证 user 模块中的权限控制和参数校验逻辑的正确性。
  • 测试辅助工具: 新增了 test/unit/api/utils.py 文件,提供了创建模拟数据(如 RunType、嵌套实验、项目数据、CSV数据)的辅助函数,以支持单元测试。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 为 OpenApi 中几个较为复杂的功能添加了单元测试,并修复了在测试过程中发现的 projects 分页功能的 bug。整体来看,新添加的测试用例结构清晰,有效地利用了 mock 来模拟依赖,覆盖了 run.history()、实验数据展平、用户权限校验等关键逻辑。

代码审查中,我发现 projects 分页的修复方式虽然解决了 bug,但在内存效率上可以进一步优化,以更好地发挥迭代器的优势。此外,针对分页功能的测试用例也可以通过模拟不同页面的返回数据来增强其健壮性。我也对 history 功能的测试断言提出了一个小的改进建议。

具体的建议请见各文件的审查评论。

@SAKURA-CAT SAKURA-CAT merged commit 126e29c into feature/open-api Jan 19, 2026
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the feat/open-api-test branch January 19, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔌 api SwanLab OpenAPI 💪 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants