diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dea75f5..151e223 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,19 +1,19 @@ --- name: bug report -about: something broke, and you have the details +about: report a reproducible problem title: '' labels: bug assignees: '' --- -what happened? say it in one sentence. +what happened? -what did you expect to happen instead? +what did you expect instead? -how do i reproduce it? a command line, a file, or a url is ideal. if it needs an -audio file, say what kind and roughly how long. +how can it be reproduced? include the exact command and a small input example +when possible. do not upload private recordings or credentials. -paste the exact error text if there is one. +paste the exact error output: ```text @@ -22,9 +22,11 @@ paste the exact error text if there is one. environment: - scribe version (`scribe --version`): -- os and terminal: -- model (if relevant): - -if it is an accuracy complaint rather than a crash, name the model first. nine -times out of ten the answer is "try large-v3-turbo", but i will read the report -anyway. +- operating system and architecture: +- terminal: +- model and language: +- input type and approximate duration: +- relevant `scribe --doctor` output: + +for transcription-quality reports, include the model name and language, plus a +short description of what was wrong with the result. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 0e575e0..b5204b7 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,17 +1,16 @@ --- name: feature request -about: an idea worth arguing about +about: propose a focused improvement title: '' labels: enhancement assignees: '' --- -what is the actual problem you are trying to solve? not "add feature x" — the -thing that makes feature x worth writing. +what problem are you trying to solve? -what would you change? +what behaviour would you expect from scribe? -what did you try already? +what alternatives or workarounds have you tried? -anything that would make you reject this idea? if the answer is "it adds a 200 -mb dependency for one flag", say so. i will probably agree. +are there compatibility, performance, privacy or maintenance trade-offs to +consider? diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 887b5f8..c4a2b33 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,29 +1,20 @@ ---- -name: pull request -about: changes for review -title: '' -labels: '' -assignees: '' ---- - -what does this change, in one sentence? +what does this change? why is it needed? link the issue if there is one. -how did you verify it? paste the commands you actually ran, not the ones you -meant to run. +how did you verify it? include the commands you actually ran. ```sh ``` -if this touches the worker, the download path, or the layout, explain the -trade-off you picked. those are the three places where the obvious fix is -usually the wrong one. +if this touches transcription workers, downloads, model caching, exports or +terminal rendering, explain the relevant failure mode and trade-off. -checklist (delete the ones that do not apply): +checklist: -- [ ] `cargo test` passes -- [ ] `cargo clippy --all-targets -- -D warnings` is clean -- [ ] `cargo fmt --all -- --check` is clean -- [ ] docs updated if behaviour changed +- [ ] `cargo fmt --all -- --check` passes +- [ ] `cargo clippy --locked --all-targets --all-features -- -D warnings` passes +- [ ] `cargo test --locked --all-targets --all-features` passes +- [ ] documentation is updated when behaviour changes +- [ ] no unrelated files or generated artifacts are included diff --git a/readme.md b/readme.md index 762229d..98e35c9 100644 --- a/readme.md +++ b/readme.md @@ -333,7 +333,7 @@ run the diagnostic command for a read-only report: scribe --doctor ``` -it checks dependencies, model integrity, paths and permissions. it does not install packages or modify files. +it checks dependencies, model integrity and configured paths. it does not install packages or modify files, and it does not probe write permissions. ## performance and implementation diff --git a/src/doctor.rs b/src/doctor.rs index 0578432..0ddeb82 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -25,6 +25,21 @@ struct Row { detail: String, } +fn cache_status(cache: &std::path::Path) -> (Verdict, &'static str) { + if cache.is_dir() { + (Verdict::Ok, "directory exists; write access not tested") + } else if cache.exists() { + (Verdict::Fail, "path exists but is not a directory") + } else if cache.parent().is_some_and(std::path::Path::is_dir) { + ( + Verdict::Warn, + "will be created on first download; write access not tested", + ) + } else { + (Verdict::Fail, "parent directory is missing") + } +} + fn version(binary: &std::path::Path, args: &[&str]) -> Option { let output = std::process::Command::new(binary) .args(args) @@ -109,18 +124,11 @@ pub fn run(selected_model: Option<&str>) -> i32 { }); let cache = model::cache_dir(); - let cache_ok = cache - .parent() - .map(|p| p.is_dir()) - .unwrap_or_else(|| cache.is_dir()); + let (cache_verdict, cache_detail) = cache_status(&cache); rows.push(Row { label: "model cache", - verdict: if cache_ok { Verdict::Ok } else { Verdict::Fail }, - detail: format!( - "{} ({})", - cache.display(), - if cache_ok { "writable" } else { "not writable" } - ), + verdict: cache_verdict, + detail: format!("{} ({cache_detail})", cache.display()), }); let chosen = selected_model.map(str::to_string).or_else(|| { @@ -276,6 +284,40 @@ pub fn run(selected_model: Option<&str>) -> i32 { mod tests { use super::*; + #[test] + fn cache_status_does_not_claim_unchecked_write_access() { + let dir = std::env::temp_dir().join(format!("scribe-doctor-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let cache = dir.join("models"); + assert_eq!( + cache_status(&cache), + ( + Verdict::Warn, + "will be created on first download; write access not tested" + ) + ); + std::fs::create_dir_all(&cache).unwrap(); + assert_eq!( + cache_status(&cache), + (Verdict::Ok, "directory exists; write access not tested") + ); + std::fs::remove_dir_all(&dir).unwrap(); + } + + #[test] + fn cache_status_rejects_a_file_at_the_cache_path() { + let dir = std::env::temp_dir().join(format!("scribe-doctor-file-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let cache = dir.join("models"); + std::fs::write(&cache, b"not a directory").unwrap(); + assert_eq!( + cache_status(&cache), + (Verdict::Fail, "path exists but is not a directory") + ); + std::fs::remove_dir_all(&dir).unwrap(); + } + #[test] fn verdict_labels_are_short() { assert_eq!(Verdict::Ok.label(), "ok"); diff --git a/src/model.rs b/src/model.rs index d58954a..20e1e9e 100644 --- a/src/model.rs +++ b/src/model.rs @@ -495,6 +495,16 @@ pub fn validate_cached(info: &ModelInfo, path: &Path) -> Result<(), String> { /// custom models have no authoritative checksum in the catalog. the least we /// can do is reject empty stubs and files that cannot possibly be ggml models. +fn read_model_header(path: &Path) -> Result<[u8; 4], String> { + use std::io::Read; + let mut file = + File::open(path).map_err(|e| format!("cannot read model {}: {e}", path.display()))?; + let mut magic = [0u8; 4]; + file.read_exact(&mut magic) + .map_err(|e| format!("cannot read model header {}: {e}", path.display()))?; + Ok(magic) +} + pub fn validate_custom(path: &Path) -> Result<(), String> { let len = fs::metadata(path) .map_err(|e| format!("cannot inspect {}: {e}", path.display()))? @@ -506,13 +516,8 @@ pub fn validate_custom(path: &Path) -> Result<(), String> { len )); } - let mut magic = [0u8; 4]; - use std::io::Read; - if let Ok(mut file) = File::open(path) - && file.read_exact(&mut magic).is_ok() - && &magic != b"ggml" - && &magic != b"GGUF" - { + let magic = read_model_header(path)?; + if &magic != b"ggml" && &magic != b"GGUF" { return Err(format!( "{} does not look like a ggml model (bad header). refusing to hand it to whisper", path.display() @@ -1378,6 +1383,16 @@ mod tests { fs::remove_dir_all(&dir).unwrap(); } + #[test] + fn custom_model_header_read_errors_are_rejected() { + let dir = std::env::temp_dir().join(format!("scribe-header-{}", std::process::id())); + fs::create_dir_all(&dir).unwrap(); + let path = dir.join("truncated.bin"); + fs::write(&path, b"gg").unwrap(); + assert!(read_model_header(&path).is_err()); + fs::remove_dir_all(&dir).unwrap(); + } + #[test] fn validate_custom_rejects_stubs_and_wrong_headers() { let dir = std::env::temp_dir().join(format!("scribe-custom-{}", std::process::id()));