tests/testthat/test-tutorial-ai-engine-registration.R

test_that("vignette documents with ai chunks register the ai engine", {
  doc_files <- list.files(
    "vignettes",
    pattern = "\\.(Rmd|qmd)$",
    full.names = TRUE,
    recursive = TRUE
  )

  ai_docs <- Filter(function(path) {
    lines <- readLines(path, warn = FALSE)
    any(grepl("^```\\{ai[ ,}]", lines)) ||
      any(grepl("^#\\|\\s*engine\\s*:\\s*ai\\s*$", lines))
  }, doc_files)

  missing_registration <- Filter(function(path) {
    !any(grepl("register_ai_engine\\s*\\(", readLines(path, warn = FALSE)))
  }, ai_docs)

  expect_equal(
    length(missing_registration),
    0,
    info = paste("Missing register_ai_engine() in:", paste(missing_registration, collapse = ", "))
  )
})

Try the aisdk package in your browser

Any scripts or data that you put into this service are public.

aisdk documentation built on May 29, 2026, 9:07 a.m.