Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion openhtf/core/phase_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ class ExceptionInfo(object):
exc_tb = attr.ib(type=types.TracebackType)

def as_base_types(self) -> Dict[Text, Text]:
return {
result = {
'exc_type': str(self.exc_type),
'exc_val': str(self.exc_val),
'exc_tb': self.get_traceback_string(),
}
# Add operator action popup data if this is a frontend-friendly error.
# Check for the required attributes to support duck-typing.
if hasattr(self.exc_val, 'title') and hasattr(self.exc_val, 'description'):
result['operator_popup'] = {
'title': self.exc_val.title,
'description': self.exc_val.description,
'image_url': getattr(self.exc_val, 'image_url', None),
}
print(f"[DEBUG ExceptionInfo.as_base_types] Added operator_popup: {result['operator_popup']}")
else:
print(f"[DEBUG ExceptionInfo.as_base_types] No operator_popup attrs on {type(self.exc_val)}")
return result

def get_traceback_string(self) -> Text:
return ''.join(
Expand Down
49 changes: 49 additions & 0 deletions openhtf/output/servers/station_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,54 @@ def post(self, test_uid, plug_name):
self.write(response)


class ProjectStaticFileHandler(web_gui_server.CorsRequestHandler):
"""Serves static files from the project root directory.

This allows RecoveryPromptError to reference images relative to the
project root, e.g., image_url="/project/path/to/image.png".

The project root defaults to the current working directory when the
server starts, but can be configured via the 'project_root' parameter.
"""

project_root = None

def initialize(self, project_root=None):
self.project_root = project_root or os.getcwd()

def get(self, path):
# Prevent directory traversal attacks
path = os.path.normpath(path)
if path.startswith('..') or os.path.isabs(path):
self.set_status(403)
self.write('Forbidden')
return

file_path = os.path.join(self.project_root, path)

if not os.path.isfile(file_path):
self.set_status(404)
self.write('File not found')
return

# Determine content type based on extension
ext = os.path.splitext(file_path)[1].lower()
content_types = {
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.webp': 'image/webp',
'.bmp': 'image/bmp',
}
content_type = content_types.get(ext, 'application/octet-stream')

self.set_header('Content-Type', content_type)
with open(file_path, 'rb') as f:
self.write(f.read())


class BaseHistoryHandler(web_gui_server.CorsRequestHandler):

history_path = None
Expand Down Expand Up @@ -913,6 +961,7 @@ def __init__(
(r'/tests/(?P<test_uid>[\w\d:]+)/phases/(?P<phase_descriptor_id>\d+)/'
'attachments/(?P<attachment_name>.+)', AttachmentsHandler),
(r'/commands/(?P<command>.+)', CommandHandler),
(r'/project/(.*)', ProjectStaticFileHandler, {'project_root': None}),
))

# Optionally enable history from disk.
Expand Down
1 change: 1 addition & 0 deletions openhtf/output/servers/web_gui_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
r'css/.*\.css',
r'css/.*\.css.map',
r'img/.*',
r'images/.*',
r'js/.*\.js',
r'js/.*\.js\.map',
r'service-worker\.js',
Expand Down
Loading
Loading