test_that("test 11", {
  # CRAN POLICY: integration test -- drives Require()/Install() against
  # real/misspelled GitHub refs via pak. Must not run on CRAN (no
  # internet-dependent tests; pak not to be driven on CRAN). Skip at the
  # top, before the first Install() call. (pak sysreqs sudo-probe is also
  # globally disabled in .onLoad.)
  skip_on_cran()

  # skip_if(getOption("Require.usePak"), message = "Not an option on usePak = TRUE")
  setupInitial <- setupTest()

  # misspelled github.com
  err <- capture_error(
    mess <- capture_messages(
      warns <- capture_warnings(
        Install("kevanrastelle/MPBforecasting")
      )))
  if (!isTRUE(getOption("Require.usePak"))) {
    expect_match(err$message, regexp = .txtDidYouSpell)
  } else {
    # pak surfaces a misspelled GitHub user as a warning, not an error.
    # Require's pak-path archive fallback now appends the same spelling hint
    # the non-pak path emits, so the user gets actionable guidance.
    expect_true(any(grepl(.txtDidYouSpell, warns, fixed = TRUE)),
                info = paste("warns =", paste(warns, collapse = " | ")))
  }

  isDev <- getOption("Require.isDev")
  isDevAndInteractive <- getOption("Require.isDevAndInteractive")

  if (isDevAndInteractive) {
    # Use a mixture of different types of "off CRAN"
    if (!isMacOS()) {
      pkgs <- c("knn", "ggplot2 (==3.4.3)", "silly1", "SpaDES.core")
      pkgsClean <- extractPkgName(pkgs)
      lala <- try(suppressWarnings(capture.output(suppressMessages(remove.packages(pkgsClean)))), silent = TRUE)

      # ERROR: dependency 'Require' is not available for package 'SpaDES.core' --> doesn't show up
      acceptableFails <- c("Require", "SpaDES.core")
      warns <- capture_warnings(# package 'Require' is in use and will not be installed
        out22 <- Require(pkgs, require = FALSE, returnDetails = TRUE)
      )
      ip <- installed.packages() ## silly1 won't be installed

      # depending on whether SpaDES.core gets installed... could be poss1 or poss2
      poss1 <- identical(setdiff(pkgsClean, ip[, "Package"]), pkgs[[3]])  # installs SpaDES.core anyway

      # This one fails to install SpaDES.core because already loaded
      poss2 <- sum(pkgsClean %in% ip[, "Package"]) ==
        length(pkgsClean) - length(acceptableFails) ## TODO: fails on macOS
      if (internetExists())
        expect_true(poss1 || poss2)
    }

    skip_if_offline2()

    ## Test Install and also (HEAD)
    messToSilence <- capture_messages(try(remove.packages("fpCompare"), silent = TRUE))
    capted1 <- capture_messages(
      out1 <- Install("PredictiveEcology/fpCompare@development (HEAD)", verbose = 5, returnDetails = TRUE) # will install
    )
    capted2 <- capture_messages(
      out2 <- Install("PredictiveEcology/fpCompare@development (HEAD)", verbose = 5, returnDetails = TRUE) # will install
    )
    theGrep1 <- .txtInstallingColon
    theGrep2 <- "SHA1 has not"
    if (!isTRUE(getOption("Require.usePak"))) {
      if (isWindows())
        testthat::expect_true(isTRUE(sum(grepl(theGrep1, capted1)) == 1))
      testthat::expect_true(isTRUE(sum(grepl(theGrep2, capted2)) == 1))
    }
    # two sources, where both are OK; use CRAN by preference
    if (!isMacOS()) {
      lala <- suppressWarnings(capture.output(suppressMessages(
        remove.packages("SpaDES.core")))) ## TODO: fails on macOS
      suppressWarnings(
        out <- Require(c("PredictiveEcology/SpaDES.core@development (>=1.1.2)",
                         "SpaDES.core (>=1.0.0)"),
                       require = FALSE, returnDetails = TRUE
        )
      )
      out2 <- attr(out, "Require")
      # try(unlink(dir(cachePkgDir(), pattern = "SpaDES.core", full.names = TRUE)))

      if (!isTRUE(getOption("Require.usePak"))) {
        testthat::expect_true(out2[Package == "SpaDES.core"]$installFrom %in% c("CRAN", .txtLocal))
        # if (isWindows())
        testthat::expect_true(out2[Package == "SpaDES.core"]$installed)
      } else {
        testthat::expect_true(any(out2[Package == "SpaDES.core"]$installResult == "OK", na.rm = TRUE))
      }

    }
  }

})


