- Introduced `card_language` attribute in ProjectRecord and Workspace classes to handle multiple languages for project cards. - Updated project creation and renaming methods to accept and store the card language. - Enhanced ZoteroReader to read and return attachment metadata, including language-specific summaries and claims. - Modified LLM client to generate card content based on the specified language, supporting both English and Chinese. - Updated tests to cover new functionality, ensuring correct handling of multilingual card generation and retrieval. - Adjusted UI tests to verify the presence of language selection options and proper rendering of multilingual content.
83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
from pathlib import Path
|
|
|
|
from zotero_kb.config import AppConfig
|
|
from zotero_kb.workspace import Workspace
|
|
|
|
|
|
def test_workspace_initialization_creates_required_directories(tmp_path: Path) -> None:
|
|
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
|
|
workspace = Workspace(config)
|
|
|
|
workspace.ensure_layout()
|
|
|
|
assert (config.workspace_dir / "library" / "collections").is_dir()
|
|
assert (config.workspace_dir / "library" / "index").is_dir()
|
|
assert (config.workspace_dir / "library" / "cache" / "source-bundles").is_dir()
|
|
assert (config.workspace_dir / "projects").is_dir()
|
|
|
|
|
|
def test_create_project_writes_project_files(tmp_path: Path) -> None:
|
|
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
|
|
workspace = Workspace(config)
|
|
workspace.ensure_layout()
|
|
|
|
project = workspace.create_project(
|
|
project_id="thesis-ch2",
|
|
name="Thesis Chapter 2",
|
|
llm_provider="openai",
|
|
llm_model="gpt-5-mini",
|
|
card_language="zh",
|
|
)
|
|
|
|
assert project.project_id == "thesis-ch2"
|
|
assert (config.workspace_dir / "projects" / "thesis-ch2" / "project.json").is_file()
|
|
assert (config.workspace_dir / "projects" / "thesis-ch2" / "selected-items.json").is_file()
|
|
assert (config.workspace_dir / "projects" / "thesis-ch2" / "project-index.json").is_file()
|
|
assert '"card_language": "zh"' in (
|
|
config.workspace_dir / "projects" / "thesis-ch2" / "project.json"
|
|
).read_text(encoding="utf-8")
|
|
|
|
|
|
def test_rename_project_updates_project_name(tmp_path: Path) -> None:
|
|
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
|
|
workspace = Workspace(config)
|
|
workspace.ensure_layout()
|
|
workspace.create_project(
|
|
project_id="thesis-ch2",
|
|
name="Old Name",
|
|
llm_provider="openai",
|
|
llm_model="gpt-5-mini",
|
|
card_language="en",
|
|
)
|
|
|
|
project = workspace.rename_project("thesis-ch2", "New Name", "zh")
|
|
|
|
assert project.project_id == "thesis-ch2"
|
|
assert project.name == "New Name"
|
|
assert '"name": "New Name"' in (
|
|
config.workspace_dir / "projects" / "thesis-ch2" / "project.json"
|
|
).read_text(encoding="utf-8")
|
|
assert '"card_language": "zh"' in (
|
|
config.workspace_dir / "projects" / "thesis-ch2" / "project.json"
|
|
).read_text(encoding="utf-8")
|
|
|
|
|
|
def test_delete_project_removes_project_directory_only(tmp_path: Path) -> None:
|
|
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
|
|
workspace = Workspace(config)
|
|
workspace.ensure_layout()
|
|
workspace.create_project(
|
|
project_id="thesis-ch2",
|
|
name="Thesis Chapter 2",
|
|
llm_provider="openai",
|
|
llm_model="gpt-5-mini",
|
|
card_language="en",
|
|
)
|
|
preserved_index = config.workspace_dir / "library" / "index" / "items.json"
|
|
preserved_index.write_text('{"PAPER0001": {"title": "Keep me"}}', encoding="utf-8")
|
|
|
|
workspace.delete_project("thesis-ch2")
|
|
|
|
assert not (config.workspace_dir / "projects" / "thesis-ch2").exists()
|
|
assert preserved_index.is_file()
|