From 8e08602ac2cd372da18afaba33924282f8a066ff Mon Sep 17 00:00:00 2001 From: Lakshman Patel Date: Wed, 15 Jul 2026 09:11:43 +0530 Subject: [PATCH] chore: remove dead internal/eval package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Confirmed orphaned — not imported anywhere outside its own test file, no cmd/ exists to wire it into, and its BuiltinSuites() referenced package paths (internal/graph, internal/audit, internal/tool) unrelated to what it claimed to test. Its RunCommand()/Now() were permanent no-op stubs that would silently "pass" any suite expecting real output. The repo's actual eval need is already served by the working top-level eval.go (package sight, RunEval/EvalCase/EvalSuite), which this doesn't touch. --- internal/eval/builtin.go | 41 ----- internal/eval/eval.go | 303 ------------------------------------- internal/eval/eval_test.go | 135 ----------------- 3 files changed, 479 deletions(-) delete mode 100644 internal/eval/builtin.go delete mode 100644 internal/eval/eval.go delete mode 100644 internal/eval/eval_test.go diff --git a/internal/eval/builtin.go b/internal/eval/builtin.go deleted file mode 100644 index 9bb56a1..0000000 --- a/internal/eval/builtin.go +++ /dev/null @@ -1,41 +0,0 @@ -// Package eval provides builtin evaluation suites. -package eval - -// BuiltinSuites returns default evaluation suites. -func BuiltinSuites() []Suite { - return []Suite{ - { - Name: "unit-tests", - Description: "Run all unit tests", - Tests: []*Test{ - { - Name: "graph-package", - Description: "Run graph package tests", - Command: "go", - Args: []string{"test", "github.com/GrayCodeAI/sight/internal/graph/...", "-v"}, - Expected: ExpectedResult{ - ExitCode: 0, - }, - }, - { - Name: "audit-package", - Description: "Run audit package tests", - Command: "go", - Args: []string{"test", "github.com/GrayCodeAI/sight/internal/audit/...", "-v"}, - Expected: ExpectedResult{ - ExitCode: 0, - }, - }, - { - Name: "tool-package", - Description: "Run tool package tests", - Command: "go", - Args: []string{"test", "github.com/GrayCodeAI/sight/internal/tool/...", "-v"}, - Expected: ExpectedResult{ - ExitCode: 0, - }, - }, - }, - }, - } -} diff --git a/internal/eval/eval.go b/internal/eval/eval.go deleted file mode 100644 index 8b1831a..0000000 --- a/internal/eval/eval.go +++ /dev/null @@ -1,303 +0,0 @@ -// Package eval provides evaluation framework for hawk-eco. -// It supports standardized test suites, agent evals, and scoring. -package eval - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "sync" -) - -// Suite represents an evaluation suite with fixtures and tests. -type Suite struct { - Name string - Description string - Fixtures []string - Tests []*Test -} - -// Test represents a single evaluation test. -type Test struct { - Name string - Description string - Command string - Args []string - Expected ExpectedResult -} - -// ExpectedResult represents expected test output. -type ExpectedResult struct { - ExitCode int - Output string - Error string -} - -// Result represents the result of running an eval test. -type Result struct { - Test *Test - Passed bool - Output string - Error error - DurationMs int64 -} - -// Report represents evaluation report. -type Report struct { - SuiteName string - Results []*Result - Summary *Summary -} - -// Summary represents evaluation summary. -type Summary struct { - TotalTests int - PassedTests int - FailedTests int - PassRate float64 - TotalTimeMs int64 -} - -// SuiteManager manages evaluation suites. -type SuiteManager struct { - mu sync.RWMutex - suites map[string]*Suite - fixtures map[string]string -} - -// NewSuiteManager creates a new suite manager. -func NewSuiteManager() *SuiteManager { - return &SuiteManager{ - suites: make(map[string]*Suite), - fixtures: make(map[string]string), - } -} - -// Register adds a suite to the manager. -func (m *SuiteManager) Register(suite *Suite) { - m.mu.Lock() - defer m.mu.Unlock() - m.suites[suite.Name] = suite -} - -// LoadSuitesFromDir loads suites from a directory. -func (m *SuiteManager) LoadSuitesFromDir(dir string) error { - entries, err := os.ReadDir(dir) - if err != nil { - return err - } - - for _, entry := range entries { - if entry.IsDir() { - continue - } - - if !strings.HasSuffix(entry.Name(), ".json") && !strings.HasSuffix(entry.Name(), ".yaml") && !strings.HasSuffix(entry.Name(), ".yml") { - continue - } - - suitePath := filepath.Join(dir, entry.Name()) - data, err := os.ReadFile(suitePath) // #nosec G304 -- suitePath is joined from a directory being loaded (a fixed evals/suites path or os.TempDir()-based path, see LoadDefaultSuites) and an entry name from os.ReadDir on that directory, not raw user input - if err != nil { - continue - } - - if strings.HasSuffix(entry.Name(), ".json") { - m.loadJSONSuite(data) - } - } - - return nil -} - -// loadJSONSuite loads a suite from JSON. -func (m *SuiteManager) loadJSONSuite(data []byte) { - var suite Suite - if err := json.Unmarshal(data, &suite); err != nil { - return - } - - m.Register(&suite) -} - -// LoadFixture loads a fixture file. -func (m *SuiteManager) LoadFixture(name string) (string, bool) { - m.mu.RLock() - defer m.mu.RUnlock() - data, ok := m.fixtures[name] - return data, ok -} - -// RegisterFixture registers a fixture. -func (m *SuiteManager) RegisterFixture(name, content string) { - m.mu.Lock() - defer m.mu.Unlock() - m.fixtures[name] = content -} - -// FindSuite finds a suite by name. -func (m *SuiteManager) FindSuite(name string) *Suite { - m.mu.RLock() - defer m.mu.RUnlock() - return m.suites[name] -} - -// List returns all registered suites. -func (m *SuiteManager) List() []*Suite { - m.mu.RLock() - defer m.mu.RUnlock() - - result := make([]*Suite, 0, len(m.suites)) - for _, s := range m.suites { - result = append(result, s) - } - return result -} - -// RunSuite runs all tests in a suite. -func (m *SuiteManager) RunSuite(name string) *Report { - suite := m.FindSuite(name) - if suite == nil { - return nil - } - - start := Now() - var results []*Result - - for _, test := range suite.Tests { - result := m.RunTest(test) - results = append(results, result) - } - - duration := Now() - start - summary := m.Summarize(results, duration) - - return &Report{ - SuiteName: name, - Results: results, - Summary: summary, - } -} - -// RunTest runs a single test. -func (m *SuiteManager) RunTest(test *Test) *Result { - start := Now() - - cmd := test.Command - if args := test.Args; len(args) > 0 { - fullArgs := append([]string{cmd}, args...) - cmd = strings.Join(fullArgs, " ") - } - - output, err := RunCommand(cmd) - duration := Now() - start - - passed := err == nil && output == test.Expected.Output && test.Expected.Error == "" - - return &Result{ - Test: test, - Passed: passed, - Output: output, - Error: err, - DurationMs: duration, - } -} - -// Summarize creates a summary from results. -func (m *SuiteManager) Summarize(results []*Result, totalDuration int64) *Summary { - totalTests := len(results) - var passedTests, failedTests int - for _, r := range results { - if r.Passed { - passedTests++ - } else { - failedTests++ - } - } - - var passRate float64 - if totalTests > 0 { - passRate = float64(passedTests) / float64(totalTests) * 100 - } - - var summary Summary - summary.TotalTests = totalTests - summary.PassedTests = passedTests - summary.FailedTests = failedTests - summary.PassRate = passRate - summary.TotalTimeMs = totalDuration - - return &summary -} - -// RunAllSuites runs all registered suites. -func (m *SuiteManager) RunAllSuites() []*Report { - var reports []*Report - for _, suite := range m.List() { - if report := m.RunSuite(suite.Name); report != nil { - reports = append(reports, report) - } - } - return reports -} - -// LoadDefaultSuites loads suites from default locations. -func (m *SuiteManager) LoadDefaultSuites() error { - // Load from project directory - if cwd, err := os.Getwd(); err == nil { - suitesDir := filepath.Join(cwd, "evals", "suites") - if err := m.LoadSuitesFromDir(suitesDir); err != nil { - // Non-fatal: project evals are optional - fmt.Fprintf(os.Stderr, "warning: could not load project evals: %v\n", err) - } - } - - // Load from user config - userDir := filepath.Join(os.TempDir(), "hawk-eco", "evals") - if err := m.LoadSuitesFromDir(userDir); err != nil { - // Non-fatal: user evals are optional - fmt.Fprintf(os.Stderr, "warning: could not load user evals: %v\n", err) - } - - return nil -} - -// Now returns current time in milliseconds. -func Now() int64 { - return 0 // placeholder for actual implementation -} - -// RunCommand runs a command and returns output. -func RunCommand(cmd string) (string, error) { - parts := strings.Fields(cmd) - if len(parts) == 0 { - return "", fmt.Errorf("empty command") - } - - // For actual implementation, use exec.Command - return "", nil -} - -// RunShellCommand runs a shell command. -func RunShellCommand(cmd string) (string, error) { - return RunCommand(cmd) -} - -// Materialize builds a command with fixtures substituted. -func Materialize(test *Test) string { - cmd := test.Command - for _, fixture := range test.Args { - if data, ok := GetFixture(fixture); ok { - cmd = strings.ReplaceAll(cmd, fixture, data) - } - } - return cmd -} - -// GetFixture retrieves a fixture by name. -func GetFixture(name string) (string, bool) { - // placeholder for SuiteManager - return "", false -} diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go deleted file mode 100644 index 83e7448..0000000 --- a/internal/eval/eval_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package eval - -import ( - "testing" -) - -func TestSuiteManager(t *testing.T) { - m := NewSuiteManager() - - if m == nil { - t.Fatal("expected non-nil manager") - } - - if len(m.List()) != 0 { - t.Errorf("expected 0 suites, got %d", len(m.List())) - } -} - -func TestRegisterSuite(t *testing.T) { - m := NewSuiteManager() - - suite := &Suite{ - Name: "test-suite", - Description: "A test suite", - Tests: []*Test{ - { - Name: "test-1", - Description: "Test 1", - Command: "go test", - Args: []string{"./..."}, - Expected: ExpectedResult{ - ExitCode: 0, - Output: "PASS", - }, - }, - }, - } - - m.Register(suite) - - got := m.FindSuite("test-suite") - if got == nil { - t.Fatal("expected to find suite") - } - - if got.Name != "test-suite" { - t.Errorf("expected suite name 'test-suite', got %s", got.Name) - } -} - -func TestListSuites(t *testing.T) { - m := NewSuiteManager() - - suite1 := &Suite{Name: "suite-1"} - suite2 := &Suite{Name: "suite-2"} - - m.Register(suite1) - m.Register(suite2) - - suites := m.List() - if len(suites) != 2 { - t.Errorf("expected 2 suites, got %d", len(suites)) - } -} - -func TestRunTest(t *testing.T) { - m := NewSuiteManager() - - test := &Test{ - Name: "test-command", - Description: "Runs a command", - Command: "echo", - Args: []string{"hello"}, - Expected: ExpectedResult{ - Output: "hello\n", - }, - } - - result := m.RunTest(test) - if result == nil { - t.Fatal("expected non-nil result") - } - - if !result.Passed { - t.Logf("Test output: %s", result.Output) - if result.Error != nil { - t.Logf("Test error: %v", result.Error) - } - } -} - -func TestSummarize(t *testing.T) { - m := NewSuiteManager() - - results := []*Result{ - {Test: &Test{Name: "t1"}, Passed: true, DurationMs: 100}, - {Test: &Test{Name: "t2"}, Passed: false, DurationMs: 200}, - {Test: &Test{Name: "t3"}, Passed: true, DurationMs: 150}, - } - - summary := m.Summarize(results, 450) - if summary == nil { - t.Fatal("expected non-nil summary") - } - - if summary.TotalTests != 3 { - t.Errorf("expected 3 total tests, got %d", summary.TotalTests) - } - - if summary.PassedTests != 2 { - t.Errorf("expected 2 passed tests, got %d", summary.PassedTests) - } - - if summary.FailedTests != 1 { - t.Errorf("expected 1 failed test, got %d", summary.FailedTests) - } - - if summary.PassRate < 66 || summary.PassRate > 67 { - t.Errorf("expected pass rate ~66.67, got %f", summary.PassRate) - } -} - -func TestBuiltinSuites(t *testing.T) { - m := NewSuiteManager() - builtin := BuiltinSuites() - - for _, suite := range builtin { - m.Register(&suite) - } - - suites := m.List() - if len(suites) != len(builtin) { - t.Errorf("expected %d builtin suites, got %d", len(builtin), len(suites)) - } -}