Skip to content

Conversation

@ivanauth
Copy link
Contributor

Fixes #556

Summary

Tests running with -count=10 would panic with "flag redefined" errors. Package-level cobra.Command global variables were reused across test runs, causing flag registration conflicts when InitialiseRootCmd was called multiple times in the same process.

Changes

  • Converted all register*Cmd functions to create fresh command instances locally instead of relying on global variables
  • Modified 13 files (9 in internal/cmd, 4 in internal/commands)
  • Added regression test TestMultipleInitialiseRootCmd to verify the fix

Test Plan

  • All tests pass with go test -race -count=10 ./internal/cmd
  • All tests pass with go test -race -count=10 ./internal/commands
  • New regression test verifies InitialiseRootCmd can be called multiple times
  • Commands still function correctly (zed version --help, zed schema --help)

This ensures InitialiseRootCmd is now idempotent and can be called multiple times without panicking.

Fixes authzed#556 where tests running with -count=10 would panic with
"flag redefined" errors. Package-level cobra.Command globals were
reused across test runs, causing flag registration conflicts.

Converted all register*Cmd functions to create fresh command
instances locally instead of relying on global variables. This
ensures InitialiseRootCmd can be called multiple times without
conflicts.

Added regression test TestMultipleInitialiseRootCmd to verify
the fix.
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 51.57895% with 138 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.31%. Comparing base (7ed5ab0) to head (ddcdd6f).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
internal/commands/permission.go 0.00% 55 Missing ⚠️
internal/commands/relationship.go 0.00% 46 Missing ⚠️
internal/commands/watch.go 0.00% 15 Missing ⚠️
internal/cmd/schema.go 81.25% 7 Missing and 2 partials ⚠️
internal/commands/schema.go 0.00% 8 Missing ⚠️
internal/cmd/validate.go 76.19% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #566      +/-   ##
==========================================
+ Coverage   39.28%   41.31%   +2.02%     
==========================================
  Files          37       37              
  Lines        5448     5800     +352     
==========================================
+ Hits         2140     2396     +256     
- Misses       3063     3148      +85     
- Partials      245      256      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it. Thank you!

@tstirrat15 tstirrat15 merged commit d7db764 into authzed:main Oct 20, 2025
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test TestCommandOutput: panic: list flag redefined: reveal-tokens [recovered, repanicked]

3 participants