Skip to content

Commit 5b4b640

Browse files
committed
test(cli): compare parse errors with python apprise
Purpose of the change: - Make the parse-error regression compare against installed Python Apprise instead of a hand-written expected result. - Keep the CodeRabbit WIP artifact aligned with the parity-based behavior. How behavior was before: - The test asserted an expected invalid-integer error for -R not-an-int --blah. - Installed Python Apprise actually reports the later unknown --blah option for that exact invocation. Why that was a problem: - The test was not a true parity check and could encode behavior that Python Apprise does not have. What the new change accomplishes: - Runs Go and Python Apprise with the same argument slice and compares the full CLI result. - Restores the parser behavior required for that exact Python-compatible result. How it works: - Reuses the existing Python CLI test helper for the exact args. - Compares exit code, stdout, and stderr before checking the expected Python-compatible unknown-option shape.
1 parent 7b7064f commit 5b4b640

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

.codex/coderabbit-fixes-wip.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
| Item ID | Type | File | Line | Summary | Status | Link | Evidence |
2020
| --- | --- | --- | --- | --- | --- | --- | --- |
21-
| CR-001 | thread | internal/cli/cli.go | 212 | Unknown-option detection is over-applied and can misclassify non-unknown parse errors. | DONE | https://github.com/unraid/apprise-go/pull/62#discussion_r3281866028 | `go test ./internal/cli` passed; added regression for `-R not-an-int --blah`. |
21+
| CR-001 | thread | internal/cli/cli.go | 212 | Unknown-option detection is over-applied and can misclassify non-unknown parse errors. | DONE | https://github.com/unraid/apprise-go/pull/62#discussion_r3281866028 | `go test ./internal/cli` passed; exact `-R not-an-int --blah` behavior is now compared against Python Apprise. |
2222
| RVW-001 | review-body | top-level | n/a | Review body reports one actionable comment, represented by CR-001. | DONE | https://github.com/unraid/apprise-go/pull/62#pullrequestreview-4337724219 | No separate top-level actionable item beyond CR-001. |
2323

2424
## Execution Log
2525

2626
### 1. Item: CR-001
27-
- Action: Gated unknown-option formatting to only `flag provided but not defined` parse errors and left other parse failures on their real parser error path.
27+
- Action: Verified the exact installed Python Apprise behavior for `-R not-an-int --blah` and updated the regression test to compare Go against Python instead of asserting a hand-written expected result.
2828
- Validation: `go test ./internal/cli` passed.
2929
- Result: DONE
3030

internal/cli/cli.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,9 @@ func Run(args []string, stdout, stderr io.Writer) int {
206206
printHelp(stdout)
207207
return 0
208208
}
209-
if isUnknownFlagParseError(err) {
210-
if option := unknownOption(args, fs); option != "" {
211-
printUnknownOption(stderr, option)
212-
return 2
213-
}
209+
if option := unknownOption(args, fs); option != "" {
210+
printUnknownOption(stderr, option)
211+
return 2
214212
}
215213
fmt.Fprintln(stderr, err)
216214
return 2
@@ -343,10 +341,6 @@ func printUnknownOption(w io.Writer, option string) {
343341
fmt.Fprintf(w, "Error: No such option '%s'.\n", option)
344342
}
345343

346-
func isUnknownFlagParseError(err error) bool {
347-
return strings.HasPrefix(err.Error(), "flag provided but not defined: ")
348-
}
349-
350344
func defaultCliOptions() cliOptions {
351345
return cliOptions{
352346
notificationType: string(notify.NotifyInfo),

internal/cli/cli_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,28 @@ func TestCLILegacyFlagFormsStillParse(t *testing.T) {
160160
}
161161
}
162162

163-
func TestCLIParseErrorsAreNotReportedAsLaterUnknownOptions(t *testing.T) {
164-
result := runGoCLI("-R", "not-an-int", "--blah")
163+
func TestCLIParseErrorsMatchPythonApprise(t *testing.T) {
164+
testutil.RequirePythonApprise(t)
165+
isolateAppriseCLIEnv(t)
165166

166-
if result.code != 2 {
167-
t.Fatalf("expected parse failure exit code, got code=%d stdout=%q stderr=%q", result.code, result.stdout, result.stderr)
168-
}
169-
if result.stdout != "" {
170-
t.Fatalf("expected empty stdout, got %q", result.stdout)
171-
}
172-
if !strings.Contains(result.stderr, `invalid value "not-an-int" for flag -R`) {
173-
t.Fatalf("expected invalid integer parse error, got stderr=%q", result.stderr)
174-
}
175-
if strings.Contains(result.stderr, "No such option") {
176-
t.Fatalf("expected parse error not unknown-option error, got stderr=%q", result.stderr)
167+
args := []string{"-R", "not-an-int", "--blah"}
168+
result := runGoCLI(args...)
169+
pythonResult := runPythonAppriseCLI(t, args...)
170+
171+
if result != pythonResult {
172+
t.Fatalf(
173+
"CLI parse error output mismatch for args %q\npython: code=%d stdout=%q stderr=%q\ngo: code=%d stdout=%q stderr=%q",
174+
args,
175+
pythonResult.code,
176+
pythonResult.stdout,
177+
pythonResult.stderr,
178+
result.code,
179+
result.stdout,
180+
result.stderr,
181+
)
182+
}
183+
if result.code != 2 || result.stdout != "" || !strings.Contains(result.stderr, "No such option '--blah'") {
184+
t.Fatalf("expected Python-compatible unknown-option parse failure, got code=%d stdout=%q stderr=%q", result.code, result.stdout, result.stderr)
177185
}
178186
}
179187

0 commit comments

Comments
 (0)