From b6435a62d838e199178e63dc642f3b794e359f80 Mon Sep 17 00:00:00 2001 From: Junjun Zhang Date: Thu, 22 Oct 2026 18:44:19 +0800 Subject: [PATCH] chore: remove confirmed dead code (deadcode r84: tool/a2a x5, wailskit-block map) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five confirmed-dead symbols removed with their dedicated-only tests (deadcode -tags goolm fresh-main scan + repo-wide grep dual-verify): - internal/a2a: isToolAllowed (+ TestIsToolAllowed) — zero prod refs, only its own unit test - internal/tool: SetPrecommitGateEnabled (+ test), SetPostEditDiagEnabled (+ test) — config setters never wired, vars stay live - internal/tool: LoadProtectedPatternsFromFile (+ test) — .ggcode/protect loader never wired; "os" import pruned with it - internal/tool: readFileRange (+ read_file_range_test.go, 6 tests all dedicated to it) — thin wrapper over live readFileRangeWithOptions Kept (classification ledger): resetPeerBreakers/stateSnapshot (test-only helpers, 8 tests), NewMemoryBindingStore (4 tui panel tests), decodeSSE (zz565 regression), VerifyAgentCardSignature (tests live pipeline via wrapper), agent 7-check family (revival precedent), agentruntime desktop/ interaction/session family (wailskit dead-block dependency, frozen), sdk/plugin + a2a exported options (SDK API face), shell_sandbox/atspi/ydo (Linux build-tag false-positive family). Verified: go build -tags goolm ./... ; go vet ; go test internal/a2a internal/tool all pass. Co-Authored-By: ggcode --- internal/a2a/a2a_test.go | 13 --- internal/a2a/handler.go | 12 --- internal/tool/file_guard.go | 24 ------ internal/tool/file_guard_test.go | 24 ------ internal/tool/post_edit_diagnostics.go | 5 -- internal/tool/post_edit_diagnostics_test.go | 14 ---- internal/tool/precommit_gate.go | 5 -- internal/tool/precommit_gate_test.go | 15 ---- internal/tool/read_file_range.go | 11 --- internal/tool/read_file_range_test.go | 90 --------------------- 10 files changed, 213 deletions(-) delete mode 100644 internal/tool/read_file_range_test.go diff --git a/internal/a2a/a2a_test.go b/internal/a2a/a2a_test.go index e2c9aaa98..b7db86527 100644 --- a/internal/a2a/a2a_test.go +++ b/internal/a2a/a2a_test.go @@ -449,19 +449,6 @@ func TestExtractText(t *testing.T) { } } -func TestIsToolAllowed(t *testing.T) { - allowed := []string{"read_file", "search_files", "glob"} - if !isToolAllowed("read_file", allowed) { - t.Error("expected read_file to be allowed") - } - if isToolAllowed("run_command", allowed) { - t.Error("expected run_command to NOT be allowed") - } - if !isToolAllowed("read_file", nil) { - t.Error("nil allowed should permit all tools") - } -} - func TestPickToolForSkill(t *testing.T) { tests := []struct { skill string diff --git a/internal/a2a/handler.go b/internal/a2a/handler.go index ea336af0a..687197536 100644 --- a/internal/a2a/handler.go +++ b/internal/a2a/handler.go @@ -942,18 +942,6 @@ var skillPermissions = map[string]*SkillPermission{ // Helpers // --------------------------------------------------------------------------- -func isToolAllowed(toolName string, allowed []string) bool { - if len(allowed) == 0 { - return true // nil/empty = all tools allowed - } - for _, a := range allowed { - if a == toolName { - return true - } - } - return false -} - // restrictRegistry builds a registry exposing only the tools named in // allowed (fix #565 A). Tool instances are shared with src — the same // ownership model as the previous direct pass-through; the agent package diff --git a/internal/tool/file_guard.go b/internal/tool/file_guard.go index 6a8663604..f346cb24f 100644 --- a/internal/tool/file_guard.go +++ b/internal/tool/file_guard.go @@ -1,7 +1,6 @@ package tool import ( - "os" "path/filepath" "runtime" "strings" @@ -387,26 +386,3 @@ func MergeFileGuards(sandbox AllowedPathChecker, guard *FileGuard, workingDir st return true } } - -// LoadProtectedPatternsFromFile reads protected patterns from a .ggcode/protect file. -// This is a simple newline-delimited format, # for comments. -// Returns nil if the file doesn't exist (use defaults). -func LoadProtectedPatternsFromFile(workspaceDir string) []string { - if workspaceDir == "" { - return nil - } - path := filepath.Join(workspaceDir, ".ggcode", "protect") - data, err := os.ReadFile(path) - if err != nil { - return nil - } - var patterns []string - for _, line := range strings.Split(string(data), "\n") { - line = strings.TrimSpace(line) - if line == "" || strings.HasPrefix(line, "#") { - continue - } - patterns = append(patterns, line) - } - return patterns -} diff --git a/internal/tool/file_guard_test.go b/internal/tool/file_guard_test.go index f10e954c4..1449feccd 100644 --- a/internal/tool/file_guard_test.go +++ b/internal/tool/file_guard_test.go @@ -132,30 +132,6 @@ func TestMergeFileGuards_ProtectedPath(t *testing.T) { } } -func TestLoadProtectedPatternsFromFile(t *testing.T) { - dir := t.TempDir() - - // Non-existent file returns nil - pats := LoadProtectedPatternsFromFile(dir) - if pats != nil { - t.Errorf("expected nil for non-existent file, got %v", pats) - } - - // Create file - ggcodeDir := filepath.Join(dir, ".ggcode") - os.MkdirAll(ggcodeDir, 0755) - content := "# Comment\n*.lock\n\n.env\n# another comment\nsecrets/**\n" - os.WriteFile(filepath.Join(ggcodeDir, "protect"), []byte(content), 0644) - - pats = LoadProtectedPatternsFromFile(dir) - if len(pats) != 3 { - t.Fatalf("expected 3 patterns, got %d: %v", len(pats), pats) - } - if pats[0] != "*.lock" || pats[1] != ".env" || pats[2] != "secrets/**" { - t.Errorf("unexpected patterns: %v", pats) - } -} - func TestFileGuard_SymlinkEnv(t *testing.T) { // .env should be blocked regardless of working directory dir := t.TempDir() diff --git a/internal/tool/post_edit_diagnostics.go b/internal/tool/post_edit_diagnostics.go index a8a13c00f..9a07dcf9c 100644 --- a/internal/tool/post_edit_diagnostics.go +++ b/internal/tool/post_edit_diagnostics.go @@ -16,11 +16,6 @@ import ( // Defaults to true. Can be disabled via configuration. var postEditDiagEnabled = true -// SetPostEditDiagEnabled enables or disables post-edit LSP diagnostics globally. -func SetPostEditDiagEnabled(enabled bool) { - postEditDiagEnabled = enabled -} - // postEditDiagTimeout is the maximum time to wait for LSP diagnostics after // an edit. Kept under 1s to avoid blocking the agent loop — if the LSP // server is slow to respond, we skip diagnostics rather than stalling the diff --git a/internal/tool/post_edit_diagnostics_test.go b/internal/tool/post_edit_diagnostics_test.go index 335220cef..7803365c8 100644 --- a/internal/tool/post_edit_diagnostics_test.go +++ b/internal/tool/post_edit_diagnostics_test.go @@ -118,17 +118,3 @@ func TestFormatDiagnostics_ErrorAndWarningCap(t *testing.T) { t.Fatalf("expected warning cap message, got %q", result) } } - -func TestSetPostEditDiagEnabled(t *testing.T) { - old := postEditDiagEnabled - defer func() { postEditDiagEnabled = old }() - - SetPostEditDiagEnabled(false) - if postEditDiagEnabled { - t.Fatal("expected postEditDiagEnabled to be false") - } - SetPostEditDiagEnabled(true) - if !postEditDiagEnabled { - t.Fatal("expected postEditDiagEnabled to be true") - } -} diff --git a/internal/tool/precommit_gate.go b/internal/tool/precommit_gate.go index e43949efc..e63f5276a 100644 --- a/internal/tool/precommit_gate.go +++ b/internal/tool/precommit_gate.go @@ -48,11 +48,6 @@ const precommitMaxErrors = 10 // Defaults to true. Can be disabled via configuration. var precommitGateEnabled = true -// SetPrecommitGateEnabled enables or disables the pre-commit build gate globally. -func SetPrecommitGateEnabled(enabled bool) { - precommitGateEnabled = enabled -} - // precommitBuildCheck runs a fast project-wide build verification before // committing. Returns an advisory warning string if the build fails, or empty // string if the build passes, is disabled, or cannot be determined. diff --git a/internal/tool/precommit_gate_test.go b/internal/tool/precommit_gate_test.go index 2a3553c9b..fc4ca6e43 100644 --- a/internal/tool/precommit_gate_test.go +++ b/internal/tool/precommit_gate_test.go @@ -199,18 +199,3 @@ func TestIsBuildErrorLine(t *testing.T) { }) } } - -func TestSetPrecommitGateEnabled(t *testing.T) { - old := precommitGateEnabled - defer func() { precommitGateEnabled = old }() - - SetPrecommitGateEnabled(false) - if precommitGateEnabled != false { - t.Error("expected precommitGateEnabled to be false") - } - - SetPrecommitGateEnabled(true) - if precommitGateEnabled != true { - t.Error("expected precommitGateEnabled to be true") - } -} diff --git a/internal/tool/read_file_range.go b/internal/tool/read_file_range.go index 58a29d640..c02f62f98 100644 --- a/internal/tool/read_file_range.go +++ b/internal/tool/read_file_range.go @@ -14,17 +14,6 @@ type readFileRangeOptions struct { moreHint string } -// readFileRange formats content with cat -n style line numbers, returning -// lines [offset, offset+limit) from the full content. -// offset is 1-based; 0 or 1 means start from the beginning. -// limit <= 0 means read to end (capped at maxOutputLines). -func readFileRange(content string, offset, limit int, totalLines int) string { - return readFileRangeWithOptions(content, offset, limit, readFileRangeOptions{ - defaultLimit: maxOutputLines, - moreHint: "Use read_file with offset/limit for more.", - }) -} - func readFileRangeWithOptions(content string, offset, limit int, opts readFileRangeOptions) string { lines := strings.Split(content, "\n") diff --git a/internal/tool/read_file_range_test.go b/internal/tool/read_file_range_test.go deleted file mode 100644 index 86a1f1471..000000000 --- a/internal/tool/read_file_range_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package tool - -import ( - "strings" - "testing" -) - -func makeLines(n int) string { - lines := make([]string, n) - for i := 0; i < n; i++ { - lines[i] = "line content here" - } - return strings.Join(lines, "\n") -} - -func TestReadFileRangeFull(t *testing.T) { - content := "line1\nline2\nline3" - result := readFileRange(content, 0, 0, 0) - if !strings.Contains(result, " 1\tline1") { - t.Errorf("expected line 1, got:\n%s", result) - } - if !strings.Contains(result, " 2\tline2") { - t.Errorf("expected line 2, got:\n%s", result) - } - if !strings.Contains(result, " 3\tline3") { - t.Errorf("expected line 3, got:\n%s", result) - } -} - -func TestReadFileRangeWithOffset(t *testing.T) { - content := "line1\nline2\nline3\nline4\nline5" - result := readFileRange(content, 3, 0, 0) - if strings.Contains(result, "line1") && strings.Contains(result, " 1\t") { - t.Error("should not contain line 1 when offset=3") - } - if !strings.Contains(result, " 3\tline3") { - t.Errorf("expected line 3 as first line, got:\n%s", result) - } - if !strings.Contains(result, " 5\tline5") { - t.Errorf("expected line 5, got:\n%s", result) - } -} - -func TestReadFileRangeWithLimit(t *testing.T) { - content := "line1\nline2\nline3\nline4\nline5" - result := readFileRange(content, 1, 3, 0) - if !strings.Contains(result, " 1\tline1") { - t.Errorf("expected line 1, got:\n%s", result) - } - if !strings.Contains(result, " 3\tline3") { - t.Errorf("expected line 3, got:\n%s", result) - } - if strings.Contains(result, "line4") { - t.Error("should not contain line 4 with limit=3") - } -} - -func TestReadFileRangeTruncation(t *testing.T) { - // Create content with more than maxOutputLines lines - content := makeLines(2500) - result := readFileRange(content, 0, 0, 0) - if !strings.Contains(result, "File truncated") { - t.Error("expected truncation notice") - } - if strings.Contains(result, "2001") { - t.Error("should not contain line 2001 when capped at 2000") - } -} - -func TestReadFileRangeOffsetBeyondEnd(t *testing.T) { - content := "line1\nline2\nline3" - result := readFileRange(content, 100, 0, 0) - if !strings.Contains(result, "beyond end") { - t.Errorf("expected offset beyond end notice, got:\n%s", result) - } -} - -func TestReadFileRangeOffsetLimitCombo(t *testing.T) { - content := makeLines(100) - result := readFileRange(content, 10, 5, 0) - if !strings.Contains(result, " 10\t") { - t.Errorf("expected line 10, got:\n%s", result) - } - if !strings.Contains(result, " 14\t") { - t.Errorf("expected line 14, got:\n%s", result) - } - if strings.Contains(result, " 15\t") { - t.Error("should not contain line 15 with limit=5 starting at offset=10") - } -}