fix: dispatch plugin CLI commands#591
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Enables wfctl to route unknown top-level commands to installed external plugins that declare cliCommands, using $WFCTL_PLUGIN_DIR (or the default data/plugins) as the discovery root, and tightens validation so plugins cannot shadow any built-in wfctl command names.
Changes:
- Treats all static wfctl command names as reserved during plugin CLI command validation (via
commandsmap). - Adds main dispatch path to execute plugin binaries for unknown commands discovered from installed plugins.
- Extends tests to cover the “all static commands are reserved” invariant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/wfctl/plugin_cli_commands.go | Expands reserved-name detection to include all static command names in commands. |
| cmd/wfctl/plugin_cli_commands_test.go | Updates fixtures and adds coverage asserting every static command is reserved. |
| cmd/wfctl/main.go | Adds runtime dispatch for unknown commands via plugin cliCommands and chooses plugin directory via env/default. |
Comment on lines
+189
to
+193
| if _, isStatic := commands[cmd]; !isStatic { | ||
| registry, err := BuildCLIRegistry(defaultPluginCommandDir()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "error: load plugin CLI commands: %v\n", err) //nolint:gosec // G705 | ||
| os.Exit(1) |
Comment on lines
+190
to
+197
| registry, err := BuildCLIRegistry(defaultPluginCommandDir()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "error: load plugin CLI commands: %v\n", err) //nolint:gosec // G705 | ||
| os.Exit(1) | ||
| } | ||
| if entry := registry.LookupCLICommand(cmd); entry != nil { | ||
| if err := DispatchCLICommand(entry, os.Args[1:]); err != nil { | ||
| fmt.Fprintf(os.Stderr, "error: %v\n", err) //nolint:gosec // G705 |
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
3 tasks
intel352
added a commit
that referenced
this pull request
May 10, 2026
…name (#595) PR #591 wired BuildCLIRegistry into main.go's dispatch fallback, but the binary-path computation joined manifest.Name twice: binaryPath := filepath.Join(pluginsDir, pluginName, pluginName) where pluginName comes from the manifest map key (= manifest.Name). This works only when the install directory name matches the manifest name. In practice setup-plugins composite + `wfctl plugin install` both extract tarballs to short directory names — `data/plugins/payments`, `data/plugins/digitalocean`, etc. — while the binary inside is named after the manifest (`workflow-plugin-payments`). The path therefore resolved to: data/plugins/workflow-plugin-payments/workflow-plugin-payments which doesn't exist, so DispatchCLICommand reported a fork/exec failure. Worse, when LookupCLICommand succeeded but Dispatch failed, operators got a confusing "no such file" error rather than the plugin's own help. Refactor BuildCLIRegistry to walk the plugins directory once and capture both the dir name (for the install path) and the manifest name (for the binary file name): binaryPath := filepath.Join(pluginsDir, dirEntry, manifest.Name) LoadPluginManifests is no longer used by this path because its keyed return collapses on manifest.Name and loses the dir name. Reproducer + regression tests: TestPluginCLIRegistry_DirVsManifestNameMismatch — short dir + full manifest name (the bug from buymywishlist#260 retrigger). TestPluginCLIRegistry_EmptyManifestNameUsesDirName — covers the fallback when manifest.Name is empty. Local repro (pre-fix) reported: fork/exec /tmp/test-plugins/workflow-plugin-payments/workflow-plugin-payments: no such file or directory Same plugin tree post-fix dispatches correctly (binary lives at /tmp/test-plugins/payments/workflow-plugin-payments). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wfctlcommands through installed plugincliCommands$WFCTL_PLUGIN_DIRordata/pluginsfor plugin command discoveryVerification
GOWORK=off go test ./cmd/wfctl -run 'TestPluginCLIRegistry|TestStaticCommandWins|TestRunValidatePluginDir'GOWORK=off go test ./cmd/wfctlworkflow-plugin-compute:wfctl compute audit,pools,run, andenrollrouted through the installed plugin path to a local compute-serverReview
workflow-plugin-computebefore relying on this path.