Repository navigation
Connect Zotero directory/enrich workflow with local full-text excerpt signing - #180
Conversation
|
Claude encountered an error after 1s —— View job I'll analyze this and get back to you. |
|
Claude finished @cmungall's task in 1m 19s —— View job PR Review: Zotero directory / enrich → excerpt signing
Overall this is a useful feature. The 🔴 Must fix:
|
…d items, and enrich filters
|
Thanks for the thorough review! Addressed all items in
|
|
Claude finished @cmungall's task in 1m 42s —— View job Re-review after
|
| Earlier point | Status |
|---|---|
🔴 _fetch_bytes read any file:// URL |
Fixed. The generic branch is gone. read_zotero_storage_file reads a file only if zotero_dir is set, the host is local and the path resolves inside zotero_dir/storage. Callers also require provider == "zotero". The regression test test_url_source_and_generic_providers_reject_file_urls covers it. |
| Trashed items | Fixed. deletedItems is excluded for both the parent and the attachment, and the code checks that the table exists first. |
DOI in extra |
Fixed. _index_extra_identifiers is shared by both backends. |
| Copying SQLite while Zotero is running | Fixed. The -wal and -journal sidecars are copied too, and OSError/DatabaseError become a ZoteroAPIError that says "close Zotero or retry". |
rel_name containment |
Fixed. Both att_dir and pdf_path are checked to resolve inside their parent folder. |
attachment_file_url returning a directory |
Fixed. It now returns Optional[str]. |
| HTTP vs. directory PDF behaviour | Now documented in export-cache-to-zotero.md. |
get_private_cache_dir() side effects, and the fallback when both directories are set |
Fixed, and documented. |
| Private helpers imported across modules | same_reference_id and expand_globs are now public. |
O(refs × wanted) filter, warning for uncached --reference IDs, lazy iterator |
All fixed. |
PDF parsed twice, UnreadablePDFError, logging for abstract-only files |
Fixed, with tests. |
| Missing tests | All six have been added. |
🟠 excerpts sign can sign against text that isn't local when the mapped file is abstract-only
excerpt_signing.py:420-430 together with reference_fetcher.py:589-598
_with_local_full_text now skips a cache-formatted .md file that has no full text and returns the normal fetch outcome. local_full_text_path() doesn't know about that skip, so it still returns the file's path. As a result, in sign_excerpts:
source = fetcher.local_full_text_path(reference_id)is notNone, so the reference is processed.fetcher.fetch(reference_id)returns the usual fetch result. That is the public cache, or a network fetch giving the abstract or open-access text.- Quotes are validated against that text, but
source_sha256is the hash of the skipped private file.
The bundle then says it was verified against the local file when it wasn't, and signing can make network requests. This breaks the "Verify against the local text only" rule in the comment at L379. The new automatic private_cache_dir fallback makes this more likely, because whatever is in the private cache gets picked up without the user choosing it.
Suggested fix: skip the reference, and add it to report.no_local_text, unless the fetched text actually came from the local file. For example:
reference = fetcher.fetch(reference_id)
if (reference is None or not reference.content
or reference.full_text_provider != LOCAL_FULL_TEXT_CONTENT_TYPE):
report.no_local_text.append(reference_id)
continueA cleaner option is to have local_full_text_path return None for cache files without full text, so lookup and use agree. The test would be: put an abstract_only cache .md in private_cache_dir with a quote that appears in the abstract. Signing should then write no bundle.
🟡 Minor points
- Formatting.
ruff format --checkwould reformatetl/acquire.py,etl/fulltext/zotero.pyandexcerpt_signing.py. There are 3 blank lines after_index_extra_identifiers, a trailing blank line at the end ofacquire.py, and some long lines.just formatonly runsruff check, so CI won't catch this. Runninguv run ruff formaton those files would tidy it up. - Compatibility aliases.
_same_reference_id = same_reference_idand_expand_globs = expand_globsare kept, andreference_fetcher.py,supporting_text_validator.pyandsigned_excerpts.py:162still use the private names. Either switch those call sites to the public names and drop the aliases, or keep them on purpose. Right now there are two names for each function. - Relative
private_cache_dir.private_dir.is_dir()(excerpt_signing.py:385) is checked against the current working directory.local_full_text_pathresolves directories againstreference_base_dir. For a relativeprivate_cache_dir(for example--private-cache-dir references_cacherun from somewhere else) these can disagree. The default is absolute, so this is an edge case. Resolving withFileSource.resolve_pathwould make the two consistent. - Mutating the config in place.
checking.local_full_text[reference_id] = priv_path(excerpt_signing.py:417) works only becausefetchershares thecheckingobject. It would be clearer to build the full mapping first and then create the validator fromchecking.model_copy(update={"local_full_text": merged}). - Loopback
file://redirect (existed before this PR). The HTTP-backend path atacquire.py:~221, where a loopback server redirects tofile://, still calls_read_local_filewith no storage containment check. It's out of scope here, but now thatread_zotero_storage_fileexists, a similar check would be cheap wheneverzotero_diris known.
The remaining item is the abstract-only signing issue above.
Summary
Connects the Zotero
cache enrichworkflow directly withexcerpts signand supports reading a local Zotero directory (~/Zotero) without requiring the Zotero desktop HTTP API to be running:ZoteroDirectoryClient(zotero_dir/--zotero-dir):zotero.sqliteandstorage/<KEY>/(.zotero-ft-cacheand.pdffiles), indexing large local Zotero libraries in milliseconds without HTTP pagination or requiring the Zotero GUI app to be open.download_pdfsis enabled,ZoteroFullTextProvideralso supplies thefile://PDF URI socache enrich --applysaves the PDF attachment (files/<STEM>.pdf).cache enrichfilters (--reference/-rand--referenced-in):--referenced-in 'kb/disorders/MyDisease.yaml') or specific IDs (--reference DOI:...) instead of scanning the entire cache directory.local_full_text/local_full_text_dir:FileSourcenow extracts.pdffiles viaPDFExtractor(LOCAL_FULL_TEXT_SUFFIXES = (".md", ".txt", ".pdf")).local_full_textorlocal_full_text_dirpoints to a cache-formatted.mdfile (with---YAML frontmatter and## Content),_with_local_full_textstrips the frontmatter and# Titleheader so only the article body is matched.private_cache_dirfallback inexcerpts sign:local_full_text_diris unset andprivate_cache_dir(~/.cache/linkml-reference-validator/private, populated bycache enrich --provider zotero --apply) exists,excerpts signautomatically checksprivate_cache_dirfor full-text entries while normalvalidatecontinues to ignoreprivate_cache_dir.Test plan
just doctest(338 passed)just mypy(0 issues in 160 files)just format(ruff check .passed)uv run pytest tests/test_zotero_provider.py tests/test_cli_cache_enrich.py tests/test_local_full_text.py tests/test_excerpts_sign.py