Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: align file backup verifier gate with UI toggle key (#4803)

S1aec482ae118
diff --git a/src/local_deep_research/storage/file.py b/src/local_deep_research/storage/file.py
index 37950358e4..241ca3d71f 100644
--- a/src/local_deep_research/storage/file.py
+++ b/src/local_deep_research/storage/file.py
@@ -59,7 +59,7 @@ class FileReportStorage(ReportStorage):
write_file_verified(
report_path,
content,
- "storage.allow_file_backup",
+ "report.enable_file_backup",
context="file storage backup",
)
@@ -69,7 +69,7 @@ class FileReportStorage(ReportStorage):
write_json_verified(
metadata_path,
metadata,
- "storage.allow_file_backup",
+ "report.enable_file_backup",
context="file storage metadata",
)
diff --git a/tests/storage/test_file_storage.py b/tests/storage/test_file_storage.py
index a55365786a..f4cb106da7 100644
--- a/tests/storage/test_file_storage.py
+++ b/tests/storage/test_file_storage.py
@@ -153,6 +153,127 @@ class TestSaveReport:
assert result is False
+ def test_save_report_gates_on_report_enable_file_backup(
+ self, tmp_path, sample_report_content
+ ):
+ """Regression: the verifier gate must consult the same setting key
+ that the UI toggle writes (``report.enable_file_backup``). The
+ previous literal ``storage.allow_file_backup`` was never registered
+ in ``default_settings.json``, so every save raised
+ ``FileWriteSecurityError`` regardless of the user's toggle.
+ """
+ from local_deep_research.security.file_write_verifier import (
+ FileWriteSecurityError,
+ )
+
+ captured = {}
+
+ def fake_write_file_verified(path, content, setting_name, **_kwargs):
+ captured["setting_name"] = setting_name
+ raise FileWriteSecurityError("ignored")
+
+ storage = FileReportStorage(base_dir=tmp_path)
+
+ with patch(
+ "local_deep_research.security.file_write_verifier.write_file_verified",
+ fake_write_file_verified,
+ ):
+ result = storage.save_report("abc", sample_report_content)
+
+ # The exception is swallowed by FileReportStorage.save_report, so the
+ # outer result is False -- the bug we care about is the *key* passed
+ # to the verifier, not the return value.
+ assert result is False
+ assert captured["setting_name"] == "report.enable_file_backup"
+
+ def test_save_metadata_gates_on_report_enable_file_backup(
+ self, tmp_path, sample_report_content, sample_metadata
+ ):
+ """The metadata write must consult the same UI-visible key as the
+ body write. A divergence here would silently drop the
+ ``_metadata.json`` sidecar even when the body lands on disk.
+ """
+ from local_deep_research.security.file_write_verifier import (
+ FileWriteSecurityError,
+ )
+
+ captured = {}
+
+ def fake_write_file_verified(path, content, setting_name, **_kwargs):
+ # Allow the body write through so the metadata branch runs.
+ captured.setdefault("body_setting_name", setting_name)
+
+ def fake_write_json_verified(path, payload, setting_name, **_kwargs):
+ captured["metadata_setting_name"] = setting_name
+ raise FileWriteSecurityError("ignored")
+
+ storage = FileReportStorage(base_dir=tmp_path)
+
+ with (
+ patch(
+ "local_deep_research.security.file_write_verifier.write_file_verified",
+ fake_write_file_verified,
+ ),
+ patch(
+ "local_deep_research.security.file_write_verifier.write_json_verified",
+ fake_write_json_verified,
+ ),
+ ):
+ storage.save_report(
+ "abc", sample_report_content, metadata=sample_metadata
+ )
+
+ assert captured["body_setting_name"] == "report.enable_file_backup"
+ assert captured["metadata_setting_name"] == "report.enable_file_backup"
+
+ def test_save_report_and_factory_agree_on_setting_key(
+ self, tmp_path, sample_report_content, mock_session
+ ):
+ """End-to-end key-alignment check: the key consulted by
+ ``FileReportStorage.save_report`` must match the key consulted by
+ ``get_report_storage``. If either side drifts, a user who flipped
+ the UI toggle would still see no files on disk.
+ """
+ from local_deep_research.storage.factory import get_report_storage
+
+ factory_calls = []
+
+ def fake_get_setting(name, settings_snapshot=None):
+ factory_calls.append(name)
+ return True
+
+ file_calls = []
+
+ from local_deep_research.security.file_write_verifier import (
+ FileWriteSecurityError,
+ )
+
+ def fake_write_file_verified(path, content, setting_name, **_kwargs):
+ file_calls.append(setting_name)
+ raise FileWriteSecurityError("ignored")
+
+ with (
+ patch(
+ "local_deep_research.storage.factory.get_setting_from_snapshot",
+ fake_get_setting,
+ ),
+ patch(
+ "local_deep_research.security.file_write_verifier.write_file_verified",
+ fake_write_file_verified,
+ ),
+ ):
+ # Factory side: which key unlocks file backup?
+ factory = get_report_storage(session=mock_session)
+ assert factory.enable_file_storage is True
+
+ # Storage side: which key gates the disk write?
+ fs = FileReportStorage(base_dir=tmp_path)
+ fs.save_report("abc", sample_report_content)
+
+ assert factory_calls == ["report.enable_file_backup"]
+ assert file_calls == ["report.enable_file_backup"]
+ assert factory_calls == file_calls
+
class TestGetReport:
"""Tests for get_report method."""