Skip to content

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented Sep 29, 2025

Fix overly strict condition in ReplacePlaceHoldersVariables that prevented
correct evaluation of placeholders when rawEvent or headers were nil.

Changes:

  • body.* placeholders now work when rawEvent != nil (regardless of headers)
  • headers.* placeholders now work when headers != nil (regardless of rawEvent)
  • files.* placeholders now work independently of rawEvent/headers

Add comprehensive unit tests improving coverage from 49.0% to 86.0%:

  • Nil parameter handling scenarios
  • CEL type conversions (numeric, boolean, array, object)
  • Error paths for invalid keys and expressions
  • Edge cases for missing dictionary placeholders
  • Mixed scenarios combining dico, body, and header lookups

initiali coverage was:

image

📝 Description of the Change

👨🏻‍ Linked Jira

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

🔗 Linked GitHub Issue

Fixes #

🚀 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

@Copilot Copilot AI review requested due to automatic review settings September 29, 2025 11:12
Copy link

Summary of Changes

Hello @chmouel, 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 focuses on enhancing the robustness and reliability of the templating logic by introducing a comprehensive suite of unit tests for the ReplacePlaceHoldersVariables function. The added tests cover a wide array of input conditions, data types, and error scenarios, ensuring the function behaves as expected across diverse use cases and significantly boosting its test coverage.

Highlights

  • Improved Test Coverage: The pull request significantly increases the unit test coverage for the ReplacePlaceHoldersVariables function from 49.0% to 83.7%.
  • Comprehensive Unit Tests: New unit tests have been added to cover various scenarios, including nil handling for rawEvent and headers parameters, and Common Expression Language (CEL) type conversions for numeric, boolean, array, and object values.
  • Error and Edge Case Handling: Tests now include error paths for invalid keys and expressions, as well as edge cases for missing dictionary placeholders.
  • Mixed Placeholder Scenarios: New test cases validate the function's behavior in mixed scenarios, combining lookups from dictionaries, request bodies, and headers.
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

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves test coverage for the ReplacePlaceHoldersVariables function from 49.0% to 83.7% by adding comprehensive unit tests. The changes focus on enhancing test coverage for templating functionality with various edge cases and data type scenarios.

Key Changes

  • Added tests for nil parameter handling (rawEvent and headers)
  • Added tests for CEL type conversions (numeric, boolean, array, object types)
  • Added tests for error handling scenarios (invalid keys, missing dictionary placeholders)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pipelines-as-code pipelines-as-code bot added go Pull requests that update Go code plumbing testing labels Sep 29, 2025
@chmouel chmouel requested a review from vdemeester September 29, 2025 11:13
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 significantly improves test coverage for the templating functionality, which is a great addition. However, I've identified that several of the new test cases are written to confirm existing buggy behavior in ReplacePlaceHoldersVariables rather than testing for the correct functionality. Specifically, tests involving nil rawEvent or nil headers have incorrect expectations because the implementation has an overly strict check (if rawEvent != nil && headers != nil). My review comments point out these specific test cases and suggest how to correct them to properly expose and guide the fix for the underlying bug. Once these tests are corrected, they will be a valuable addition to the test suite.

@chmouel
Copy link
Member Author

chmouel commented Sep 29, 2025

gemini properly identified a bug in the implementation, let's hold on

@chmouel chmouel force-pushed the improve-unittests-for-templating.go branch from af8d3b7 to b7447e8 Compare September 29, 2025 11:25
@chmouel chmouel changed the title test: improve templating coverage from 49.0% to 83.7% fix: resolve templating placeholder evaluation bug Sep 29, 2025
@chmouel
Copy link
Member Author

chmouel commented Sep 29, 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 effectively resolves a bug in placeholder evaluation by relaxing an overly strict condition, ensuring body, headers, and files placeholders are evaluated correctly even when some contexts are nil. The addition of comprehensive unit tests is a significant improvement, greatly increasing test coverage and confidence in the change. I have one minor suggestion to improve code conciseness.

@chmouel chmouel force-pushed the improve-unittests-for-templating.go branch from b7447e8 to c9c096d Compare September 29, 2025 11:38
Fix overly strict condition in ReplacePlaceHoldersVariables that prevented
correct evaluation of placeholders when rawEvent or headers were nil.

Changes:
- body.* placeholders now work when rawEvent != nil (regardless of headers)
- headers.* placeholders now work when headers != nil (regardless of rawEvent)
- files.* placeholders now work independently of rawEvent/headers

Add comprehensive unit tests improving coverage from 49.0% to 88.9%:
- Nil parameter handling scenarios
- CEL type conversions (numeric, boolean, array, object, double, int, bytes)
- Error paths for invalid keys and expressions
- Edge cases for missing dictionary placeholders
- Complex nested object and array access
- Mixed scenarios combining dico, body, and header lookups

Split tests into focused functions:
- TestReplacePlaceHoldersVariables: exact-match tests for deterministic cases
- TestReplacePlaceHoldersVariablesJSONOutput: flexible JSON serialization tests
- TestReplacePlaceHoldersVariablesEdgeCases: complex nested access patterns

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Chmouel Boudjnah <[email protected]>
@chmouel chmouel force-pushed the improve-unittests-for-templating.go branch from c9c096d to 6408a34 Compare September 29, 2025 11:45
Copy link

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🎫 Jira reference

Add a Jira reference in the description using one of the following formats:

  • https://issues.redhat.com/browse/SRVKP-<number>

If no SRVKP ticket exists yet, link a GitHub issue instead (e.g., Fixes #123).
Minor housekeeping PRs without Jira coverage can skip this after confirming with reviewers.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

@chmouel
Copy link
Member Author

chmouel commented Oct 9, 2025

it's a minor fix since it may never happen...

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

Labels

go Pull requests that update Go code plumbing testing

Development

Successfully merging this pull request may close these issues.

2 participants