Repository navigation
fix(plugin-subcommands-advanced): run the preconditions of a subcommand piece - #282
Conversation
…nd piece The delegate installed on the parent now runs runPreconditions with the child piece as the target before its chatInputRun, and throws the denial so the command store emits chatInputCommandDenied. The function is read from the framework namespace, so the plugin still loads on frameworks older than 6.3.0. Closes #268
|
Architecture Data flow Review 1 finding · reviewed
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full single-commit diff, checked against the installed @wolfstar/http-framework 6.5.1 (runPreconditions, _emitCommandFailure), with the package tests run locally (all pass).
- Delegate runs piece preconditions —
wiring.tsnow awaitsrunPreconditions(child, "chatInput", interaction)beforechatInputRunand throws theUserErroron denial, so the command store emitschatInputCommandDenied, as the framework does for any denied command. - Older framework majors stay loadable —
runPreconditionsis read from the namespace at call time and skipped when absent, so the^3.1.0 || ^5.0.0peer range still links. - Tests — cover denial and success for direct and grouped subcommands, plus parent denial taking precedence over the child's.
- Docs and release — README note (including the double run of global preconditions), patch changeset, and
@sapphire/resultdevDependency with the matching lockfile entry.
claude-sonnet-5-5 | 𝕏
| function getRunPreconditions(): RunPreconditions | undefined { | ||
| const run = (framework as Record<string, unknown>)["runPreconditions"]; | ||
| return typeof run === "function" ? (run as RunPreconditions) : undefined; |
There was a problem hiding this comment.
Older framework loading goes untested
The new fallback protects supported frameworks that lack runPreconditions, but the tests import source code and use framework 6.5.1, where the export exists. They cannot catch a build change that turns this lookup into a required import and prevents older applications from starting.
Add a test that imports the built plugin with a framework version that lacks runPreconditions, then runs a modular subcommand.
Knowledge Base Used: Advanced subcommands plugin package
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/plugin-subcommands-advanced/src/lib/utils/wiring.ts
Line: 167-169
Comment:
**Older framework loading goes untested**
The new fallback protects supported frameworks that lack `runPreconditions`, but the tests import source code and use framework 6.5.1, where the export exists. They cannot catch a build change that turns this lookup into a required import and prevents older applications from starting.
Add a test that imports the built plugin with a framework version that lacks `runPreconditions`, then runs a modular subcommand.
**Knowledge Base Used:** [Advanced subcommands plugin package](https://app.greptile.com/-/switch-tenant?tenant=wolfstar-project&next=%2Fcustom-context%2Fknowledge-base%2Fwolfstar-project%2Fplugins%2F-%2Fdocs%2Fplugin-subcommands-advanced.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Addressed in #284 (#282 had already merged): older-framework.test.ts builds the entries and imports them in a Node process whose module hooks serve the framework without runPreconditions, and runs a modular subcommand with the export missing. Turning the lookup into a named import makes the build test fail with does not provide an export named 'runPreconditions'.

🔗 Linked issue
Resolves #268
🧭 Context
A subcommand piece registered with
RegisterAsSubcommandorRegisterAsSubcommandGroupis a command of its own, so it accepts thepreconditionsoption of@wolfstar/http-framework. Nothing checked it: the delegate the plugin installs on the parent only called the child'schatInputRun. A subcommand that setpreconditions: ['administrator']ran for everybody.📚 Description
The delegate now runs
runPreconditionswith the child piece as the target beforechatInputRun. On a denial it throws theUserError, so the command store emitschatInputCommandDeniedand replies as it does for any denied command. The parent's preconditions still run first, through the framework, and apply to every subcommand.runPreconditionsexists since framework 6.3.0, the release that added thepreconditionsoption. The plugin reads it from the framework namespace at call time instead of a named import, so it still loads on the older majors of its peer range (^3.1.0 || ^5.0.0), where nothing changes.Since
runPreconditionsalways runs the global preconditions first, those run a second time for a modular subcommand. The README notes this, so global preconditions should stay free of side effects such as a cooldown counter. Avoiding the double run would mean reimplementing the framework's And/Or array semantics, which it does not export.Key changes
src/lib/utils/wiring.ts: the delegate isasyncand checks the child's preconditions before running it.tests/subcommands-advanced.test.ts: a failing piece precondition denies a direct and a grouped subcommand without running it; a passing one runs it; a parent denial wins over the child's. Adds@sapphire/resultas a devDependency to build theResultvalues.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.The PR appears safe to merge, with a non-blocking request to test loading the built plugin on older frameworks.
Reviews (1) · Last reviewed commit: "fix(plugin-subcommands-advanced): run th..." · Reviewed by Greptile