Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Refuse pictures over 20 MB when they are added (#720)

Alex Joaquim Pereira801f060368c3
diff --git a/crates/engine/src/workspace.rs b/crates/engine/src/workspace.rs
index 9ce7d6de..5ec1e69e 100644
--- a/crates/engine/src/workspace.rs
+++ b/crates/engine/src/workspace.rs
@@ -826,7 +826,8 @@ impl Workspace {
}
/// Copy pictures of the original into reference/ as picture-N.ext. Returns how many were
- /// added; files that aren't PNG, JPEG, WebP or GIF, or are over 20 MB, are skipped.
+ /// added; files that aren't PNG, JPEG, WebP or GIF are skipped, and a picture over 20 MB
+ /// refuses the whole call before anything is copied.
pub fn add_references(&self, files: &[PathBuf]) -> Result<usize, ToolError> {
copy_pictures(&self.reference_dir(), files).map(|v| v.len())
}
@@ -1061,8 +1062,17 @@ fn pictures_in(dir: &Path) -> Vec<PathBuf> {
}
/// Copy pictures into `dir` as picture-N.ext, numbering on from what's there. Files that aren't
-/// PNG, JPEG, WebP or GIF, or are over 20 MB, are skipped.
+/// PNG, JPEG, WebP or GIF are skipped; a picture over 20 MB is refused before anything is copied.
fn copy_pictures(dir: &Path, files: &[PathBuf]) -> Result<Vec<PathBuf>, ToolError> {
+ // Check the whole list first: a mixed add must not leave the valid pictures half-copied when
+ // one is too large.
+ for f in files {
+ if picture_too_large(f) {
+ let name = f.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| f.display().to_string());
+ return Err(ToolError::new(ErrorCode::OverLimit, format!("{name} can't be attached: a message takes pictures up to 20 MB."))
+ .with_remediation("Attach a smaller picture, or save it as a JPEG."));
+ }
+ }
std::fs::create_dir_all(dir).map_err(|e| ToolError::io(dir.display(), e))?;
let mut next = pictures_in(dir).iter().map(|p| picture_number(p)).max().unwrap_or(0);
let mut added = Vec::new();
@@ -1087,7 +1097,7 @@ fn picture_number(p: &Path) -> u32 {
/// The most pixels a pasted picture may have (a 16K screen): more is refused before encoding.
const MAX_PASTED_PIXELS: u64 = 15360 * 8640;
-/// The largest picture a message sends ([`copy_pictures`] skips bigger files).
+/// The largest picture a message sends ([`copy_pictures`] refuses bigger files).
const MAX_PICTURE_BYTES: u64 = 20 * 1024 * 1024;
/// Whether the file starts the way a PNG, JPEG, GIF or WebP picture does, whatever its name says.
@@ -1105,6 +1115,11 @@ pub fn picture_content(p: &Path) -> bool {
|| (head.starts_with(b"RIFF") && head.get(8..12) == Some(b"WEBP".as_slice()))
}
+/// Whether `p` is a picture larger than a message can take. Reads its size, so not while drawing.
+pub fn picture_too_large(p: &Path) -> bool {
+ is_picture(p) && p.metadata().is_ok_and(|m| m.is_file() && m.len() > MAX_PICTURE_BYTES)
+}
+
/// A picture file a message can take: a picture ([`is_picture`]) of at most 20 MB. Reads its
/// size, so not while drawing.
pub fn attachable_picture(p: &Path) -> bool {
@@ -1187,6 +1202,8 @@ mod tests {
std::fs::write(&small, b"png").unwrap();
let big = dir.path().join("big.PNG");
std::fs::File::create(&big).unwrap().set_len(MAX_PICTURE_BYTES + 1).unwrap();
+ let exact = dir.path().join("exact.png");
+ std::fs::File::create(&exact).unwrap().set_len(MAX_PICTURE_BYTES).unwrap();
let text = dir.path().join("notes.txt");
std::fs::write(&text, b"hi").unwrap();
let folder = dir.path().join("folder.png");
@@ -1195,8 +1212,32 @@ mod tests {
for no in [&big, &text, &folder, &dir.path().join("gone.png")] {
assert!(!attachable_picture(no), "{}", no.display());
}
- let copied = copy_pictures(&dir.path().join("attachments"), &[small, big]).unwrap();
- assert_eq!(copied.len(), 1, "the big one is left out: {copied:?}");
+ assert!(picture_too_large(&big));
+ assert!(attachable_picture(&exact));
+ assert!(!picture_too_large(&exact), "exactly 20 MB is allowed");
+ assert!(!picture_too_large(&small));
+ let attachments = dir.path().join("attachments");
+ let err = copy_pictures(&attachments, &[small, big]).unwrap_err();
+ assert_eq!(err.code, ErrorCode::OverLimit, "{err:?}");
+ assert!(!attachments.join("picture-1.png").exists(), "nothing is copied before the refusal");
+ }
+
+ #[test]
+ fn an_oversized_picture_is_refused_by_references_and_attachments() {
+ let dir = tempfile::tempdir().unwrap();
+ let ws = Workspace::create(dir.path(), "Game", "Copy it", TargetRef::None).unwrap();
+ let small = dir.path().join("small.png");
+ std::fs::write(&small, b"png").unwrap();
+ let big = dir.path().join("big.png");
+ std::fs::File::create(&big).unwrap().set_len(MAX_PICTURE_BYTES + 1).unwrap();
+
+ let err = ws.add_references(&[small, big.clone()]).unwrap_err();
+ assert_eq!(err.code, ErrorCode::OverLimit, "{err:?}");
+ assert!(ws.references().is_empty(), "nothing is copied before the refusal");
+
+ let err = ws.add_attachments(&[big]).unwrap_err();
+ assert_eq!(err.code, ErrorCode::OverLimit, "{err:?}");
+ assert!(!ws.attachments_dir().join("picture-1.png").exists());
}
#[test]
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 577446f7..5f880a2d 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -192,6 +192,14 @@ pub enum Done {
Pasted {
project: Option<PathBuf>,
files: Vec<PathBuf>,
+ /// The first picture over 20 MB, if any (checked on the worker that read the paste).
+ refused: Option<String>,
+ },
+ /// Picture sizes were checked on a worker, before the UI attaches them.
+ PicturesChecked {
+ files: Vec<PathBuf>,
+ refused: Option<String>,
+ target: crate::project::PictureTarget,
},
/// The game engines on this computer were listed.
GameEngines(craft_anything_engines::game::Inventory),
@@ -1534,7 +1542,8 @@ impl CraftApp {
}
Done::Pictures(files) => self.add_pictures(files),
Done::ToAttach(files) => self.attach(files),
- Done::Pasted { project, files } => self.pasted(project, files),
+ Done::Pasted { project, files, refused } => self.pasted(project, files, refused),
+ Done::PicturesChecked { files, refused, target } => self.pictures_checked(files, refused, target),
Done::Attached { root, text, attachments, files } => self.deliver(root, text, attachments, files),
Done::GameEngines(inv) => self.engines_found(inv),
Done::GameFound { path, found } => {
diff --git a/crates/ui-egui/src/project.rs b/crates/ui-egui/src/project.rs
index e6d15b8a..051b28be 100644
--- a/crates/ui-egui/src/project.rs
+++ b/crates/ui-egui/src/project.rs
@@ -341,7 +341,7 @@ impl CraftApp {
}
/// Pictures of the original: straight into the open project, else kept with the draft until
- /// Start.
+ /// Start. The size check runs on a worker.
pub fn add_pictures(&mut self, files: Vec<PathBuf>) {
if files.is_empty() {
return;
@@ -349,10 +349,32 @@ impl CraftApp {
if self.state.screen == Screen::Project
&& let Some(ws) = self.workspace.clone()
{
- // Copied on a worker; `pictures_added` says how it went.
- self.jobs.spawn(tr("Add pictures"), false, move |_| Ok(Done::PicturesAdded(ws.add_references(&files).map_err(|e| e.message))));
+ self.check_pictures(files, PictureTarget::Project(ws.root));
return;
}
+ self.check_pictures(files, PictureTarget::Make);
+ }
+
+ /// Read picture sizes off the UI thread, then apply the result on it.
+ fn check_pictures(&mut self, files: Vec<PathBuf>, target: PictureTarget) {
+ self.jobs.spawn(tr("Add pictures"), false, move |_| {
+ let refused = oversized_picture_name(&files);
+ Ok(Done::PicturesChecked { files, refused, target })
+ });
+ }
+
+ /// Add pictures that already passed the worker check to the project prompt box.
+ fn attach_checked(&mut self, files: Vec<PathBuf>) {
+ let list = &mut self.state.project_attachments;
+ for f in files {
+ if craft_anything_engine::workspace::is_picture(&f) && !list.contains(&f) {
+ list.push(f);
+ }
+ }
+ }
+
+ /// Add pictures that already passed the worker check to Make's draft.
+ fn add_pictures_checked(&mut self, files: Vec<PathBuf>) {
let d = &mut self.state.make.pictures;
for f in files {
if craft_anything_engine::workspace::is_picture(&f) && !d.contains(&f) {
@@ -361,6 +383,37 @@ impl CraftApp {
}
}
+ /// Show the same refusal paste uses.
+ fn show_picture_refused(&mut self, name: &str) {
+ self.toast(trf("{name} can't be attached: a message takes pictures up to 20 MB.", &[("name", name)]), true);
+ }
+
+ /// The worker checked the pictures: refuse them, attach them, keep them for Make, or copy
+ /// them into the project that is still open.
+ pub(crate) fn pictures_checked(&mut self, files: Vec<PathBuf>, refused: Option<String>, target: PictureTarget) {
+ if let Some(name) = refused {
+ self.show_picture_refused(&name);
+ return;
+ }
+ match target {
+ PictureTarget::Attach(root) => {
+ let showing = root.as_ref().is_none_or(|r| self.workspace.as_ref().is_some_and(|w| &w.root == r));
+ if showing {
+ self.attach_checked(files);
+ }
+ }
+ PictureTarget::Make => self.add_pictures_checked(files),
+ PictureTarget::Project(root) => {
+ let showing = self.state.screen == Screen::Project;
+ let ws = self.workspace.clone().filter(|w| w.root == root);
+ let Some(ws) = ws.filter(|_| showing) else {
+ return self.toast(tr("The pasted picture wasn't attached: another screen was opened meanwhile."), true);
+ };
+ self.jobs.spawn(tr("Add pictures"), false, move |_| Ok(Done::PicturesAdded(ws.add_references(&files).map_err(|e| e.message))));
+ }
+ }
+ }
+
pub(crate) fn pictures_added(&mut self, added: Result<usize, String>) {
match added {
Ok(0) => self.toast(tr("Those aren't pictures we can use (PNG, JPEG, WebP or GIF, up to 20 MB)."), true),
@@ -1685,6 +1738,24 @@ pub struct PendingPaste {
pub job: u64,
pub root: PathBuf,
pub send: bool,
+ /// The pasted picture was actually attached (false when it was refused, e.g. over 20 MB).
+ pub attached: bool,
+}
+
+/// Where pictures that passed the worker check go.
+pub enum PictureTarget {
+ /// `Some(root)`: only attach while that project is still open.
+ Attach(Option<PathBuf>),
+ Make,
+ Project(PathBuf),
+}
+
+/// The first picture over 20 MB, by display name. Reads file sizes, so run it on a worker.
+fn oversized_picture_name(files: &[PathBuf]) -> Option<String> {
+ files
+ .iter()
+ .find(|f| craft_anything_engine::workspace::picture_too_large(f))
+ .map(|f| f.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| f.display().to_string()))
}
/// What was typed for a note while its project's builder worked.
@@ -1695,12 +1766,20 @@ pub struct Draft {
}
impl CraftApp {
- /// Pictures for the next message on the open project (pictures only, once each).
+ /// Pictures for the next message on the open project (pictures only, once each). The size
+ /// check runs on a worker.
pub fn attach(&mut self, files: Vec<PathBuf>) {
- let list = &mut self.state.project_attachments;
+ if !files.is_empty() {
+ let root = self.workspace.as_ref().map(|w| w.root.clone());
+ self.check_pictures(files, PictureTarget::Attach(root));
+ }
+ }
+
+ /// Put saved attachments back without checking their size again; sending checks it.
+ fn restore_attachments(&mut self, files: Vec<PathBuf>) {
for f in files {
- if craft_anything_engine::workspace::is_picture(&f) && !list.contains(&f) {
- list.push(f);
+ if !self.state.project_attachments.contains(&f) {
+ self.state.project_attachments.push(f);
}
}
}
@@ -1739,11 +1818,12 @@ impl CraftApp {
if files.is_empty() {
return Err(tr("There's no picture on the clipboard to paste."));
}
- Ok(Done::Pasted { project, files })
+ let refused = oversized_picture_name(&files);
+ Ok(Done::Pasted { project, files, refused })
});
// A message sent before the picture is in waits for it (`send_message`).
if let Some(root) = root {
- self.pending_paste = Some(PendingPaste { job, root, send: false });
+ self.pending_paste = Some(PendingPaste { job, root, send: false, attached: false });
}
}
}
@@ -1753,22 +1833,40 @@ impl CraftApp {
self.pending_paste.as_ref().filter(|p| self.jobs.running().any(|j| j.id == p.job))
}
- /// A job finished: when it was the paste a message is waiting for, the message goes now, with
- /// its picture. If the paste failed, what was typed stays in the box to send again.
+ /// A job finished: when it was the paste a message is waiting for and the picture was attached,
+ /// the message goes now, with it. If the paste failed or its picture was refused, what was
+ /// typed stays in the box to send again.
pub(crate) fn paste_done(&mut self, job: u64, ok: bool) {
let Some(p) = self.pending_paste.take_if(|p| p.job == job) else { return };
- if p.send && ok && self.state.screen == Screen::Project && self.workspace.as_ref().is_some_and(|w| w.root == p.root) {
+ if p.send && ok && p.attached && self.state.screen == Screen::Project && self.workspace.as_ref().is_some_and(|w| w.root == p.root) {
self.send_message();
}
}
/// Pasted pictures were read: attached to the project they were pasted in while its screen is
/// still showing, or added to Make's pictures while Make is still showing.
- pub(crate) fn pasted(&mut self, project: Option<PathBuf>, files: Vec<PathBuf>) {
+ pub(crate) fn pasted(&mut self, project: Option<PathBuf>, files: Vec<PathBuf>, refused: Option<String>) {
let showing = |root: &PathBuf| self.state.screen == Screen::Project && self.workspace.as_ref().is_some_and(|w| &w.root == root);
match project {
- Some(root) if showing(&root) => self.attach(files),
- None if self.state.screen == Screen::Home => self.add_pictures(files),
+ Some(root) if showing(&root) => {
+ let attached = match refused {
+ Some(name) => {
+ self.show_picture_refused(&name);
+ false
+ }
+ None => {
+ self.attach_checked(files);
+ true
+ }
+ };
+ if let Some(p) = self.pending_paste.as_mut() {
+ p.attached = attached;
+ }
+ }
+ None if self.state.screen == Screen::Home => match refused {
+ Some(name) => self.show_picture_refused(&name),
+ None => self.add_pictures_checked(files),
+ },
_ => self.toast(tr("The pasted picture wasn't attached: another screen was opened meanwhile."), true),
}
}
@@ -1839,7 +1937,9 @@ impl CraftApp {
let (text, attachments) = self.drafts.remove(&id).map_or((note.shown, Vec::new()), |d| (d.text, d.attachments));
let input = &mut self.state.project_input;
*input = if input.trim().is_empty() { text } else { format!("{text}\n{input}") };
- self.attach(attachments);
+ // These were saved with the note, so put them back as they were. Size is checked again
+ // only when the message is sent.
+ self.restore_attachments(attachments);
}
/// Start another run on the open project: with a message (already shown in the app's feed;
@@ -1893,9 +1993,9 @@ mod tests {
let (project, files) = (Some(root.clone()), vec![shot.clone()]);
let job = app.jobs.spawn("Paste pictures", false, move |_| {
let _ = wait.recv_timeout(std::time::Duration::from_secs(10));
- Ok(Done::Pasted { project, files })
+ Ok(Done::Pasted { project, files, refused: None })
});
- app.pending_paste = Some(PendingPaste { job, root, send: false });
+ app.pending_paste = Some(PendingPaste { job, root, send: false, attached: false });
// While it's read, it's the one paste: another Ctrl+V waits (`paste_pictures` checks this).
assert!(app.pasting().is_some_and(|p| p.job == job));
app.state.project_input = "Like this".into();
@@ -1912,6 +2012,63 @@ mod tests {
assert!(app.pasting().is_none(), "a next paste can start");
}
+ /// Checking a Make picture finishes after the person opened a project: it still belongs to the
+ /// Make draft, not the project.
+ #[test]
+ fn a_make_picture_checked_after_opening_a_project_stays_in_the_draft() {
+ let pic = PathBuf::from("shot.png");
+ let mut app = crate::demo::app(crate::demo::engine(craft_anything_engine::Mode::Beginner, true));
+ app.state.screen = Screen::Project;
+ app.pictures_checked(vec![pic.clone()], None, PictureTarget::Make);
+ assert_eq!(app.state.make.pictures, vec![pic]);
+ }
+
+ /// Taking a note back restores the pictures saved with it, even if they have since grown past
+ /// the size a new attachment may be; sending checks the size again.
+ #[test]
+ fn a_taken_back_note_restores_its_saved_pictures_without_the_size_guard() {
+ let d = tempfile::tempdir().unwrap();
+ let big = d.path().join("big.png");
+ std::fs::File::create(&big).unwrap().set_len(20 * 1024 * 1024 + 1).unwrap();
+ let mut app = crate::demo::app(crate::demo::engine(craft_anything_engine::Mode::Beginner, true));
+ app.restore_attachments(vec![big.clone()]);
+ assert_eq!(app.state.project_attachments, vec![big]);
+ }
+
+ /// A refused paste (over 20 MB) must not send the message waiting for it.
+ #[test]
+ fn a_refused_paste_does_not_send_the_waiting_message() {
+ let d = tempfile::tempdir().unwrap();
+ let ws = Workspace::create(d.path(), "Notes", "A notes app", TargetRef::None).unwrap();
+ let root = ws.root.clone();
+ let mut app = crate::demo::app(crate::demo::engine(craft_anything_engine::Mode::Beginner, true));
+ app.open_workspace(ws);
+ app.state.screen = Screen::Project;
+ let big = d.path().join("big.png");
+ std::fs::File::create(&big).unwrap().set_len(20 * 1024 * 1024 + 1).unwrap();
+ let (go, wait) = std::sync::mpsc::channel::<()>();
+ let (project, files) = (Some(root.clone()), vec![big]);
+ let job = app.jobs.spawn("Paste pictures", false, move |_| {
+ let _ = wait.recv_timeout(std::time::Duration::from_secs(10));
+ Ok(Done::Pasted { project, files, refused: Some("big.png".into()) })
+ });
+ app.pending_paste = Some(PendingPaste { job, root, send: false, attached: false });
+ app.state.project_input = "Like this".into();
+ app.send_message();
+ assert_eq!(app.state.project_input, "Like this", "it waits for the picture");
+ go.send(()).unwrap();
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
+ while app.pending_paste.is_some() && std::time::Instant::now() < deadline {
+ app.take_finished_jobs();
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ assert_eq!(app.state.project_input, "Like this", "the refused picture leaves the message in the box");
+ assert!(app.state.project_attachments.is_empty());
+ assert!(app.pasting().is_none(), "a next paste can start");
+ assert!(app.state.toasts.iter().any(|(t, error)| *error && t.contains("20 MB")), "{:?}", app.state.toasts);
+ assert!(!app.jobs.running().any(|j| j.title == "Attach pictures"), "nothing was sent");
+ }
+
/// A paste read while the person went Home goes nowhere, though the project is still the
/// open one: it would land in a prompt box nobody can see.
#[test]
@@ -1923,11 +2080,11 @@ mod tests {
app.open_workspace(ws);
let shot = vec![PathBuf::from("pasted-1.png")];
app.state.screen = Screen::Home;
- app.pasted(Some(root.clone()), shot.clone());
+ app.pasted(Some(root.clone()), shot.clone(), None);
assert!(app.state.project_attachments.is_empty());
assert!(app.state.toasts.iter().any(|(t, error)| *error && t.contains("another screen")), "{:?}", app.state.toasts);
app.state.screen = Screen::Project;
- app.pasted(Some(root), shot.clone());
+ app.pasted(Some(root), shot.clone(), None);
assert_eq!(app.state.project_attachments, shot);
}
diff --git a/crates/ui-egui/tests/headless_parity.rs b/crates/ui-egui/tests/headless_parity.rs
index feeb93bf..53d59002 100644
--- a/crates/ui-egui/tests/headless_parity.rs
+++ b/crates/ui-egui/tests/headless_parity.rs
@@ -149,6 +149,9 @@ const PLUMBING: &[(&str, &str)] = &[
("engines_found", "a job's result"), ("engine_got", "a job's result"), ("ghidra_got", "a job's result"),
("ghidra_ready", "a query"), ("ghidra_missing", "a query"),
("load_prefs", "startup"), ("after_first_frames", "startup"), ("log", "the log panel"), ("toast", "a message"),
+ ("check_pictures", "a picture-size preflight"),
+ ("attach_checked", "part of pictures_checked"), ("add_pictures_checked", "part of pictures_checked"),
+ ("show_picture_refused", "a job's refusal"), ("restore_attachments", "part of unsend"),
("settings_changed", "marks settings dirty; each setting has its row"), ("flush_settings", "saves settings"),
("refresh_view", "redraw data"), ("resolve_chat_evidence", "redraw data"), ("mark_dirty", "redraw data"),
("poll_conversation", "polling"), ("allow_for_project", "part of answer_consent"),
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index 6c6b2f75..8dd483c6 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -406,8 +406,7 @@ fn the_prompt_box_sends_on_enter_with_its_pictures() {
});
h.run_steps(3);
h.state_mut().attach(vec![pic.clone(), d.path().join("notes.txt"), pic]);
- h.run_steps(2);
- assert_eq!(h.state().state.project_attachments.len(), 1, "pictures only, once each");
+ assert!(wait(&mut h, |a| a.state.project_attachments.len() == 1), "pictures only, once each: {:?}", h.state().state.project_attachments);
h.get_by_label("shot.png");
h.get_by_label("Ask for a change").focus();
h.run_steps(2);
@@ -436,6 +435,41 @@ fn the_prompt_box_sends_on_enter_with_its_pictures() {
);
}
+#[test]
+fn an_oversized_picture_is_refused_when_attached() {
+ use craft_anything_engine::workspace::{TargetRef, Workspace};
+ let d = tempfile::tempdir().unwrap();
+ let small = d.path().join("ok.png");
+ std::fs::write(&small, b"png").unwrap();
+ let big = d.path().join("huge.png");
+ std::fs::File::create(&big).unwrap().set_len(20 * 1024 * 1024 + 1).unwrap();
+ let ws = Workspace::create(&d.path().join("projects"), "Game", "Recreate this game", TargetRef::None).unwrap();
+ let mut h = harness(move || {
+ let mut a = demo::app(demo::engine(Mode::Beginner, true));
+ a.workspace = Some(ws);
+ a.state.screen = Screen::Project;
+ a
+ });
+ h.run_steps(3);
+ h.state_mut().attach(vec![small, big]);
+ assert!(wait(&mut h, |a| a.state.toasts.iter().any(|(t, err)| *err && t.contains("20 MB"))), "{:?}", h.state().state.toasts);
+ assert!(h.state().state.project_attachments.is_empty(), "the valid picture is not half-attached");
+}
+
+#[test]
+fn an_oversized_picture_is_refused_in_the_make_draft() {
+ let d = tempfile::tempdir().unwrap();
+ let small = d.path().join("ok.png");
+ std::fs::write(&small, b"png").unwrap();
+ let big = d.path().join("huge.png");
+ std::fs::File::create(&big).unwrap().set_len(20 * 1024 * 1024 + 1).unwrap();
+ let mut h = harness(|| demo::app(demo::engine(Mode::Beginner, true)));
+ h.run_steps(2);
+ h.state_mut().add_pictures(vec![small, big]);
+ assert!(wait(&mut h, |a| a.state.toasts.iter().any(|(t, err)| *err && t.contains("20 MB"))), "{:?}", h.state().state.toasts);
+ assert!(h.state().state.make.pictures.is_empty(), "the valid picture is not half-added");
+}
+
#[test]
fn tab_completes_a_slash_command_and_keeps_focus() {
use craft_anything_ai::rebuild::StandIns;
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 2ef7c648..96a008fe 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -547,9 +547,8 @@ Gaps found while using the app for real projects.
- [x] Ctrl+V (Shift+Insert, Cmd+V) in a prompt box that takes pictures pastes a copied image (saved
as a PNG) or copied picture files; attachments show as square picture tiles, the whole
picture on hover, decoded on a worker
-- [ ] A picture over 20 MB dropped on a prompt box or picked in its dialog still shows as
- attached, and the message then goes without it (`copy_pictures` skips it); refuse it when
- it's added, as a paste does (`workspace::attachable_picture`)
+- [x] A picture over 20 MB dropped on a prompt box or picked in its dialog is refused when it's
+ added, as a paste does (`workspace::attachable_picture`), before anything is copied
- [ ] When the builder decides a question, show the question and its choice as an answered card
in the feed (the run sees only the tool call today; the builder's words say what it chose)
- [ ] A question's own cost: a forked Claude Code session reports the whole session's running