@@ -321,6 +321,66 @@ describe('context static API with config override', function()
321321 end )
322322end )
323323
324+ describe (' context toggle API' , function ()
325+ local original_context_config
326+ local original_load
327+
328+ before_each (function ()
329+ original_context_config = vim .deepcopy (state .current_context_config )
330+ original_load = context .load
331+ end )
332+
333+ after_each (function ()
334+ state .current_context_config = original_context_config
335+ context .load = original_load
336+ end )
337+
338+ it (' set_context updates state config for a supported key' , function ()
339+ local load_called = false
340+ context .load = function ()
341+ load_called = true
342+ end
343+
344+ local enabled = context .set_context (' current_file' , false )
345+
346+ assert .is_false (enabled )
347+ assert .is_false (state .current_context_config .current_file .enabled )
348+ assert .is_true (load_called )
349+ end )
350+
351+ it (' toggle_context inverts the current value' , function ()
352+ context .load = function () end
353+ state .current_context_config = {
354+ current_file = { enabled = false },
355+ }
356+
357+ local enabled = context .toggle_context (' current_file' )
358+
359+ assert .is_true (enabled )
360+ assert .is_true (state .current_context_config .current_file .enabled )
361+ end )
362+
363+ it (' set_context supports buffer and git_diff keys' , function ()
364+ context .load = function () end
365+
366+ local enabled_buffer = context .set_context (' buffer' , true )
367+ local enabled_git_diff = context .set_context (' git_diff' , true )
368+
369+ assert .is_true (enabled_buffer )
370+ assert .is_true (enabled_git_diff )
371+ assert .is_true (state .current_context_config .buffer .enabled )
372+ assert .is_true (state .current_context_config .git_diff .enabled )
373+ end )
374+
375+ it (' returns error for unsupported keys' , function ()
376+ context .load = function () end
377+
378+ local enabled = context .toggle_context (' files' )
379+
380+ assert .is_nil (enabled )
381+ end )
382+ end )
383+
324384describe (' get_diagnostics with chat context selections' , function ()
325385 local ChatContext
326386
0 commit comments