"""
ShelfAI test suite.

Tests core functionality: shelf operations, index parsing,
transcript parsing, session management, and CLI commands.
"""



class TestBackups:
    """Tests for backup and restore functionality."""

    def test_backup_creates_copies(self, shelf_dir):
        from shelfai.core.safety import backup_files

        backup_dir = backup_files(
            shelf_dir,
            ["skills/code_review.md", "index.md"],
            "test_session_001",
        )
        assert (backup_dir / "skills" / "code_review.md").exists()
        assert (backup_dir / "index.md").exists()

    def test_backup_missing_file_skipped(self, shelf_dir):
        from shelfai.core.safety import backup_files

        # Should not crash on missing files
        backup_dir = backup_files(
            shelf_dir,
            ["nonexistent.md"],
            "test_session_002",
        )
        assert backup_dir.exists()

    def test_restore_backup(self, shelf_dir):
        from shelfai.core.safety import backup_files, restore_backup

        # Create backup
        backup_files(shelf_dir, ["index.md"], "test_session_003")

        # Corrupt the original
        (shelf_dir / "index.md").write_text("CORRUPTED")

        # Restore
        restored = restore_backup(shelf_dir, "test_session_003")
        assert "index.md" in restored
        assert "CORRUPTED" not in (shelf_dir / "index.md").read_text()


# ──────────────────────────────────────────────
# Test: Safety — File Locking
# ──────────────────────────────────────────────


