Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
607 changes: 607 additions & 0 deletions crates/ui-egui/src/bug_report.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/ui-egui/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest
| crate::state::Dialog::SaveEffect { .. }
| crate::state::Dialog::CaptureTime { .. }
| crate::state::Dialog::LensDatabase { .. }
| crate::state::Dialog::ReportBug { .. }
| crate::state::Dialog::TextPrompt { .. }
))
|| (r.is_ok() && crate::panels::dialogs::keeps_open(app, &d))
Expand Down
6 changes: 6 additions & 0 deletions crates/ui-egui/src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context, blocked: bool) {
Dialog::Welcome { .. } => 460.0,
Dialog::LensDatabase { .. } => 440.0,
Dialog::ManageEffects { .. } => 560.0,
Dialog::ReportBug { .. } => 560.0,
_ => 380.0,
})
.show(ctx, |ui| {
Expand Down Expand Up @@ -465,6 +466,7 @@ fn dialog_title(app: &LightcraftApp, dlg: &Dialog) -> String {
Dialog::NewSmartAlbum { .. } => "Create Smart Album",
Dialog::AllMetadata { .. } => "All Metadata",
Dialog::SystemInfo { .. } => "System Info",
Dialog::ReportBug { .. } => "Report a Bug",
Dialog::DenoiseModel { .. } => "AI Denoise Model",
Dialog::FaceModel { info, .. } if info["download"].is_string() => "Download Face Model",
Dialog::FaceModel { .. } => "Add Face Model",
Expand Down Expand Up @@ -616,6 +618,7 @@ fn fixed_ok_label(app: &LightcraftApp, dlg: &Dialog, informational: bool) -> &'s
d @ Dialog::LightroomDestination { .. } => crate::lightroom_destination::ok_label(d),
Dialog::Welcome { .. } => "",
Dialog::LensDatabase { .. } => "Download",
Dialog::ReportBug { .. } => "Create Report",
Dialog::SynchronizeFolder { .. } if informational => "Close",
Dialog::SynchronizeFolder { .. } => "Synchronize",
Dialog::RenamePerson { from, to, .. } if person_rename_plan(&app.session.catalog, from, to).needs_merge => "Merge",
Expand Down Expand Up @@ -743,6 +746,8 @@ fn confirmed(app: &mut LightcraftApp, ctx: &egui::Context, dlg: &mut Dialog) ->
| Dialog::SaveEffect { .. }
| Dialog::CaptureTime { .. }
| Dialog::LensDatabase { .. }
// a report that can't be written or opened keeps what was typed (#1128 review)
| Dialog::ReportBug { .. }
) =>
{
app.toast(ctx, e)
Expand Down Expand Up @@ -2152,6 +2157,7 @@ fn dialog_content(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, body_m
Dialog::FaceModel { info, accepted, .. } => crate::panels::faces::model_dialog(app, ui, t, info, accepted),
Dialog::LightroomResult { .. } => lightroom_result_body(ui, dlg),
Dialog::SystemInfo { .. } => system_info_body(ui, t, dlg),
Dialog::ReportBug { opts, rows, logs } => crate::bug_report::dialog_body(ui, t, opts, rows, logs),
Dialog::AllMetadata { .. } => all_metadata_body(ui, t, dlg),
Dialog::SmartRules { .. } => smart_rules_body(app, ui, t, dlg),
Dialog::NewSmartAlbum { .. } => new_smart_album_body(app, ui, t, confirm, dlg),
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/dialogs/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub fn confirm_dialog(app: &mut LightcraftApp, dlg: &Dialog) -> Result<serde_jso
Dialog::DenoiseModel { info, accepted } => crate::panels::denoise::install(app, info, *accepted),
Dialog::FaceModel { path, info, accepted } => crate::panels::faces::install(app, path, info, *accepted),
Dialog::AllMetadata { .. } | Dialog::SystemInfo { .. } | Dialog::WhatsNew | Dialog::Welcome { .. } => Ok(serde_json::Value::Null),
Dialog::ReportBug { opts, rows, logs } => crate::bug_report::create(app, opts, rows, logs),
Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity, reset_bursts } => {
app.ui.cull_burst = Some((*burst_gap, *similarity));
app.ui.cull_stack = *stack_groups;
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const UPDATE_APP: craft_update::app::App = craft_update::app::App {
};

pub mod brush_live;
pub mod bug_report;
pub mod canvas_keys;
pub mod channel;
mod command_error;
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/menus/menubar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ const LAYOUT: &[(&str, &[&str])] = &[
&[
"app.discord",
"app.feedback",
"app.reportBug",
"---",
"app.website",
"app.github",
Expand Down
40 changes: 2 additions & 38 deletions crates/ui-egui/src/menus/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ fn ui_commands_10(app: &mut LightcraftApp, ctx: &egui::Context, id: &str, p: &Va
Ok(json!({"text": crate::panels::dialogs::WHATS_NEW}))
}
"app.systemInfo" => app_system_info_command(app, p),
"app.reportBug" => crate::bug_report::command(app, p),
"app.shortcuts" => {
app.ui.dialog = Some(Dialog::Shortcuts);
Ok(Value::Null)
Expand Down Expand Up @@ -1859,44 +1860,7 @@ fn dialog_smart_album_command(app: &mut LightcraftApp, _id: &str, p: &Value) ->

/// The `app.systemInfo` command.
fn app_system_info_command(app: &mut LightcraftApp, p: &Value) -> Result<Value, String> {
let info = app.session.execute("library.info", &json!({})).unwrap_or_default();
let gpu = (lightcraft_engine::gpu::ready() && lightcraft_engine::gpu::available()).then(lightcraft_engine::gpu::adapter_name).flatten();
let mb = |b: u64| format!("{:.0} MB", b as f64 / (1u64 << 20) as f64);
let mut rows = vec![
("Version".to_string(), crate::channel::display_version()),
("System".to_string(), format!("{} ({})", std::env::consts::OS, std::env::consts::ARCH)),
("CPU threads".to_string(), std::thread::available_parallelism().map(|n| n.get().to_string()).unwrap_or_else(|_| "?".into())),
(
"GPU".to_string(),
gpu.unwrap_or_else(|| match lightcraft_engine::gpu::unavailable_reason() {
Some(why) => crate::i18n::tr_format!("none (CPU rendering): {why}", why = why),
None => "none (CPU rendering)".into(),
}),
),
("GPU rendering".to_string(), if app.ui.settings.gpu { "on".into() } else { "off".into() }),
("Memory budget".to_string(), mb(lightcraft_engine::memory::default_budget() as u64)),
(
"Preview size".to_string(),
match app.ui.settings.preview_limit {
0 => "automatic".to_string(),
n => format!("{n} px"),
},
),
("Photos".to_string(), info["photos"].to_string()),
("Albums".to_string(), info["albums"].to_string()),
];
if let Some(dir) = info["dir"].as_str().or(info["path"].as_str()) {
rows.push(("Library".into(), dir.to_string()));
}
rows.push(("Frame time".into(), format!("{:.1} ms ({:.0} fps)", app.perf.frame_ms, app.perf.fps)));
rows.push((
"Frame update".into(),
format!("{:.1} ms (logic {:.1} ms; slowest {:.0} ms)", app.perf.update_ms, app.perf.logic_ms, app.perf.max_update_ms),
));
rows.push(("Last loupe render".into(), format!("{:.0} ms", app.renderer.last_main_ms)));
if let Some(f) = lightcraft_engine::gpu::last_fallback() {
rows.push(("Last GPU fallback".into(), f));
}
let rows = crate::bug_report::system_rows(app);
let r = json!(rows.iter().map(|(k, v)| json!({"label": k, "value": v})).collect::<Vec<_>>());
if p.get("open").and_then(Value::as_bool).unwrap_or(true) {
app.ui.dialog = Some(Dialog::SystemInfo { rows });
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/menus/ui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub const UI_COMMANDS: &[UiCommand] = &[
("app.about", "About LightCraft", None, "Help"),
("app.checkForUpdates", "Check for Updates…", None, "Help"),
("app.systemInfo", "System Info…", None, "Help"),
("app.reportBug", "Report a Bug…", None, "Help"),
("app.openLogFolder", "Open Log Folder", None, "Help"),
// the frame-rate display (`frame_rate`): a debugging aid, never saved
("view.frameRate", "Frame Rate", None, "Help>Debug"),
Expand Down
7 changes: 7 additions & 0 deletions crates/ui-egui/src/state/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ pub enum Dialog {
SystemInfo {
rows: Vec<(String, String)>,
},
/// Help ▸ Report a Bug… (#1015): the choices, and the logs found when it opened.
ReportBug {
opts: crate::bug_report::ReportOptions,
/// The System Info rows when it opened: what the preview shows is what the report holds.
rows: Vec<(String, String)>,
logs: Vec<crate::bug_report::LogInfo>,
},
/// Every metadata field of a photo's file (`photo.allMetadata`), filtered by `search`.
AllMetadata {
title: String,
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ mod rating;
mod recheck;
mod reduce_motion;
mod rename_person;
mod report_bug;
mod rules_editor;
mod rules_reorder;
mod sam_setup;
Expand Down
159 changes: 159 additions & 0 deletions crates/ui-egui/src/tests/report_bug.rs
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());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let current = dir.join("lightcraft.log");
std::fs::write(&current, 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);
}
Loading
Loading