open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

refactor(test): unify config compat helpers to use cobra subcommand tree

Open lizhengfeng101 opened this issue 4 months ago • 2 comments

Description

In compat_test.go, the test compatibility helpers for config commands use manual arg slicing and hand-written dispatch, while all other helpers in the same file use cobra subcommand trees:

Function Style Lines
parseReviewFlags cobra ✅ 7–21
parseScanFlags cobra ✅ 54–69
runSession cobra ✅ 110–130
parseConfigArgs manual slicing ❌ 30–49
runConfig manual dispatch ❌ 136–166

parseConfigArgs manually checks len(args) and slices into a configAction struct. runConfig does a switch args[0] to route subcommands — duplicating the routing that config_cmd.go already defines via cobra's AddCommand.

This inconsistency means:

  • The test compat layer can drift from production routing logic.
  • New config subcommands must be added in both the cobra tree and the manual dispatch.

Scope

  • File: cmd/opencodereview/compat_test.go
  • Functions: parseConfigArgs, runConfig, configAction, configParseError
  • Refactor to use cobra subcommand tree, matching the pattern used by runSession.

Acceptance Criteria

  • [ ] parseConfigArgs and runConfig replaced with cobra-based helpers (similar to runSession)
  • [ ] configAction and configParseError types removed if no longer needed
  • [ ] All existing config tests continue to pass with identical behavior
  • [ ] Tests pass (make test)
  • [ ] Code check passes (make check)

Context

Discovered during code review of the Cobra CLI migration PR. The other compat helpers were properly migrated to cobra, but the config helpers retained the pre-migration manual parsing style.

lizhengfeng101 avatar Jul 31 '26 09:07 lizhengfeng101

would love to take this up.

Haxor44 avatar Jul 31 '26 12:07 Haxor44

I'd like to take this. I've rebuilt runConfig on a fresh cobra tree that mirrors the production config command and dropped the manual parseConfigArgs/configAction/configParseError helpers. PR coming.

DoTuanAnh2k1 avatar Jul 31 '26 15:07 DoTuanAnh2k1