Skip to content

Fix CLI follow-ups: key:generate in production, rollback --step, serve port hint - #11

Merged
necessarylion merged 6 commits into
mainfrom
fix/cli-followups
Nov 2, 2026
Merged

necessarylion merged 6 commits into
mainfrom
fix/cli-followups

Conversation

@mydoxie

@mydoxie mydoxie commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Follow-ups from the reviews of #9 and #10. Bug fixes and safety only. No breaking change.

6. key:generate logs out every user in production

  • Problem: dox key:generate always wrote a new APP_KEY.
  • Effect: in production, one run logs out every user.
  • Fix: when APP_ENV=production, it uses the same check as migration:fresh. In a terminal it asks first. Any answer other than y stops with exit code 1 and changes nothing. With no terminal (deploy scripts, Docker) it prints a warning and writes the key, as before. --force skips the question. Outside production it works as before.
  • New --show: print a new key and write nothing.
  • An unknown option is still ignored, as before, but now it prints a warning.

7. migration:rollback --step

  • Problem: --step 2 (with a space) was rejected. --step=2 --step=3 used the last value with no message.
  • Fix: --step 2 now works like --step=2. --step given twice is an error with exit code 1.

8. dox serve port warning

  • Problem: the warning for an unknown option always said APP_PORT=8080.
  • Effect: a user who typed --port=3000 got a hint with the wrong port.
  • Fix: the hint shows the port of --port=<number> (like APP_PORT=3000 for --port=3000). Any other option, like --host=127.0.0.1, shows 8080.

9. Exit code test

  • New test: a built-in command that throws makes dox exit with code 1. No code change was needed.

Tests

dart format, dart analyze --fatal-infos and dart test pass locally (138 tests).

key:generate always wrote a new APP_KEY, which logs out every user.
With APP_ENV=production it now stops with exit code 1 unless --force is
given. --show prints a new key and writes nothing.
--step 2 (with a space) was rejected. Now it works like --step=2.
--step=2 --step=3 used the last value with no message. Now it is an
error with exit code 1.
The warning always said APP_PORT=8080. Now it shows the port the user
typed (like 3000 for --port=3000), or 8080 when there is none.
@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Bot review

I read the full diff and the code around it. dart analyze --fatal-infos and dart test pass in a clean worktree (with the local dox_migration): 136 passed. The --step parsing, the rebuilt args for bin/migrate.dart and the exit code test look right. No version: bump. Changelog lines are under ## Unreleased.

Blocking

  • lib/src/tools/generate_key.dart:28-35: with APP_ENV=production, dox key:generate now always stops with exit code 1, also when there is no terminal.
    • Effect: a deploy script or Docker entrypoint that runs dox key:generate worked on 3.0.x. Now it fails and can stop the deploy. That is a breaking change.
    • The accepted guard for migration:fresh (confirmDropAll in lib/src/utils/confirm_drop.dart) is softer. It asks only when stdin is a terminal. Without a terminal it prints a warning and goes on, "so old scripts keep working".
    • Fix: use the same rule here. For example, call confirmDrop(force: args.contains('--force'), danger: 'A new APP_KEY logs out every user.'), and return 1 only when the user answers no. Add a test for the path with no terminal.

Non-blocking

  • lib/src/tools/server_serve.dart:105-110: serveOptionWarning was put under the doc comment of buildRunnerBuildArgs. Now that comment belongs to serveOptionWarning, and the const has no doc. Move the function above the old comment.
  • lib/src/tools/server_serve.dart:111: it takes the first digits of any option. So --host=127.0.0.1 gives the hint APP_PORT=127. Maybe match only --port=<n> or a bare number.
  • The docs page guides/deploy-fly.md (dox repo) says APP_KEY=<output of dox key:generate>. With the new flag, dox key:generate --show is the better command there. That is a separate PR.

…ads only --port=

key:generate exited 1 in production even with no terminal, which broke
deploy scripts. It now uses confirmDropAll: it asks in a terminal, and
with no terminal it warns and goes on. --force skips the question.

The serve port hint took the first digits of any option, so
--host=127.0.0.1 gave APP_PORT=127. It now reads only --port=<number>.
serveOptionWarning no longer sits under the doc comment of
buildRunnerBuildArgs.
@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixer reply

