Conversation
gherrit-pr-id: G5964d13c9ffb7a47ed4662892ef92c90ddc51e12
Summary of ChangesHello @jswrenn, 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 establishes a new framework for codegen testing within the Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces codegen tests, which is a valuable addition for ensuring the quality and performance of the generated code. My review identified a critical bug in the test runner's logic that would prevent the tests from working as intended, along with a minor typo in a data structure. Once these issues are addressed, the PR will be in great shape.
| let mut expected_file = OpenOptions::new() | ||
| .read(true) | ||
| .write(true) | ||
| .create(true) | ||
| .append(false) | ||
| .truncate(true) | ||
| .open(expected_file_path) | ||
| .unwrap(); | ||
|
|
||
| let expected_result = { | ||
| let mut buf = Vec::new(); | ||
| expected_file.read_to_end(&mut buf).unwrap(); | ||
| buf | ||
| }; | ||
|
|
||
| if bless { | ||
| expected_file.write_all(&actual_result).unwrap(); | ||
| } else { | ||
| if actual_result == expected_result { | ||
| ; // Success | ||
| } else { | ||
| panic!("Bless codegen tests with BLESS=1"); | ||
| } | ||
| } |
There was a problem hiding this comment.
The logic for checking against the blessed file is incorrect. OpenOptions is configured with .truncate(true), which means the expected output file is always cleared before being read. This results in expected_result always being empty, causing the test to fail incorrectly if there's any actual output.
The file handling logic should be separated for blessing and checking. When checking, the file should be opened for reading only. When blessing, it should be opened for writing and truncating.
Here's a more concise and correct implementation using std::fs::read and std::fs::write:
| let mut expected_file = OpenOptions::new() | |
| .read(true) | |
| .write(true) | |
| .create(true) | |
| .append(false) | |
| .truncate(true) | |
| .open(expected_file_path) | |
| .unwrap(); | |
| let expected_result = { | |
| let mut buf = Vec::new(); | |
| expected_file.read_to_end(&mut buf).unwrap(); | |
| buf | |
| }; | |
| if bless { | |
| expected_file.write_all(&actual_result).unwrap(); | |
| } else { | |
| if actual_result == expected_result { | |
| ; // Success | |
| } else { | |
| panic!("Bless codegen tests with BLESS=1"); | |
| } | |
| } | |
| if bless { | |
| std::fs::write(expected_file_path, &actual_result).unwrap(); | |
| } else { | |
| let expected_result = std::fs::read(expected_file_path).unwrap_or_default(); | |
| if actual_result != expected_result { | |
| panic!("Bless codegen tests with BLESS=1"); | |
| } | |
| } |
| struct MinimialViableSource { | ||
| header: [u8; 4], | ||
| trailer: [[u8; 2]] | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &MinimialViableSource) -> Option<&coco::Packet> { |
There was a problem hiding this comment.
There's a typo in the struct name MinimialViableSource. It should be MinimalViableSource.
| struct MinimialViableSource { | |
| header: [u8; 4], | |
| trailer: [[u8; 2]] | |
| } | |
| #[unsafe(no_mangle)] | |
| fn codegen_test(source: &MinimialViableSource) -> Option<&coco::Packet> { | |
| struct MinimalViableSource { | |
| header: [u8; 4], | |
| trailer: [[u8; 2]] | |
| } | |
| #[unsafe(no_mangle)] | |
| fn codegen_test(source: &MinimalViableSource) -> Option<&coco::Packet> { |
⬇️ Download this PR
Branch
git fetch origin refs/heads/G5964d13c9ffb7a47ed4662892ef92c90ddc51e12 && git checkout -b pr-G5964d13c9ffb7a47ed4662892ef92c90ddc51e12 FETCH_HEADCheckout
git fetch origin refs/heads/G5964d13c9ffb7a47ed4662892ef92c90ddc51e12 && git checkout FETCH_HEADCherry Pick
git fetch origin refs/heads/G5964d13c9ffb7a47ed4662892ef92c90ddc51e12 && git cherry-pick FETCH_HEADPull
Stacked PRs enabled by GHerrit.