Skip to content

fix: handle prefixed types in validation and use dynamic port allocation#106

Merged
yibeichan merged 2 commits intomainfrom
fix/validate-prefixed-types
Jan 29, 2026
Merged

fix: handle prefixed types in validation and use dynamic port allocation#106
yibeichan merged 2 commits intomainfrom
fix/validate-prefixed-types

Conversation

@yibeichan
Copy link
Contributor

Summary

  • Add normalization for prefixed type forms (reproschema:X) to full URIs in identify_model_class() for more robust validation
  • Change HTTP server to use port 0 by default, letting the OS assign an available port instead of hardcoded 8000/4001
  • Return actual assigned port from simple_http_server()

Problem

Tests were failing when port 8000 was already in use (e.g., by Docker), causing JSON-LD context loading to fail during validation. The expanded @type remained as prefixed forms like reproschema:ResponseActivity instead of full URIs.

Test plan

  • pytest reproschema/tests/test_validate.py - all 3 tests pass
  • pytest reproschema/tests/ - 60 passed, 2 skipped

Release Notes

This PR is intended to be part of v1.1.0 release which includes:

  • New loris2reproschema converter
  • New nbdc2reproschema converter
  • This validation fix

🤖 Generated with Claude Code

- Add normalization for prefixed type forms (reproschema:X) to full URIs
  in identify_model_class() for more robust validation
- Change HTTP server to use port 0 by default, letting the OS assign
  an available port instead of hardcoded 8000/4001
- Return actual assigned port from simple_http_server()

This fixes test failures that occurred when port 8000 was already in use
(e.g., by Docker) causing JSON-LD context loading to fail.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yibeichan yibeichan added release Ready to go! minor labels Jan 29, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @yibeichan, 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 significantly enhances the stability and robustness of the system by addressing critical issues related to schema validation and HTTP server port management. It ensures that schema types are correctly interpreted by normalizing prefixed forms to full URIs, and it resolves test failures caused by hardcoded port conflicts by implementing dynamic port allocation for internal HTTP servers. These changes contribute to a more reliable validation process and smoother test execution.

Highlights

  • Validation Robustness: Implemented normalization for prefixed schema types (e.g., "reproschema:X") to their full URI forms within identify_model_class(), ensuring more reliable validation of schema elements.
  • Dynamic Port Allocation: Configured the internal HTTP server functions (simple_http_server and start_server) to use port 0 by default, allowing the operating system to assign an available port dynamically and preventing conflicts.
  • Actual Port Reporting: Modified simple_http_server() to return the actual port assigned by the operating system, improving visibility and control over server operations and debugging.

🧠 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.

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.

@yibeichan yibeichan requested a review from Copilot January 29, 2026 19:52
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 introduces two valuable improvements: handling prefixed types during validation and using dynamic port allocation for the HTTP server to prevent conflicts. The implementation for dynamic port allocation is solid, correctly obtaining and utilizing the OS-assigned port. The logic for normalizing prefixed URIs is also correct. I have one minor suggestion to enhance the robustness of the string replacement logic. Overall, these changes effectively address the stated problems and improve the reliability of the codebase.

def identify_model_class(category):
# Normalize prefixed forms to full URIs
if category.startswith("reproschema:"):
category = category.replace(

Choose a reason for hiding this comment

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

medium

Using replace() without a count argument will replace all occurrences of the substring. While the startswith() check makes it likely you only want to replace the prefix, it's safer and clearer to explicitly replace only the first occurrence by specifying count=1. This prevents potential bugs if the category string unexpectedly contains the prefix multiple times.

Suggested change
category = category.replace(
category = category.replace("reproschema:", "http://schema.repronim.org/", 1)

Copy link

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 fixes validation failures that occurred when port 8000 was already in use and handles prefixed type forms in JSON-LD documents more robustly.

Changes:

  • Added normalization logic to convert prefixed type forms (reproschema:X) to full URIs in the identify_model_class() function
  • Changed HTTP server functions to use dynamic port allocation (port 0) by default, allowing the OS to assign available ports
  • Updated return values to provide the actual assigned port number

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
reproschema/models/utils.py Added prefix normalization in identify_model_class() to convert reproschema: prefixed types to full http://schema.repronim.org/ URIs
reproschema/utils.py Changed default port from hardcoded values (4001/8000) to 0 for OS-assigned ports; updated simple_http_server() to return actual assigned port; added documentation about dynamic port allocation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yibeichan yibeichan merged commit 4e86b81 into main Jan 29, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor release Ready to go!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants