Skip to content

fix(node): validate --format before bootstrap does any work - #187

Merged
tas50 merged 1 commit into
mainfrom
fix/bootstrap-validates-format-first
Sep 8, 2026
Merged

fix(node): validate --format before bootstrap does any work#187
tas50 merged 1 commit into
mainfrom
fix/bootstrap-validates-format-first

Conversation

@tas50

@tas50 tas50 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

The defect

node bootstrap resolved --format after the SSH run. Every other command in the tree resolves it first, before touching anything.

So a typo costs the user a real bootstrap. With --format yaml, the command generates a client key, creates the client on the server, connects over SSH, runs the installer, and only then fails:

error = printer: unknown output format "yaml" (want human or json)
client created on server = true; ssh runs = 1

The user is left with an orphaned client on the server and a half-configured host, plus a non-zero exit that mentions neither. bootstrap is the single most side-effecting command in the CLI, which makes it the worst place to validate flags late.

The fix

Resolve the format at the top of RunE. Nothing else moves.

Tests

TestNodeBootstrapRejectsBadFormatBeforeDoingWork drives the real command with a bad --format and asserts no client was created and no SSH ran. Verified red before the fix by stashing it:

--- FAIL: TestNodeBootstrapRejectsBadFormatBeforeDoingWork
    a client was created on the server before --format was validated
    bootstrap ran over SSH before --format was validated: [...]

go test ./..., go vet ./..., and gofmt -l . are clean.

Note

This touches the same function as the --dry-run profile-validation fix in the sibling PR. They are independent changes so they are separate PRs as requested, but whichever lands second will want a trivial rebase.

@tas50
tas50 force-pushed the fix/bootstrap-validates-format-first branch from 95d2412 to 05deeab Compare September 8, 2026 15:16
`node bootstrap` resolved --format after the SSH run, so a typo cost the
user a real bootstrap first. With `--format yaml` the command generated a
client key, created the client on the server, connected over SSH and ran
the installer, and only then failed:

  error = printer: unknown output format "yaml" (want human or json)
  client created on server = true; ssh runs = 1

The user is left with an orphaned client and a half-configured host, and
a non-zero exit that says nothing about either.

Resolve the format first, as every other command in the tree already
does. Nothing else moves.

Signed-off-by: Tim Smith <tim@mondoo.com>
@tas50
tas50 force-pushed the fix/bootstrap-validates-format-first branch from 05deeab to a32afbd Compare September 8, 2026 17:32
@tas50
tas50 merged commit 65ebf1d into main Sep 8, 2026
6 checks passed
@tas50
tas50 deleted the fix/bootstrap-validates-format-first branch September 8, 2026 17:35
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