Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions internal/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,39 @@ func TestLoadEnvAndMergedSettings(t *testing.T) {
assert.Equal(t, "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", s.User.EthPrivateKey)
}

// helper to build a command with optional --broadcast flag and parse args
// helper to build a leaf workflow subcommand with the same CommandPath shape as the real CLI (cre workflow <use>).
func makeCmd(use string, defineBroadcast bool, args ...string) *cobra.Command {
cmd := &cobra.Command{
root := &cobra.Command{Use: "cre"}
workflow := &cobra.Command{Use: "workflow"}
leaf := &cobra.Command{
Use: use,
Run: func(cmd *cobra.Command, args []string) {},
}
if defineBroadcast {
cmd.Flags().Bool("broadcast", false, "broadcast the tx")
leaf.Flags().Bool("broadcast", false, "broadcast the tx")
}
_ = cmd.Flags().Parse(args) // parse only the provided flag args
return cmd
_ = leaf.Flags().Parse(args) // parse only the provided flag args
workflow.AddCommand(leaf)
root.AddCommand(workflow)
return leaf
}

// secretsCmdPath builds cre secrets <leaf> so CommandPath matches production.
func secretsCmdPath(leaf, secretsAuth string) *cobra.Command {
root := &cobra.Command{Use: "cre"}
secrets := &cobra.Command{Use: "secrets"}
secrets.PersistentFlags().String("secrets-auth", secretsAuth, "")
var leafCmd *cobra.Command
if leaf == "" {
leafCmd = secrets
} else {
leafCmd = &cobra.Command{Use: leaf, Run: func(cmd *cobra.Command, args []string) {}}
secrets.AddCommand(leafCmd)
}
root.AddCommand(secrets)
// Merge parent persistent flags into Flags() so GetString("secrets-auth") matches real CLI behavior.
_ = leafCmd.ParseFlags([]string{})
return leafCmd
}

func TestLoadEnvAndSettingsInvalidTarget(t *testing.T) {
Expand Down Expand Up @@ -455,6 +477,21 @@ func TestShouldSkipGetOwner(t *testing.T) {
cmd: makeCmd("deploy", false),
wantSkip: false,
},
{
name: "secrets list with browser auth → skip",
cmd: secretsCmdPath("list", "browser"),
wantSkip: true,
},
{
name: "secrets create with owner-key-signing → do NOT skip",
cmd: secretsCmdPath("create", "owner-key-signing"),
wantSkip: false,
},
{
name: "cre secrets root with browser auth → skip",
cmd: secretsCmdPath("", "browser"),
wantSkip: true,
},
}

for _, tc := range tests {
Expand All @@ -463,7 +500,7 @@ func TestShouldSkipGetOwner(t *testing.T) {
t.Parallel()
got := settings.ShouldSkipGetOwner(tc.cmd)
if got != tc.wantSkip {
t.Fatalf("ShouldSkipGetOwner(%q) = %v, want %v", tc.cmd.Name(), got, tc.wantSkip)
t.Fatalf("ShouldSkipGetOwner(%q) = %v, want %v", tc.cmd.CommandPath(), got, tc.wantSkip)
}
})
}
Expand Down
17 changes: 10 additions & 7 deletions internal/settings/workflow_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,23 @@ func IsValidChainName(name string) error {
}

// For commands that don't need the private key, we skip getting the owner address.
// ShouldSkipGetOwner returns true if the command is `simulate` and
// `--broadcast` is false or not set. `cre help` should skip as well.
// ShouldSkipGetOwner returns true for `cre workflow hash`; for `cre workflow simulate` when
// `--broadcast` is false or unset; and for any `cre secrets ...` command when `--secrets-auth` is browser.
func ShouldSkipGetOwner(cmd *cobra.Command) bool {
switch cmd.Name() {
case "help":
path := cmd.CommandPath()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

cre help is listed under isLoadSettings’s exclusions in cmd/root.go, so that path does not call AttachSettings / loadWorkflowSettings at all. In practice ShouldSkipGetOwner never runs for normal cre help.

switch path {
case "cre workflow hash":
return true
case "hash":
return true
case "simulate":
case "cre workflow simulate":
// Treat missing/invalid flag as false (i.e., skip).
// If broadcast is explicitly true, don't skip.
b, _ := cmd.Flags().GetBool("broadcast")
return !b
default:
if path == "cre secrets" || strings.HasPrefix(path, "cre secrets ") {
smethod, _ := cmd.Flags().GetString("secrets-auth")
return smethod == "browser"
}
return false
}
}
Expand Down
Loading