Skip to content

fix: validate payment timeout values - #130

Open
samsamtrum wants to merge 2 commits into
google-agentic-commerce:mainfrom
samsamtrum:fix-payment-timeout-validation
Open

fix: validate payment timeout values#130
samsamtrum wants to merge 2 commits into
google-agentic-commerce:mainfrom
samsamtrum:fix-payment-timeout-validation

Conversation

@samsamtrum

Copy link
Copy Markdown

create_payment_requirements accepted invalid timeout values and passed them into the generated payment requirements.

This adds a small validation step so the timeout must be a positive integer before the payment requirement is built. It also adds regression coverage for zero, negative, fractional, and boolean values.

@samsamtrum
samsamtrum requested a review from a team as a code owner June 15, 2026 21:00
@google-cla

google-cla Bot commented Jun 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 adds validation to ensure that max_timeout_seconds is a positive integer (and not a boolean) in create_payment_requirements, along with corresponding unit tests. The review feedback suggests improving the test coverage by asserting the specific exception messages and testing additional invalid types like None and stringified integers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +142 to +149
for timeout in (0, -1, 1.5, True):
with pytest.raises(ValueError):
create_payment_requirements(
price="$1.00",
pay_to_address="0x123",
resource="/test",
max_timeout_seconds=timeout,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current test uses a generic pytest.raises(ValueError) without verifying the exception message. This can lead to false positives if a ValueError is raised from another part of the function (e.g., during price processing).

Additionally, we should expand the test coverage to include other common invalid types such as None and stringified integers (e.g., "60").

We can improve this by using pytest.raises(ValueError, match=...) and parameterizing or looping over the expected error messages.

Suggested change
for timeout in (0, -1, 1.5, True):
with pytest.raises(ValueError):
create_payment_requirements(
price="$1.00",
pay_to_address="0x123",
resource="/test",
max_timeout_seconds=timeout,
)
for timeout, expected_msg in [
(0, "max_timeout_seconds must be positive"),
(-1, "max_timeout_seconds must be positive"),
(1.5, "max_timeout_seconds must be an integer"),
(True, "max_timeout_seconds must be an integer"),
(None, "max_timeout_seconds must be an integer"),
("60", "max_timeout_seconds must be an integer"),
]:
with pytest.raises(ValueError, match=expected_msg):
create_payment_requirements(
price="$1.00",
pay_to_address="0x123",
resource="/test",
max_timeout_seconds=timeout,
)

@samsamtrum
samsamtrum force-pushed the fix-payment-timeout-validation branch from bf4b3d1 to 181ef11 Compare June 15, 2026 21:01
@samsamtrum samsamtrum changed the title Validate payment timeout values fix: validate payment timeout values Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant