import XCTest
import Metal
import PhysarumEngine
@testable import Physarum
/// Wiring tests for the live render path. The macOS test host has a real GPU,
/// so engine-backed construction is verifiable headlessly.
final class RenderCoordinatorTests: XCTestCase {
private func anyPreset() -> Preset {
PresetCatalog.loadAll().first ?? PresetCatalog.fallbackPreset
}
/// The coordinator starts on the real (non-square) target field so the first
/// draw doesn't discard a freshly built square engine (startup double-build).
func testInitAcceptsNonSquareInitialFieldAndTier() throws {
guard MTLCreateSystemDefaultDevice() != nil else { throw XCTSkip("no Metal device") }
let p = anyPreset()
let c = RenderCoordinator(initialField: FieldSize(width: 512, height: 1110),
tier: .phone, initialPreset: p, live: p.params)
XCTAssertNotNil(c)
}
func testIsStructuralChange() {
let p = anyPreset().params
XCTAssertFalse(RenderCoordinator.isStructuralChange(p, p)) // identical → live adoption, no re-seed
var count = p; count.agentCount = p.agentCount / 2 + 1
XCTAssertTrue(RenderCoordinator.isStructuralChange(count, p))
var pop = p; pop.species[0].populationShare += 0.1
XCTAssertTrue(RenderCoordinator.isStructuralChange(pop, p))
}
}