Repository navigation
MENU-HELP-REPORTBUG: Help ▸ Report a Bug… (carries #1128, with echelon's three review points) #3763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bruno-Alumn
wants to merge
11
commits into
storytold:main
Choose a base branch
from
Bruno-Alumn:adopt/report-bug-1128
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
693f0ef
MENU-HELP-REPORTBUG: Help ▸ Report a Bug… (#1015)
lloyd-nich f33b3a4
Merge upstream/main into adopt/report-bug-1128
Bruno-Alumn 4de03df
MENU-HELP-REPORTBUG: names with punctuation are hidden whole, and a f…
Bruno-Alumn 1675a40
MENU-HELP-REPORTBUG: once a name after a path is hidden, the next nam…
Bruno-Alumn fdec0d4
MENU-HELP-REPORTBUG: CodeRabbit's points on #3763
Bruno-Alumn a63bb43
Merge upstream/main
Bruno-Alumn 5a47b44
Merge remote-tracking branch 'upstream/main' into adopt/report-bug-1128
Bruno-Alumn 216d15f
Report a Bug: a report never replaces another; the write-failure test…
Bruno-Alumn e13f5a7
Merge remote-tracking branch 'upstream/main' into tmp/fix-3763
Bruno-Alumn eeec1cb
Report a Bug: the logs read when the dialog opened are shared, not co…
Bruno-Alumn 1c3a421
Merge current main into Report a Bug branch
FredApps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| //! #1015: Help ▸ Report a Bug… writes a report file next to the logs, shows it in the file manager | ||
| //! and opens a pre-filled GitHub issue. Nothing is sent; personal paths and photo names are hidden by | ||
| //! default. | ||
|
|
||
| use crate::headless::Headless; | ||
| use crate::{LightcraftApp, Services}; | ||
| use serde_json::json; | ||
| use std::sync::{Arc, Mutex}; | ||
| use std::time::Duration; | ||
|
|
||
| const T: Duration = Duration::from_secs(20); | ||
| const SETTLE: Duration = Duration::from_secs(60); | ||
|
|
||
| /// A log folder with this run's log and the one before, which name a photo under the home folder. | ||
| fn log_dir(tag: &str) -> (std::path::PathBuf, String) { | ||
| let dir = std::env::temp_dir().join(format!("lc-report-bug-{tag}-{}", std::process::id())); | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| std::fs::create_dir_all(&dir).unwrap(); | ||
| let home = crate::bug_report::home_dir().unwrap_or_else(|| "/home/someone".into()); | ||
| let current = dir.join("lightcraft.log"); | ||
| std::fs::write(¤t, format!("10:00 INFO start\n10:01 WARN import: {home}/Pictures/Ann birthday.CR2: no preview\n")).unwrap(); | ||
| std::fs::write(dir.join("lightcraft.1.log"), "09:00 ERROR the run before\n").unwrap(); | ||
| (dir, current.to_string_lossy().to_string()) | ||
| } | ||
|
|
||
| /// The demo app with a log file, recording what it reveals and which links it opens. | ||
| fn app(log_file: Option<String>) -> (Headless, Arc<Mutex<Vec<String>>>, Arc<Mutex<Vec<String>>>) { | ||
| let (revealed, opened) = (Arc::new(Mutex::new(Vec::new())), Arc::new(Mutex::new(Vec::new()))); | ||
| let (r, o) = (revealed.clone(), opened.clone()); | ||
| let services = Services { | ||
| png: None, | ||
| log_file, | ||
| reveal: Some(Box::new(move |p: &str| { | ||
| r.lock().unwrap().push(p.to_string()); | ||
| Ok(()) | ||
| })), | ||
| open_url: Some(Box::new(move |u: &str| { | ||
| o.lock().unwrap().push(u.to_string()); | ||
| Ok(()) | ||
| })), | ||
| ..Default::default() | ||
| }; | ||
| let mut h = Headless::new(LightcraftApp::new(lightcraft_engine::Session::with_demo(), services), [1300.0, 900.0], 1.0); | ||
| h.settle(SETTLE); | ||
| (h, revealed, opened) | ||
| } | ||
|
|
||
| fn has(h: &Headless, id: &str) -> bool { | ||
| h.app.widgets.iter().any(|(w, _)| w == id) | ||
| } | ||
|
|
||
| #[test] | ||
| fn the_report_file_and_the_issue_hold_what_was_chosen() { | ||
| let (dir, log) = log_dir("create"); | ||
| let (mut h, revealed, opened) = app(Some(log)); | ||
| let r = h.request("engine.execute", json!({"command": "app.reportBug", "params": {"create": true, "what": "Export hangs at 90 %"}}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| let path = r["result"]["path"].as_str().expect("a report file").to_string(); | ||
| assert!(path.starts_with(&dir.to_string_lossy().to_string()) && path.ends_with(".txt"), "{path}"); | ||
| let text = std::fs::read_to_string(&path).unwrap(); | ||
| assert!(text.contains("Export hangs at 90 %") && text.contains("Version: ") && text.contains("== lightcraft.log =="), "{text}"); | ||
| // this run's log only, with the home folder and the photo's name hidden | ||
| assert!(!text.contains("lightcraft.1.log") && !text.contains("the run before"), "{text}"); | ||
| assert!(!text.contains("Ann birthday"), "{text}"); | ||
| // the home folder becomes `~` only where there is one to find (CI runners may have none) | ||
| if crate::bug_report::home_dir().is_some() { | ||
| assert!(text.contains("~/Pictures/<photo>.CR2"), "{text}"); | ||
| } | ||
| assert_eq!(*revealed.lock().unwrap(), vec![path.clone()]); | ||
| let url = opened.lock().unwrap().last().cloned().expect("the issue opened"); | ||
| assert!( | ||
| url.starts_with("https://github.com/storytold/lightcraft/issues/new?title=Bug%3A%20Export%20hangs") | ||
| && url.len() <= crate::bug_report::MAX_URL, | ||
| "{url}" | ||
| ); | ||
| assert!(!url.contains("birthday"), "{url}"); | ||
|
|
||
| // the previous run's log too, names shown when asked; a second report in the same second gets a | ||
| // name of its own and leaves the first one as it was | ||
| h.app.session.clock = Box::new(|| "2026-11-10T09:00:00".to_string()); | ||
| let first = h.request("engine.execute", json!({"command": "app.reportBug", "params": {"create": true, "what": "First"}}), T); | ||
| let r = h.request("engine.execute", json!({"command": "app.reportBug", "params": {"create": true, "previousLogs": true, "private": false}}), T); | ||
| let (a, b) = (first["result"]["path"].as_str().unwrap(), r["result"]["path"].as_str().unwrap()); | ||
| assert!(a.ends_with("lightcraft-report-20261110090000.txt") && b.ends_with("lightcraft-report-20261110090000-2.txt"), "{a} {b}"); | ||
| assert!(std::fs::read_to_string(a).unwrap().contains("First"), "the first report is kept"); | ||
| let text = std::fs::read_to_string(b).unwrap(); | ||
| assert!(text.contains("== lightcraft.1.log ==") && text.contains("the run before") && text.contains("Ann birthday.CR2"), "{text}"); | ||
| assert_eq!(r["result"]["logs"], json!(["lightcraft.log", "lightcraft.1.log"])); | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| } | ||
|
|
||
| #[test] | ||
| fn the_dialog_previews_the_issue_and_creates_the_report() { | ||
| let (dir, log) = log_dir("dialog"); | ||
| let (mut h, revealed, opened) = app(Some(log)); | ||
| let r = h.request("ui.menu.invoke", json!({"id": "app.reportBug"}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| h.step(); | ||
| h.step(); | ||
| assert!(matches!(h.app.ui.dialog, Some(crate::state::Dialog::ReportBug { .. }))); | ||
| for id in | ||
| ["field:reportBugWhat", "check:reportBugPrivate", "check:reportBugPrevious", "button:reportBugCopy", "button:dialogCancel", "button:dialogOk"] | ||
| { | ||
| assert!(has(&h, id), "no {id}"); | ||
| } | ||
| let text = h.painted_text().join("\n"); | ||
| assert!(text.contains("Create Report") && text.contains("### What happened") && text.contains("lightcraft.log"), "{text}"); | ||
| // the preview hides what the report hides | ||
| assert!(text.contains("<photo>.CR2") && !text.contains("Ann birthday"), "{text}"); | ||
| let r = h.request("ui.clickWidget", json!({"id": "button:dialogOk"}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| h.step(); | ||
| assert!(h.app.ui.dialog.is_none(), "Create Report closes the dialog"); | ||
| assert_eq!(revealed.lock().unwrap().len(), 1); | ||
| assert_eq!(opened.lock().unwrap().len(), 1); | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| } | ||
|
|
||
| #[test] | ||
| fn without_a_log_the_issue_holds_the_system_info_only() { | ||
| let (mut h, revealed, opened) = app(None); | ||
| let r = h.request("engine.execute", json!({"command": "app.reportBug", "params": {"create": true}}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| assert!(r["result"]["path"].is_null(), "{r}"); | ||
| assert!(revealed.lock().unwrap().is_empty()); | ||
| let url = opened.lock().unwrap().last().cloned().expect("the issue opened"); | ||
| assert!(url.contains("title=Bug%20report") && url.contains("Version%3A%20"), "{url}"); | ||
| let r = h.request("ui.menu.invoke", json!({"id": "app.reportBug"}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| h.step(); | ||
| h.step(); | ||
| assert!(!has(&h, "check:reportBugPrevious"), "no previous logs to offer"); | ||
| assert!(h.painted_text().join("\n").contains("keeps no log")); | ||
| } | ||
|
|
||
| /// A report that can't be written keeps the dialog, and what was typed, open with the error, through | ||
| /// the control channel as through its button (#1128 review). | ||
| #[test] | ||
| fn a_report_that_cant_be_written_keeps_the_dialog() { | ||
| let (dir, log) = log_dir("unwritable"); | ||
| let (mut h, _, opened) = app(Some(log)); | ||
| let r = h.request("ui.menu.invoke", json!({"id": "app.reportBug"}), T); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| if let Some(crate::state::Dialog::ReportBug { opts, .. }) = h.app.ui.dialog.as_mut() { | ||
| opts.what = "Export hangs".into(); | ||
| } | ||
| // the report goes next to the log: under a plain file it can't be written, for any user (root too) | ||
| let blocker = dir.join("not-a-folder"); | ||
| std::fs::write(&blocker, "").unwrap(); | ||
| h.app.services.log_file = Some(blocker.join("lightcraft.log").to_string_lossy().to_string()); | ||
| let r = h.request("ui.dialog.confirm", json!({}), T); | ||
| assert_eq!(r["ok"], false, "the report file can't be written: {r}"); | ||
| match &h.app.ui.dialog { | ||
| Some(crate::state::Dialog::ReportBug { opts, .. }) => assert_eq!(opts.what, "Export hangs", "what was typed is kept"), | ||
| other => panic!("the dialog closed: {other:?}"), | ||
| } | ||
| assert!(opened.lock().unwrap().is_empty(), "no issue opened for a report that wasn't made"); | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.