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
{{ message }}
Repository navigation
Reject png/jpeg targets in file.save instead of writing zip bytes - #1698
Found while testing crates/engine/src/cmd/file.rs:489 (save, with save_bytes at :341-349 and format_for_path at :440) (no existing issue): file.save to a .png/.jpg path writes native deckcraft zip bytes under an image name and marks the deck saved.
Cause
format_for_path maps .png/.jpg/.jpeg to "png"/"jpeg", but save_bytes has no writer for them and falls through to the native .deckcraft zip. file.save then wrote that zip under an image name and marked the deck saved with the image path.
Fix
save_bytes now returns an error for the "png" and "jpeg" formats, so file.save and file.saveAs fail before anything is written or the deck is marked saved. The error points to file.export for image output.
Verified
Regression test tests::save_to_image_path_is_an_error_not_zip_bytes: fails on main without the fix and passes with it (cargo test -p deckcraft-engine save_to_image_path).
cargo xtask ci passes except backstage::tests::start_screen_opens_the_palette_and_preferences, which also fails on main without this change.
Not changed
Saving to other extensions with no writer, such as .odp, still falls back to native bytes. Image export (file.export and the UI's image exporter) is unchanged.
🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models
Summary by CodeRabbit
Bug Fixes
Saving a presentation directly as PNG or JPEG now returns an error instead of creating a file. The document path remains unchanged when the save fails.
To create a single-image presentation, use the export option.
Found while testing crates/engine/src/cmd/file.rs:489 (save, with save_bytes at :341-349 and format_for_path at :440)
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
save_bytes now rejects PNG and JPEG formats. Regression coverage checks that the affected save commands return errors, create no file, and leave the document path unchanged.
Changes: Image save rejection
Layer / File(s)
Summary
Reject image saves and verify state crates/engine/src/cmd/file.rs, crates/engine/src/tests.rs
save_bytes rejects PNG and JPEG formats instead of using the native DeckCraft serializer. The regression test checks .png, .jpeg, and .jpg save requests for errors, no file creation, and an unchanged document path.
This change makes saving to a PNG or JPEG path fail with a message pointing to file.export, instead of writing ZIP bytes under an image name. The one remaining edge case needs an explicit format override that the user chose deliberately. No merge-blocking risk remains.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: rejecting PNG and JPEG targets in file.save instead of writing ZIP bytes.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
crates/engine/src/cmd/file.rs-348-348: 1
348-348: Major · Data Integrity & Integration · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Reject image paths, not only image formats.
If file.save or file.saveAs receives {"path":"a.png","format":"deckcraft"}, this branch is bypassed. The _ arm writes native DeckCraft ZIP bytes to a.png, then mark_saved updates the document state. file.save explicitly accepts a format parameter, and the save flow applies it before writing. (raw.githubusercontent.com)
Reject .png, .jpg, and .jpeg paths before applying an explicit format. Add a regression case with "format": "deckcraft".
Proposed fix
- let format = str_param(p, "format").unwrap_or(format_for_path(&path));+ let path_format = format_for_path(&path);+ if matches!(path_format, "png" | "jpeg") {+ return Err(EngineError::Other(+ "saving a presentation as a single image isn't supported; use file.export".into(),+ ));+ }+ let format = str_param(p, "format").unwrap_or(path_format);
Reviewing files that changed from the base of the PR and between f68150e and 58c2488.
Files selected for processing: 2
crates/engine/src/cmd/file.rs
crates/engine/src/tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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.
Found while testing
crates/engine/src/cmd/file.rs:489 (save, with save_bytes at :341-349 and format_for_path at :440)(no existing issue): file.save to a .png/.jpg path writes native deckcraft zip bytes under an image name and marks the deck saved.Cause
format_for_path maps .png/.jpg/.jpeg to "png"/"jpeg", but save_bytes has no writer for them and falls through to the native .deckcraft zip. file.save then wrote that zip under an image name and marked the deck saved with the image path.
Fix
save_bytes now returns an error for the "png" and "jpeg" formats, so file.save and file.saveAs fail before anything is written or the deck is marked saved. The error points to file.export for image output.
Verified
tests::save_to_image_path_is_an_error_not_zip_bytes: fails onmainwithout the fix and passes with it (cargo test -p deckcraft-engine save_to_image_path).cargo xtask cipasses exceptbackstage::tests::start_screen_opens_the_palette_and_preferences, which also fails onmainwithout this change.Not changed
Saving to other extensions with no writer, such as .odp, still falls back to native bytes. Image export (file.export and the UI's image exporter) is unchanged.
🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models
Summary by CodeRabbit