Repository navigation
fix: harden model validation and doctor checks - #6
Conversation
Reviewer's GuideImplementationMake custom-model validation reject files whose four-byte header cannot be read, rather than silently accepting truncated or unreadable headers.
Report cache-path readiness based on whether the cache is a directory, an invalid file path, or has a usable parent, without claiming write access was tested.
DocumentationClarify that doctor checks configured paths but neither modifies files nor probes write permissions.
Revise the bug-report template to request reproducible steps, environment details, doctor output, and useful transcription-quality context.
Refocus the feature-request template on the problem, expected behavior, alternatives, and potential trade-offs.
Update the pull-request template to request verification commands, relevant failure modes and trade-offs, and explicit quality checks.
TestsAdd regression tests for truncated custom-model headers and cache-path readiness and invalid-file states.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/doctor.rs" line_range="36" />
<code_context>
+ } 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")
+ }
+}
</code_context>
<issue_to_address>
**Fresh cache reports failure**
When the cache directory or one of its parent directories has not been created yet, `cache_status` returns `Fail` because it checks only the immediate parent, so `scribe --doctor` exits with status 1 for a cache tree that `DownloadLock::acquire` can create recursively; the regression test also fails because it expects `Warn`.
Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.
Also at `src/doctor.rs:37`, `src/doctor.rs:290-292`.
</issue_to_address>
### Comment 2
<location path="src/doctor.rs" line_range="31" />
<code_context>
+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) {
</code_context>
<issue_to_address>
**Doctor misses unusable cache**
When the configured cache path is a dangling symlink and its parent directory exists, `cache.exists()` follows symlinks and returns false, so `cache_status` reports that the cache will be created; `DownloadLock::acquire` then fails when `create_dir_all` encounters the symlink, and the user sees a download error despite the doctor warning.
Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.
Also at `src/doctor.rs:33-34`.
</issue_to_address>
### Comment 3
<location path="src/model.rs" line_range="1392" />
<code_context>
+ 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();
+ }
</code_context>
<issue_to_address>
**Validator rejection goes untested**
When `validate_custom` is changed to ignore a header-read error, `custom_model_header_read_errors_are_rejected` asserts only that `read_model_header` returns an error, so it still passes if `validate_custom` stops propagating that error and accepts an unreadable header.
Exercise `validate_custom` with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/doctor.rs:36, src/doctor.rs:31, src/model.rs:1392
| } 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") |
There was a problem hiding this comment.
🔴 Critical · Fresh cache reports failure
When the cache directory or one of its parent directories has not been created yet, cache_status returns Fail because it checks only the immediate parent, so scribe --doctor exits with status 1 for a cache tree that DownloadLock::acquire can create recursively; the regression test also fails because it expects Warn.
Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.
Also at src/doctor.rs:37, src/doctor.rs:290-292.
Prompt for AI agents
In `src/doctor.rs` at line 36:
**Fresh cache reports failure**
When the cache directory or one of its parent directories has not been created yet, `cache_status` returns `Fail` because it checks only the immediate parent, so `scribe --doctor` exits with status 1 for a cache tree that `DownloadLock::acquire` can create recursively; the regression test also fails because it expects `Warn`.
Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.
Also at `src/doctor.rs:37`, `src/doctor.rs:290-292`.| 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() { |
There was a problem hiding this comment.
🟡 Medium · Doctor misses unusable cache
When the configured cache path is a dangling symlink and its parent directory exists, cache.exists() follows symlinks and returns false, so cache_status reports that the cache will be created; DownloadLock::acquire then fails when create_dir_all encounters the symlink, and the user sees a download error despite the doctor warning.
Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.
Also at src/doctor.rs:33-34.
Prompt for AI agents
In `src/doctor.rs` at line 31:
**Doctor misses unusable cache**
When the configured cache path is a dangling symlink and its parent directory exists, `cache.exists()` follows symlinks and returns false, so `cache_status` reports that the cache will be created; `DownloadLock::acquire` then fails when `create_dir_all` encounters the symlink, and the user sees a download error despite the doctor warning.
Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.
Also at `src/doctor.rs:33-34`.| 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()); |
There was a problem hiding this comment.
🟡 Medium · Validator rejection goes untested
When validate_custom is changed to ignore a header-read error, custom_model_header_read_errors_are_rejected asserts only that read_model_header returns an error, so it still passes if validate_custom stops propagating that error and accepts an unreadable header.
Exercise validate_custom with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.
Prompt for AI agents
In `src/model.rs` at line 1392:
**Validator rejection goes untested**
When `validate_custom` is changed to ignore a header-read error, `custom_model_header_read_errors_are_rejected` asserts only that `read_model_header` returns an error, so it still passes if `validate_custom` stops propagating that error and accepts an unreadable header.
Exercise `validate_custom` with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.Sourcery withdrew this approval because the latest commits introduced blocking findings.
Summary
Verification
Summary by Sourcery
Harden custom model validation and doctor diagnostics while improving contribution templates.
Bug Fixes:
Enhancements:
Documentation:
Tests: