#!/usr/bin/env python3 # -*- coding: utf-8 -*- """百度网盘备份 · 解析自测(不连网盘)。""" from __future__ import annotations import json import sys import tempfile from pathlib import Path import _bootstrap # noqa: F401 import backup_settings as S from backup_collect import build_backup_bundle, collect_files, load_manifest def test_manifest_exists() -> None: m = load_manifest() assert "include_dirs" in m assert "scripts_cursor" in m["include_dirs"] def test_collect_finds_docs() -> None: m = load_manifest() included, _ = collect_files(S.ROOT, m) paths = {x["path"] for x in included} assert any(p.startswith("docs/md_cursor/") for p in paths) assert any(p.startswith("scripts_cursor/") for p in paths) def test_build_bundle_smoke() -> None: with tempfile.TemporaryDirectory() as td: root = Path(td) (root / "docs/md_cursor").mkdir(parents=True) (root / "scripts_cursor").mkdir() (root / "docs/md_cursor/demo_cursor.md").write_text("# demo", encoding="utf-8") mini_manifest = { "include_dirs": ["docs/md_cursor", "scripts_cursor"], "include_files": [], "include_globs_root": [], "exclude_dir_names": [], "exclude_file_names": [], "exclude_globs": [], "max_file_bytes": 1024 * 1024, "remote_snapshot": {"enabled": False}, } old = S.MANIFEST_PATH old_state = S.STATE_DIR tmp_manifest = root / "backup_manifest.json" tmp_manifest.write_text(json.dumps(mini_manifest), encoding="utf-8") S.MANIFEST_PATH = tmp_manifest S.STATE_DIR = root / "baidu_backup" try: meta = build_backup_bundle(root=root, pull_remote=False) assert Path(meta["zip_path"]).is_file() assert meta["file_count"] >= 1 assert Path(meta["guide_html_path"]).is_file() assert "备份说明" in Path(meta["guide_html_path"]).read_text(encoding="utf-8") finally: S.MANIFEST_PATH = old S.STATE_DIR = old_state def test_guide_categories() -> None: from backup_guide_html import categorize_files cats = categorize_files( [ {"path": "dify_api.py", "size": 1}, {"path": "langfuse_api_keys.txt", "size": 1}, {"path": "platform_snapshot/xinference/models.txt", "size": 1}, {"path": "docs/md_cursor/a.md", "size": 1}, ] ) assert "dify" in cats assert "langfuse" in cats assert "xinference" in cats assert "docs" in cats def main() -> int: test_manifest_exists() test_collect_finds_docs() test_guide_categories() test_build_bundle_smoke() print("[PASS] 百度网盘备份 解析自测") return 0 if __name__ == "__main__": sys.exit(main())