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
4 changes: 3 additions & 1 deletion cmd/sin-code/internal/grasp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
graspFormat string
)

var graspAbsPath = filepath.Abs

var GraspCmd = &cobra.Command{
Use: "grasp [path]",
Short: "Deep code understanding for a single file",
Expand All @@ -34,7 +36,7 @@ Example:
Args: cobra.ExactArgs(1),
Version: Version,
RunE: func(cmd *cobra.Command, args []string) error {
absPath, err := filepath.Abs(args[0])
absPath, err := graspAbsPath(args[0])
if err != nil {
return fmt.Errorf("invalid path: %w", err)
}
Expand Down
15 changes: 8 additions & 7 deletions cmd/sin-code/internal/lsp_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (
)

var (
lspLang string
lspRoot string
lspFile string
lspLine int
lspCol int
lspNewName string
lspLang string
lspRoot string
lspFile string
lspLine int
lspCol int
lspDetectAvailable = lsp.DetectAvailable
lspNewName string

// filepathAbs is a test hook for lspSetup error paths.
// osGetwd is defined in serve.go as a shared package hook.
Expand Down Expand Up @@ -81,7 +82,7 @@ var lspServersCmd = &cobra.Command{
Use: "servers",
Short: "List detected LSP servers on PATH",
RunE: func(cmd *cobra.Command, args []string) error {
specs := lsp.DetectAvailable()
specs := lspDetectAvailable()
if len(specs) == 0 {
fmt.Println("(no LSP servers detected on PATH)")
fmt.Println("Install one of: gopls (go), pyright-langserver (python), typescript-language-server (ts/js)")
Expand Down
4 changes: 3 additions & 1 deletion cmd/sin-code/internal/scout.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var (

// scoreScoutModifier is a test hook for adjusting scout relevance scores.
scoreScoutModifier func(score float64) float64

scoutAbsPath = filepath.Abs
)

// searchFileFn is the searchFile implementation used by searchWithIndex.
Expand All @@ -65,7 +67,7 @@ Examples:
if scoutQuery == "" {
return fmt.Errorf("--query is required")
}
absPath, err := filepath.Abs(scoutPath)
absPath, err := scoutAbsPath(scoutPath)
if err != nil {
return fmt.Errorf("invalid path: %w", err)
}
Expand Down
135 changes: 135 additions & 0 deletions cmd/sin-code/internal/stcov2_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"strings"
"testing"
"time"

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

type stcov2ErrorReader struct{}
Expand Down Expand Up @@ -974,6 +976,139 @@ func TestRunCommand_StreamError_stcov2(t *testing.T) {
}
}

func TestDiscoverCmd_JSONSuccess_stcov2(t *testing.T) {
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "x.go"), []byte("package x\n"), 0644)
final := captureStdout(t)
DiscoverCmd.SetArgs([]string{dir, "--format", "json", "--pattern", "*.go"})
if err := DiscoverCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "x.go") {
t.Errorf("expected x.go in output, got %q", out)
}
}

func TestMapCmd_JSONSuccess_stcov2(t *testing.T) {
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "x.go"), []byte("package x\n"), 0644)
final := captureStdout(t)
MapCmd.SetArgs([]string{dir, "--format", "json", "--action", "map"})
if err := MapCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "x.go") {
t.Errorf("expected x.go in output, got %q", out)
}
}

func TestExecuteCmd_JSONSuccess_stcov2(t *testing.T) {
final := captureStdout(t)
ExecuteCmd.SetArgs([]string{"--command", "echo hello", "--format", "json", "--timeout", "5"})
if err := ExecuteCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "hello") {
t.Errorf("expected hello in output, got %q", out)
}
}

func TestReadCmd_JSONSuccess_stcov2(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "x.go")
os.WriteFile(path, []byte("package x\n"), 0644)
final := captureStdout(t)
ReadCmd.SetArgs([]string{path, "--format", "json"})
if err := ReadCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "package x") {
t.Errorf("expected package x in output, got %q", out)
}
}

