fix: resolve CI failures and implement read-only database safeguards#62
fix: resolve CI failures and implement read-only database safeguards#62OGKevin merged 13 commits intofeat/lib-managementfrom
Conversation
- Add Send/Sync implementations for CalibreDatabase - Remove unused Schema validation methods - Fix clippy::useless_vec warning in tests - Apply cargo fmt formatting
- Remove unused useRef import from BooksTable - Add required blank lines before return statements - Add blank lines after if statements per eslint rules
Prevent auto-load effect from triggering when manually opening a library. The auto-load effect should only trigger when loading a saved path from localStorage on mount, not when calling openLibrary() manually. This fixes the flaky test 'can manually load books after opening library' which was sometimes seeing 2 calls to libraryGetAllBooks instead of 1.
Co-authored-by: OGKevin <17928966+OGKevin@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull Request Overview
This pull request focuses on code formatting and cleanup improvements across TypeScript frontend and Rust backend files. The main changes involve reformatting code to improve readability and consistency, plus some minor structural adjustments.
- Reformatted TypeScript and Rust files to improve code consistency and readability
- Added thread safety implementations for Rust database types
- Removed unused Schema validation code from the Calibre database module
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/hooks/useStreamBookCovers.ts | Reformatted indentation and added blank lines for better readability |
| src/hooks/useLibrary.ts | Added early setting of autoLoadAttemptedRef to prevent race conditions; cleaned up import formatting |
| src/components/BooksTable.tsx | Reformatted JSX attributes across multiple lines for readability; removed unused import |
| src-tauri/tests/lib_tests.rs | Changed from vec![] to array literal [] for static test data |
| src-tauri/src/library/commands.rs | Consolidated enum variant definitions to single lines |
| src-tauri/calibre_db/src/schema.rs | Removed unused Schema struct and validation methods |
| src-tauri/calibre_db/src/models.rs | Reordered imports alphabetically; reformatted function calls |
| src-tauri/calibre_db/src/lib.rs | Added unsafe Send/Sync implementations with safety documentation; reordered imports and exports alphabetically |
| src-tauri/calibre_db/src/error.rs | Reordered imports alphabetically |
| flake.nix | Updated cargoHash for Nix build |
|
@copilot Regarding comment 2: Regarding comment 1: At the time of writing, only read operations are done. So the comment is correct. When/If writes are introduced this shall be re-assed. The comments shall be updated to reflect their current correctness. Linting is not happy yet: To be explicit, lets use named lifetime for this signature. |
- Update safety comment to clarify current read-only operations - Add note about reassessing if write operations are introduced - Fix mismatched_lifetime_syntaxes warning by using explicit named lifetime in DatabaseConnection::prepare method
Updated both issues in commit 75a3d65:
pub fn prepare<'a>(&'a self, query: &str) -> Result<rusqlite::Statement<'a>>Clippy now passes with no warnings. |
Refactored the BookBuilder pattern to eliminate mid-construction state exposure and improve encapsulation. The builder now holds an optional database reference and uses boolean flags to control which relations to fetch during build(). - Made BookBuilder database-aware with optional &DatabaseConnection - Added 9 boolean flags to control relation fetching (authors, publishers, tags, series, comments, rating, formats, identifiers, languages) - Moved relation-fetching logic into build() method - Exposed fetch_book_*() functions as public query API - Added with_db() and fetch_all() builder methods - Updated get_book() and all_books() to use new pattern - Removed get_id() method that broke encapsulation - Added comprehensive doc tests with lifetime design explanation - All tests pass: 11 unit tests + 17 integration tests
|
@copilot apply changes based on the comments in this thread Refactoring the DB connections to use something like For the bulk relation fetching, either a query builder approach can be used, so that one big sql is build and that is executed to fetch all the relations. Another approach could be to always build the query that returns all the relations, and only actually fill the data that has been requested. |
- Add ReadOnlyDatabase trait to mark database types as read-only - Remove execute() method from DatabaseConnection to prevent write operations - Add compile-time query validation in debug builds to ensure only SELECT queries - Add comprehensive tests for read-only constraint validation - Update safety documentation with ReadOnlyDatabase marker trait - Update CI workflow to use --workspace flag for consistency Changes ensure type-safe read-only guarantee at compile time while maintaining runtime validation in debug builds. Write operations now require explicit removal of ReadOnlyDatabase implementation.
Implemented all requested changes in commit 48c1a55: 1. ReadOnlyDatabase trait with safeguards:
2. Comprehensive tests:
3. CI workflow:
4. Safety documentation:
The implementation provides type-safe read-only guarantees at compile time, with runtime validation in debug builds. Write operations now require explicit removal of the |
…ase trait for improved database operations
…ffs and query strategy rationale
…roved relation fetching
The read-only validation in DatabaseConnection was unnecessary defensive programming. Since only the ReadOnlyDatabase trait is exposed to users (with SELECT-only methods), and DatabaseConnection is an internal implementation detail, the type system already enforces read-only semantics at the public API level. - Removed is_read_only_query() function and helpers - Removed comment/string literal stripping logic - Simplified prepare() method - Removed validation-related tests - Kept essential connection and query tests
|
@copilot apply changes based on the comments in this thread Only look at the unresolved discussions.
There is no need for validation method due to the trait approach. So this comment is indeed outdated. And should not have any mention to automatic validation etc. |
- Extract long tuple type into BookRow struct with named fields - Add named constants for SQL column indices (IDX_ID, IDX_TITLE, etc.) - Remove redundant list_books() method from ReadOnlyDatabase trait - Update safety comment to suggest ReadWriteDatabase trait for future writes - Replace Into::into with explicit CalibreDbError::from for clarity - Simplify all_books() by using BookRow::from_row helper These changes improve code maintainability and make the codebase easier to understand.
Implemented all requested changes in commit 4d65855: 1. BookRow struct (addresses comment on lib.rs:43-62):
2. Named column indices (addresses comment on lib.rs:44-50):
3. Removed redundant list_books():
4. Fixed outdated comment (addresses comment on lib.rs:279):
5. Explicit error conversion (addresses comment on schema.rs:20):
All tests pass (27 total: 10 unit + 17 integration). |
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.