Skip to content

refactor: improve pathlib usage and add link parser tests#500

Open
biryazilimciysf wants to merge 4 commits into
Universal-Commerce-Protocol:mainfrom
biryazilimciysf:fix-windows-encoding
Open

refactor: improve pathlib usage and add link parser tests#500
biryazilimciysf wants to merge 4 commits into
Universal-Commerce-Protocol:mainfrom
biryazilimciysf:fix-windows-encoding

Conversation

@biryazilimciysf

Copy link
Copy Markdown

Description

What does this PR do?

  • Explicitly sets encoding="utf-8" in hooks.py for file writing operations to prevent platform-specific encoding issues.
  • Refactors pathlib usage in hooks.py and scripts/check_links.py to be more idiomatic.
  • Improves exception handling in scripts/check_links.py by avoiding overly broad except Exception: blocks and replacing TOCTOU patterns with EAFP.
  • Adds a new unit test suite (scripts/test_check_links.py) to verify the behavior of the LinkParser.

Category (Required)

Please select one or more categories that apply to this change.

  • Core Protocol: Changes to the base communication layer, global context, or breaking refactors. (Requires Technical Council approval)
  • Governance/Contributing: Updates to GOVERNANCE.md, CONTRIBUTING.md, or CODEOWNERS. (Requires Governance Council approval)
  • Capability: New schemas (Discovery, Cart, etc.) or extensions. (Requires Maintainer approval)
  • Documentation: Updates to README, or documentations regarding schema or capabilities. (Requires Maintainer approval)
  • Infrastructure: CI/CD, Linters, or build scripts. (Requires DevOps Maintainer approval)
  • Maintenance: Version bumps, lockfile updates, or minor bug fixes. (Requires DevOps Maintainer approval)
  • SDK: Language-specific SDK updates and releases. (Requires DevOps Maintainer approval)
  • Samples / Conformance: Maintaining samples and the conformance suite. (Requires Maintainer approval)
  • UCP Schema: Changes to the ucp-schema tool (resolver, linter, validator). (Requires Maintainer approval)
  • Community Health (.github): Updates to templates, workflows, or org-level configs. (Requires DevOps Maintainer approval)

Related Issues

N/A

Checklist

  • I have followed the Contributing Guide (including Conventional Commits title requirements and ! for breaking changes).
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • (For Core/Capability) I have included/updated the relevant JSON schemas.
  • I have regenerated Python Pydantic models by running generate_models.sh under python_sdk.

Screenshots / Logs (if applicable)

N/A

@biryazilimciysf biryazilimciysf requested review from a team as code owners June 4, 2026 12:39
@biryazilimciysf

Copy link
Copy Markdown
Author

Hello! The PR is ready for review. All local tests and CI checks are passing. Please let me know if you need any changes. Thanks!

@ptiper ptiper added the devops label Jun 4, 2026
@ptiper ptiper removed request for jingyli and mmohades June 4, 2026 14:39
@damaz91 damaz91 self-assigned this Jun 8, 2026
Comment thread .pre-commit-config.yaml
- id: validate-examples-changed
name: Validate JSON examples (changed docs)
entry: python3 scripts/validate_examples.py --schema-base source/schemas/ --file
entry: python scripts/validate_examples.py --schema-base source/schemas/ --file

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.

just confirming, the python3 -> python change in pre-commit is for Windows compatibility?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi! Yes, that's exactly correct. Changing python3 to python ensures better cross-platform compatibility, especially for Windows users where the alias is typically just python.

Thank you for catching this and for your contribution to the UCP project! Merging this now.

@damaz91

damaz91 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Hi @biryazilimciysf, thank you for this PR! The Windows encoding fixes and the new unit tests for the link checker are great improvements.

I noticed that one of the new tests, test_multiple_bare_urls_with_quotes, is currently failing:

AssertionError: 'https://ucp.dev/b' not found in ['https://ucp.dev/a']

Additionally, you might need to rebase your branch on the latest main to pull in recent changes.

Could you please fix and update the PR? Thanks again for your contribution!

@biryazilimciysf

Copy link
Copy Markdown
Author

Hi @damaz91 , thanks for the review and the helpful feedback!

I've addressed all the points you raised:

The failing test (test_multiple_bare_urls_with_quotes) is now fixed.
I've rebased the branch on the latest main.
I also took care of the ruff linter/formatter issues that the CI caught.
The PR should be ready for another review. Let me know if there's anything else!

Comment thread .github/workflows/ci.yaml
run: |
python -m pip install --upgrade pip
pip install requests mkdocs
# Projenin kendi gereksinimleri varsa kuruyoruz

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.

can you please ensure all comments in this file are in english? thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

:) Sure, my bad, good eye.

Comment thread .github/workflows/ci.yaml

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.

this file looks redundant to me; aren't the tests already triggered in .pre-commit-config.yaml?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's a great question, thanks for asking! It brings up an important point about our testing strategy.

While it might seem redundant at first, the two validation steps serve distinct purposes:

validate_examples.py is our integration test. It runs against the entire documentation corpus to ensure all real examples are valid.
test_validate_examples.py is the unit test for the validator itself. It uses small, crafted inputs to verify that the validator's logic correctly enforces all the rules and handles edge cases (e.g., rejecting non-conformant examples).
The docstring in test_validate_examples.py puts it well: "The doc corpus is the integration test... This file is the unit test layer."

We run both in CI to be thorough. The unit tests ensure the tool is working, and the integration test ensures the documentation is correct using that tool. While some of these checks might also be in pre-commit for local developer convenience, the CI pipeline is our ultimate guarantee of quality.

Hope this clarifies things!

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've implemented the requested changes and pushed the updates to the fix-windows-encoding branch. The PR is ready for another review.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants