diff --git a/cmd/sin-code/internal/index_cmd.go b/cmd/sin-code/internal/index_cmd.go index a09cdff..27bb1b1 100644 --- a/cmd/sin-code/internal/index_cmd.go +++ b/cmd/sin-code/internal/index_cmd.go @@ -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", @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/cmd/sin-code/internal/memory_cmd.go b/cmd/sin-code/internal/memory_cmd.go index fb7e6c7..7346baf 100644 --- a/cmd/sin-code/internal/memory_cmd.go +++ b/cmd/sin-code/internal/memory_cmd.go @@ -25,6 +25,8 @@ var ( memForgetID string memForget bool memFormat string + + openMemoryStoreFn = openMemoryStore ) var MemoryCmd = &cobra.Command{ @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/cmd/sin-code/internal/plugin_cmd.go b/cmd/sin-code/internal/plugin_cmd.go index 4d00c14..67e414b 100644 --- a/cmd/sin-code/internal/plugin_cmd.go +++ b/cmd/sin-code/internal/plugin_cmd.go @@ -18,6 +18,8 @@ var ( pluginNameArg string walkFn = filepath.Walk relFn = filepath.Rel + + loadPluginFn = loadPlugin ) var PluginCmd = &cobra.Command{ @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/cmd/sin-code/internal/stcov2_coverage_test.go b/cmd/sin-code/internal/stcov2_coverage_test.go index daac70f..5b360d5 100644 --- a/cmd/sin-code/internal/stcov2_coverage_test.go +++ b/cmd/sin-code/internal/stcov2_coverage_test.go @@ -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{} @@ -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 {