Skip to content

dotbot/cli: read swarm group options only before the subcommand - #299

Merged
geonnave merged 1 commit into
DotBots:mainfrom
geonnave:swarm-inject-prefix
Sep 24, 2026
Merged

geonnave merged 1 commit into
DotBots:mainfrom
geonnave:swarm-inject-prefix

Conversation

@geonnave

Copy link
Copy Markdown
Contributor

Symptom

dotbot swarm flash -y -s <file> did not pick up the swarm id from config. The same invocation without -s did.

Root cause

dotbot swarm prepends --conn / --swarm-id from the resolved config before handing the arguments to swarmit, unless the user already passed one of those flags. The "did the user pass it?" check scanned every token on the command line. -s is --swarm-id at the group level, but under flash it is --start, so flash -s was read as an explicit swarm id and the config value was never injected.

Fix

The injection now only looks at the group options, the tokens before the subcommand name. A new subcommand_index() walks the arguments using swarmit's own group definition, so it knows which group options take a value (-d ADDR, -sA001, --conn=..., short clusters like -vd ADDR) and stops at the first positional token. Anything after that belongs to the subcommand and can reuse short letters freely. --help anywhere still disables injection.

The same boundary fixes a second case: flash <name> (resolving a bundled app name to its fetched .bin) only triggered when flash was the very first token. With group options in front, such as dotbot swarm -d <addr> flash <name>, the name was passed through unresolved. It now resolves wherever the subcommand sits.

Open question for the reviewer

dotbot swarm -d X calibrate-lh2 ... is still not intercepted. The calibrate-lh2 intercept only matches when it is the first token, so with a group option in front the command falls through to the swarmit passthrough instead of the PyDotBot-native handler that carries the resolved config. Routing it through the intercept as-is would silently drop -d. My recommendation is an explicit error ("group options are not supported before calibrate-lh2") rather than a silent drop, but I left it out of this PR to keep it to the injection fix. Happy to add it here if you prefer.

Validation

Unit tests in dotbot/tests/test_cli_swarm_inject.py against a stub group shaped like swarmit's: flash -s no longer counts as a swarm id, group-level -s / --swarm-id / attached -sA001 still win over config, -d values and short clusters are skipped correctly, and flash <name> resolves after -d. Not run against a live swarm.

File + -
dotbot/cli/_swarm_inject.py +60 -9
dotbot/tests/test_cli_swarm_inject.py +86 -1
1 small file: dotbot/cli/swarm.py +6 -5
Total, 3 files +152 -15

`flash -s` is `--start`, but every token was scanned, so it read as
`--swarm-id` and the config swarm id was never injected. The same
boundary lets `flash <name>` resolve after group options such as `-d`.

AI-assisted: Claude Opus 5.5
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.29412% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.71%. Comparing base (56e2637) to head (3c38c05).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dotbot/tests/test_cli_swarm_inject.py 93.61% 3 Missing ⚠️
dotbot/cli/_swarm_inject.py 96.87% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
+ Coverage   84.65%   84.71%   +0.05%     
==========================================
  Files         204      204              
  Lines       25336    25410      +74     
  Branches     1822     1821       -1     
==========================================
+ Hits        21449    21526      +77     
+ Misses       3880     3876       -4     
- Partials        7        8       +1     
Flag Coverage Δ
console 75.59% <ø> (ø)
frontend 97.66% <ø> (-0.14%) ⬇️
python 86.19% <95.29%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
dotbot/cli/swarm.py 88.57% <100.00%> (+35.63%) ⬆️
dotbot/cli/_swarm_inject.py 98.03% <96.87%> (-1.97%) ⬇️
dotbot/tests/test_cli_swarm_inject.py 96.15% <93.61%> (-3.85%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@geonnave
geonnave merged commit 64c3e5e into DotBots:main Sep 24, 2026
16 checks passed
@geonnave
geonnave deleted the swarm-inject-prefix branch September 24, 2026 07:11
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