Repository navigation
Port agent PRs to GO - 3 - #16596
Port agent PRs to GO - 3#16596
Conversation
📝 WalkthroughWalkthroughReplaces the AkShare stub with an HTTP-backed Eastmoney stock news tool, renames the crawler tool's primary input from ChangesAkShare Stock News Tool
Web Crawler Query Argument Rename
Estimated code review effort: 4 (Complex) | ~60 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 4
🧹 Nitpick comments (1)
internal/agent/tool/registry_test.go (1)
119-190: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCoverage gap: no test exercises
buildAkShareTool'stop_nvalidation.The alias/schema sweep here only builds
aksharewith empty params, so the unknown-key and non-positive/invalidtop_nerror paths inbuildAkShareTool(registry.go Lines 110-126) aren't covered here, unlike the dedicatedTestBuildAll_KeenableRejectsEmptyNodeAPIKeypattern (Lines 95-105). If akshare's own test file doesn't cover this either, consider adding a similar rejection test here.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/tool/registry_test.go` around lines 119 - 190, Add coverage for buildAkShareTool’s top_n validation by introducing a dedicated rejection test that exercises the akshare registry path with invalid input, since the current BuildAll alias/schema sweep only uses empty params and misses the unknown-key and non-positive/invalid top_n cases. Follow the pattern used by TestBuildAll_KeenableRejectsEmptyNodeAPIKey, and reference buildAkShareTool and BuildAll in the new test so the failure path is covered even if akshare’s own test file does not already assert it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/agent/tool/akshare_test.go`:
- Around line 31-40: The assertions inside the HTTP handler in akshare_test.go
should not use t.Fatalf because they run in a separate goroutine and can leave
the test in an inconsistent state. Update the handler logic in the test around
the request validation for r.URL.Path, json.Unmarshal, and req.Keyword to use
t.Errorf for failures and return immediately from the handler after each failed
check, so the main test can observe the error cleanly.
In `@internal/agent/tool/akshare.go`:
- Around line 156-207: The Eastmoney request is ignoring the resolved topN and
always using the default page size, so larger requested counts are never
honored. Update InvokableRun’s call path into buildAkShareStockNewsURL so the
effective topN is passed through, and change buildAkShareStockNewsURL to use
that value in the request payload instead of defaultAkShareTopN. Make sure the
generated URL/request in akshare.go reflects the caller’s requested top_n while
preserving the existing error handling and response parsing.
- Around line 177-183: The akshare response handling in parse flow currently
uses io.ReadAll on resp.Body without any size limit, which can consume unbounded
memory if the upstream payload is too large. Update the response reading logic
in the akshare request path to cap the body size before parsing the JSONP
payload, and keep the existing error wrapping and akshareErrJSON handling intact
when the read fails or the limit is exceeded.
In `@internal/agent/tool/registry.go`:
- Around line 110-126: The AkShare tool builder currently treats an unparsable
top_n as missing and silently falls back to the default, which hides
misconfiguration. Update buildAkShareTool to distinguish between an absent top_n
and a present-but-invalid one by checking the key before calling intParam, and
return an error when top_n exists but cannot be parsed as an integer. Keep the
existing validation and return path in buildAkShareTool/NewAkShareToolWithTopN,
but make sure invalid top_n inputs fail fast instead of using
defaultAkShareTopN.
---
Nitpick comments:
In `@internal/agent/tool/registry_test.go`:
- Around line 119-190: Add coverage for buildAkShareTool’s top_n validation by
introducing a dedicated rejection test that exercises the akshare registry path
with invalid input, since the current BuildAll alias/schema sweep only uses
empty params and misses the unknown-key and non-positive/invalid top_n cases.
Follow the pattern used by TestBuildAll_KeenableRejectsEmptyNodeAPIKey, and
reference buildAkShareTool and BuildAll in the new test so the failure path is
covered even if akshare’s own test file does not already assert it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ea3e05b4-f447-4b53-8c1c-12c1fb57536f
📒 Files selected for processing (7)
internal/agent/tool/akshare.gointernal/agent/tool/akshare_test.gointernal/agent/tool/crawler.gointernal/agent/tool/crawler_test.gointernal/agent/tool/registry.gointernal/agent/tool/registry_test.gotools/gen-component-parity/main.go
| func buildAkShareTool(params map[string]any) (einotool.BaseTool, error) { | ||
| topN := defaultAkShareTopN | ||
| if len(params) != 0 { | ||
| for key := range params { | ||
| if key != "top_n" { | ||
| return nil, fmt.Errorf("agent tool: tool %q only accepts node-level param top_n", "akshare") | ||
| } | ||
| } | ||
| if v, ok := intParam(params, "top_n"); ok { | ||
| topN = v | ||
| } | ||
| if topN <= 0 { | ||
| return nil, fmt.Errorf("agent tool: tool %q requires positive integer node-level param top_n", "akshare") | ||
| } | ||
| } | ||
| return NewAkShareToolWithTopN(nil, topN), nil | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm intParam's ok-return semantics on type mismatch
rg -n -A15 'func intParam' internal/agent/tool/registry.goRepository: infiniflow/ragflow
Length of output: 523
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect sibling tool builders and nearby validation patterns in registry.go
ast-grep outline internal/agent/tool/registry.go --view expanded || true
printf '\n---\n'
sed -n '1,260p' internal/agent/tool/registry.go | cat -n | sed -n '1,220p'Repository: infiniflow/ragflow
Length of output: 10100
Reject non-integer top_n values
internal/agent/tool/registry.go:118 — if top_n is present but not an integer, intParam returns false and the builder silently falls back to defaultAkShareTopN, masking a misconfiguration. Return an error when the key is present but unparsable.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/agent/tool/registry.go` around lines 110 - 126, The AkShare tool
builder currently treats an unparsable top_n as missing and silently falls back
to the default, which hides misconfiguration. Update buildAkShareTool to
distinguish between an absent top_n and a present-but-invalid one by checking
the key before calling intParam, and return an error when top_n exists but
cannot be parsed as an integer. Keep the existing validation and return path in
buildAkShareTool/NewAkShareToolWithTopN, but make sure invalid top_n inputs fail
fast instead of using defaultAkShareTopN.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/agent/tool/akshare.go`:
- Around line 270-281: The raw JSON handling in stripJSONP is being bypassed
whenever the body contains any parentheses, which can cause valid JSON to be
truncated. Update stripJSONP to check for a JSON payload first (using the
existing strings.HasPrefix(s, "{") path) before searching for parentheses, then
only extract the content inside (...) when the response is actually JSONP. Keep
the behavior and error message in stripJSONP consistent for invalid akshare
responses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 27eb9b61-4d92-4b1e-a702-d24b11044b9f
📒 Files selected for processing (7)
internal/agent/tool/akshare.gointernal/agent/tool/akshare_test.gointernal/agent/tool/crawler.gointernal/agent/tool/crawler_test.gointernal/agent/tool/registry.gointernal/agent/tool/registry_test.gotools/gen-component-parity/main.go
🚧 Files skipped from review as they are similar to previous changes (6)
- internal/agent/tool/crawler_test.go
- tools/gen-component-parity/main.go
- internal/agent/tool/registry_test.go
- internal/agent/tool/registry.go
- internal/agent/tool/crawler.go
- internal/agent/tool/akshare_test.go
| func stripJSONP(s string) (string, error) { | ||
| s = strings.TrimSpace(s) | ||
| start := strings.IndexByte(s, '(') | ||
| end := strings.LastIndexByte(s, ')') | ||
| if start < 0 || end <= start { | ||
| if strings.HasPrefix(s, "{") { | ||
| return s, nil | ||
| } | ||
| return "", fmt.Errorf("akshare: invalid JSONP response") | ||
| } | ||
| return strings.TrimSpace(s[start+1 : end]), nil | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Check for raw JSON before extracting between parentheses.
The HasPrefix(s, "{") fallback is only reached when no valid (...) pair exists. A raw JSON body that happens to contain parentheses (e.g. inside a string value) satisfies start >= 0 && end > start, so it gets truncated to the substring between the first ( and last ) instead of being returned intact. Reorder so the raw-JSON case is handled first.
🐛 Proposed fix
func stripJSONP(s string) (string, error) {
s = strings.TrimSpace(s)
+ if strings.HasPrefix(s, "{") {
+ return s, nil
+ }
start := strings.IndexByte(s, '(')
end := strings.LastIndexByte(s, ')')
if start < 0 || end <= start {
- if strings.HasPrefix(s, "{") {
- return s, nil
- }
return "", fmt.Errorf("akshare: invalid JSONP response")
}
return strings.TrimSpace(s[start+1 : end]), nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func stripJSONP(s string) (string, error) { | |
| s = strings.TrimSpace(s) | |
| start := strings.IndexByte(s, '(') | |
| end := strings.LastIndexByte(s, ')') | |
| if start < 0 || end <= start { | |
| if strings.HasPrefix(s, "{") { | |
| return s, nil | |
| } | |
| return "", fmt.Errorf("akshare: invalid JSONP response") | |
| } | |
| return strings.TrimSpace(s[start+1 : end]), nil | |
| } | |
| func stripJSONP(s string) (string, error) { | |
| s = strings.TrimSpace(s) | |
| if strings.HasPrefix(s, "{") { | |
| return s, nil | |
| } | |
| start := strings.IndexByte(s, '(') | |
| end := strings.LastIndexByte(s, ')') | |
| if start < 0 || end <= start { | |
| return "", fmt.Errorf("akshare: invalid JSONP response") | |
| } | |
| return strings.TrimSpace(s[start+1 : end]), nil | |
| } |
🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 270-270: : # ragflow/internal/ingestion/compilation/extractor [ragflow/internal/ingestion/compilation/extractor.test]
internal/ingestion/compilation/extractor/dep_relation.go:270:9: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:281:69: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:281:109: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:353:27: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:401:37: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:416:56: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:430:97: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:505:90: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:505:113: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:604:88: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:604:88: too many errors
(typecheck)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/agent/tool/akshare.go` around lines 270 - 281, The raw JSON handling
in stripJSONP is being bypassed whenever the body contains any parentheses,
which can cause valid JSON to be truncated. Update stripJSONP to check for a
JSON payload first (using the existing strings.HasPrefix(s, "{") path) before
searching for parentheses, then only extract the content inside (...) when the
response is actually JSONP. Keep the behavior and error message in stripJSONP
consistent for invalid akshare responses.
Summary
Port
#16415
#16417