♻️ Refactor static site screenshot naming to use properties#59
♻️ Refactor static site screenshot naming to use properties#59
Conversation
Moves viewport metadata from screenshot name to properties for better grouping and to avoid CLI validation issues with slashes in paths. Before: configuration/billing@default (fails validation) After: configuration-billing with viewport properties - Remove viewport from screenshot name generation - Add generateScreenshotProperties() for viewport metadata - Sanitize page paths (replace / and \ with -, handle ..) - Pass properties to vizzlyScreenshot() for Vizzly grouping - Update tests for new naming scheme (76 tests passing)
PR Review: Refactor static site screenshot naming to use propertiesSummaryThis PR successfully refactors the static-site plugin to avoid screenshot naming conflicts with Vizzly's security validation. The approach of moving viewport information from the name into properties is architecturally sound and aligns with Vizzly's design patterns. ✅ Strengths1. Problem Resolution
2. Code Quality
3. Test Coverage
🔍 Issues & Recommendations1. Path Sanitization Gap (Medium Priority)Issue: Line 39 in cleanPath = cleanPath.replace(/\.\./g, '.');Concerns:
Recommendation: Consider more robust sanitization: // Remove all instances of .. (not just replace)
cleanPath = cleanPath.replace(/\.{2,}/g, '');
// Or use a whitelist approach
cleanPath = cleanPath.replace(/[^a-zA-Z0-9._-]/g, '-');Note: This is currently mitigated by 2. Missing Test Coverage (Medium Priority)Tests needed:
3. Property Validation Compatibility (Low Priority)Current implementation: return {
viewport: viewport.name,
viewportWidth: viewport.width,
viewportHeight: viewport.height,
};Observation: Looking at Impact: This works because the validator allows custom string properties (lines 183-194), but Recommendation: Consider aligning with the validator's expected structure: return {
viewport: {
width: viewport.width,
height: viewport.height,
},
viewportName: viewport.name, // or use a different key
};Or keep as-is if the flat structure better serves your use case. Just document the decision. 4. Input Validation (Low Priority)Current code assumes:
Recommendation: Add defensive checks: export function generateScreenshotName(page) {
if (!page || typeof page.path !== 'string') {
throw new Error('Invalid page object: must have a string path property');
}
// ... rest of function
}
export function generateScreenshotProperties(viewport) {
if (!viewport || typeof viewport.name !== 'string') {
throw new Error('Invalid viewport object');
}
// ... rest of function
}🔒 Security Analysis✅ No security concerns identified
⚡ Performance Considerations✅ No performance issues
📊 Test Coverage AnalysisCurrent: 74% coverage is good, but could be improved to 85%+ by adding:
💡 SuggestionsNice-to-have improvements:
🎯 VerdictRecommended for approval with minor improvements This is a solid refactoring that solves the immediate problem effectively. The code is clean, well-tested, and follows the repository's patterns. The issues identified are minor and can be addressed in a follow-up PR if preferred. Suggested action items before merge:
Review generated by Claude Code - analyzed 2 changed files with 89 additions and 40 deletions |
Addresses Claude review feedback by adding comprehensive tests for: - Backslash handling (foo\bar → foo-bar) - Path traversal attempts (../../etc → .-.-etc) - Triple dots (...) - Trailing slashes All edge cases verified - 80 tests passing
Problem
The static site plugin was generating screenshot names like
configuration/billing@defaultwhich failed CLI validation because forward slashes aren't allowed in screenshot names (security restriction insrc/utils/security.js).Solution
Refactored to use Vizzly's properties system for viewport metadata instead of embedding it in the name.
Before:
configuration/billing@default❌ (fails validation)After:
configuration-billing✅ (clean, unique per page){ viewport: 'default', viewportWidth: 1920, viewportHeight: 1080 }Changes
generateScreenshotProperties()for viewport metadata/and\with-, handle..)vizzlyScreenshot()for Vizzly groupingBenefits
✅ No naming conflicts with security validation
✅ Viewport info in properties for better grouping
✅ Cleaner, more semantic approach
✅ All paths work:
/configuration/billing,/api/v1/users, etc.Testing