Skip to content

fix(test): restore root flag Changed bits after Run and guard plain mode - #901

Merged
discostu105 merged 1 commit into
mainfrom
fix/run-flag-restore-followup
Dec 5, 2026
Merged

discostu105 merged 1 commit into
mainfrom
fix/run-flag-restore-followup

Conversation

@discostu105

Copy link
Copy Markdown
Member

Follow-up to #893, addressing its post-merge review.

  • Changed bits: a serialized cmd.Run restored the root flag values but not their pflag Changed bits. A later direct rootCmd.Execute() could then see outputFormatChanged() with the default format. Run now snapshots and restores those bits too. Production is unaffected, because every serialized Run resets them first.
  • Coverage: new TestRunRestoresRootFlags runs Run(--agent -o json version). It asserts that agent mode, plain mode and the Changed bits are off afterwards, and that a caller's cfgFile survives. I checked that it fails when either half of the restore is reverted.
  • Guard: the TestMain leak guard now checks plainMode as well. Running each test alone against it found three tests that leaked plain mode: TestDownloadExtensionValidation, TestNewPrinter and TestAgentModeAutoDetectWithExplicitJSON. They now restore it.

Verified: go build ./..., go vet ./cmd, and go test ./cmd ./pkg/engine with CLAUDECODE=1 AI_AGENT=… CLAUDE_CODE_ENTRYPOINT=cli set.

Follow-ups from the post-merge review of #893:
- A serialized cmd.Run now restores the root persistent flags' Changed bits
  along with gFlags, so a later direct rootCmd.Execute() no longer sees
  outputFormatChanged() for an -o it never passed.
- TestRunRestoresRootFlags pins the restore: --agent/-o leave agent mode,
  plain mode and the Changed bits off, and a caller's cfgFile survives.
- The TestMain leak guard also fails on a leaked gFlags.plainMode. That
  surfaced three tests that leaked it (TestDownloadExtensionValidation,
  TestNewPrinter, TestAgentModeAutoDetectWithExplicitJSON); they now
  restore it.
@discostu105
discostu105 requested a review from a team as a code owner December 5, 2026 03:33
@discostu105
discostu105 merged commit 7d1d818 into main Dec 5, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant