"Error handling and edge cases work correctly"
"Invalid file paths are handled properly"
# Will fail anyway, but testing parameter validation
"Memory constraints are handled properly"
"No test model available for memory constraint tests"
"Corrupted or invalid model files are handled"
"This is a very long sentence that goes on and on."
"SQL: SELECT * FROM users; DROP TABLE users;"
"No test model available for edge case tests"
"No test model available for concurrency tests"
"No test model available for exception safety tests"

Error in `edge_load_model(dummy_path, n_ctx = -1)`: Model file not found: dummy.gguf
Try these options:
  1. Download a model: edge_download_model('TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF', 'tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf')
  2. Quick setup: edge_quick_setup('TinyLlama-1.1B')
  3. List models: edge_list_models()

Error in `edge_load_model("nonexistent.gguf")`: Model file not found: nonexistent.gguf
Try these options:
  1. Download a model: edge_download_model('TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF', 'tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf')
  2. Quick setup: edge_quick_setup('TinyLlama-1.1B')
  3. List models: edge_list_models()

Error in `edge_load_model("nonexistent_model.gguf")`: Model file not found: nonexistent_model.gguf
Try these options:
  1. Download a model: edge_download_model('TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF', 'tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf')
  2. Quick setup: edge_quick_setup('TinyLlama-1.1B')
  3. List models: edge_list_models()

# Test 1: edge_list_models() returns a data frame
test_that("edge_list_models returns valid data", {
required_cols <- c("name", "size", "model_id", "filename", "use_case")
# Check for no empty values in critical columns
# Check filename format (should end with .gguf)
expect_true(all(grepl("\\.gguf$", models$filename, ignore.case = TRUE)))
# Check model_id format (should contain /)
# Test 2: edge_load_model with invalid inputs
test_that("edge_load_model handles invalid paths", {
# Test 2b: edge_load_model parameter validation
expect_error(edge_load_model("nonexistent.gguf", n_ctx = 1e10)) # Too large
# Test 3: is_valid_model with invalid contexts
test_that("is_valid_model handles invalid contexts", {
# Test with missing arguments - function returns FALSE instead of erroring
# Test 3b: edge_free_model with invalid contexts
test_that("edge_free_model handles invalid contexts gracefully", {
# Test 4: Model loading with real model (if available)
test_that("Model loading with real model (if available)", {
test_that("edge_load_model works with valid GGUF file", {
# Test that context is still valid after validation
# Note: In current implementation, contexts may remain valid after cleanup
# This is acceptable behavior for this R package implementation
test_that("edge_load_model works with different context sizes", {
ctx1 <- edge_load_model(model_path, n_ctx = 32)
ctx2 <- edge_load_model(model_path, n_ctx = 128)
ctx3 <- edge_load_model(model_path, n_ctx = 512)
ctx4 <- edge_load_model(model_path, n_ctx = 1024)
# Very large context (may fail on low memory systems)
ctx5 <- edge_load_model(model_path, n_ctx = 4096)
# This is expected on systems with limited memory
expect_true(grepl("memory|context", e$message, ignore.case = TRUE))
test_that("edge_load_model handles GPU layers parameter", {
# Should work with 0 GPU layers (CPU only)
ctx1 <- edge_load_model(model_path, n_ctx = 256, n_gpu_layers = 0)
# Test with small number of GPU layers (may or may not work)
ctx2 <- edge_load_model(model_path, n_ctx = 256, n_gpu_layers = 1)
expect_true(grepl("gpu|cuda|opencl|metal", e$message, ignore.case = TRUE))
# Test multiple model loading and cleanup
test_that("Multiple model contexts can be managed", {
ctx1 <- edge_load_model(model_path, n_ctx = 256)
ctx2 <- edge_load_model(model_path, n_ctx = 256)
# Cleanup one, other should still be valid
# Note: Contexts may remain valid after cleanup in this implementation
# Note: Resource cleanup is handled internally
# Note: Context may remain valid after cleanup
skip("No test model available for real model loading tests")
# Test 5: Edge cases for model file validation
test_that("Model file validation edge cases", {
long_path <- paste0(rep("a", 1000), collapse = "")
path_with_special <- paste0("test", char, "model.gguf")
unicode_path <- "test_\u4e2d\u6587.gguf"  # Chinese characters
expect_error(edge_load_model(unicode_path))  # File doesn't exist