8 Commits

Author SHA1 Message Date
Marcello Pichini
05188b51e0 fix(storage): shorten attachment names that exceed the filesystem limit (#2750)
The stored name is "<attachment_id>_<filename>", so a valid 240-byte filename
exceeded the 255-byte component limit and put() raised ENAMETOOLONG. Trim the
stem by bytes, keeping a short extension, so saving and lookup stay consistent.
2026-11-28 19:42:02 +08:00
Bingxi Zhao (Frank)
92a26ae3cc fix(storage): isolate attachment writes and settle document parsing
Local dev repairs for #2244, #2245, #2255, #2426, #2453. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Bingxi Zhao
3f41345d8f Merge pull request #2240 from rudycelekli/fix/library-unicode-filename-search-20261031
fix(library): match Unicode filename case during search
2026-10-31 16:41:42 +08:00
Rudy Celekli
b450c589a4 fix(library): match Unicode filename case during search
Apply Unicode casefolding to filename and query instead of relying on SQLite LIKE ASCII-only folding. Preserve literal wildcard escaping, soft-deletion filtering and result ordering.

AI-assisted: implemented and validated with OpenAI Codex; actual SQLite stores and isolated API fixtures.
2026-10-31 02:00:07 -04:00
Rudy Celekli
520d1bf556 fix(library): report restore content conflicts without a server error
Translate only an actual active-SHA uniqueness conflict into a safe 409 response. Preserve both records and their bytes so restoring the earlier entry can be retried after deleting the replacement; unrelated database failures still propagate.

AI-assisted: implemented and validated with OpenAI Codex; isolated API and real SQLite constraints, no user workspace writes.
2026-10-31 01:53:57 -04:00
Rudy Celekli
1e7bc227b0 fix(storage): escape LIKE wildcards in file library search
search_files promises case-insensitive substring matching, but _search_files_sync
interpolated the query into a LIKE pattern without escaping. SQLite LIKE treats
'_' as any single character and '%' as any run, so a query like 'report_v1'
matched 'reportXv1.pdf' too — filenames commonly contain '_', so the false
positives are routine. Escape the query's LIKE metacharacters and add ESCAPE.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-26 10:50:54 -04:00
evan188199-tech
6e208560da test(storage): lock file library disk-deletion failure paths (#1719)
Merge the six DT-22 regression cases (previously on a separate
test_file_library_deletion.py branch) into the existing per-module
test file, right after the delete_file / hard_delete_file sections:

- successful delete prunes now-empty parents, keeps non-empty ones
  and the library root itself
- missing on-disk target is a silent no-op; hard delete still clears
  the DB row when the disk file vanished out-of-band
- unlink failure is only logged (list-vs-disk inconsistency window)
- an exception while pruning parents is swallowed: file still
  removed, empty dirs left behind, caller unaffected (current
  behaviour pinned)

Coverage of deeptutor.services.storage.file_library: 84% -> 87%
(196-197 and 203-206 now covered). No product code changes.

Co-authored-by: XZH <cto@xzh.ai>
2026-10-07 20:13:15 +08:00
Srini Jagadeesh
3006ec3671 feat: Persistent File Library with API router (issue #1437) (#1446)
* feat: Persistent File Library with API router (issue #1437)

FileLibraryStore (deeptutor/services/storage/file_library.py):
- add_file: stores bytes to disk, deduplicates by SHA-256
- get_file: returns entry by id
- delete_file: soft-delete, idempotent
- hard_delete_file: permanent delete (requires prior soft-delete)
- restore_file: clears is_deleted, idempotent
- list_files: active entries, newest-first, paginated
- search_files: case-insensitive filename LIKE search
- resolve_path: returns absolute Path or None

API router (deeptutor/api/routers/file_library.py):
- GET    /files/library/              — list files
- POST   /files/library/              — multipart upload with SHA-256 deduplication
- GET    /files/library/search        — filename search
- GET    /files/library/{id}          — get entry
- GET    /files/library/{id}/download — download file bytes
- DELETE /files/library/{id}          — soft-delete
- POST   /files/library/{id}/restore   — restore soft-deleted

25 unit tests + 20 API integration tests, all passing.

* fix: ruff import-sort/unused-import fixes for file library

* fix: scope file library singleton per user, close upload dedup race

- get_file_library_store() was caching the FileLibraryStore under a
  hardcoded key ("default") instead of the resolved per-user root, so
  in multi-user deployments every user after the first shared one
  library (list/get/download/delete/restore all leaked across
  accounts). Now resolves get_path_service().get_user_root() on every
  call and keys the cache by str(user_root), mirroring
  get_attachment_store().

- _add_file_sync's SHA-256 dedup check was a plain SELECT followed by
  an INSERT with no synchronization; concurrent uploads of identical
  content (double-click, duplicate tabs, client retries) could both
  miss the dedup lookup and each create a duplicate row/file. Added a
  per-instance lock around the check-then-write-then-insert sequence,
  plus a partial unique index on sha256 (active rows only) with
  IntegrityError handling as a defense-in-depth backstop for
  multi-process deployments.

- Fixed the test fixture in test_file_library_router.py: it patched
  file_library._fl.get_file_library_store then reverted the patch
  before any request ran, so the mock never actually intercepted
  anything; removed the dead code and added tokens/auth_enabled
  support for multi-user testing.

- Added regression tests: test_upload_and_list_are_isolated_between_users
  and test_add_file_concurrent_uploads_of_same_content_do_not_duplicate,
  both verified to fail against the pre-fix code.

- ruff format on the three touched files (pre-existing line-length
  debt in code this change touches).
2026-09-14 01:28:50 +08:00