Skip to content

Commit ae8522a

Browse files
author
razvan
committed
fix: resolve all golangci-lint violations
- list_package_exports_test.go: _ = tool.Execute (errcheck) - search_test.go: Expect(json.Unmarshal(...)) (errcheck) - go/analyzer_test.go: require.NoError(t, os.WriteFile) (errcheck) - workspace/integration_test.go: check errRes after step 2 (ineffassign) - php/phpdoc.go: ReturnInfo(r) direct conversion (gosimple S1016) - cmd/rag-code-install/main.go: errCh for ollama serve early exit - internal/updater/updater.go: regex validation for remote model name
1 parent d852ed1 commit ae8522a

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

cmd/rag-code-install/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,34 @@ func setupEnvironment() {
145145
fmt.Printf(" Would you like to try starting the local Ollama service? [Y/n]: ")
146146
if askConfirm(true) {
147147
log("Starting Ollama service in background...")
148-
// Start ollama serve in a way that doesn't block the installer
148+
// Start ollama serve; capture early exit errors via channel
149+
errCh := make(chan error, 1)
149150
go func() {
150-
if err := exec.Command("ollama", "serve").Run(); err != nil {
151-
fmt.Printf("⚠️ Warning: Failed to serve ollama: %v\n", err)
152-
}
151+
errCh <- exec.Command("ollama", "serve").Run()
153152
}()
154153
// Give it a few seconds to bind to the port
155154
log("Waiting for Ollama to bind to port 11434...")
155+
started := false
156156
for i := 0; i < 10; i++ {
157+
select {
158+
case err := <-errCh:
159+
if err != nil {
160+
fmt.Printf("⚠️ Warning: ollama serve exited early: %v\n", err)
161+
}
162+
goto ollamaDone
163+
default:
164+
}
157165
if isPortOpen(11434) {
158166
success("Ollama service started successfully")
159-
break
167+
started = true
168+
goto ollamaDone
160169
}
161170
time.Sleep(1 * time.Second)
162171
}
172+
ollamaDone:
173+
if !started && !isPortOpen(11434) {
174+
fmt.Printf("⚠️ Ollama did not bind to port 11434 in time\n")
175+
}
163176
}
164177
}
165178

