-
Notifications
You must be signed in to change notification settings - Fork 138
fix: correct UCP version data format in samples #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dipankar1415
wants to merge
5
commits into
Universal-Commerce-Protocol:main
Choose a base branch
from
dipankar1415:agent_version_compare_server_version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−18
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c7afa5
ucp version data format correction in samples
dd426ee
style: fix linting issues
damaz91 7afcaee
changes for date format for ucp version support
dipankaraws01-git 0bade5a
chore: add copyright header to ucp_version_test.py
damaz91 b7e3c4a
style: fix linting issues in ucp_version.py
damaz91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright 2026 UCP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """UCP version string parsing (YYYY-MM-DD).""" | ||
|
|
||
| import datetime | ||
| import re | ||
|
|
||
| from exceptions import UcpVersionError | ||
|
|
||
| _UCP_VERSION_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$") | ||
|
|
||
|
|
||
| def parse_ucp_version(version: str) -> datetime.date: | ||
| """Parse a UCP version string in YYYY-MM-DD format. | ||
|
|
||
| Args: | ||
| version: The version string to parse. | ||
|
|
||
| Returns: | ||
| A datetime.date representing the version. | ||
|
|
||
| Raises: | ||
| TypeError: If version is not a string. | ||
| UcpVersionError: If the string is not a valid YYYY-MM-DD calendar date. | ||
| No provision for other formats supported like YYYY-MM-DDTHH:MM:SSZ | ||
|
|
||
| """ | ||
| if not isinstance(version, str): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: do we need this? version is type-hinted to str - ideally this'd be caught by mypy. If not, version.strip() would throw an error anyway if it's not a str. |
||
| raise TypeError(f"Version must be a string, got {type(version).__name__}.") | ||
|
|
||
| version = version.strip() | ||
| if not _UCP_VERSION_RE.fullmatch(version): | ||
| raise UcpVersionError( | ||
| f"Version '{version}' is invalid. Expected YYYY-MM-DD.", | ||
| code="VERSION_INVALID_FORMAT", | ||
| ) | ||
|
|
||
| try: | ||
| return datetime.date.fromisoformat(version) | ||
| except ValueError as exc: | ||
| raise UcpVersionError( | ||
| f"Version '{version}' is invalid. Expected YYYY-MM-DD.", | ||
| code="VERSION_INVALID_FORMAT", | ||
| ) from exc | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Copyright 2026 UCP Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Unit tests for UCP version parsing.""" | ||
|
|
||
| import datetime | ||
| import unittest | ||
|
|
||
| from exceptions import UcpVersionError | ||
| from ucp_version import parse_ucp_version | ||
|
|
||
|
|
||
| class UcpVersionTest(unittest.TestCase): | ||
| """Tests parse_ucp_version behavior.""" | ||
|
|
||
| def test_parse_valid_date(self) -> None: | ||
| """Test parsing a valid YYYY-MM-DD date.""" | ||
| parsed = parse_ucp_version("2026-01-23") | ||
| self.assertEqual(parsed, datetime.date(2026, 1, 23)) | ||
|
|
||
| def test_parse_strips_whitespace(self) -> None: | ||
| """Test that leading/trailing whitespace is stripped before parsing.""" | ||
| parsed = parse_ucp_version(" 2026-01-23 ") | ||
| self.assertEqual(parsed, datetime.date(2026, 1, 23)) | ||
|
|
||
| def test_parse_rejects_non_string(self) -> None: | ||
| """Test that non-string inputs raise TypeError.""" | ||
| with self.assertRaises(TypeError): | ||
| parse_ucp_version(123) # type: ignore[arg-type] | ||
|
|
||
| def test_parse_rejects_invalid_format(self) -> None: | ||
| """Test that invalid formats raise UcpVersionError.""" | ||
| with self.assertRaises(UcpVersionError) as exc: | ||
| parse_ucp_version("2026/01/23") | ||
| self.assertEqual(exc.exception.code, "VERSION_INVALID_FORMAT") | ||
|
|
||
| def test_parse_rejects_invalid_calendar_date(self) -> None: | ||
| """Test that invalid calendar dates (e.g. Feb 30) raise UcpVersionError.""" | ||
| with self.assertRaises(UcpVersionError) as exc: | ||
| parse_ucp_version("2026-02-30") | ||
| self.assertEqual(exc.exception.code, "VERSION_INVALID_FORMAT") | ||
|
|
||
| def test_parse_rejects_datetime_format(self) -> None: | ||
| """Test that datetime formats (with time component) are rejected.""" | ||
| with self.assertRaises(UcpVersionError) as exc: | ||
| parse_ucp_version("2026-01-23T10:11:12Z") | ||
| self.assertEqual(exc.exception.code, "VERSION_INVALID_FORMAT") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this helper function really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this error is in the same shape as what UcpVersionError to_detail returns.
Can we have some kind of data class? e.g. UcpErrorDetail(BaseModel) - I guess we can use pydantic. AFAIK FastAPI will also automatically document pydantic models.