Skip to content

Conversation

@theakshaypant
Copy link
Contributor

@theakshaypant theakshaypant commented Oct 24, 2025

πŸ“ Description of the Change

Add comprehensive unit test coverage for StartPR functionality in new pipelineascode_startpr_test.go file.

πŸ‘¨πŸ»β€ Linked Jira

https://issues.redhat.com/browse/SRVKP-9060

πŸ”— Linked GitHub Issue

N/A

πŸš€ Type of Change

  • πŸ› Bug fix (fix:)
  • ✨ New feature (feat:)
  • πŸ’₯ Breaking change (feat!:, fix!:)
  • πŸ“š Documentation update (docs:)
  • βš™οΈ Chore (chore:)
  • πŸ’… Refactor (refactor:)
  • πŸ”§ Enhancement (enhance:)
  • πŸ“¦ Dependency update (deps:)

πŸ§ͺ Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

πŸ€– AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Gemini [email protected]
Co-authored-by: ChatGPT [email protected]
Co-authored-by: Claude [email protected]
Co-authored-by: Cursor [email protected]
Co-authored-by: Copilot [email protected]

**πŸ’‘You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

βœ… Submitter Checklist

  • πŸ“ My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • β™½ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • πŸ“– I have added or updated documentation for any user-facing changes.
  • πŸ§ͺ I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • πŸ”Ž I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@gemini-code-assist
Copy link

Summary of Changes

Hello @theakshaypant, 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 significantly enhances the test coverage for the StartPR function within the pipelineascode package. By introducing a new, dedicated test file and a comprehensive suite of unit tests, it ensures the robustness and reliability of the PipelineRun initiation process. The tests validate behavior across various operational and error conditions, including concurrent executions, secret management, and status reporting, thereby improving the overall stability of the system.

Highlights

  • New Unit Test File: A new file, pipelineascode_startpr_test.go, has been added to house comprehensive unit tests specifically for the StartPR functionality.
  • Comprehensive Test Coverage: The new tests cover a wide array of scenarios, including successful PipelineRun creation, secret auto-creation (success, failure, and already exists cases), handling of concurrency limits (pending vs. immediate start), propagation of GitLab project IDs, and various error conditions during PipelineRun creation, secret ownerRef updates, and status reporting.
  • Concurrency Testing: Dedicated tests have been added to validate the behavior of StartPR under concurrent calls, ensuring proper isolation when creating multiple PipelineRuns with unique secrets, and graceful handling of race conditions when multiple calls attempt to create the same shared secret.
  • Refactoring of Test Utilities: The KinterfaceTestWithError struct and its CreateSecret method have been moved from pipelineascode_test.go to the new pipelineascode_startpr_test.go file, centralizing test utilities relevant to StartPR.
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. ↩

@pipelines-as-code pipelines-as-code bot added enhancement New feature or request testing labels Oct 24, 2025
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 a comprehensive suite of unit tests for the startPR function in a new pipelineascode_startpr_test.go file. The tests are well-structured, covering a wide range of success, failure, and concurrency scenarios, which significantly improves the robustness and maintainability of the startPR logic. The changes also include refactoring some test helper code into the new file, which is a good cleanup. I've found a couple of minor issues in a test setup that could be improved for clarity.

@chmouel
Copy link
Member

chmouel commented Oct 24, 2025

a lot of those fakes are already provided in pkg/test/ and i believe a lot of those unittests are covered in https://github.com/openshift-pipelines/pipelines-as-code/blob/6c646e453/pkg/pipelineascode/pipelineascode_test.go isnt it ?

@theakshaypant theakshaypant marked this pull request as draft October 24, 2025 08:46
@theakshaypant
Copy link
Contributor Author

a lot of those fakes are already provided in pkg/test/ and i believe a lot of those unittests are covered in https://github.com/openshift-pipelines/pipelines-as-code/blob/6c646e453/pkg/pipelineascode/pipelineascode_test.go isnt it ?

Wanted to put this in draft. Haven't cleaned up the redundant tests yet.
Will also look at the fakes and make changes accordingly.

@theakshaypant theakshaypant force-pushed the SRVKP-9060-unit-tests-startpr branch from 0c0a38b to c2eb052 Compare October 27, 2025 06:32
@pipelines-as-code pipelines-as-code bot added the go Pull requests that update Go code label Oct 27, 2025
@theakshaypant
Copy link
Contributor Author

/gemini review

1 similar comment
@zakisk
Copy link
Contributor

zakisk commented Oct 27, 2025

/gemini review

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 a comprehensive suite of unit tests for the startPR function in a new pipelineascode_startpr_test.go file. This is an excellent addition that significantly improves test coverage for this critical functionality. The changes also include refactoring the existing pipelineascode_test.go to remove tests that are now covered in the new file, which is a good cleanup.

My review focuses on improving the maintainability and clarity of the newly added tests. I've identified a few areas where the tests can be made more readable and robust, such as reducing repetitive setup code, clarifying the intent of some tests, and simplifying complex test logic. Overall, this is a high-quality contribution.

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 a comprehensive suite of unit tests for the startPR function, significantly improving test coverage and code reliability. The refactoring of existing tests into a new, dedicated file (pipelineascode_startpr_test.go) is a great organizational improvement. The tests are well-structured, covering a wide range of success paths, error conditions, and concurrency scenarios. I've included a few suggestions to further enhance the new test suite by reducing redundancy and improving clarity. Overall, this is a high-quality contribution.

@theakshaypant theakshaypant force-pushed the SRVKP-9060-unit-tests-startpr branch 2 times, most recently from 0d61aee to 72dc237 Compare October 27, 2025 07:39
@theakshaypant
Copy link
Contributor Author

/gemini review

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 a new test file, pipelineascode_startpr_test.go, to provide comprehensive unit test coverage for the StartPR functionality. The changes also include modifications to pipelineascode_test.go and kubernetesint.go to support the new tests. I have identified some areas where improvements can be made to enhance the code's robustness and clarity.

Comment on lines +46 to +56
func (k *KinterfaceTestWithSecretTracking) CreateSecret(ctx context.Context, ns string, secret *corev1.Secret) error {
// Atomically increment and get the new count
count := k.secretCreationCount.Add(1)

// First creation succeeds, subsequent ones return AlreadyExists to simulate race condition
if count > 1 {
return errors.NewAlreadyExists(schema.GroupResource{Group: "", Resource: "secrets"}, secret.GetName())
}

Choose a reason for hiding this comment

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

medium

Consider adding a more descriptive error message when count > 1 to provide better context for debugging. For example, include the secret name in the error message.

return errors.NewAlreadyExists(schema.GroupResource{Group: "", Resource: "secrets"}, secret.GetName())

@theakshaypant theakshaypant force-pushed the SRVKP-9060-unit-tests-startpr branch from 72dc237 to 3d3528c Compare October 27, 2025 09:09
@zakisk
Copy link
Contributor

zakisk commented Oct 27, 2025

I see that you have created multiple funcs for every scenario can you please make them in one func like we usually do in PaC

@theakshaypant theakshaypant marked this pull request as ready for review October 27, 2025 11:03
Add comprehensive unit test coverage for StartPR functionality
in new pipelineascode_startpr_test.go file.

Signed-off-by: Akshay Pant <[email protected]>
Co-authored-by: Claude-4.5-Sonnet (via Cursor)
@theakshaypant theakshaypant force-pushed the SRVKP-9060-unit-tests-startpr branch from 3d3528c to 554009e Compare October 28, 2025 04:27
test func(t *testing.T)
}{
{
name: "success - comprehensive success test covering the full startPR flow",
Copy link
Member

@chmouel chmouel Oct 28, 2025

Choose a reason for hiding this comment

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

This is a very weird way to do testcases, you redoing the testing constructions all the time.. it's not supposed to work like that

@chmouel
Copy link
Member

chmouel commented Oct 29, 2025

This look a bit vibe coded, which is fine, no problem with that... but you may need to be careful to make sure it output the code the same way as what we have before.. (which is again fine, you just need to know how the project structure works to be able to drive the LLM to output things as expected)

@theakshaypant
Copy link
Contributor Author

This look a bit vibe coded, which is fine, no problem with that... but you may need to be careful to make sure it output the code the same way as what we have before.. (which is again fine, you just need to know how the project structure works to be able to drive the LLM to output things as expected)

Yes, tried to restructure the tests into a single one using Cursor. Have gone through the individual cases in detail though.
Will make changes to the file to conform to the existing test structure in the repo.

@theakshaypant
Copy link
Contributor Author

@chmouel @zakisk How do we feel about going back to a previous version of these tests where we have multiple test funcs? Given the amount of functionality covered in startPR, I feel it would be a bit hard to consolidate all the scenarios into a single table driven test func.

For your reference, the test funcs earlier were the following with fairly different assertion and configuration involved.

  • TestStartPR - Basic success case
  • TestStartPR_MissingSecretAnnotation
  • TestStartPR_CreationFailureWithSecretCleanup
  • TestStartPR_SecretCleanupError
  • TestStartPR_StatusCreationFailure
  • TestStartPR_GitHubAppLogURLHandling
  • TestStartPR_LoggingWithConditions
  • TestStartPR_MultipleCustomAnnotations
  • TestStartPR_ConcurrentCreation
  • TestStartPR_ConcurrentWithSameSecret
  • TestStartPR_SecretCreationScenarios - 3 subtests
  • TestStartPR_AnnotationAndLabelPropagation - 3 subtests
  • TestStartPR_ConcurrencyLimitBehavior - 5 subtests
  • TestStartPR_SecretOwnerRefUpdateErrors - 2 subtests
  • TestStartPR_StateManagement - 2 subtests
  • TestStartPR_PatchBehavior - 2 subtests

@chmouel
Copy link
Member

chmouel commented Oct 31, 2025

I am okay with that, it's ncie to have testcase but if the test construtions cannot be the same across all tests then it defeat to use testcase... i am guessing all LLMs failed to do it properly?

@theakshaypant
Copy link
Contributor Author

I am okay with that, it's ncie to have testcase but if the test construtions cannot be the same across all tests then it defeat to use testcase... i am guessing all LLMs failed to do it properly?

Yes, the current code is the best version that was generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code testing

Development

Successfully merging this pull request may close these issues.

3 participants