You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add comprehensive test suite for IrisFaceMeshTracker with 614 test cases covering initialization, iris position calculation, gaze prediction, saccade detection, and CSV export
Add JSDoc documentation to IrisFaceMeshTracker class methods explaining parameters, return values, and functionality
Enhance saccadeData tests with additional test cases for delayed saccades, anti-saccade latency bounds, hypometric rate calculation, and error handling
Clean up test file comments and improve test data structure consistency
Diagram Walkthrough
flowchart LR
A["IrisFaceMeshTracker<br/>Implementation"] -->|"Test Coverage"| B["iris-facemesh.test.js<br/>614 test cases"]
A -->|"Documentation"| C["JSDoc Comments<br/>Method descriptions"]
D["saccadeData<br/>Analysis"] -->|"Enhanced Tests"| E["saccadeData.test.js<br/>Additional scenarios"]
B -->|"Validates"| F["Initialization & Tracking"]
B -->|"Validates"| G["Iris Position & Gaze"]
B -->|"Validates"| H["Saccade Detection"]
E -->|"Tests"| I["Latency Classification"]
E -->|"Tests"| J["Data Quality Metrics"]
Loading
File Walkthrough
Relevant files
Tests
iris-facemesh.test.js
Comprehensive test suite for iris tracking functionality
src/tests/utils/iris-facemesh.test.js
Created comprehensive test suite with 614 lines covering all IrisFaceMeshTracker functionality
Tests include constructor initialization, iris position calculation, gaze prediction with calibration models, trial context management, saccade detection, CSV export, and cleanup operations
Includes helper function createLandmarks() to generate mock MediaPipe landmark data with configurable overrides
Mocks MediaPipe FaceLandmarker and detectSaccade dependencies for isolated unit testing
Covers edge cases like missing landmarks, invalid eye sides, null calibration models, and empty tracking data
Integration tests verify trial context persistence and bilateral iris position consistency
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Missing input validation: getRelativeIrisPos() does not validate eyeSide and will throw when EYE_INDICES[eyeSide] is undefined instead of handling the edge case gracefully.
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Unvalidated input parameter: getRelativeIrisPos() uses the externally-provided eyeSide parameter without validation, allowing crashes (DoS-style) when an unexpected value is passed.
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Logs include model: The tracker logs the full model object via console.log, which could inadvertently include sensitive or high-volume data and is unstructured for auditing.
Referred Code
setCalibrationModel(model){this.calibrationModel=model;console.log("Calibration model set in tracker:",model);}
Decompose the monolithic IrisFaceMeshTracker class
The IrisFaceMeshTracker class handles too many responsibilities, such as camera management, data processing, and exporting. It should be refactored into smaller, more focused classes to improve modularity.
classIrisFaceMeshTracker{// State propertiesfaceLandmarker;isTracking;trackingData;videoElement;calibrationModel;// Responsibilitiesasyncinitialize(){/* MediaPipe & video setup */}asyncstartCamera(){/* getUserMedia */}processFrame(){/* Main processing loop */}getRelativeIrisPos(...){/* Data calculation */}predictGaze(...){/* Data calculation */}startTracking(){/* State management */}stopTracking(){/* State management */}addTrialContext(...){/* Context management */}exportCSV(){/* Data export */}cleanup(){/* Resource cleanup */}}
After:
classCameraManager{videoElement;initialize(){/* Creates and manages video element */}start(){/* Starts camera stream */}stop(){/* Stops camera stream */}cleanup(){/* Removes video element */}}classGazeProcessor{faceLandmarker;calibrationModel;initialize(){/* Sets up MediaPipe */}processFrame(videoFrame){/* Processes a single frame */}// ... other calculation methods}classTrackingSession{trackingData;isTracking;start(){/* Manages session state */}stop(){/* Manages session state */}addTrialContext(...){/* Adds context to data */}exportCSV(){/* Exports session data */}}
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a critical architectural flaw (God Class) in IrisFaceMeshTracker and astutely uses the PR's new 600+ line test file as strong evidence for the class's excessive complexity.
High
Possible issue
Prevent errors from missing iris data
In the exportCSV function, add optional chaining (?.) when accessing point.leftIris, point.rightIris, and point.avgIris properties to prevent TypeError if this data is missing.
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 8
__
Why: This suggestion correctly identifies a potential TypeError in the exportCSV function if iris data is missing for a frame and provides a robust fix using optional chaining, preventing a runtime crash.
Medium
Add null check for quality object
In aggregateTrialStatistics, add a check for t.quality before accessing t.quality.dataQuality to prevent a TypeError if the quality object is missing from a trial.
export const aggregateTrialStatistics = (trialsData, trialType = 'unknown') => {
const validTrials = trialsData.filter(t =>
t.isSaccade &&
t.isPhysiologicallyPlausible &&
- t.quality.dataQuality > 0.7 // Only include high-quality trials+ t.quality && t.quality.dataQuality > 0.7 // Only include high-quality trials
);
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential TypeError when filtering trials if the quality object is missing and provides a simple, effective guard to prevent the application from crashing.
Medium
Use modern fake timers for testing
To fix a failing test for getRelativeTime, switch to modern fake timers in Jest, which correctly mock Date.now(), ensuring the time advancement is properly simulated.
Why: The suggestion correctly identifies that the test for getRelativeTime is flawed because legacy fake timers do not mock Date.now(), and proposes a valid fix using modern timers, ensuring the test's correctness.
Medium
General
Prevent divide by zero
In predictGaze, guard against division-by-zero by ensuring window.innerWidth and window.innerHeight are at least 1 before using them as divisors.
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 5
__
Why: This suggestion correctly identifies a potential division-by-zero error if window.innerWidth or innerHeight is zero and provides a simple guard, improving the code's robustness in edge cases.
Low
Null out references in cleanup
In the cleanup method, set this.faceLandmarker and this.videoElement to null after their resources are released to aid garbage collection.
Why: The suggestion offers a minor improvement for memory management by nullifying references in the cleanup method, which is good practice but has a low impact on functionality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Tests, Enhancement, Documentation
Description
Add comprehensive test suite for IrisFaceMeshTracker with 614 test cases covering initialization, iris position calculation, gaze prediction, saccade detection, and CSV export
Add JSDoc documentation to IrisFaceMeshTracker class methods explaining parameters, return values, and functionality
Enhance saccadeData tests with additional test cases for delayed saccades, anti-saccade latency bounds, hypometric rate calculation, and error handling
Clean up test file comments and improve test data structure consistency
Diagram Walkthrough
File Walkthrough
iris-facemesh.test.js
Comprehensive test suite for iris tracking functionalitysrc/tests/utils/iris-facemesh.test.js
IrisFaceMeshTracker functionality
gaze prediction with calibration models, trial context management,
saccade detection, CSV export, and cleanup operations
createLandmarks()to generate mock MediaPipelandmark data with configurable overrides
isolated unit testing
calibration models, and empty tracking data
position consistency
saccadeData.test.js
Enhanced saccade analysis tests with additional scenariossrc/tests/utils/saccadeData.test.js
detectSaccade.calculateAdaptiveThresholdfunctionplausibility check
aggregateTrialStatistics
compareProVsAnti
values
metrics
iris-facemesh.js
Add comprehensive JSDoc documentation to tracker classsrc/views/GameTest/utils/iris-facemesh.js
overall responsibility
getRelativeIrisPos()method with parameter andreturn value descriptions
initialize()method explaining MediaPipeFaceLandmarker setup
setCalibrationModel()method documenting modelparameter structure
predictGaze()method with iris coordinates andeye parameter documentation
startCamera()method explaining camera streaminitialization
processFrame()method describing the mainvideo processing loop
performSaccadeDetection()method explainingsaccade detection logic
startTracking()andstopTracking()methodsaddTrialContext()method explaining trialcontext attachment
exportCSV()methodcleanup()method explaining resource cleanup