Deleting unnecesary features
This commit is contained in:
@@ -44,5 +44,4 @@ require("codetyper").setup({
|
||||
enabled = false, -- Disable scheduler during tests
|
||||
},
|
||||
auto_gitignore = false,
|
||||
auto_open_ask = false,
|
||||
})
|
||||
|
||||
@@ -1,427 +0,0 @@
|
||||
--- Tests for agent tools system
|
||||
|
||||
describe("codetyper.agent.tools", function()
|
||||
local tools
|
||||
|
||||
before_each(function()
|
||||
tools = require("codetyper.agent.tools")
|
||||
-- Clear any existing registrations
|
||||
for name, _ in pairs(tools.get_all()) do
|
||||
tools.unregister(name)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("tool registration", function()
|
||||
it("should register a tool", function()
|
||||
local test_tool = {
|
||||
name = "test_tool",
|
||||
description = "A test tool",
|
||||
params = {
|
||||
{ name = "input", type = "string", description = "Test input" },
|
||||
},
|
||||
func = function(input, opts)
|
||||
return "result", nil
|
||||
end,
|
||||
}
|
||||
|
||||
tools.register(test_tool)
|
||||
local retrieved = tools.get("test_tool")
|
||||
|
||||
assert.is_not_nil(retrieved)
|
||||
assert.equals("test_tool", retrieved.name)
|
||||
end)
|
||||
|
||||
it("should unregister a tool", function()
|
||||
local test_tool = {
|
||||
name = "temp_tool",
|
||||
description = "Temporary",
|
||||
func = function() end,
|
||||
}
|
||||
|
||||
tools.register(test_tool)
|
||||
assert.is_not_nil(tools.get("temp_tool"))
|
||||
|
||||
tools.unregister("temp_tool")
|
||||
assert.is_nil(tools.get("temp_tool"))
|
||||
end)
|
||||
|
||||
it("should list all tools", function()
|
||||
tools.register({ name = "tool1", func = function() end })
|
||||
tools.register({ name = "tool2", func = function() end })
|
||||
tools.register({ name = "tool3", func = function() end })
|
||||
|
||||
local list = tools.list()
|
||||
assert.equals(3, #list)
|
||||
end)
|
||||
|
||||
it("should filter tools with predicate", function()
|
||||
tools.register({ name = "safe_tool", requires_confirmation = false, func = function() end })
|
||||
tools.register({ name = "dangerous_tool", requires_confirmation = true, func = function() end })
|
||||
|
||||
local safe_list = tools.list(function(t)
|
||||
return not t.requires_confirmation
|
||||
end)
|
||||
|
||||
assert.equals(1, #safe_list)
|
||||
assert.equals("safe_tool", safe_list[1].name)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("tool execution", function()
|
||||
it("should execute a tool and return result", function()
|
||||
tools.register({
|
||||
name = "adder",
|
||||
params = {
|
||||
{ name = "a", type = "number" },
|
||||
{ name = "b", type = "number" },
|
||||
},
|
||||
func = function(input, opts)
|
||||
return input.a + input.b, nil
|
||||
end,
|
||||
})
|
||||
|
||||
local result, err = tools.execute("adder", { a = 5, b = 3 }, {})
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.equals(8, result)
|
||||
end)
|
||||
|
||||
it("should return error for unknown tool", function()
|
||||
local result, err = tools.execute("nonexistent", {}, {})
|
||||
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("Unknown tool"))
|
||||
end)
|
||||
|
||||
it("should track execution history", function()
|
||||
tools.clear_history()
|
||||
tools.register({
|
||||
name = "tracked_tool",
|
||||
func = function()
|
||||
return "done", nil
|
||||
end,
|
||||
})
|
||||
|
||||
tools.execute("tracked_tool", {}, {})
|
||||
tools.execute("tracked_tool", {}, {})
|
||||
|
||||
local history = tools.get_history()
|
||||
assert.equals(2, #history)
|
||||
assert.equals("tracked_tool", history[1].tool)
|
||||
assert.equals("completed", history[1].status)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("tool schemas", function()
|
||||
it("should generate JSON schema for tools", function()
|
||||
tools.register({
|
||||
name = "schema_test",
|
||||
description = "Test schema generation",
|
||||
params = {
|
||||
{ name = "required_param", type = "string", description = "A required param" },
|
||||
{ name = "optional_param", type = "number", description = "Optional", optional = true },
|
||||
},
|
||||
returns = {
|
||||
{ name = "result", type = "string" },
|
||||
},
|
||||
to_schema = require("codetyper.agent.tools.base").to_schema,
|
||||
func = function() end,
|
||||
})
|
||||
|
||||
local schemas = tools.get_schemas()
|
||||
assert.equals(1, #schemas)
|
||||
|
||||
local schema = schemas[1]
|
||||
assert.equals("function", schema.type)
|
||||
assert.equals("schema_test", schema.function_def.name)
|
||||
assert.is_not_nil(schema.function_def.parameters.properties.required_param)
|
||||
assert.is_not_nil(schema.function_def.parameters.properties.optional_param)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("process_tool_call", function()
|
||||
it("should process tool call with name and input", function()
|
||||
tools.register({
|
||||
name = "processor_test",
|
||||
func = function(input, opts)
|
||||
return "processed: " .. input.value, nil
|
||||
end,
|
||||
})
|
||||
|
||||
local result, err = tools.process_tool_call({
|
||||
name = "processor_test",
|
||||
input = { value = "test" },
|
||||
}, {})
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.equals("processed: test", result)
|
||||
end)
|
||||
|
||||
it("should parse JSON string arguments", function()
|
||||
tools.register({
|
||||
name = "json_parser_test",
|
||||
func = function(input, opts)
|
||||
return input.key, nil
|
||||
end,
|
||||
})
|
||||
|
||||
local result, err = tools.process_tool_call({
|
||||
name = "json_parser_test",
|
||||
arguments = '{"key": "value"}',
|
||||
}, {})
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.equals("value", result)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("codetyper.agent.tools.base", function()
|
||||
local base
|
||||
|
||||
before_each(function()
|
||||
base = require("codetyper.agent.tools.base")
|
||||
end)
|
||||
|
||||
describe("validate_input", function()
|
||||
it("should validate required parameters", function()
|
||||
local tool = setmetatable({
|
||||
params = {
|
||||
{ name = "required", type = "string" },
|
||||
{ name = "optional", type = "string", optional = true },
|
||||
},
|
||||
}, base)
|
||||
|
||||
local valid, err = tool:validate_input({ required = "value" })
|
||||
assert.is_true(valid)
|
||||
assert.is_nil(err)
|
||||
end)
|
||||
|
||||
it("should fail on missing required parameter", function()
|
||||
local tool = setmetatable({
|
||||
params = {
|
||||
{ name = "required", type = "string" },
|
||||
},
|
||||
}, base)
|
||||
|
||||
local valid, err = tool:validate_input({})
|
||||
assert.is_false(valid)
|
||||
assert.truthy(err:match("Missing required parameter"))
|
||||
end)
|
||||
|
||||
it("should validate parameter types", function()
|
||||
local tool = setmetatable({
|
||||
params = {
|
||||
{ name = "num", type = "number" },
|
||||
},
|
||||
}, base)
|
||||
|
||||
local valid1, _ = tool:validate_input({ num = 42 })
|
||||
assert.is_true(valid1)
|
||||
|
||||
local valid2, err2 = tool:validate_input({ num = "not a number" })
|
||||
assert.is_false(valid2)
|
||||
assert.truthy(err2:match("must be number"))
|
||||
end)
|
||||
|
||||
it("should validate integer type", function()
|
||||
local tool = setmetatable({
|
||||
params = {
|
||||
{ name = "int", type = "integer" },
|
||||
},
|
||||
}, base)
|
||||
|
||||
local valid1, _ = tool:validate_input({ int = 42 })
|
||||
assert.is_true(valid1)
|
||||
|
||||
local valid2, err2 = tool:validate_input({ int = 42.5 })
|
||||
assert.is_false(valid2)
|
||||
assert.truthy(err2:match("must be an integer"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("get_description", function()
|
||||
it("should return string description", function()
|
||||
local tool = setmetatable({
|
||||
description = "Static description",
|
||||
}, base)
|
||||
|
||||
assert.equals("Static description", tool:get_description())
|
||||
end)
|
||||
|
||||
it("should call function description", function()
|
||||
local tool = setmetatable({
|
||||
description = function()
|
||||
return "Dynamic description"
|
||||
end,
|
||||
}, base)
|
||||
|
||||
assert.equals("Dynamic description", tool:get_description())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("to_schema", function()
|
||||
it("should generate valid schema", function()
|
||||
local tool = setmetatable({
|
||||
name = "test",
|
||||
description = "Test tool",
|
||||
params = {
|
||||
{ name = "input", type = "string", description = "Input value" },
|
||||
{ name = "count", type = "integer", description = "Count", optional = true },
|
||||
},
|
||||
}, base)
|
||||
|
||||
local schema = tool:to_schema()
|
||||
|
||||
assert.equals("function", schema.type)
|
||||
assert.equals("test", schema.function_def.name)
|
||||
assert.equals("Test tool", schema.function_def.description)
|
||||
assert.equals("object", schema.function_def.parameters.type)
|
||||
assert.is_not_nil(schema.function_def.parameters.properties.input)
|
||||
assert.is_not_nil(schema.function_def.parameters.properties.count)
|
||||
assert.same({ "input" }, schema.function_def.parameters.required)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("built-in tools", function()
|
||||
describe("view tool", function()
|
||||
local view
|
||||
|
||||
before_each(function()
|
||||
view = require("codetyper.agent.tools.view")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("view", view.name)
|
||||
assert.is_string(view.description)
|
||||
assert.is_table(view.params)
|
||||
assert.is_function(view.func)
|
||||
end)
|
||||
|
||||
it("should require path parameter", function()
|
||||
local result, err = view.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("path is required"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("grep tool", function()
|
||||
local grep
|
||||
|
||||
before_each(function()
|
||||
grep = require("codetyper.agent.tools.grep")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("grep", grep.name)
|
||||
assert.is_string(grep.description)
|
||||
assert.is_table(grep.params)
|
||||
assert.is_function(grep.func)
|
||||
end)
|
||||
|
||||
it("should require pattern parameter", function()
|
||||
local result, err = grep.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("pattern is required"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("glob tool", function()
|
||||
local glob
|
||||
|
||||
before_each(function()
|
||||
glob = require("codetyper.agent.tools.glob")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("glob", glob.name)
|
||||
assert.is_string(glob.description)
|
||||
assert.is_table(glob.params)
|
||||
assert.is_function(glob.func)
|
||||
end)
|
||||
|
||||
it("should require pattern parameter", function()
|
||||
local result, err = glob.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("pattern is required"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("edit tool", function()
|
||||
local edit
|
||||
|
||||
before_each(function()
|
||||
edit = require("codetyper.agent.tools.edit")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("edit", edit.name)
|
||||
assert.is_string(edit.description)
|
||||
assert.is_table(edit.params)
|
||||
assert.is_function(edit.func)
|
||||
end)
|
||||
|
||||
it("should require path parameter", function()
|
||||
local result, err = edit.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("path is required"))
|
||||
end)
|
||||
|
||||
it("should require old_string parameter", function()
|
||||
local result, err = edit.func({ path = "/tmp/test" }, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("old_string is required"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("write tool", function()
|
||||
local write
|
||||
|
||||
before_each(function()
|
||||
write = require("codetyper.agent.tools.write")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("write", write.name)
|
||||
assert.is_string(write.description)
|
||||
assert.is_table(write.params)
|
||||
assert.is_function(write.func)
|
||||
end)
|
||||
|
||||
it("should require path parameter", function()
|
||||
local result, err = write.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("path is required"))
|
||||
end)
|
||||
|
||||
it("should require content parameter", function()
|
||||
local result, err = write.func({ path = "/tmp/test" }, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("content is required"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("bash tool", function()
|
||||
local bash
|
||||
|
||||
before_each(function()
|
||||
bash = require("codetyper.agent.tools.bash")
|
||||
end)
|
||||
|
||||
it("should have required fields", function()
|
||||
assert.equals("bash", bash.name)
|
||||
assert.is_function(bash.func)
|
||||
end)
|
||||
|
||||
it("should require command parameter", function()
|
||||
local result, err = bash.func({}, {})
|
||||
assert.is_nil(result)
|
||||
assert.truthy(err:match("command is required"))
|
||||
end)
|
||||
|
||||
it("should require confirmation by default", function()
|
||||
assert.is_true(bash.requires_confirmation)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,312 +0,0 @@
|
||||
---@diagnostic disable: undefined-global
|
||||
-- Unit tests for the agentic system
|
||||
|
||||
describe("agentic module", function()
|
||||
local agentic
|
||||
|
||||
before_each(function()
|
||||
-- Reset and reload
|
||||
package.loaded["codetyper.agent.agentic"] = nil
|
||||
agentic = require("codetyper.agent.agentic")
|
||||
end)
|
||||
|
||||
it("should list built-in agents", function()
|
||||
local agents = agentic.list_agents()
|
||||
assert.is_table(agents)
|
||||
assert.is_true(#agents >= 3) -- coder, planner, explorer
|
||||
|
||||
local names = {}
|
||||
for _, agent in ipairs(agents) do
|
||||
names[agent.name] = true
|
||||
end
|
||||
|
||||
assert.is_true(names["coder"])
|
||||
assert.is_true(names["planner"])
|
||||
assert.is_true(names["explorer"])
|
||||
end)
|
||||
|
||||
it("should have description for each agent", function()
|
||||
local agents = agentic.list_agents()
|
||||
for _, agent in ipairs(agents) do
|
||||
assert.is_string(agent.description)
|
||||
assert.is_true(#agent.description > 0)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should mark built-in agents as builtin", function()
|
||||
local agents = agentic.list_agents()
|
||||
local coder = nil
|
||||
for _, agent in ipairs(agents) do
|
||||
if agent.name == "coder" then
|
||||
coder = agent
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(coder)
|
||||
assert.is_true(coder.builtin)
|
||||
end)
|
||||
|
||||
it("should have init function to create directories", function()
|
||||
assert.is_function(agentic.init)
|
||||
assert.is_function(agentic.init_agents_dir)
|
||||
assert.is_function(agentic.init_rules_dir)
|
||||
end)
|
||||
|
||||
it("should have run function for executing tasks", function()
|
||||
assert.is_function(agentic.run)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("tools format conversion", function()
|
||||
local tools_module
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools"] = nil
|
||||
tools_module = require("codetyper.agent.tools")
|
||||
-- Load tools
|
||||
if tools_module.load_builtins then
|
||||
pcall(tools_module.load_builtins)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should have to_openai_format function", function()
|
||||
assert.is_function(tools_module.to_openai_format)
|
||||
end)
|
||||
|
||||
it("should have to_claude_format function", function()
|
||||
assert.is_function(tools_module.to_claude_format)
|
||||
end)
|
||||
|
||||
it("should convert tools to OpenAI format", function()
|
||||
local openai_tools = tools_module.to_openai_format()
|
||||
assert.is_table(openai_tools)
|
||||
|
||||
-- If tools are loaded, check format
|
||||
if #openai_tools > 0 then
|
||||
local first_tool = openai_tools[1]
|
||||
assert.equals("function", first_tool.type)
|
||||
assert.is_table(first_tool["function"])
|
||||
assert.is_string(first_tool["function"].name)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should convert tools to Claude format", function()
|
||||
local claude_tools = tools_module.to_claude_format()
|
||||
assert.is_table(claude_tools)
|
||||
|
||||
-- If tools are loaded, check format
|
||||
if #claude_tools > 0 then
|
||||
local first_tool = claude_tools[1]
|
||||
assert.is_string(first_tool.name)
|
||||
assert.is_table(first_tool.input_schema)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("edit tool", function()
|
||||
local edit_tool
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.edit"] = nil
|
||||
edit_tool = require("codetyper.agent.tools.edit")
|
||||
end)
|
||||
|
||||
it("should have name 'edit'", function()
|
||||
assert.equals("edit", edit_tool.name)
|
||||
end)
|
||||
|
||||
it("should have description mentioning matching strategies", function()
|
||||
local desc = edit_tool:get_description()
|
||||
assert.is_string(desc)
|
||||
-- Should mention the matching capabilities
|
||||
assert.is_true(desc:lower():match("match") ~= nil or desc:lower():match("replac") ~= nil)
|
||||
end)
|
||||
|
||||
it("should have params defined", function()
|
||||
assert.is_table(edit_tool.params)
|
||||
assert.is_true(#edit_tool.params >= 3) -- path, old_string, new_string
|
||||
end)
|
||||
|
||||
it("should require path parameter", function()
|
||||
local valid, err = edit_tool:validate_input({
|
||||
old_string = "test",
|
||||
new_string = "test2",
|
||||
})
|
||||
assert.is_false(valid)
|
||||
assert.is_string(err)
|
||||
end)
|
||||
|
||||
it("should require old_string parameter", function()
|
||||
local valid, err = edit_tool:validate_input({
|
||||
path = "/test",
|
||||
new_string = "test",
|
||||
})
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should require new_string parameter", function()
|
||||
local valid, err = edit_tool:validate_input({
|
||||
path = "/test",
|
||||
old_string = "test",
|
||||
})
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should accept empty old_string for new file creation", function()
|
||||
local valid, err = edit_tool:validate_input({
|
||||
path = "/test/new_file.lua",
|
||||
old_string = "",
|
||||
new_string = "new content",
|
||||
})
|
||||
assert.is_true(valid)
|
||||
assert.is_nil(err)
|
||||
end)
|
||||
|
||||
it("should have func implementation", function()
|
||||
assert.is_function(edit_tool.func)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("view tool", function()
|
||||
local view_tool
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.view"] = nil
|
||||
view_tool = require("codetyper.agent.tools.view")
|
||||
end)
|
||||
|
||||
it("should have name 'view'", function()
|
||||
assert.equals("view", view_tool.name)
|
||||
end)
|
||||
|
||||
it("should require path parameter", function()
|
||||
local valid, err = view_tool:validate_input({})
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should accept valid path", function()
|
||||
local valid, err = view_tool:validate_input({
|
||||
path = "/test/file.lua",
|
||||
})
|
||||
assert.is_true(valid)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("write tool", function()
|
||||
local write_tool
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.write"] = nil
|
||||
write_tool = require("codetyper.agent.tools.write")
|
||||
end)
|
||||
|
||||
it("should have name 'write'", function()
|
||||
assert.equals("write", write_tool.name)
|
||||
end)
|
||||
|
||||
it("should require path and content parameters", function()
|
||||
local valid, err = write_tool:validate_input({})
|
||||
assert.is_false(valid)
|
||||
|
||||
valid, err = write_tool:validate_input({ path = "/test" })
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should accept valid input", function()
|
||||
local valid, err = write_tool:validate_input({
|
||||
path = "/test/file.lua",
|
||||
content = "test content",
|
||||
})
|
||||
assert.is_true(valid)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("grep tool", function()
|
||||
local grep_tool
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.grep"] = nil
|
||||
grep_tool = require("codetyper.agent.tools.grep")
|
||||
end)
|
||||
|
||||
it("should have name 'grep'", function()
|
||||
assert.equals("grep", grep_tool.name)
|
||||
end)
|
||||
|
||||
it("should require pattern parameter", function()
|
||||
local valid, err = grep_tool:validate_input({})
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should accept valid pattern", function()
|
||||
local valid, err = grep_tool:validate_input({
|
||||
pattern = "function.*test",
|
||||
})
|
||||
assert.is_true(valid)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("glob tool", function()
|
||||
local glob_tool
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.glob"] = nil
|
||||
glob_tool = require("codetyper.agent.tools.glob")
|
||||
end)
|
||||
|
||||
it("should have name 'glob'", function()
|
||||
assert.equals("glob", glob_tool.name)
|
||||
end)
|
||||
|
||||
it("should require pattern parameter", function()
|
||||
local valid, err = glob_tool:validate_input({})
|
||||
assert.is_false(valid)
|
||||
end)
|
||||
|
||||
it("should accept valid pattern", function()
|
||||
local valid, err = glob_tool:validate_input({
|
||||
pattern = "**/*.lua",
|
||||
})
|
||||
assert.is_true(valid)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("base tool", function()
|
||||
local Base
|
||||
|
||||
before_each(function()
|
||||
package.loaded["codetyper.agent.tools.base"] = nil
|
||||
Base = require("codetyper.agent.tools.base")
|
||||
end)
|
||||
|
||||
it("should have validate_input method", function()
|
||||
assert.is_function(Base.validate_input)
|
||||
end)
|
||||
|
||||
it("should have to_schema method", function()
|
||||
assert.is_function(Base.to_schema)
|
||||
end)
|
||||
|
||||
it("should have get_description method", function()
|
||||
assert.is_function(Base.get_description)
|
||||
end)
|
||||
|
||||
it("should generate valid schema", function()
|
||||
local test_tool = setmetatable({
|
||||
name = "test",
|
||||
description = "A test tool",
|
||||
params = {
|
||||
{ name = "arg1", type = "string", description = "First arg" },
|
||||
{ name = "arg2", type = "number", description = "Second arg", optional = true },
|
||||
},
|
||||
}, Base)
|
||||
|
||||
local schema = test_tool:to_schema()
|
||||
assert.equals("function", schema.type)
|
||||
assert.equals("test", schema.function_def.name)
|
||||
assert.is_table(schema.function_def.parameters.properties)
|
||||
assert.is_table(schema.function_def.parameters.required)
|
||||
assert.is_true(vim.tbl_contains(schema.function_def.parameters.required, "arg1"))
|
||||
assert.is_false(vim.tbl_contains(schema.function_def.parameters.required, "arg2"))
|
||||
end)
|
||||
end)
|
||||
@@ -1,229 +0,0 @@
|
||||
--- Tests for ask intent detection
|
||||
local intent = require("codetyper.ask.intent")
|
||||
|
||||
describe("ask.intent", function()
|
||||
describe("detect", function()
|
||||
-- Ask/Explain intent tests
|
||||
describe("ask intent", function()
|
||||
it("detects 'what' questions as ask", function()
|
||||
local result = intent.detect("What does this function do?")
|
||||
assert.equals("ask", result.type)
|
||||
assert.is_true(result.confidence > 0.3)
|
||||
end)
|
||||
|
||||
it("detects 'why' questions as ask", function()
|
||||
local result = intent.detect("Why is this variable undefined?")
|
||||
assert.equals("ask", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'how does' as ask", function()
|
||||
local result = intent.detect("How does this algorithm work?")
|
||||
assert.is_true(result.type == "ask" or result.type == "explain")
|
||||
end)
|
||||
|
||||
it("detects 'explain' requests as explain", function()
|
||||
local result = intent.detect("Explain me the project structure")
|
||||
assert.equals("explain", result.type)
|
||||
assert.is_true(result.confidence > 0.4)
|
||||
end)
|
||||
|
||||
it("detects 'walk me through' as explain", function()
|
||||
local result = intent.detect("Walk me through this code")
|
||||
assert.equals("explain", result.type)
|
||||
end)
|
||||
|
||||
it("detects questions ending with ? as likely ask", function()
|
||||
local result = intent.detect("Is this the right approach?")
|
||||
assert.equals("ask", result.type)
|
||||
end)
|
||||
|
||||
it("sets needs_brain_context for ask intent", function()
|
||||
local result = intent.detect("What patterns are used here?")
|
||||
assert.is_true(result.needs_brain_context)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Generate intent tests
|
||||
describe("generate intent", function()
|
||||
it("detects 'create' commands as generate", function()
|
||||
local result = intent.detect("Create a function to sort arrays")
|
||||
assert.equals("generate", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'write' commands as generate", function()
|
||||
local result = intent.detect("Write a unit test for this module")
|
||||
-- Could be generate or test
|
||||
assert.is_true(result.type == "generate" or result.type == "test")
|
||||
end)
|
||||
|
||||
it("detects 'implement' as generate", function()
|
||||
local result = intent.detect("Implement a binary search")
|
||||
assert.equals("generate", result.type)
|
||||
assert.is_true(result.confidence > 0.4)
|
||||
end)
|
||||
|
||||
it("detects 'add' commands as generate", function()
|
||||
local result = intent.detect("Add error handling to this function")
|
||||
assert.equals("generate", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'fix' as generate", function()
|
||||
local result = intent.detect("Fix the bug in line 42")
|
||||
assert.equals("generate", result.type)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Refactor intent tests
|
||||
describe("refactor intent", function()
|
||||
it("detects explicit 'refactor' as refactor", function()
|
||||
local result = intent.detect("Refactor this function")
|
||||
assert.equals("refactor", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'clean up' as refactor", function()
|
||||
local result = intent.detect("Clean up this messy code")
|
||||
assert.equals("refactor", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'simplify' as refactor", function()
|
||||
local result = intent.detect("Simplify this logic")
|
||||
assert.equals("refactor", result.type)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Document intent tests
|
||||
describe("document intent", function()
|
||||
it("detects 'document' as document", function()
|
||||
local result = intent.detect("Document this function")
|
||||
assert.equals("document", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'add documentation' as document", function()
|
||||
local result = intent.detect("Add documentation to this class")
|
||||
assert.equals("document", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'add jsdoc' as document", function()
|
||||
local result = intent.detect("Add jsdoc comments")
|
||||
assert.equals("document", result.type)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Test intent tests
|
||||
describe("test intent", function()
|
||||
it("detects 'write tests for' as test", function()
|
||||
local result = intent.detect("Write tests for this module")
|
||||
assert.equals("test", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'add unit tests' as test", function()
|
||||
local result = intent.detect("Add unit tests for the parser")
|
||||
assert.equals("test", result.type)
|
||||
end)
|
||||
|
||||
it("detects 'generate tests' as test", function()
|
||||
local result = intent.detect("Generate tests for the API")
|
||||
assert.equals("test", result.type)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Project context tests
|
||||
describe("project context detection", function()
|
||||
it("detects 'project' as needing project context", function()
|
||||
local result = intent.detect("Explain the project architecture")
|
||||
assert.is_true(result.needs_project_context)
|
||||
end)
|
||||
|
||||
it("detects 'codebase' as needing project context", function()
|
||||
local result = intent.detect("How is the codebase organized?")
|
||||
assert.is_true(result.needs_project_context)
|
||||
end)
|
||||
|
||||
it("does not need project context for simple questions", function()
|
||||
local result = intent.detect("What does this variable mean?")
|
||||
assert.is_false(result.needs_project_context)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Exploration tests
|
||||
describe("exploration detection", function()
|
||||
it("detects 'explain me the project' as needing exploration", function()
|
||||
local result = intent.detect("Explain me the project")
|
||||
assert.is_true(result.needs_exploration)
|
||||
end)
|
||||
|
||||
it("detects 'explain the codebase' as needing exploration", function()
|
||||
local result = intent.detect("Explain the codebase structure")
|
||||
assert.is_true(result.needs_exploration)
|
||||
end)
|
||||
|
||||
it("detects 'explore project' as needing exploration", function()
|
||||
local result = intent.detect("Explore this project")
|
||||
assert.is_true(result.needs_exploration)
|
||||
end)
|
||||
|
||||
it("does not need exploration for simple questions", function()
|
||||
local result = intent.detect("What does this function do?")
|
||||
assert.is_false(result.needs_exploration)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("get_prompt_type", function()
|
||||
it("maps ask to ask", function()
|
||||
local result = intent.get_prompt_type({ type = "ask" })
|
||||
assert.equals("ask", result)
|
||||
end)
|
||||
|
||||
it("maps explain to ask", function()
|
||||
local result = intent.get_prompt_type({ type = "explain" })
|
||||
assert.equals("ask", result)
|
||||
end)
|
||||
|
||||
it("maps generate to code_generation", function()
|
||||
local result = intent.get_prompt_type({ type = "generate" })
|
||||
assert.equals("code_generation", result)
|
||||
end)
|
||||
|
||||
it("maps refactor to refactor", function()
|
||||
local result = intent.get_prompt_type({ type = "refactor" })
|
||||
assert.equals("refactor", result)
|
||||
end)
|
||||
|
||||
it("maps document to document", function()
|
||||
local result = intent.get_prompt_type({ type = "document" })
|
||||
assert.equals("document", result)
|
||||
end)
|
||||
|
||||
it("maps test to test", function()
|
||||
local result = intent.get_prompt_type({ type = "test" })
|
||||
assert.equals("test", result)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("produces_code", function()
|
||||
it("returns false for ask", function()
|
||||
assert.is_false(intent.produces_code({ type = "ask" }))
|
||||
end)
|
||||
|
||||
it("returns false for explain", function()
|
||||
assert.is_false(intent.produces_code({ type = "explain" }))
|
||||
end)
|
||||
|
||||
it("returns true for generate", function()
|
||||
assert.is_true(intent.produces_code({ type = "generate" }))
|
||||
end)
|
||||
|
||||
it("returns true for refactor", function()
|
||||
assert.is_true(intent.produces_code({ type = "refactor" }))
|
||||
end)
|
||||
|
||||
it("returns true for document", function()
|
||||
assert.is_true(intent.produces_code({ type = "document" }))
|
||||
end)
|
||||
|
||||
it("returns true for test", function()
|
||||
assert.is_true(intent.produces_code({ type = "test" }))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user