Skip to content

Mergemaster#129

Merged
beniroquai merged 2 commits intomasterfrom
mergemaster
Jan 20, 2026
Merged

Mergemaster#129
beniroquai merged 2 commits intomasterfrom
mergemaster

Conversation

@beniroquai
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings January 20, 2026 20:28
@beniroquai beniroquai merged commit d8d5697 into master Jan 20, 2026
2 checks passed
Copy link
Contributor

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 pull request adds two new files to support motor configuration management and firmware file serving:

  1. A comprehensive motor configuration module (motor_config.py) with dataclasses for managing motor settings
  2. A simple file server (fwServer.py) for serving firmware files over HTTP

Changes:

  • Introduced structured motor configuration using dataclasses with support for TMC driver settings, homing, motion parameters, and limits
  • Added conversion methods to interface with existing ImSwitch configuration format
  • Created a FastAPI-based file server for browsing and downloading files

Reviewed changes

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

File Description
uc2rest/motor_config.py Comprehensive dataclass-based motor configuration system with serialization/deserialization support and ImSwitch compatibility
binaries/latest/fwServer.py Simple FastAPI file server with directory browsing and file download capabilities

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

fs_path = safe_path(req_path)

if not fs_path.exists():
raise HTTPException(status_code=404)
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The error message for HTTP 404 (Not Found) is empty. Provide a descriptive error message to help users understand what resource was not found, such as "Resource not found".

Suggested change
raise HTTPException(status_code=404)
raise HTTPException(status_code=404, detail=f"Resource not found: {req_path}")

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +73
html = "<ul>" + "".join(
f"<li><a href='{e['name']}'>{e['name']}</a></li>"
for e in entries
) + "</ul>"
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The HTML generation for directory listing does not escape the entry names, which could lead to Cross-Site Scripting (XSS) vulnerabilities if filenames contain HTML or JavaScript. Use proper HTML escaping for the name values in both the href and display text.

Copilot uses AI. Check for mistakes.
# index.html suppresses listing
index = fs_path / "index.html"
if index.exists():
return HTMLResponse(index.read_text())
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Reading the entire index.html file into memory using read_text() without error handling could cause issues with very large files or encoding errors. Consider adding error handling or using FileResponse instead for consistency with how other files are served.

Suggested change
return HTMLResponse(index.read_text())
return FileResponse(index, media_type="text/html")

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +84
def from_dict(cls, data: dict) -> 'MotionSettings':
if data is None:
return cls()
# Handle None values from JSON
if data.get('min_pos') is None:
data['min_pos'] = float('-inf')
if data.get('max_pos') is None:
data['max_pos'] = float('inf')
return cls(**{k: v for k, v in data.items() if k in cls.__dataclass_fields__})
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The from_dict method mutates the input data dictionary when handling None values for min_pos and max_pos. This can lead to unexpected side effects if the caller reuses the dictionary. Consider creating a copy of the data dictionary before modifying it, or use a different approach that doesn't mutate the input.

Copilot uses AI. Check for mistakes.
return cls.from_dict(json.loads(json_str))

@classmethod
def from_imswitch_config(cls, manager_properties: dict, stage_offsets: dict = None) -> 'MotorSystemConfig':
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The stage_offsets parameter in the method signature is documented but never used in the implementation. Either remove this unused parameter or implement its intended functionality.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,79 @@
# dummy_caddy_like_server.py
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The comment refers to this file as "dummy_caddy_like_server.py" but the actual filename is "fwServer.py". This inconsistency can cause confusion. Update the comment to match the actual filename.

Suggested change
# dummy_caddy_like_server.py
# fwServer.py

Copilot uses AI. Check for mistakes.
def safe_path(req_path: str) -> Path:
p = (ROOT / req_path).resolve()
if not p.is_relative_to(ROOT):
raise HTTPException(status_code=403)
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The error message for HTTP 403 (Forbidden) in the safe_path function is empty. Provide a descriptive error message to help users understand why their request was denied, such as "Access denied: path is outside allowed directory".

Suggested change
raise HTTPException(status_code=403)
raise HTTPException(
status_code=403,
detail="Access denied: path is outside allowed directory",
)

Copilot uses AI. Check for mistakes.
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