Spaces:
Sleeping
Sleeping
File size: 3,117 Bytes
a67549f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
"""
State Schema for LangGraph UI Regression Testing Workflow
Updated to be fully serializable for LangGraph persistence.
"""
from typing import Dict, List, Any, Optional, Annotated, TypedDict
import operator
# Use TypedDict for all state components to ensure serializability
class ViewportDict(TypedDict):
name: str
width: int
height: int
class VisualDifferenceDict(TypedDict):
category: str
severity: str
title: str
description: str
viewport: str
location: Optional[Dict[str, int]]
class VisualDifference:
"""Class representing a visual difference between design and implementation."""
def __init__(
self,
category: str,
severity: str,
issue_id: str,
title: str,
description: str,
design_value: str,
website_value: str,
viewport: str,
confidence: float = 1.0,
detection_method: str = "manual",
location: Optional[Dict[str, int]] = None
):
self.category = category
self.severity = severity
self.issue_id = issue_id
self.title = title
self.description = description
self.design_value = design_value
self.website_value = website_value
self.viewport = viewport
self.confidence = confidence
self.detection_method = detection_method
self.location = location
def to_dict(self) -> VisualDifferenceDict:
"""Convert to dictionary for serialization."""
return {
"category": self.category,
"severity": self.severity,
"title": self.title,
"description": self.description,
"viewport": self.viewport,
"location": self.location
}
class WorkflowState(TypedDict):
# Configuration
figma_file_key: str
figma_access_token: str
website_url: str
hf_token: str
execution_id: str
# Viewports and Categories
viewports: List[ViewportDict]
test_plan: Dict[str, Any]
# Agent Results
figma_screenshots: Dict[str, str]
website_screenshots: Dict[str, str]
visual_differences: Annotated[List[VisualDifferenceDict], operator.add]
# Analysis Results
hf_analysis: Optional[Dict[str, Any]]
similarity_score: float
# Status and Metadata
status: str
error_message: str
user_approval: bool
def create_initial_state(
figma_file_key: str,
figma_access_token: str,
website_url: str,
hf_token: str,
execution_id: str
) -> WorkflowState:
"""Create initial workflow state."""
return {
"figma_file_key": figma_file_key,
"figma_access_token": figma_access_token,
"website_url": website_url,
"hf_token": hf_token,
"execution_id": execution_id,
"viewports": [],
"test_plan": {},
"figma_screenshots": {},
"website_screenshots": {},
"visual_differences": [],
"hf_analysis": None,
"similarity_score": 0.0,
"status": "initialized",
"error_message": "",
"user_approval": False
}
|