test_that("binomial GLM receives model-specific tests", {
  set.seed(101)
  n <- 300
  dat <- data.frame(
    treatment = factor(sample(c("control", "new"), n, replace = TRUE)),
    age = rnorm(n, 60, 10),
    severity = rnorm(n)
  )
  eta <- -0.3 + 0.7 * (dat$treatment == "new") - 0.01 * dat$age - 0.4 * dat$severity
  dat$recovered <- rbinom(n, 1, plogis(eta))

  out <- statwitness(
    recovered ~ treatment + age + severity,
    data = dat,
    family = binomial(),
    focus = "treatment"
  )

  expect_s3_class(out, "statwitness_audit")
  expect_true(any(out$tests$id == "binary_outcome_reversal"))
  expect_true(any(out$tests$id == "likelihood_reconstruction"))
  expect_false(any(out$tests$status %in% c("FAIL", "ERROR")))
})

test_that("Poisson likelihood is reconstructed", {
  set.seed(202)
  n <- 220
  dat <- data.frame(x = rnorm(n), z = rnorm(n))
  dat$y <- rpois(n, exp(0.2 + 0.3 * dat$x - 0.1 * dat$z))

  out <- statwitness(y ~ x + z, data = dat, family = poisson(), focus = "x")
  ll <- out$tests[out$tests$id == "likelihood_reconstruction", , drop = FALSE]

  expect_equal(nrow(ll), 1L)
  expect_identical(ll$status, "PASS")
})
