From ba0bc4ba7e6c452fe1fc49c0826e9fecb83f2d83 Mon Sep 17 00:00:00 2001 From: andev0x Date: Mon, 22 Jun 2026 20:42:27 +0700 Subject: [PATCH] build: update version and improve test setup - bump version from 0.2.1 to 0.2.2 - add temporary directory setup for tests --- Makefile | 2 +- internal/cli/commands/hook_test.go | 34 ++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 8e83347..e1da5fe 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/internal/cli/commands/hook_test.go b/internal/cli/commands/hook_test.go index 61740e9..da617de 100644 --- a/internal/cli/commands/hook_test.go +++ b/internal/cli/commands/hook_test.go @@ -2,14 +2,35 @@ package commands 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() + // 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) @@ -23,22 +44,23 @@ func TestHookPreToolInvalidSymbol(t *testing.T) { } 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) 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{}) }