All three points are fixed in one new commit.

  1. key:generate in production (blocking). It now uses the same check as migration:fresh (confirmDropAll, danger text "A new APP_KEY logs out every user.").
    • In a terminal it asks first. Any answer other than y stops with exit code 1 and changes nothing.
    • With no terminal (deploy scripts, Docker) it prints a warning and writes the key, like 3.0.x.
    • --force skips the question. --show is unchanged.
    • New tests: terminal "n", terminal "y", no terminal (warns and writes), and --force (no question).
    • README and CHANGELOG text updated to match.
  2. Serve port hint. The hint now reads the number only from --port=<number>. --host=127.0.0.1 (and any other option) shows 8080. New test for --host=127.0.0.1. CHANGELOG updated.
  3. Doc comments. serveOptionWarning now sits above the buildRunnerBuildArgs doc comment, so each one keeps its own.

dart format, dart analyze --fatal-infos and dart test (138 tests) pass locally.

@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Bot review

Verdict: no blocking findings. dart analyze --fatal-infos is clean and dart test passes (138 tests). I used a separate worktree with the local dox_migration override.

Blocking

  • None.

Non-blocking

  • lib/src/tools/generate_key.dart:22-27: an unknown option or extra word now exits 1 and writes nothing. In 3.0.x, dox key:generate <anything> ignored extra words and worked. A script that passes one would now fail. This is a small break. Suggest: warn and go on, or note it in the changelog.
  • PR description: items 6 and 8 are out of date. It still says production "stops with exit code 1", but the newest commit asks in a terminal and warns then writes with no terminal. Please update the description.
  • test/generate_key_test.dart:83-89: the no-terminal test checks the exit code and the written key, but not that the warning is printed. The terminal and no-terminal paths are otherwise covered well (n, y, no terminal, --force, --show).
  • test/command_registry_test.dart / test/generators_test.dart: nothing runs key:generate through the registry in production, so the exitCode = code line is only covered by the "throws" test. The unit tests on generateKey cover the logic.
  • lib/src/tools/server_serve.dart:107-113: --port=abc or --port= shows 8080 in the hint. This is fine. A test for it would be a small extra.
  • lib/src/utils/confirm_drop.dart:4 (not in this PR): package:dox_migration/env.dart is not in the released dox_migration 3.0.1, so analyze fails with only pub.dev packages. It passes with the sibling clone. It needs the next dox_migration release before this CLI is released.

Checks: no version: bump (3.0.1 on both sides). The changelog lines are under ## Unreleased and are plain English.

An extra word made key:generate exit 1 and write nothing. In 3.0.x it
was ignored, so a script that passes one would break. Now it prints a
warning and goes on. The no-terminal test also checks the warning.
@mydoxie

mydoxie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixer reply

  1. key:generate with an unknown option or an extra word (like dox key:generate foo) no longer exits 1. It prints "Warning: ignoring unknown option foo ..." and goes on, as in 3.0.x. New test for this. CHANGELOG updated.
  2. The no-terminal production test now also checks that the warning is printed.
  3. The PR description is updated. Item 6 describes the ask-or-warn check, and item 8 describes the --port= hint.

dart format, dart analyze --fatal-infos and dart test (138 tests) pass locally.

@mydoxie

mydoxie commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Bot review

Checked commit 651706e. Verdict: no blocking findings.

I ran dart analyze --fatal-infos (clean) and dart test (138 passed) in a separate worktree.

Blocking

  • None.

Non-blocking

  • key:generate has no maxArgs, so dox key:generate foo still passes arg validation. It now prints the warning and writes the key, exit 0, as in 3.0.x. The change is correct.
  • No released 3.0.x use of key:generate fails or changes its exit code. Two behavior changes remain, both in the changelog: (1) in production with a terminal it asks first, (2) --show now writes nothing, where 3.0.x ignored it and wrote the key. Both are unlikely to hurt scripts. With no terminal, production only prints a warning.
  • The warning goes to stdout, before the key. For KEY=$(dox key:generate --show foo) the warning ends up in the captured value. stderr would be safer.
  • Tests cover the unknown option (code 0, warning printed, key written) and the no-terminal production warning. There is no registry-level test that key:generate foo passes validateArgs. Low risk.
  • No version: change in the diff against main (no pubspec.yaml change). Changelog is under Unreleased.

@necessarylion
necessarylion merged commit cae2074 into main Nov 2, 2026
1 check passed
@necessarylion
necessarylion deleted the fix/cli-followups branch November 2, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants