"""CH-FILE-001 — staging upload → files on disk."""

from __future__ import annotations

import pytest

from server.api.sync_v2 import _persist_staging_files

pytestmark = pytest.mark.chain


@pytest.mark.asyncio
async def test_staging_upload_then_listable(tmp_path):
    staging = str(tmp_path / "nexus_upload_chain")

    class FakeUpload:
        def __init__(self, name: str, data: bytes):
            self.filename = name
            self._data = data

        async def read(self):
            return self._data

    meta = await _persist_staging_files(
        staging,
        [FakeUpload("deploy.txt", b"hello-chain")],
    )

    assert meta["file_count"] == 1
    assert (tmp_path / "nexus_upload_chain" / "deploy.txt").read_bytes() == b"hello-chain"
    assert meta["source_path"] == staging
