Skip to content

fix(cli): order CLI commands deterministically#4027

Open
assinscreedFC wants to merge 2 commits into
dlt-hub:develfrom
assinscreedFC:fix/cli-deterministic-command-order
Open

fix(cli): order CLI commands deterministically#4027
assinscreedFC wants to merge 2 commits into
dlt-hub:develfrom
assinscreedFC:fix/cli-deterministic-command-order

Conversation

@assinscreedFC

Copy link
Copy Markdown

Problem

group_commands (in dlt/_workspace/cli/compose.py) returned top-level and sub-commands in plugin discovery order, which varies from system to system. That non-determinism leaks into:

  • the CLI help output (dlt --help subcommand order), and
  • the generated reference docs/website/docs/reference/command-line-interface.md, producing spurious diffs / a flaky make check-cli-docs.

Closes #3454.

Fix

Sort the grouped commands deterministically before returning:

top = {name: top[name] for name in sorted(top)}
sub = {key: sub[key] for key in sorted(sub)}

Top-level commands are ordered alphabetically by name, sub-commands by (parent, command). Group contents keep their insertion order, so the primary command (group[0]) and the extend execute order are unaffected.

Result

dlt --help now lists {ai, dashboard, deploy, init, pipeline, schema, telemetry} in a stable order regardless of discovery order. Regenerated the CLI reference docs (make update-cli-docs) to match.

Tests

  • Added test_group_orders_commands_deterministically (regression for cli docs renderer works in non-deterministic order #3454): commands fed in non-alphabetical order come back sorted. Fails on devel, passes with the fix.
  • Existing test_cli_compose.py suite still green (single-key cases unaffected; within-group order preserved).
  • make check-cli-docs passes against the regenerated reference.
  • black --check, flake8, mypy clean on the changed files.

If you'd prefer a curated order over alphabetical, the sort key is a one-line change.

group_commands returned top-level and sub-commands in plugin discovery
order, which varies across systems. That non-determinism leaked into the
CLI help output and the generated command-line-interface.md reference,
producing spurious docs diffs.

Sort the grouped commands alphabetically by name (and sub-commands by
(parent, command)) before returning. Group contents keep their insertion
order, so the primary command and 'extend' execute order are unchanged.
Regenerated the CLI reference docs to match.

Fixes dlt-hub#3454
…rder

The previous docs regeneration ran without the 'cli' extra, which dropped
the 'dlt pipeline mcp' section. Regenerated with 'uv sync --extra cli
--group workspace-deps' (the env CI uses for check-cli-docs), so the only
change to the reference is deterministic reordering, no content loss.

Also add a test asserting the alphabetical key sort preserves within-group
order (primary command and 'extend' execute order).
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.

cli docs renderer works in non-deterministic order

1 participant