Skip to content

Conversation

@blakeli0
Copy link
Contributor

@blakeli0 blakeli0 commented Jan 2, 2026

The generator use the current year to generate copyright headers, so there are multiple tests failing when a new year comes. The general fix is to introduce an environment variable TEST_CURRENT_YEAR so that we can override it in tests. See below for the exact fix for each scenario:

  • Java generator golden unit tests
  • Java generator golden integration tests
    • Updated the golden files. These tests are generated from Bazel rules. Bazel builds are pretty hermetic and I couldn't find a way to override the environment variable. This is because the Bazel rule java_gapic_library calls the generator through proto_custom_library which does not pass any environment variables.
  • Python hermetic build scripts unit tests.
    • Override it with mocks. This requires a small refactoring in java.py.
  • Hermetic build scripts integration tests.
    • Changed these tests to non-required for now. These tests use a hardcoded generator version that does not recognize the environment variable. Once the generator is released, we can update the generator version and override the environment variable in CloudBuild yamls.
  • SpringCodeGen unit tests.
    • Once the generator is released, we can override the same environment variable with Maven in spring-cloud-gcp.

Separately, updated zlib version in Bazel build because there is a known incompatibility between old zlib library and the latest macOS version.

fixes: #3547

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Jan 2, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @blakeli0, 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 enhances the robustness of the test suite by introducing a configurable copyright year for generated code. By allowing the copyright year to be set via an environment variable, particularly for tests, it ensures that test outcomes remain consistent and independent of the actual calendar year, thereby preventing potential test failures caused by year transitions.

Highlights

  • Test Stability Improvement: Introduced a mechanism to fix the copyright year used in generated code during testing, which prevents tests from failing due to year changes.
  • Configurable Copyright Year: The copyright year can now be overridden for testing purposes using the test_current_year environment variable.
  • Maven Surefire Plugin Configuration: The pom.xml was updated to set the test_current_year environment variable to 2025 specifically for test execution.
  • Dynamic Year Retrieval: A new getCurrentYear() helper method was added to CommentComposer.java to dynamically determine the copyright year, prioritizing the environment variable over the system's current year.

🧠 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

This pull request introduces a mechanism to use a fixed copyright year for tests by using an environment variable. The changes in pom.xml set this environment variable for the test execution, and CommentComposer.java is updated to read this variable. This is a good approach for making tests deterministic.

I've added one comment with a suggestion to refactor the new getCurrentYear method to improve maintainability by extracting the magic string into a constant and to use the modern java.time API instead of Calendar.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Jan 2, 2026
@blakeli0 blakeli0 changed the title tests: Used fixed copyright year in tests. tests: Use fixed copyright year in tests. Jan 2, 2026
@blakeli0 blakeli0 marked this pull request as ready for review January 5, 2026 18:02
@blakeli0 blakeli0 requested review from lqiu96 and zhumin8 January 5, 2026 18:02
</additionalClasspathElement>
</additionalClasspathElements>
<environmentVariables>
<TEST_CURRENT_YEAR>2025</TEST_CURRENT_YEAR>
Copy link
Member

Choose a reason for hiding this comment

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

qq, would this override the value of an env var I set locally on my computer? Do you know which one has precendence?

If this takes precedence, maybe we can set this as a maven property so that we can configure this (if we need to ever test locally) with something like -DoverrideYear=YEAR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I made it a Maven property since it's generally a better practice. I tested that this override does take precedence.

@blakeli0 blakeli0 requested review from lqiu96 and zhumin8 January 5, 2026 19:54
Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

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

LTGM. I'd be great if you could add a bit of documentation:

@blakeli0
Copy link
Contributor Author

blakeli0 commented Jan 5, 2026

LTGM. I'd be great if you could add a bit of documentation:

I added more comments to CommentComposer, including nuances of the golden integration tests as well.
I don't think we should document this in README though because this is more like a test only thing to make developers' life easier, it's actually better if developers do not notice this at all.

@blakeli0 blakeli0 requested a review from zhumin8 January 5, 2026 21:37
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
75.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@blakeli0 blakeli0 merged commit 6f59f7c into main Jan 5, 2026
58 of 61 checks passed
@blakeli0 blakeli0 deleted the use_fixed_copyright branch January 5, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests should not automatically start failing when new year comes

4 participants