- Introduced Makefile with targets for testing (all, coverage, agent-specific), building, installing, cleaning, and help - Added unit and integration tests for agent command, edit command, and CleanCodeResponse function - Refactored CleanCodeResponse to use regex for robust markdown fence removal in agent and client modules - Ensured tests cover code cleaning, plan generation placeholders, and file editing functionality
31 lines
630 B
Go
31 lines
630 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEditCommand(t *testing.T) {
|
|
tmpfile, err := os.CreateTemp("", "test_edit_*.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(tmpfile.Name())
|
|
|
|
original := []byte("package main\n\nfunc hello() {}\n")
|
|
os.WriteFile(tmpfile.Name(), original, 0644)
|
|
|
|
cmd := rootCmd
|
|
cmd.SetArgs([]string{"edit", tmpfile.Name(), "add a comment at the top"})
|
|
|
|
if err := cmd.Execute(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
content, _ := os.ReadFile(tmpfile.Name())
|
|
if !strings.HasPrefix(string(content), "//") {
|
|
t.Errorf("Expected a comment at the very top. Got:\n%s", content)
|
|
}
|
|
}
|