Skip to content

fix: Update regex to support TC-I-XXX tests in CLI#66

Open
aligruenhaupt wants to merge 1 commit intoproject-chip:mainfrom
aligruenhaupt:main
Open

fix: Update regex to support TC-I-XXX tests in CLI#66
aligruenhaupt wants to merge 1 commit intoproject-chip:mainfrom
aligruenhaupt:main

Conversation

@aligruenhaupt
Copy link

What this PR does:
This PR updates the regex pattern to properly handle test cases like TC-I-XXX.

Why it is needed:
Previously, running these specific tests via the CLI tool threw an error because the regex did not match the test case format correctly.

Fixes #873

Edited the regex pattern, so that Tests such as TC-I-XXX work with the CLI, which threw an error before.
@CLAassistant
Copy link

CLAassistant commented Feb 16, 2026

CLA assistant check
All committers have signed the CLA.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aligruenhaupt, 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 addresses a critical bug in the CLI tool's test ID validation logic. Previously, the regex pattern was too restrictive, preventing certain valid test case formats from being recognized, which led to errors when attempting to execute them. The updated regex now correctly accommodates these formats, ensuring that all intended test cases can be processed without issues through the command-line interface.

Highlights

  • Regex Update: The regular expression used for validating test IDs has been modified to correctly recognize test cases formatted as 'TC-I-XXX'.
  • CLI Compatibility: This change resolves an issue where running specific test cases (e.g., TC-I-XXX) via the CLI tool would previously result in an error due to a mismatch in the validation pattern.

🧠 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
  • th_cli/validation.py
    • Modified the valid_pattern regex in the validate_test_ids function to allow for single-character identifiers (e.g., 'I') in the test case format 'TC-I-XXX'.
Activity
  • No specific activity has been recorded for this pull request since its creation.
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 updates the regular expression for test ID validation to support test cases with single-character components, such as TC-I-XXX. The change correctly modifies the quantifier to allow for this. I've added one suggestion regarding regex compilation performance.


# Validate each test ID format
valid_pattern = re.compile(r"^TC[-_][A-Z_]{2,20}([-_\.]\d+){2,3}(-custom)?$")
valid_pattern = re.compile(r"^TC[-_][A-Z_]{1,20}([-_\.]\d+){2,3}(-custom)?$")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved performance, it's recommended to compile this regex at the module level, outside of this function. Compiling a regex can be a relatively expensive operation, and doing it inside a function that might be called in a loop can lead to unnecessary overhead. By defining the compiled pattern as a module-level constant, it's compiled only once when the module is imported.

For example:

# At module level, outside any function
_VALID_TEST_ID_PATTERN = re.compile(r"^TC[-_][A-Z_]{1,20}([-_.]\d+){2,3}(-custom)?$")

def validate_test_ids(test_ids: str) -> list[str]:
    # ...
    # inside the function, just use it
    for test_id in ids:
        if not _VALID_TEST_ID_PATTERN.match(test_id):
            # ...

As a minor point, the backslash before the dot in [-_\.] is not necessary as . is not a special character inside a character set []. You can simplify it to [-_.].

References
  1. For performance, regular expressions should be compiled once at the module level rather than inside a function that may be called multiple times.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants

Comments