internal/service/tools/tests/list_package_exports_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("ListPackageExportsTool", func() {
3535
resJSON, err := tool.Execute(ctx, map[string]interface{}{"file_path": "main.go"})
3636
Expect(err).NotTo(HaveOccurred())
3737
var resp tools.ToolResponse
38-
json.Unmarshal([]byte(resJSON), &resp)
38+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
3939
Expect(resp.Status).To(Equal("error"))
4040
Expect(resp.Error).To(ContainSubstring("package parameter is required"))
4141
})
@@ -71,7 +71,7 @@ var _ = Describe("ListPackageExportsTool", func() {
7171
Expect(err).NotTo(HaveOccurred())
7272

7373
var resp tools.ToolResponse
74-
json.Unmarshal([]byte(resJSON), &resp)
74+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
7575
if resp.Status != "success" {
7676
GinkgoWriter.Printf("ListPackageExports Error: %s\n", resp.Error)
7777
}
@@ -95,7 +95,7 @@ var _ = Describe("ListPackageExportsTool", func() {
9595
return []storage.SearchResult{}, nil
9696
}
9797

98-
tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
98+
_, _ = tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
9999

100100
Expect(capturedFilter).NotTo(BeNil())
101101
Expect(capturedFilter["package"]).To(Equal("mypkg"))
@@ -119,7 +119,7 @@ var _ = Describe("ListPackageExportsTool", func() {
119119
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
120120
Expect(err).NotTo(HaveOccurred())
121121
var resp tools.ToolResponse
122-
json.Unmarshal([]byte(resJSON), &resp)
122+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
123123
Expect(resp.Status).To(Equal("success"))
124124
data := resp.Data.(map[string]interface{})
125125
funcs := data["function"].([]interface{})
@@ -142,7 +142,7 @@ var _ = Describe("ListPackageExportsTool", func() {
142142
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
143143
Expect(err).NotTo(HaveOccurred())
144144
var resp tools.ToolResponse
145-
json.Unmarshal([]byte(resJSON), &resp)
145+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
146146
Expect(resp.Status).To(Equal("success"))
147147
Expect(resp.Data).To(BeNil(), "internalHelper should be excluded by isExported check")
148148
})
@@ -168,7 +168,7 @@ var _ = Describe("ListPackageExportsTool", func() {
168168
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
169169
Expect(err).NotTo(HaveOccurred())
170170
var resp tools.ToolResponse
171-
json.Unmarshal([]byte(resJSON), &resp)
171+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
172172
Expect(resp.Status).To(Equal("success"))
173173
Expect(resp.Message).To(ContainSubstring("**Relations:** 3"), "Output should display RelationsCount when > 0")
174174
})

internal/service/tools/tests/search_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = Describe("RagSearchCodeTool", func() {
4545
resJSON, err := tool.Execute(ctx, map[string]interface{}{"query": "test", "file_path": "main.go"})
4646
Expect(err).NotTo(HaveOccurred())
4747
var resp tools.ToolResponse
48-
json.Unmarshal([]byte(resJSON), &resp)
48+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
4949
Expect(resp.Status).To(Equal("no_results"))
5050
})
5151
})
@@ -58,7 +58,7 @@ var _ = Describe("RagSearchCodeTool", func() {
5858
resJSON, err := tool.Execute(ctx, map[string]interface{}{"query": "test", "file_path": "main.go"})
5959
Expect(err).NotTo(HaveOccurred())
6060
var resp tools.ToolResponse
61-
json.Unmarshal([]byte(resJSON), &resp)
61+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
6262
Expect(resp.Status).To(Equal("error"))
6363
Expect(resp.Error).To(ContainSubstring("search failed"))
6464
})
@@ -87,7 +87,7 @@ var _ = Describe("RagSearchCodeTool", func() {
8787
resJSON, err := tool.Execute(ctx, map[string]interface{}{"query": "find func", "file_path": "main.go"})
8888
Expect(err).NotTo(HaveOccurred())
8989
var resp tools.ToolResponse
90-
json.Unmarshal([]byte(resJSON), &resp)
90+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
9191
Expect(resp.Status).To(Equal("success"), "Error: "+resp.Error)
9292

9393
// Verify Data list
@@ -147,7 +147,7 @@ var _ = Describe("RagSearchCodeTool", func() {
147147
Expect(err).NotTo(HaveOccurred())
148148

149149
var resp tools.ToolResponse
150-
json.Unmarshal([]byte(resJSON), &resp)
150+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
151151
Expect(resp.Status).To(Equal("success"), "Error: "+resp.Error)
152152
Expect(resp.Message).To(ContainSubstring("Auto-fetched 1 related dependencies"))
153153

@@ -196,7 +196,7 @@ var _ = Describe("RagSearchCodeTool", func() {
196196
Expect(err).NotTo(HaveOccurred())
197197

198198
var resp tools.ToolResponse
199-
json.Unmarshal([]byte(resJSON), &resp)
199+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
200200
Expect(resp.Status).To(Equal("success"), "Error: "+resp.Error)
201201

202202
// Only root result — dependency was skipped (not in index, no fallback)
@@ -242,7 +242,7 @@ var _ = Describe("RagSearchCodeTool", func() {
242242
resJSON, err := tool.Execute(ctx, map[string]interface{}{"query": "test", "file_path": "main.go"})
243243
Expect(err).NotTo(HaveOccurred())
244244
var resp tools.ToolResponse
245-
json.Unmarshal([]byte(resJSON), &resp)
245+
Expect(json.Unmarshal([]byte(resJSON), &resp)).NotTo(HaveOccurred())
246246
Expect(resp.Status).To(Equal("success"), "Error: "+resp.Error)
247247

248248
// Despite 3 identical relations, output should have exactly root + 1 Shared

internal/updater/updater.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"os"
1313
"path/filepath"
14+
"regexp"
1415
"runtime"
1516
"strings"
1617
"sync"
@@ -432,6 +433,13 @@ func fetchRemoteStableModel(ctx context.Context) (string, error) {
432433
return "", fmt.Errorf("ollama_embed key not found or empty in remote config.yaml")
433434
}
434435

436+
// Validate model name: allow alphanum, hyphens, dots, slashes, colons (tag separator).
437+
// Rejects anything that looks like shell injection or corrupted data.
438+
var validModel = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9./_-]*(:[a-zA-Z0-9][a-zA-Z0-9._-]*)?$`)
439+
if !validModel.MatchString(cfg.LLM.OllamaEmbed) {
440+
return "", fmt.Errorf("remote ollama_embed value %q is not a valid model name", cfg.LLM.OllamaEmbed)
441+
}
442+
435443
return cfg.LLM.OllamaEmbed, nil
436444
}
437445

pkg/parser/go/analyzer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestCodeAnalyzer_EdgeCases(t *testing.T) {
131131

132132
hiddenDir := filepath.Join(tmpDir, ".hidden")
133133
require.NoError(t, os.Mkdir(hiddenDir, 0755))
134-
os.WriteFile(filepath.Join(hiddenDir, "skip.go"), []byte("package hidden"), 0644)
134+
require.NoError(t, os.WriteFile(filepath.Join(hiddenDir, "skip.go"), []byte("package hidden"), 0644))
135135

136136
res, err := ca.AnalyzePaths([]string{tmpDir})
137137
assert.NoError(t, err)
@@ -148,7 +148,7 @@ type Data struct {
148148
Handler func(int) error
149149
}
150150
`
151-
os.WriteFile(filepath.Join(complexDir, "complex.go"), []byte(code), 0644)
151+
require.NoError(t, os.WriteFile(filepath.Join(complexDir, "complex.go"), []byte(code), 0644))
152152
res, err := ca.Analyze(context.Background(), complexDir)
153153
assert.NoError(t, err)
154154
assert.NotEmpty(t, res.Symbols)

pkg/parser/php/phpdoc.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ func parseTag(line string, doc *PHPDocInfo) {
162162
func convertPHPDocToReturnInfo(docReturns []ReturnDoc) []ReturnInfo {
163163
returns := make([]ReturnInfo, len(docReturns))
164164
for i, r := range docReturns {
165-
returns[i] = ReturnInfo{
166-
Type: r.Type,
167-
Description: r.Description,
168-
}
165+
returns[i] = ReturnInfo(r)
169166
}
170167
return returns
171168
}

pkg/workspace/tests/integration_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func TestBranchIsolationAndFeedbackPromotionIntegration(t *testing.T) {
7676

7777
req2 := contract.ResolveWorkspaceRequest{WorkspaceRoot: projectRoot}
7878
resp2, errRes := r.Resolve(ctx, req2)
79+
if errRes != nil {
80+
t.Fatalf("Step 2 resolve failed: %v", errRes)
81+
}
7982
if id1 == resp2.WorkspaceID {
8083
t.Errorf("Workspace IDs should be different for different branches")
8184
}

0 commit comments

Comments
 (0)