fix(recordings): preserve media referenced by saved projects#282
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a test suite for pruneAutoRecordings and enhances prune logic with loadSavedProjectMediaPaths() to detect recordings referenced by saved projects and skip pruning of those files. Changes
Sequence DiagramsequenceDiagram
participant App as App
participant Prune as pruneAutoRecordings()
participant Projects as Projects Dir
participant Files as Recording Files
App->>Prune: invoke pruneAutoRecordings()
Prune->>Projects: loadSavedProjectMediaPaths()
Projects->>Projects: read project files (json / legacy)
Projects->>Projects: extract videoPath & editor.webcam.sourcePath
Projects->>Projects: normalize paths & attempt realpath()
Projects-->>Prune: return Set(protected paths)
Prune->>Files: list recordings in recordings dir
loop per recording file
Prune->>Prune: compute normalized and realpath forms
alt path in protected Set
Prune->>Files: skip deletion
else
Prune->>Files: delete file
end
end
Prune-->>App: complete
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
electron/ipc/recording/prune.test.ts (1)
50-87: Add coverage for webcam media references too.This test locks down
videoPath, but the implementation also preserveseditor.webcam.sourcePath. A small second case or parameterized test would prevent that branch from regressing silently.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@electron/ipc/recording/prune.test.ts` around lines 50 - 87, The test only covers preservation when a project references recordings via videoPath but misses the editor.webcam.sourcePath branch; update the test for pruneAutoRecordings to include a second saved-project file (or parameterize the test) whose JSON contains editor: { webcam: { sourcePath: protectedRecordingPath } } so that a recording referenced via editor.webcam.sourcePath is also asserted preserved (and a different late recording asserted removed). Use the same helpers/constants (getRecordingsDir, PROJECTS_DIRECTORY_NAME, PROJECT_FILE_EXTENSION) and the existing recordingPaths array to create the protected and prunable paths and then call pruneAutoRecordings and assert access outcomes as done for videoPath.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@electron/ipc/recording/prune.ts`:
- Around line 49-94: The pruning currently treats any fs.readdir or per-project
JSON parse/read error as benign and continues, which can cause valid projects to
be ignored and recordings to be deleted; change the logic so only a missing
Projects directory (fs.readdir error code 'ENOENT') is treated as empty, but any
other error from fs.readdir should abort pruning (rethrow or propagate).
Likewise, inside the projectEntries.map block, do not swallow
JSON.parse/fs.readFile errors for existing project files—if reading/parsing a
project (the JSON.parse(await fs.readFile(projectPath, "utf-8")) step) fails,
propagate/abort pruning instead of continuing; still allow ignoring fs.realpath
failures for missing referenced media (the existing try/catch around
fs.realpath), and continue adding normalizedCandidatePath (via
normalizeVideoSourcePath and normalizePath) to protectedPaths when valid.
---
Nitpick comments:
In `@electron/ipc/recording/prune.test.ts`:
- Around line 50-87: The test only covers preservation when a project references
recordings via videoPath but misses the editor.webcam.sourcePath branch; update
the test for pruneAutoRecordings to include a second saved-project file (or
parameterize the test) whose JSON contains editor: { webcam: { sourcePath:
protectedRecordingPath } } so that a recording referenced via
editor.webcam.sourcePath is also asserted preserved (and a different late
recording asserted removed). Use the same helpers/constants (getRecordingsDir,
PROJECTS_DIRECTORY_NAME, PROJECT_FILE_EXTENSION) and the existing recordingPaths
array to create the protected and prunable paths and then call
pruneAutoRecordings and assert access outcomes as done for videoPath.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4ed398ea-6912-48f6-aba6-7d8a24994fa5
📒 Files selected for processing (2)
electron/ipc/recording/prune.test.tselectron/ipc/recording/prune.ts
Description
Prevent the auto-recording retention job from deleting recordings that are still referenced by saved project files in the
Projectsdirectory.Motivation
The retention logic currently only preserves recordings when a sibling project file exists next to the media file. Saved Recordly projects live under
recordings/Projects, so older recordings can be pruned even though the project metadata still points at them.Type of Change
Related Issue(s)
Testing Guide
npx vitest --run electron/ipc/recording/prune.test.tsnpx @biomejs/biome check electron/ipc/recording/prune.ts electron/ipc/recording/prune.test.tsnpx tsc --noEmitChecklist
Projectsdirectory reference caseSummary by CodeRabbit
Bug Fixes
Tests