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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project variables
BINARY_NAME=lea
VERSION=0.2.1
VERSION=0.2.2
BUILD_DIR=bin
MAIN_PATH=./cmd/lea/main.go

Expand Down
34 changes: 28 additions & 6 deletions internal/cli/commands/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@

import (
"os"
"path/filepath"
"testing"

"github.com/PizenLabs/lea/internal/storage/sqlite"
)

func TestHookPreToolInvalidSymbol(t *testing.T) {
// Create a temp directory with a .lea directory and graph.db so the code
// proceeds past findLeaDir / sqlite.NewStore into resolveSymbolID.
tmpDir := t.TempDir()
leaDir := filepath.Join(tmpDir, ".lea")
if err := os.MkdirAll(leaDir, 0755); err != nil {
t.Fatalf("mkdir .lea: %v", err)
}

// Create a valid empty graph.db so sqlite.NewStore opens successfully.
dbPath := filepath.Join(leaDir, "graph.db")
store, err := sqlite.NewStore(dbPath)
if err != nil {
t.Fatalf("create store: %v", err)
}
store.Close()

Check failure on line 26 in internal/cli/commands/hook_test.go

View workflow job for this annotation

GitHub Actions / Lint, Test, Build

Error return value of `store.Close` is not checked (errcheck)

// Prepare JSON input with a non-existent symbol
jsonInput := []byte(`{"tool_name":"pizen-lea__impact","tool_input":{"symbol":"nonexistent_symbol"}}`)
// Replace stdin with pipe containing JSON input

oldStdin := os.Stdin
oldWd, _ := os.Getwd()

r, w, err := os.Pipe()
if err != nil {
t.Fatalf("pipe error: %v", err)
Expand All @@ -23,22 +44,23 @@
}

os.Stdin = r
// Capture exit code via mocking os.Exit
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("chdir: %v", err)
}

exitCode := 0
osExit = func(code int) {
exitCode = code
panic("os.Exit called")
}
defer func() {
// Restore stdin and osExit variable
os.Stdin = oldStdin
os.Chdir(oldWd)

Check failure on line 58 in internal/cli/commands/hook_test.go

View workflow job for this annotation

GitHub Actions / Lint, Test, Build

Error return value of `os.Chdir` is not checked (errcheck)
osExit = osExitOriginal
// Recover from mocked os.Exit panic
_ = recover() // ignore panic from os.Exit mock
_ = recover()
if exitCode != 2 {
t.Fatalf("expected exit code 2, got %d", exitCode)
}
}()
// Run the pre-tool hook command
hookPreToolCmd.Run(nil, []string{})
}
Loading