MCPcopy Create free account
hub / github.com/MigoXLab/coderio / validatePositions

Function validatePositions

src/nodes/validation/core/validate-position.ts:19–72  ·  view source on GitHub ↗
(config: ValidationIterationConfig)

Source from the content-addressed store, hash-verified

17 * @returns Validation result with MAE, SAE, misaligned components, and viewport
18 */
19export async function validatePositions(config: ValidationIterationConfig): Promise<ValidationIterationResult> {
20 const { serverUrl, figmaThumbnailUrl, protocol, positionThreshold, validationContext, elementRegistry, resolvedComponentPaths } =
21 config;
22
23 const positionTool = new PositionTool();
24
25 // Type assertion: captureBrowserPositions accepts flexible input types for compatibility
26 const captureResult = await positionTool.capturePosition({
27 protocol,
28 validationContext,
29 url: serverUrl,
30 figmaThumbnailUrl,
31 positionThreshold,
32 returnScreenshot: true,
33 elementRegistry,
34 });
35
36 // Create resolved elementToComponent mapping with absolute paths
37 // Replace alias paths with absolute filesystem paths from resolvedComponentPaths
38 const resolvedElementToComponent = new Map<string, { id: string; name: string; path: string }>();
39 for (const [elementId, componentInfo] of validationContext.elementToComponent) {
40 const resolvedPath = resolvedComponentPaths[componentInfo.id] || componentInfo.path;
41 resolvedElementToComponent.set(elementId, {
42 id: componentInfo.id,
43 name: componentInfo.name,
44 path: resolvedPath,
45 });
46 }
47
48 const aggregated = positionTool.aggregateElements(captureResult.positions, resolvedElementToComponent, positionThreshold);
49 const misalignedComponents = aggregated.misalignedComponents as unknown as MisalignedComponent[];
50 const skippedElements = aggregated.skippedElements as unknown as SkippedElement[];
51
52 // Calculate SAE
53 const sae = misalignedComponents.reduce((sum, comp) => {
54 const [errorX, errorY] = comp.validationReport.absoluteError;
55 return sum + errorX + errorY;
56 }, 0);
57
58 logger.printInfoLog(`Found ${misalignedComponents.length} misaligned components`);
59
60 return {
61 mae: captureResult.metadata.mae,
62 sae,
63 misalignedComponents,
64 skippedElements,
65 viewport: captureResult.metadata.viewport,
66 screenshots: captureResult.screenshot
67 ? {
68 renderSnap: captureResult.screenshot,
69 }
70 : undefined,
71 };
72}

Callers 1

validationLoopFunction · 0.90

Calls 2

capturePositionMethod · 0.95
aggregateElementsMethod · 0.95

Tested by

no test coverage detected