kin: KIN-070 Исправить sync с Obsidian: auto-create vault dir + корректный vault_path
- obsidian_sync.py: заменить проверку is_dir() на mkdir(parents=True, exist_ok=True) вместо ошибки при отсутствующей директории — автоматически создаём её - test_obsidian_sync.py: обновить тест #9 под новое поведение (директория создаётся) - БД fix: исправлен obsidian_vault_path (убраны лишние кавычки и /kin суффикс), теперь путь указывает на vault root, а не на подпапку проекта Результат: Exported: 79 decisions, errors: [] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8007960332
commit
71c697bf68
2 changed files with 34 additions and 31 deletions
|
|
@ -141,11 +141,15 @@ def sync_obsidian(conn: sqlite3.Connection, project_id: str) -> dict:
|
|||
vault_path = Path(vault_path_str)
|
||||
errors: list[str] = []
|
||||
|
||||
# --- Создаём vault_path если не существует ---
|
||||
try:
|
||||
vault_path.mkdir(parents=True, exist_ok=True)
|
||||
except Exception as e:
|
||||
errors.append(f"Cannot create vault path {vault_path_str}: {e}")
|
||||
return {"exported_decisions": 0, "tasks_updated": 0, "errors": errors, "vault_path": vault_path_str}
|
||||
|
||||
# --- Export decisions ---
|
||||
exported_count = 0
|
||||
if not vault_path.is_dir():
|
||||
errors.append(f"Vault path does not exist or is not a directory: {vault_path_str}")
|
||||
else:
|
||||
try:
|
||||
decisions = models.get_decisions(conn, project_id)
|
||||
created_files = export_decisions_to_md(project_id, decisions, vault_path)
|
||||
|
|
@ -155,7 +159,6 @@ def sync_obsidian(conn: sqlite3.Connection, project_id: str) -> dict:
|
|||
|
||||
# --- Import checkboxes ---
|
||||
tasks_updated = 0
|
||||
if vault_path.is_dir():
|
||||
try:
|
||||
checkboxes = parse_task_checkboxes(vault_path, project_id)
|
||||
for item in checkboxes:
|
||||
|
|
|
|||
|
|
@ -227,19 +227,19 @@ def test_export_frontmatter_has_yaml_delimiters(tmp_vault):
|
|||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 9. sync_obsidian — несуществующий vault_path → ошибка в errors, не исключение
|
||||
# 9. sync_obsidian — несуществующий vault_path → директория создаётся автоматически
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_sync_nonexistent_vault_records_error(db, tmp_path):
|
||||
"""Если vault_path не существует, sync возвращает ошибку в errors без raise."""
|
||||
def test_sync_nonexistent_vault_creates_directory(db, tmp_path):
|
||||
"""Если vault_path не существует, sync автоматически создаёт директорию."""
|
||||
nonexistent = tmp_path / "ghost_vault"
|
||||
models.update_project(db, "proj1", obsidian_vault_path=str(nonexistent))
|
||||
|
||||
result = sync_obsidian(db, "proj1")
|
||||
|
||||
assert len(result["errors"]) > 0
|
||||
assert "does not exist" in result["errors"][0].lower() or "not exist" in result["errors"][0].lower()
|
||||
assert result["exported_decisions"] == 0
|
||||
assert result["errors"] == []
|
||||
assert nonexistent.is_dir() # директория автоматически создана
|
||||
assert result["exported_decisions"] == 0 # нет decisions в DB
|
||||
assert result["tasks_updated"] == 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue