Skip to content

Conversation

@kevinlin09
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @kevinlin09, 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!

This pull request introduces several enhancements to the existing test suite, which are crucial for maintaining code quality and are likely intended to support a new 'build_test' CI action. The changes focus on improving the reliability and accuracy of API key handling tests by ensuring proper state isolation and updating various mock API responses to reflect a more standardized response format, including status codes and messages. Additionally, the request parameters for video synthesis tests have been refined to align with potential API changes.

Highlights

  • Enhanced Test Reliability for API Key Handling: Implemented mechanisms to clear API key states and manage environment variables and files more robustly, ensuring test isolation and preventing interference between tests.
  • Standardized Mock API Responses: Updated mock responses across multiple API tests (Batch Text Embedding, Half Duplex HTTP API, Image Synthesis, Video Synthesis) to consistently include 'status_code', 'code', and 'message' fields, reflecting a more complete API contract.
  • Refined Video Synthesis Request Parameters: Adjusted expected request bodies in video synthesis tests by removing 'size' and 'resolution' parameters, indicating an evolution in the API's parameter handling.

🧠 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.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/build-and-test.yml
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

@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

This pull request introduces changes to the test suite, specifically focusing on API key handling and response body assertions in various service tests. The changes include clearing the API key before each test in TestApiKey.java, and updating expected response bodies in TestBatchTextEmbedding.java, TestHalfDuplexHttpApi.java, TestImageSynthesis.java, and TestVideoSynthesis.java to include status code, code, and message fields. These modifications aim to enhance the reliability and accuracy of the tests.