func TestGraspCmd_AbsPathError_stcov2(t *testing.T) {
orig := graspAbsPath
graspAbsPath = func(path string) (string, error) { return "", errors.New("abs error") }
defer func() { graspAbsPath = orig }()
GraspCmd.SetArgs([]string{"foo.go"})
_ = GraspCmd.Execute()
// Error is returned directly; we only need to exercise the branch.
}

func TestGraspCmd_JSONSuccess_stcov2(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "x.go")
os.WriteFile(path, []byte("package x\n"), 0644)
final := captureStdout(t)
GraspCmd.SetArgs([]string{path, "--format", "json"})
if err := GraspCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "x.go") {
t.Errorf("expected x.go in output, got %q", out)
}
}

func TestScoutCmd_AbsPathError_stcov2(t *testing.T) {
orig := scoutAbsPath
scoutAbsPath = func(path string) (string, error) { return "", errors.New("abs error") }
defer func() { scoutAbsPath = orig }()
ScoutCmd.SetArgs([]string{"--query", "test"})
_ = ScoutCmd.Execute()
}

func TestWriteCmd_AbsPathError_stcov2(t *testing.T) {
orig := writeAbsPath
writeAbsPath = func(path string) (string, error) { return "", errors.New("abs error") }
defer func() { writeAbsPath = orig }()
WriteCmd.SetArgs([]string{"foo.txt", "--content", "hello"})
_ = WriteCmd.Execute()
}

func TestOracleCmd_VerifyCoverageError_stcov2(t *testing.T) {
OracleCmd.SetArgs([]string{"--claim", "/nonexistent", "--evidence", "/nonexistent"})
if err := OracleCmd.Execute(); err == nil {
t.Fatal("expected error")
}
}

func TestOracleCmd_JSONSuccess_stcov2(t *testing.T) {
dir := t.TempDir()
claim := filepath.Join(dir, "x.go")
evidence := filepath.Join(dir, "x_test.go")
os.WriteFile(claim, []byte("package x\nfunc Foo() {}\n"), 0644)
os.WriteFile(evidence, []byte("package x\nfunc TestFoo(t *testing.T) {}\n"), 0644)
final := captureStdout(t)
OracleCmd.SetArgs([]string{"--claim", claim, "--evidence", evidence, "--format", "json"})
if err := OracleCmd.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "coverage") {
t.Errorf("expected coverage in output, got %q", out)
}
}

func TestLspServersCmd_NoServers_stcov2(t *testing.T) {
orig := lspDetectAvailable
lspDetectAvailable = func() []lsp.ServerSpec { return nil }
defer func() { lspDetectAvailable = orig }()
final := captureStdout(t)
if err := lspServersCmd.RunE(lspServersCmd, nil); err != nil {
t.Fatalf("unexpected error: %v", err)
}
out := final()
if !strings.Contains(out, "no LSP servers") {
t.Errorf("expected no servers message, got %q", out)
}
}

func TestHarvestURLFetch_BodyReadError_stcov2(t *testing.T) {
orig := harvestHTTPClient
harvestHTTPClient = func(timeout int) *http.Client {
Expand Down
4 changes: 3 additions & 1 deletion cmd/sin-code/internal/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
writeStdinReader = io.Reader(os.Stdin)
)

var writeAbsPath = filepath.Abs

var WriteCmd = &cobra.Command{
Use: "write [path]",
Short: "Write files atomically with syntax pre-validation",
Expand All @@ -47,7 +49,7 @@ Examples:
sin-code write docs/new/file.md --stdin --mkdir < notes.md`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
absPath, err := filepath.Abs(args[0])
absPath, err := writeAbsPath(args[0])
if err != nil {
return fmt.Errorf("invalid path: %w", err)
}
Expand Down
Loading