Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cmd/sin-code/internal/index_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/spf13/cobra"
)

var indexAbsPath = filepath.Abs

var IndexCmd = &cobra.Command{
Use: "index",
Short: "Manage persistent incremental code index",
Expand All @@ -36,7 +38,7 @@ var indexBuildCmd = &cobra.Command{
if len(args) > 0 {
root = args[0]
}
root, err := filepath.Abs(root)
root, err := indexAbsPath(root)
if err != nil {
return err
}
Expand All @@ -62,7 +64,7 @@ var indexRefreshCmd = &cobra.Command{
if len(args) > 0 {
root = args[0]
}
root, err := filepath.Abs(root)
root, err := indexAbsPath(root)
if err != nil {
return err
}
Expand Down Expand Up @@ -96,7 +98,7 @@ var indexStatusCmd = &cobra.Command{
if len(args) > 0 {
root = args[0]
}
root, err := filepath.Abs(root)
root, err := indexAbsPath(root)
if err != nil {
return err
}
Expand Down Expand Up @@ -131,7 +133,7 @@ var indexWatchCmd = &cobra.Command{
if len(args) > 0 {
root = args[0]
}
root, err := filepath.Abs(root)
root, err := indexAbsPath(root)
if err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +174,7 @@ var indexClearCmd = &cobra.Command{
if len(args) > 0 {
root = args[0]
}
root, err := filepath.Abs(root)
root, err := indexAbsPath(root)
if err != nil {
return err
}
Expand Down
22 changes: 12 additions & 10 deletions cmd/sin-code/internal/memory_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
memForgetID string
memForget bool
memFormat string

openMemoryStoreFn = openMemoryStore
)

var MemoryCmd = &cobra.Command{
Expand Down Expand Up @@ -90,7 +92,7 @@ var memAddCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
memInsight = args[0]
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand All @@ -113,7 +115,7 @@ var memListCmd = &cobra.Command{
Use: "list",
Short: "List memories",
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand Down Expand Up @@ -149,7 +151,7 @@ var memShowCmd = &cobra.Command{
Short: "Show a single memory",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand Down Expand Up @@ -183,7 +185,7 @@ var memSearchCmd = &cobra.Command{
Short: "Semantic search",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +220,7 @@ var memLinkCmd = &cobra.Command{
Short: "Add a knowledge-graph link",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand All @@ -237,7 +239,7 @@ var memUnlinkCmd = &cobra.Command{
Short: "Remove a knowledge-graph link",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand All @@ -255,7 +257,7 @@ var memGraphCmd = &cobra.Command{
Short: "Show knowledge-graph neighborhood",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand Down Expand Up @@ -283,7 +285,7 @@ var memPrimeCmd = &cobra.Command{
Short: "Print top-K relevant memories for an LLM prompt",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand All @@ -302,7 +304,7 @@ var memForgetCmd = &cobra.Command{
Short: "Soft-delete a memory (--hard for permanent)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand All @@ -323,7 +325,7 @@ var memStatsCmd = &cobra.Command{
Use: "stats",
Short: "Show memory statistics",
RunE: func(cmd *cobra.Command, args []string) error {
store, err := openMemoryStore()
store, err := openMemoryStoreFn()
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/sin-code/internal/plugin_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var (
pluginNameArg string
walkFn = filepath.Walk
relFn = filepath.Rel

loadPluginFn = loadPlugin
)

var PluginCmd = &cobra.Command{
Expand Down Expand Up @@ -99,7 +101,7 @@ var pluginInfoCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pluginNameArg = args[0]
p, err := loadPlugin(pluginNameArg)
p, err := loadPluginFn(pluginNameArg)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,7 +191,7 @@ var pluginUninstallCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pluginNameArg = args[0]
p, err := loadPlugin(pluginNameArg)
p, err := loadPluginFn(pluginNameArg)
if err != nil {
return err
}
Expand All @@ -207,7 +209,7 @@ var pluginEnableCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pluginNameArg = args[0]
p, err := loadPlugin(pluginNameArg)
p, err := loadPluginFn(pluginNameArg)
if err != nil {
return err
}
Expand All @@ -225,7 +227,7 @@ var pluginDisableCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pluginNameArg = args[0]
p, err := loadPlugin(pluginNameArg)
p, err := loadPluginFn(pluginNameArg)
if err != nil {
return err
}
Expand Down
51 changes: 51 additions & 0 deletions cmd/sin-code/internal/stcov2_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"time"

"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/lsp"
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/memory"
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/plugins"
)

type stcov2ErrorReader struct{}
Expand Down Expand Up @@ -1109,6 +1111,55 @@ func TestLspServersCmd_NoServers_stcov2(t *testing.T) {
}
}

func TestIndexCmd_AbsPathError_stcov2(t *testing.T) {
orig := indexAbsPath
indexAbsPath = func(path string) (string, error) { return "", errors.New("abs error") }
defer func() { indexAbsPath = orig }()
_ = indexBuildCmd.RunE(indexBuildCmd, []string{"."})
_ = indexRefreshCmd.RunE(indexRefreshCmd, []string{"."})
_ = indexStatusCmd.RunE(indexStatusCmd, []string{"."})
_ = indexWatchCmd.RunE(indexWatchCmd, []string{"."})
_ = indexClearCmd.RunE(indexClearCmd, []string{"."})
}

func TestMemoryCmd_OpenStoreError_stcov2(t *testing.T) {
orig := openMemoryStoreFn
openMemoryStoreFn = func() (*memory.Store, error) { return nil, errors.New("store error") }
defer func() { openMemoryStoreFn = orig }()
_ = memAddCmd.RunE(memAddCmd, []string{"insight"})
_ = memListCmd.RunE(memListCmd, nil)
_ = memShowCmd.RunE(memShowCmd, []string{"id"})
_ = memSearchCmd.RunE(memSearchCmd, []string{"query"})
_ = memLinkCmd.RunE(memLinkCmd, []string{"a", "b"})
_ = memUnlinkCmd.RunE(memUnlinkCmd, []string{"a", "b"})
_ = memGraphCmd.RunE(memGraphCmd, []string{"id"})
_ = memPrimeCmd.RunE(memPrimeCmd, []string{"query"})
_ = memForgetCmd.RunE(memForgetCmd, []string{"id"})
_ = memStatsCmd.RunE(memStatsCmd, nil)
}

func TestPluginListCmd_NoDir_stcov2(t *testing.T) {
orig := pluginPath
pluginPath = "/nonexistent"
defer func() { pluginPath = orig }()
final := captureStdout(t)
_ = pluginListCmd.RunE(pluginListCmd, nil)
out := final()
if !strings.Contains(out, "no plugins directory") {
t.Errorf("expected no plugins directory, got %q", out)
}
}

func TestPluginCmd_LoadPluginError_stcov2(t *testing.T) {
orig := loadPluginFn
loadPluginFn = func(name string) (*plugins.Plugin, error) { return nil, errors.New("load error") }
defer func() { loadPluginFn = orig }()
_ = pluginInfoCmd.RunE(pluginInfoCmd, []string{"x"})
_ = pluginUninstallCmd.RunE(pluginUninstallCmd, []string{"x"})
_ = pluginEnableCmd.RunE(pluginEnableCmd, []string{"x"})
_ = pluginDisableCmd.RunE(pluginDisableCmd, []string{"x"})
}

func TestHarvestURLFetch_BodyReadError_stcov2(t *testing.T) {
orig := harvestHTTPClient
harvestHTTPClient = func(timeout int) *http.Client {
Expand Down
Loading