#!/bin/sh
# Smoke test for the desync CLI.
#
# Chunks a file into a local store, indexes, reconstructs and confirms the round
# trip is byte-for-byte identical.
set -eu

WORKDIR="$(mktemp -d)"
trap 'rm -rf "$WORKDIR"' EXIT
cd "$WORKDIR"

# The tool should exist and report help output.
desync --help

# Generate a few MB of random input so the rolling-hash chunker produces
# several chunks rather than a single one.
dd if=/dev/urandom of=original.bin bs=1M count=8 status=none

mkdir store

# Chunk the input into the local store and write the index.
desync make -s store original.bin.caibx original.bin

# Show some index metadata as a further sanity check.
desync info original.bin.caibx

# Reconstruct the blob from the index and store.
desync extract -s store original.bin.caibx extracted.bin

cmp original.bin extracted.bin
echo "desync smoke test: round trip OK"