@Test
@SetEnvironmentVariable(key = "DASHSCOPE_API_KEY", value = environmentValue)
public void testSetWithEnvValue() throws NoApiKeyException {
Constants.apiKey = null; // Clear any previously set API key

Choose a reason for hiding this comment

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

medium

Clearing the API key before each test ensures that previous test runs do not influence subsequent tests, leading to more reliable and isolated test results. This is a good practice to prevent unexpected behavior due to shared state.

Comment on lines 33 to +34
String apiKey = ApiKey.getApiKey(null);
assertEquals(apiKey, environmentValue);
assertEquals(environmentValue, apiKey);

Choose a reason for hiding this comment

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

medium

The assertion order was changed. It's better to keep the expected value as the first argument and the actual value as the second argument in assertEquals for better readability and debugging.

Suggested change
String apiKey = ApiKey.getApiKey(null);
assertEquals(apiKey, environmentValue);
assertEquals(environmentValue, apiKey);
String apiKey = ApiKey.getApiKey(null);
assertEquals(apiKey, environmentValue);

Comment on lines +53 to +62
Constants.apiKey = null; // Clear any previously set API key
Path homePath = Paths.get(System.getProperty("user.home"));
Path dashscopePath = homePath.resolve(".dashscope").resolve("api_key");
String expectedValue = "4444";
// Delete if exists before creating
if (Files.exists(dashscopePath.getParent()) && Files.isDirectory(dashscopePath.getParent())) {
if (Files.exists(dashscopePath)) {
Files.delete(dashscopePath);
}
}

Choose a reason for hiding this comment

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

medium

This block of code checks if the parent directory exists and is a directory before deleting the file. This prevents errors if the directory doesn't exist or isn't a directory. Good defensive programming.

Comment on lines 54 to +55
String responseBody =
"{\"request_id\":\"78a74ba9-b8eb-9ca5-ab34-5a56f453cf03\",\"output\":{\"task_id\":\"2a1d8589-7148-422a-b9e7-f41682f07160\",\"task_status\":\"PENDING\"}}";
"{\"request_id\":\"78a74ba9-b8eb-9ca5-ab34-5a56f453cf03\",\"output\":{\"task_id\":\"2a1d8589-7148-422a-b9e7-f41682f07160\",\"task_status\":\"PENDING\"},\"status_code\":200,\"code\":\"\",\"message\":\"\"}";

Choose a reason for hiding this comment

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

medium

The response body is updated to include status_code, code, and message. This ensures that the tests verify the presence and structure of these fields in the response, which is important for error handling and status reporting.

Constants.baseHttpApiUrl = String.format("http://127.0.0.1:%s", port);
DashScopeResult result = syncApi.call(param);
assertEquals(JsonUtils.toJson(result), "{}");
assertEquals(JsonUtils.toJson(result), "{\"statusCode\":200,\"code\":\"\",\"message\":\"\"}");

Choose a reason for hiding this comment

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

medium

The expected JSON string now includes statusCode, code, and message. This ensures that the test verifies the presence of these fields in the response, which is important for proper status reporting.

InputRequiredException {
String responseBody =
"{\"request_id\":\"39\",\"output\":{\"task_id\":\"e4\",\"task_status\":\"SUCCEEDED\",\"results\":[{\"url\":\"https://1\"},{\"url\":\"https://2\"},{\"url\":\"https://\"},{\"url\":\"https://4\"}],\"task_metrics\":{\"TOTAL\":4,\"SUCCEEDED\":4,\"FAILED\":0}},\"usage\":{\"image_count\":4}}";
"{\"request_id\":\"39\",\"output\":{\"task_id\":\"e4\",\"task_status\":\"SUCCEEDED\",\"results\":[{\"url\":\"https://1\"},{\"url\":\"https://2\"},{\"url\":\"https://\"},{\"url\":\"https://4\"}],\"task_metrics\":{\"TOTAL\":4,\"SUCCEEDED\":4,\"FAILED\":0}},\"usage\":{\"image_count\":4},\"status_code\":200,\"code\":\"\",\"message\":\"\"}";

Choose a reason for hiding this comment

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

medium

The response body is updated to include status_code, code, and message. This ensures that the tests verify the presence and structure of these fields in the response, which is important for error handling and status reporting.

InputRequiredException {
String responseBody =
"{\"request_id\":\"39\",\"output\":{\"task_id\":\"e4\",\"task_status\":\"SUCCEEDED\",\"video_url\":\"https://1\"},\"usage\":{\"video_count\":1}}";
"{\"request_id\":\"39\",\"output\":{\"task_id\":\"e4\",\"task_status\":\"SUCCEEDED\",\"video_url\":\"https://1\"},\"usage\":{\"video_count\":1,\"duration\":0.0,\"input_video_duration\":0.0,\"output_video_duration\":0.0},\"status_code\":200,\"code\":\"\",\"message\":\"\"}";

Choose a reason for hiding this comment

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

medium

The response body is updated to include status_code, code, and message. This ensures that the tests verify the presence and structure of these fields in the response, which is important for error handling and status reporting.

Comment on lines 72 to +73
String expectRequestBody =
"{\"model\":\"wanx-kf2v\",\"input\":{\"extend_prompt\":true,\"first_frame_url\":\"https://www.xxx.cn/a.png\",\"last_frame_url\":\"https://www.xxx.cn/b.png\"},\"parameters\":{\"duration\":5,\"with_audio\":false,\"size\":\"1280*720\",\"resolution\":\"720P\"}}";
"{\"model\":\"wanx-kf2v\",\"input\":{\"extend_prompt\":true,\"first_frame_url\":\"https://www.xxx.cn/a.png\",\"last_frame_url\":\"https://www.xxx.cn/b.png\"},\"parameters\":{\"with_audio\":false}}";

Choose a reason for hiding this comment

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

medium

The expected request body is updated to remove duration, size, and resolution from the parameters. This change aligns the test with the actual request being sent, ensuring the test accurately reflects the system's behavior.

Comment on lines 107 to +108
String expectRequestBody =
"{\"model\":\"wanx-kf2v\",\"input\":{\"extend_prompt\":true,\"first_frame_url\":\"https://www.xxx.cn/a.png\",\"last_frame_url\":\"https://www.xxx.cn/b.png\"},\"parameters\":{\"duration\":4,\"with_audio\":false,\"size\":\"1280*720\",\"seed\":1234,\"resolution\":\"720P\"}}";
"{\"model\":\"wanx-kf2v\",\"input\":{\"extend_prompt\":true,\"first_frame_url\":\"https://www.xxx.cn/a.png\",\"last_frame_url\":\"https://www.xxx.cn/b.png\"},\"parameters\":{\"duration\":4,\"with_audio\":false,\"seed\":1234}}";

Choose a reason for hiding this comment

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

medium

The expected request body is updated to remove size and resolution from the parameters. This change aligns the test with the actual request being sent, ensuring the test accurately reflects the system's behavior.

@kevinlin09 kevinlin09 merged commit 91ccc0d into dashscope:main Jan 22, 2026
4 checks passed
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