Error in `edge_load_model("does_not_exist.gguf")`: Model file not found: does_not_exist.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_that("Error handling and edge cases work correctly", {
test_that("Invalid file paths are handled properly", {
test_that("Invalid parameters are rejected", {
# Test edge_load_model with invalid parameters
dummy_path <- "dummy.gguf"  # Will fail anyway, but testing parameter validation
# Extremely large context size (should be handled gracefully)
test_that("edge_completion handles errors gracefully", {
edge_completion(NULL, "Hello", n_predict = 5)
invalid_contexts <- list("string", 123, list(), data.frame())
edge_completion(ctx, "Hello", n_predict = 5)
ctx <- edge_load_model(model_path, n_ctx = 256)
invalid_n_predict <- c(-1, 0, "string", NULL, c(5, 10), list(5), Inf, -Inf, NaN)
for (invalid_pred in invalid_n_predict) {
edge_completion(ctx, "Hello", n_predict = invalid_pred)
invalid_temperature <- c(-1, "string", NULL, c(0.8, 1.0), list(0.8), Inf, -Inf, NaN)
for (invalid_temp in invalid_temperature) {
edge_completion(ctx, "Hello", n_predict = 5, temperature = invalid_temp)
edge_completion(ctx, "Hello", n_predict = 5, top_p = invalid_p)
invalid_prompts <- list(NULL, 123, c("a", "b"), list("hello"), data.frame(text = "hi"), TRUE, factor("test"))
for (invalid_prompt in invalid_prompts) {
edge_completion(ctx, invalid_prompt, n_predict = 5)
test_that("Memory constraints are handled properly", {
# Test very small context size (should work)
ctx_small <- edge_load_model(model_path, n_ctx = 16)
ctx_normal <- edge_load_model(model_path, n_ctx = 512)
skip("No test model available for memory constraint tests")
test_that("Corrupted or invalid model files are handled", {
# Create a fake GGUF file with wrong content
writeLines("This is not a real GGUF file", fake_gguf)
test_that("Edge cases in text completion", {
# Test with very long prompt (might exceed context)
long_prompt <- paste(rep("This is a very long sentence that goes on and on.", 20), collapse = " ")
# Should either work or give a reasonable error
result <- edge_completion(ctx, long_prompt, n_predict = 5)
# If it errors, the error should be informative
expect_true(grepl("context|length|size", e$message, ignore.case = TRUE))
paste("Very long word:", paste(rep("a", 200), collapse = "")),
"SQL: SELECT * FROM users; DROP TABLE users;",
result <- edge_completion(ctx, prompt, n_predict = 3)
# If there's an error, it should be a reasonable one
skip("No test model available for edge case tests")
test_that("Concurrent access and thread safety", {
# Test loading the same model multiple times
contexts[[i]] <- edge_load_model(model_path, n_ctx = 128)
result <- edge_completion(contexts[[i]], paste("Test", i), n_predict = 3)
# Note: Context cleanup is handled internally
skip("No test model available for concurrency tests")
test_that("Resource cleanup after errors", {
# Test that resources are properly cleaned up even when errors occur
# Multiple failed attempts should not accumulate resources
# Test all parameter combinations and edge cases
# Test edge_load_model with comprehensive invalid inputs
for (invalid_path in invalid_model_paths) {
# Test n_gpu_layers parameter validation
for (invalid_layers in invalid_gpu_layers) {
# Test error message quality and informativeness
test_that("Error messages are informative", {
# Test that error messages contain useful information
# Error message should mention the file or path
grepl("file|path|exist|found", e$message, ignore.case = TRUE),
info = paste("Error message should be informative:", e$message)
# Test error messages for invalid contexts
grepl("context|model|invalid", e$message, ignore.case = TRUE),
info = paste("Error message should mention context:", e$message)
test_that("Boundary and overflow conditions", {
# Should handle extreme values gracefully
edge_load_model("fake.gguf", n_ctx = val)  # Will fail due to file, not parameter
# Test exception safety and stack unwinding
# Test that partially constructed objects are cleaned up properly
ctx <- edge_load_model(model_path, n_ctx = 128)
# Generate error in middle of operation and ensure cleanup works
edge_completion(ctx, "test", n_predict = -5)  # Invalid parameter
# Context should still be valid after error
# Should still be able to use it normally
result <- edge_completion(ctx, "test", n_predict = 2)
skip("No test model available for exception safety tests")
# Test for memory leaks under error conditions
test_that("Memory leak prevention under errors", {
# Repeatedly try to load invalid models to test for memory leaks
# Test that failed completions don't leak