## Simplified test for Nippels Merkle Tree Integration (Task 8.4)

import std/[unittest, os, times, strutils]
import ../src/nimpak/nippels

suite "Nippels Merkle Tree Integration (Task 8.4) - Simplified":
  var manager: NippelManager
  let testRoot = getTempDir() / "nippels_merkle_simple_" & $epochTime().int

  setup:
    createDir(testRoot)
    manager = newNippelManager(testRoot)

  teardown:
    if dirExists(testRoot):
      removeDir(testRoot)

  test "Create Nippel builds initial merkle tree":
    let result = manager.createNippel("test-merkle", Homestation)
    check result.isOk

    if result.isOk:
      let nippel = result.value
      check nippel.merkleRoot.len > 0
      check nippel.merkleRoot.startsWith("xxh3-")
      echo "   ✅ Merkle tree created with root: ", nippel.merkleRoot

  test "Merkle root is stored in configuration":
    let result = manager.createNippel("test-config", Homestation)
    check result.isOk

    if result.isOk:
      let nippel = result.value
      let configPath = nippel.cellRoot / "cell.json"
      check fileExists(configPath)
      echo "   ✅ Configuration file exists"

  test "Multiple Nippels have independent merkle roots":
    let result1 = manager.createNippel("test-1", Homestation)
    let result2 = manager.createNippel("test-2", Workstation)

    check result1.isOk
    check result2.isOk

    if result1.isOk and result2.isOk:
      let nippel1 = result1.value
      let nippel2 = result2.value

      check nippel1.merkleRoot.len > 0
      check nippel2.merkleRoot.len > 0
      echo "   ✅ Multiple independent merkle roots created"

echo "✅ All Task 8.4 simplified tests completed"
