Skip to content

feat(cli): rename --default-branch (scan create) to --make-default-branch; harden default-branch flags#1230

Open
John-David Dalton (jdalton) wants to merge 6 commits intomainfrom
fix/scan-default-branch-misuse-detection
Open

feat(cli): rename --default-branch (scan create) to --make-default-branch; harden default-branch flags#1230
John-David Dalton (jdalton) wants to merge 6 commits intomainfrom
fix/scan-default-branch-misuse-detection

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 18, 2026

Summary

Ends the --default-branch overload between socket scan create and the socket repository commands by giving each command a flag name that matches what the Socket API actually does.

Command Before After API field
scan create --default-branch (bool) --make-default-branch (bool) make_default_branch
repository create --default-branch=<name> --default-branch=<name> (unchanged) default_branch
repository update --default-branch=<name> --default-branch=<name> (unchanged) default_branch

Why

--default-branch historically meant two different things:

  • On repository create/update: "the name of this repo's default branch" (string — sent as default_branch).
  • On scan create: "mark this scan as the default-branch scan" (boolean — sent as make_default_branch).

Same flag name, different shapes. Users naturally carried the string-accepting form over to scan create and lost their branch name silently (meow coerces a value on a boolean flag to true and drops the value). The root cause is the naming collision, not the parser behavior.

Changes

scan create

  • New flag: --make-default-branch (boolean) — primary name, mirrors the make_default_branch API field.
  • Legacy flag: --default-branch / --defaultBranch — kept as a deprecated alias via meow's aliases. Emits logger.warn on use so scripts keep working but authors know to migrate.
  • Misuse detection preserved: --default-branch=<name> and --default-branch <name> (space-separated) still produce an actionable error even though the flag is deprecated, because silently dropping the branch name is worse than nagging.
  • Help text: the misleading "Note: for a first run you probably want to set --default-branch to indicate the default branch name, like 'main' or 'master'" note is rewritten to describe what the flag actually does.

repository create / repository update

  • Flag name unchanged (--default-branch=<name> — it already matches the API field).
  • Added empty-value validation: bare --default-branch or --default-branch= now warns that a value is required.

Tests

  • cmd-scan-create.test.mts — new suite for --make-default-branch primary path; existing --default-branch misuse tests kept and extended to also assert the deprecation warning on legacy use.
  • cmd-repository-create.test.mts / cmd-repository-update.test.mts — new tests for the empty-value warning.

Test plan

  • pnpm run type
  • pnpm --filter @socketsecurity/cli run test:unit
  • pnpm run build:cli
  • Manual: socket scan create --default-branch shows deprecation warning; socket scan create --make-default-branch works; socket scan create --default-branch=main still errors with actionable message.
  • CHANGELOG updated under ### Changed and ### Deprecated.

`--default-branch` is a boolean meow flag, so
`--default-branch=main` silently becomes `defaultBranch=true` with
the `"main"` portion discarded. Users with that (reasonable)
intuition ended up with scans that weren't tagged with any branch
name and didn't show up in the Main/PR dashboard tabs.

Pre-flight check in `run()` scans the raw argv for
`--default-branch=<value>`. Values that coerce to boolean
(`true` / `false`, any case) are let through; anything else is
treated as a misuse and fails with:

    ✗ "--default-branch=main" looks like you meant the branch name "main".
    --default-branch is a boolean flag; pass the branch name with --branch instead:
      socket scan create --branch main --default-branch

Exits with code 2 (invalid usage), consistent with other flag
validation failures in this command.

Added tests:
  * misuse form with a branch-name value is caught and logged
  * explicit `--default-branch=true|false|TRUE` all pass through
  * bare `--default-branch` with paired `--branch main` flows through
@jdalton John-David Dalton (jdalton) force-pushed the fix/scan-default-branch-misuse-detection branch from 50d4d2b to 385aad4 Compare April 18, 2026 00:25
@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Comment thread packages/cli/src/commands/scan/cmd-scan-create.mts
Addresses Cursor bugbot feedback on PR #1230. yargs-parser expands
camelCase flag names, so users can type either --default-branch= or
--defaultBranch= from the shell. The pre-flight misuse check now
tests both prefixes.

Added a regression test for the camelCase variant.
@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d461dc7. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Comment thread packages/cli/src/commands/scan/cmd-scan-create.mts Outdated
@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d461dc7. Configure here.

Addresses Cursor bugbot feedback on PR #1230. findDefaultBranchValueMisuse
only returned the extracted value, so the error message always quoted
'--default-branch=<value>' even when the user typed the camelCase
'--defaultBranch=<value>' form. Return the matched prefix alongside the
value so the error quotes what the user actually typed.
@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 54f92cc. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 54f92cc. Configure here.

Match the sibling `cmd-scan-*` convention of placing
`export const cmd*` immediately before `async function run`, and drop
comments that restated the code rather than explaining non-obvious
*why*. The one remaining comment on the misuse check keeps the
meow/yargs-parser coercion detail, which isn't derivable from reading
the code.
@jdalton John-David Dalton (jdalton) changed the title fix(scan create): detect --default-branch=<name> misuse feat(cli): rename --default-branch (scan create) to --make-default-branch; harden default-branch flags Apr 20, 2026
…anch

Ends the --default-branch overload by aligning each command's flag name
with the Socket API field it triggers:

- scan create: new --make-default-branch (bool) mirrors `make_default_branch`.
  Legacy --default-branch / --defaultBranch kept as a deprecated boolean
  alias (declared as its own flag because meow's `aliases` forwarding
  was unreliable inside this command's flag set). Deprecation warning
  fires when the legacy name is used; misuse heuristic still catches
  --default-branch=<name> and --default-branch <name> on the deprecated
  alias.
- repository create / repository update: flag unchanged (already matches
  `default_branch`). Added empty-value validation that rejects bare
  --default-branch and --default-branch= instead of silently persisting
  a blank default-branch name.

Help text in cmd-scan-create.mts rewritten to describe what the flag
actually does (reassigns the repo's default-branch pointer).

Tests cover: primary flag happy path, primary flag misuse detection,
deprecation warning on legacy flag, back-compat wiring of legacy flag,
and empty-value rejection on both repository commands.
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.

2 participants