Skip to content

Commit 5222bd6

Browse files
committed
Fix desktop reading report output paths
1 parent b7fb99f commit 5222bd6

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

deployments/desktop/shared/agents.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ def _reading_report_dirs() -> List[Path]:
465465
if _env_text("PAPERFLOW_READING_REPORTS_DIR", ""):
466466
return [configured] if configured.exists() and configured.is_dir() else [configured]
467467
fallback = (PROJECT_ROOT / "data" / "reading_reports").resolve()
468-
ordered = [configured, fallback]
468+
legacy_exports = (PROJECT_ROOT / "data" / "exports").resolve()
469+
ordered = [configured, fallback, legacy_exports]
469470
results: List[Path] = []
470471
seen: Set[str] = set()
471472
for candidate in ordered:
@@ -857,6 +858,25 @@ def fake_create_doc(title: str, content: str, folder_id: Optional[str] = None) -
857858
reading_agent.create_doc = original
858859

859860

861+
@contextmanager
862+
def _reading_agent_output_env_patch():
863+
"""Expose GUI-derived output paths to reading-agent, which reads os.environ directly."""
864+
patched = {
865+
"PAPERFLOW_READING_REPORTS_DIR": _configured_path("PAPERFLOW_READING_REPORTS_DIR", "data/exports"),
866+
"PAPERFLOW_PDF_DIR": _configured_path("PAPERFLOW_PDF_DIR", "data/exports"),
867+
}
868+
previous = {key: os.environ.get(key) for key in patched}
869+
os.environ.update(patched)
870+
try:
871+
yield
872+
finally:
873+
for key, value in previous.items():
874+
if value is None:
875+
os.environ.pop(key, None)
876+
else:
877+
os.environ[key] = value
878+
879+
860880
def health() -> Dict[str, Any]:
861881
return {
862882
"ok": True,
@@ -2206,7 +2226,7 @@ def create_reading_reports(
22062226
if not selected:
22072227
return _reports_payload([], write_feishu_requested=should_write_feishu)
22082228

2209-
with _local_only_feishu_doc_patch(not should_write_feishu):
2229+
with _reading_agent_output_env_patch(), _local_only_feishu_doc_patch(not should_write_feishu):
22102230
docs = reading_agent.create_reading_report(
22112231
user_id=user_id,
22122232
paper_ids=selected,
@@ -2262,7 +2282,7 @@ def read_arxiv(
22622282

22632283
should_write_feishu = _env_bool("PAPERFLOW_WRITE_FEISHU", default=False) if write_feishu is None else bool(write_feishu)
22642284
language = _normalize_response_language(response_language)
2265-
with _local_only_feishu_doc_patch(not should_write_feishu):
2285+
with _reading_agent_output_env_patch(), _local_only_feishu_doc_patch(not should_write_feishu):
22662286
docs = reading_agent.create_reading_report(
22672287
user_id=user_id,
22682288
paper_ids=[],
@@ -2305,7 +2325,7 @@ def read_local_pdf(
23052325
}
23062326
should_write_feishu = _env_bool("PAPERFLOW_WRITE_FEISHU", default=False) if write_feishu is None else bool(write_feishu)
23072327
language = _normalize_response_language(response_language)
2308-
with _local_only_feishu_doc_patch(not should_write_feishu):
2328+
with _reading_agent_output_env_patch(), _local_only_feishu_doc_patch(not should_write_feishu):
23092329
docs = reading_agent.create_reading_report(
23102330
user_id=user_id,
23112331
paper_ids=[],

tests/test_desktop_gui.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,39 @@ def test_desktop_github_sync_rebases_remote_changes_before_push(tmp_path, monkey
13651365
assert (clone_check / "Daily Note - Jun 2026.md").exists()
13661366

13671367

1368+
def test_desktop_reading_agent_receives_derived_output_dirs(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None:
1369+
env_path = tmp_path / ".env"
1370+
notes_root = tmp_path / "Daily Note"
1371+
env_path.write_text(f'PAPERFLOW_NOTES_ROOT_DIR="{notes_root}"\n', encoding="utf-8")
1372+
monkeypatch.setattr(agents, "ENV_PATH", env_path)
1373+
monkeypatch.delenv("PAPERFLOW_NOTES_ROOT_DIR", raising=False)
1374+
monkeypatch.delenv("PAPERFLOW_READING_REPORTS_DIR", raising=False)
1375+
monkeypatch.delenv("PAPERFLOW_PDF_DIR", raising=False)
1376+
1377+
with agents._reading_agent_output_env_patch(): # noqa: SLF001 - output env bridge contract
1378+
assert agents.os.environ["PAPERFLOW_READING_REPORTS_DIR"] == str(notes_root)
1379+
assert agents.os.environ["PAPERFLOW_PDF_DIR"] == str(notes_root)
1380+
1381+
assert agents.os.environ.get("PAPERFLOW_READING_REPORTS_DIR") is None
1382+
assert agents.os.environ.get("PAPERFLOW_PDF_DIR") is None
1383+
1384+
1385+
def test_desktop_report_dirs_include_legacy_exports_for_recent_generated_reports(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None:
1386+
project_root = tmp_path / "project"
1387+
configured = tmp_path / "Daily Note"
1388+
legacy_exports = project_root / "data" / "exports"
1389+
configured.mkdir()
1390+
legacy_exports.mkdir(parents=True)
1391+
monkeypatch.setattr(agents, "PROJECT_ROOT", project_root)
1392+
monkeypatch.setattr(agents, "_configured_path", lambda _env_name, _default_relative: str(configured))
1393+
monkeypatch.setattr(agents, "_env_text", lambda _name, default="": "")
1394+
1395+
dirs = agents._reading_report_dirs() # noqa: SLF001 - report discovery contract
1396+
1397+
assert configured.resolve() in dirs
1398+
assert legacy_exports.resolve() in dirs
1399+
1400+
13681401
def test_desktop_daily_push_uses_saved_settings_when_gui_omits_filters(
13691402
tmp_path, monkeypatch: pytest.MonkeyPatch
13701403
) -> None:

0 commit comments

Comments
 (0)