Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a server-side Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ScanningService as "Scanning Service"
participant ServerConfig as "Server Config"
participant Scanner as "Scanner/Engine"
Client->>ScanningService: POST /scan (file + optional flags header)
ScanningService->>ServerConfig: Read ScanFlags & AllowFlagsOverride
alt AllowFlagsOverride == false and Server ScanFlags > 0 and flags present
ScanningService-->>Client: Emit warning (flags ignored)
ScanningService->>ScanningService: Clear request flags
else AllowFlagsOverride == true and flags present
ScanningService-->>Client: Debug log (using request flags)
end
ScanningService->>Scanner: Start scan with resolved flags + file
Scanner-->>ScanningService: Return scan result
ScanningService-->>Client: HTTP 200 + result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/service/scanning_service_test.go (1)
670-673: Variable shadowing reduces clarity.The variables
fieldName(line 670) andfile(line 673) shadow outer-scope variables with the same names. While this works correctly, it could cause confusion during maintenance.♻️ Suggested fix to avoid shadowing
for _, test := range tests { t.Run(test.name, func(t *testing.T) { myConfig.Scanning.ScanFlags = test.serverFlags myConfig.Scanning.AllowFlagsOverride = test.allowFlagsOverride myConfig.Scanning.ScanBinary = binary - filePath := file - fieldName := fieldName + filePath := file // use outer `file` directly or rename postBody := new(bytes.Buffer) mw := multipart.NewWriter(postBody) - file, err := os.Open(filePath) + wfpFile, err := os.Open(filePath) if err != nil { t.Fatal(err) } - writer, err := mw.CreateFormFile(fieldName, filePath) + writer, err := mw.CreateFormFile(fieldName, filePath) // use outer fieldName directly if err != nil { t.Fatal(err) } - if _, err = io.Copy(writer, file); err != nil { + if _, err = io.Copy(writer, wfpFile); err != nil { t.Fatal(err) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/service/scanning_service_test.go` around lines 670 - 673, The test currently shadows outer-scope variables by re-declaring fieldName and file with := inside the multipart setup; update the block in scanning_service_test.go (around the multipart writer setup) to avoid shadowing by either using assignment (fieldName = fieldNameVal; openedFile, err = os.Open(filePath)) or renaming the locals (e.g., localFieldName and openedFile) and replacing uses of fieldName and file in that scope; ensure you still check and handle err after opening the file and close the openedFile when done.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/service/scanning_service_test.go`:
- Around line 670-673: The test currently shadows outer-scope variables by
re-declaring fieldName and file with := inside the multipart setup; update the
block in scanning_service_test.go (around the multipart writer setup) to avoid
shadowing by either using assignment (fieldName = fieldNameVal; openedFile, err
= os.Open(filePath)) or renaming the locals (e.g., localFieldName and
openedFile) and replacing uses of fieldName and file in that scope; ensure you
still check and handle err after opening the file and close the openedFile when
done.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a560e008-1512-42f6-9d7e-f24862bfef78
📒 Files selected for processing (5)
CHANGELOG.mdconfig/app-config-prod.jsonpkg/config/server_config.gopkg/service/scanning_service.gopkg/service/scanning_service_test.go
pkg/service/scanning_service_test.go
Outdated
| } | ||
| } | ||
|
|
||
| func TestScanDirectSingleFlags(t *testing.T) { |
There was a problem hiding this comment.
should the test excercises 'getConfigFromRequest' and check the override behaviour instead of the asserting http.StatusOK?
Example:
tests := []struct {
name string
serverFlags int
allowFlagsOverride bool
clientFlags string
want int
wantFlags string // flags actually used in the scan
}{
{
name: "Scanning - server flags only",
serverFlags: 1248,
allowFlagsOverride: false,
clientFlags: "256",
want: http.StatusOK,
wantFlags: "1248",
},
....
`
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
myConfig.Scanning.ScanFlags = test.serverFlags
myConfig.Scanning.AllowFlagsOverride = test.allowFlagsOverride
req := httptest.NewRequest(http.MethodPost, "/scan/direct", nil)
req.Header.Set("flags", test.clientFlags)
apiService := NewAPIService(myConfig)
cfg, err := apiService.getConfigFromRequest(req, logger)
assert.NoError(t, err)
assert.Equal(t, test.wantFlags, cfg.Flags)
})
}`
There was a problem hiding this comment.
yes. will implement that
Summary by CodeRabbit
New Release
Bug Fixes
Tests