local pkg = require("assay.pkg")
local function check(cond, msg)
if not cond then error(msg, 2) end
end
local host = pkg.target.host()
check(host.kind == "host", "host kind")
check(host.id == "host", "host id")
local r = host:exec("echo hi", {})
check(type(r) == "table" and r.status == 0, "host exec succeeds")
check(r.stdout:match("hi"), "host stdout captured: " .. tostring(r.stdout))
local m = pkg.target.machine("does-not-exist-xyz")
check(m.kind == "machine", "machine kind")
check(m.id == "does-not-exist-xyz", "machine id matches name")
local mr = m:exec("/bin/true", {})
check(type(mr) == "table", "machine exec returns table")
check(mr.status ~= 0, "non-existent machine should yield non-zero status")
local ok = pcall(function() pkg.target.machine("") end)
check(not ok, "empty machine name should error")
ok = pcall(function() pkg.target.machine("host") end)
check(not ok, "machine name 'host' is reserved")
ok = pcall(function() pkg.target.machine(nil) end)
check(not ok, "nil machine name should error")
print("target_host_machine.lua OK")