Conversation
WalkthroughPorts-related CLI options transition from single strings to goflags.StringSlice. Flag registration updates to accept file or comma-separated inputs. Port loading logic now parses slices (including file-expanded values) and removes direct os.ReadFile usage. Exclusion ports parsing aligns with the new slice-based approach. Tests updated accordingly. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as CLI User
participant Flags as goflags Parser
participant Runner as runner.ParseOptions
participant Ports as runner.loadPorts
CLI->>Flags: Provide --ports-file / --exclude-ports<br/>(file or comma-separated)
Note over Flags: Handles file expansion + splitting into slices
Flags-->>Runner: Options{PortsFile:StringSlice, ExcludePorts:StringSlice}
Runner->>Ports: parsePortsSlice(Options.PortsFile)
Ports-->>Runner: []int ports
Runner->>Ports: parsePortsSlice(Options.ExcludePorts)
Ports-->>Runner: []int excluded
Runner->>Runner: Apply exclusions and proceed
Note over Runner: No direct file I/O in ports.go
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/runner/ports.go (1)
27-36: Harden parsing: prevent 0/negative ports (critical).Switching to parsePortsSlice for ports-file means inputs like "0", "-1", or "-1-2" will be accepted and even expanded, producing invalid ports. Enforce 1 ≤ port ≤ 65535 for single ports and ranges.
Also wrap underlying errors with %w for better context.
Apply:
- ports, err := parsePortsSlice(options.PortsFile) + ports, err := parsePortsSlice(options.PortsFile) if err != nil { - return nil, fmt.Errorf("could not read ports: %s", err) + return nil, fmt.Errorf("could not read ports: %w", err) } portsFileMap, err = excludePorts(options, ports) if err != nil { - return nil, fmt.Errorf("could not read ports: %s", err) + return nil, fmt.Errorf("could not read ports: %w", err) }And update parsePortsSlice to validate bounds:
func parsePortsSlice(ranges []string) ([]*port.Port, error) { @@ - if strings.Contains(r, "-") { + if strings.Contains(r, "-") { parts := strings.Split(r, "-") if len(parts) != portListStrParts { return nil, fmt.Errorf("invalid port selection segment: '%s'", r) } p1, err := strconv.Atoi(parts[0]) if err != nil { return nil, fmt.Errorf("invalid port number: '%s'", parts[0]) } p2, err := strconv.Atoi(parts[1]) if err != nil { return nil, fmt.Errorf("invalid port number: '%s'", parts[1]) } - if p1 > p2 || p2 > 65535 { - return nil, fmt.Errorf("invalid port range: %d-%d", p1, p2) - } + if p1 < 1 || p2 < 1 || p1 > p2 || p2 > 65535 { + return nil, fmt.Errorf("invalid port range: %d-%d", p1, p2) + } for i := p1; i <= p2; i++ { port := &port.Port{Port: i, Protocol: portProtocol} ports = append(ports, port) } } else { portNumber, err := strconv.Atoi(r) - if err != nil || portNumber > 65535 { + if err != nil || portNumber < 1 || portNumber > 65535 { return nil, fmt.Errorf("invalid port number: '%s'", r) } port := &port.Port{Port: portNumber, Protocol: portProtocol} ports = append(ports, port) }
🧹 Nitpick comments (1)
pkg/runner/ports_test.go (1)
51-57: Add tests for UDP, ranges, and file-expanded inputs.Now that exclusions/ports file go through slice parsing, add coverage for:
- UDP prefix (e.g., "u:53", "u:53-55")
- Invalid numbers (e.g., "0", "-1", "-1-2") to confirm they error out once parse is hardened
- File-expanded values when using FileCommaSeparatedStringSliceOptions
I can draft these test cases if you want.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pkg/runner/options.go(2 hunks)pkg/runner/ports.go(2 hunks)pkg/runner/ports_test.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/runner/ports.go (1)
pkg/port/port.go (1)
Port(10-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: build-mac
- GitHub Check: release-test-mac
- GitHub Check: build-linux
- GitHub Check: build-windows
- GitHub Check: release-test-windows
- GitHub Check: Functional Test (ubuntu-latest)
- GitHub Check: Lint Test
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
pkg/runner/ports_test.go (1)
7-7: Import change looks good.Aligns tests with updated API using goflags.StringSlice.
pkg/runner/options.go (2)
155-157: Flag wiring looks correct.Using FileCommaSeparatedStringSliceOptions on -ep/-pf aligns with the new parsing path.
57-59: API change applied; no string expectations remain Ensure downstreams consume goflags.StringSlice for PortsFile and ExcludePorts.
closes #1558
Summary by CodeRabbit
New Features
Documentation