-
Notifications
You must be signed in to change notification settings - Fork 6
Select model and behavior #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37d60e9
add EcaChatSelectModel and EcaChatSelectBehavior commands
joaopluigi 4f223a6
Add tests
ericdallo 50b5c90
fix tests
joaopluigi dc066c4
Merge branch 'async-server-download' into select-model-and-behavior
joaopluigi f1011e3
Merge branch 'async-server-download' into select-model-and-behavior
joaopluigi 71448b1
Merge branch 'main' into select-model-and-behavior
joaopluigi 87e3231
address code review changes
joaopluigi db32ed9
make server start to accept clean option and use it on tests
joaopluigi a21fac3
inject eca dependencies when using --clean mode
joaopluigi 9b3d6bd
make commands use current chat instead of state directly
joaopluigi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| local MiniTest = require("mini.test") | ||
| local eq = MiniTest.expect.equality | ||
| local child = MiniTest.new_child_neovim() | ||
|
|
||
| local T = MiniTest.new_set({ | ||
| hooks = { | ||
| pre_case = function() | ||
| child.restart({ "-u", "scripts/minimal_init.lua" }) | ||
| child.lua([[ | ||
| -- Setup commands | ||
| require('eca.commands').setup() | ||
|
|
||
| -- Instantiate state singleton | ||
| _G.State = require('eca.state').new() | ||
|
|
||
| -- Mock vim.ui.select for testing | ||
| _G.selected_choice = nil | ||
| _G.shown_items = nil | ||
| _G.shown_prompt = nil | ||
| _G.original_select = vim.ui.select | ||
|
|
||
| _G.mock_select = function(choice) | ||
| _G.selected_choice = choice | ||
| vim.ui.select = function(items, opts, on_choice) | ||
| _G.shown_items = items | ||
| _G.shown_prompt = opts.prompt | ||
| on_choice(choice) | ||
| end | ||
| end | ||
|
|
||
| _G.restore_select = function() | ||
| vim.ui.select = _G.original_select | ||
| end | ||
| ]]) | ||
| end, | ||
| post_case = function() | ||
| child.lua([[_G.restore_select()]]) | ||
| end, | ||
| post_once = child.stop, | ||
| }, | ||
| }) | ||
|
|
||
| -- Test EcaChatSelectModel command | ||
| T["EcaChatSelectModel"] = MiniTest.new_set() | ||
|
|
||
| T["EcaChatSelectModel"]["command is registered"] = function() | ||
| local commands = child.lua_get("vim.api.nvim_get_commands({})") | ||
| eq(type(commands.EcaChatSelectModel), "table") | ||
| eq(commands.EcaChatSelectModel.name, "EcaChatSelectModel") | ||
| end | ||
|
|
||
| T["EcaChatSelectModel"]["updates state when model selected"] = function() | ||
| -- Setup initial state with models | ||
| child.lua([[ | ||
| _G.State.config.models.list = { "model1", "model2", "model3" } | ||
| _G.State.config.models.selected = "model1" | ||
|
|
||
| -- Mock vim.ui.select to auto-select model2 | ||
| _G.mock_select("model2") | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectModel") | ||
|
|
||
| -- Check that state was updated | ||
| eq(child.lua_get("_G.State.config.models.selected"), "model2") | ||
| end | ||
|
|
||
| T["EcaChatSelectModel"]["handles nil selection"] = function() | ||
| -- Setup initial state | ||
| child.lua([[ | ||
| _G.State.config.models.list = { "model1", "model2" } | ||
| _G.State.config.models.selected = "model1" | ||
|
|
||
| -- Mock vim.ui.select to return nil (user cancelled) | ||
| _G.mock_select(nil) | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectModel") | ||
|
|
||
| -- Check that state was NOT updated (still model1) | ||
| eq(child.lua_get("_G.State.config.models.selected"), "model1") | ||
| end | ||
|
|
||
| T["EcaChatSelectModel"]["displays all available models"] = function() | ||
| -- Setup models list | ||
| child.lua([[ | ||
| _G.State.config.models.list = { "gpt-4", "gpt-3.5-turbo", "claude-3" } | ||
|
|
||
| -- Mock vim.ui.select to capture the items shown | ||
| _G.mock_select(nil) | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectModel") | ||
|
|
||
| -- Verify all models were shown | ||
| local shown_items = child.lua_get("_G.shown_items") | ||
| eq(shown_items[1], "gpt-4") | ||
| eq(shown_items[2], "gpt-3.5-turbo") | ||
| eq(shown_items[3], "claude-3") | ||
| end | ||
|
|
||
| -- Test EcaChatSelectBehavior command | ||
| T["EcaChatSelectBehavior"] = MiniTest.new_set() | ||
|
|
||
| T["EcaChatSelectBehavior"]["command is registered"] = function() | ||
| local commands = child.lua_get("vim.api.nvim_get_commands({})") | ||
| eq(type(commands.EcaChatSelectBehavior), "table") | ||
| eq(commands.EcaChatSelectBehavior.name, "EcaChatSelectBehavior") | ||
| end | ||
|
|
||
| T["EcaChatSelectBehavior"]["updates state when behavior selected"] = function() | ||
| -- Setup initial state with behaviors | ||
| child.lua([[ | ||
| _G.State.config.behaviors.list = { "helpful", "creative", "concise" } | ||
| _G.State.config.behaviors.selected = "helpful" | ||
|
|
||
| -- Mock vim.ui.select to auto-select creative | ||
| _G.mock_select("creative") | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectBehavior") | ||
|
|
||
| -- Check that state was updated | ||
| eq(child.lua_get("_G.State.config.behaviors.selected"), "creative") | ||
| end | ||
|
|
||
| T["EcaChatSelectBehavior"]["handles nil selection"] = function() | ||
| -- Setup initial state | ||
| child.lua([[ | ||
| _G.State.config.behaviors.list = { "helpful", "creative" } | ||
| _G.State.config.behaviors.selected = "helpful" | ||
|
|
||
| -- Mock vim.ui.select to return nil (user cancelled) | ||
| _G.mock_select(nil) | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectBehavior") | ||
|
|
||
| -- Check that state was NOT updated (still helpful) | ||
| eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful") | ||
| end | ||
|
|
||
| T["EcaChatSelectBehavior"]["displays all available behaviors"] = function() | ||
| -- Setup behaviors list | ||
| child.lua([[ | ||
| _G.State.config.behaviors.list = { "helpful", "creative", "concise", "technical" } | ||
|
|
||
| -- Mock vim.ui.select to capture the items shown | ||
| _G.mock_select(nil) | ||
| ]]) | ||
|
|
||
| -- Execute command | ||
| child.cmd("EcaChatSelectBehavior") | ||
|
|
||
| -- Verify all behaviors were shown | ||
| local shown_items = child.lua_get("_G.shown_items") | ||
| eq(shown_items[1], "helpful") | ||
| eq(shown_items[2], "creative") | ||
| eq(shown_items[3], "concise") | ||
| eq(shown_items[4], "technical") | ||
| end | ||
|
|
||
| return T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.