@@ -953,4 +953,98 @@ T["conflict_markers"]["parses conflict blocks"] = function()
953953 h .expect_match (" >>>>>>>" , result .block )
954954end
955955
956+ T [" build_commit_prompt" ] = new_set ()
957+
958+ T [" build_commit_prompt" ][" uses default template when no custom template" ] = function ()
959+ local result = child .lua ([[
960+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
961+ local prompt = GitUtils.build_commit_prompt("test diff", "English", nil, nil)
962+ return prompt:find("commit message generator") ~= nil
963+ ]] )
964+ h .eq (true , result )
965+ end
966+
967+ T [" build_commit_prompt" ][" uses default template when empty template" ] = function ()
968+ local result = child .lua ([[
969+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
970+ local prompt = GitUtils.build_commit_prompt("test diff", "English", nil, "")
971+ return prompt:find("commit message generator") ~= nil
972+ ]] )
973+ h .eq (true , result )
974+ end
975+
976+ T [" build_commit_prompt" ][" replaces language placeholder" ] = function ()
977+ local result = child .lua ([[
978+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
979+ local template = "Generate in %{language}"
980+ local prompt = GitUtils.build_commit_prompt("diff", "Chinese", nil, template)
981+ return prompt == "Generate in Chinese"
982+ ]] )
983+ h .eq (true , result )
984+ end
985+
986+ T [" build_commit_prompt" ][" replaces diff placeholder" ] = function ()
987+ local result = child .lua ([[
988+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
989+ local template = "Diff: %{diff}"
990+ local prompt = GitUtils.build_commit_prompt("my changes", "English", nil, template)
991+ return prompt == "Diff: my changes"
992+ ]] )
993+ h .eq (true , result )
994+ end
995+
996+ T [" build_commit_prompt" ][" replaces history_context placeholder" ] = function ()
997+ local result = child .lua ([[
998+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
999+ local template = "History: %{history_context}"
1000+ local prompt = GitUtils.build_commit_prompt("diff", "English", {"commit 1", "commit 2"}, template)
1001+ return prompt:find("BEGIN HISTORY") ~= nil and prompt:find("commit 1") ~= nil
1002+ ]] )
1003+ h .eq (true , result )
1004+ end
1005+
1006+ T [" build_commit_prompt" ][" handles empty history_context" ] = function ()
1007+ local result = child .lua ([[
1008+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
1009+ local template = "History: [%{history_context}]"
1010+ local prompt = GitUtils.build_commit_prompt("diff", "English", nil, template)
1011+ return prompt == "History: []"
1012+ ]] )
1013+ h .eq (true , result )
1014+ end
1015+
1016+ T [" build_commit_prompt" ][" replaces all placeholders in custom template" ] = function ()
1017+ local result = child .lua ([[
1018+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
1019+ local template = "Lang: %{language}, Diff: %{diff}, Ctx: %{history_context}"
1020+ local prompt = GitUtils.build_commit_prompt("my diff", "Japanese", {"hist1"}, template)
1021+ local has_lang = prompt:find("Lang: Japanese") ~= nil
1022+ local has_diff = prompt:find("Diff: my diff") ~= nil
1023+ local has_ctx = prompt:find("Ctx: BEGIN HISTORY") ~= nil
1024+ return has_lang and has_diff and has_ctx
1025+ ]] )
1026+ h .eq (true , result )
1027+ end
1028+
1029+ T [" build_commit_prompt" ][" handles diff with special characters" ] = function ()
1030+ local result = child .lua ([[
1031+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
1032+ local template = "Diff: %{diff}"
1033+ local diff_content = "+hello %{language} world"
1034+ local prompt = GitUtils.build_commit_prompt(diff_content, "English", nil, template)
1035+ return prompt:find("%%{language}") ~= nil
1036+ ]] )
1037+ h .eq (true , result )
1038+ end
1039+
1040+ T [" build_commit_prompt" ][" defaults language to English" ] = function ()
1041+ local result = child .lua ([[
1042+ local GitUtils = require("codecompanion._extensions.gitcommit.git_utils")
1043+ local template = "Lang: %{language}"
1044+ local prompt = GitUtils.build_commit_prompt("diff", nil, nil, template)
1045+ return prompt == "Lang: English"
1046+ ]] )
1047+ h .eq (true , result )
1048+ end
1049+
9561050return T
0 commit comments