🐛 Fix around() min middleware ordering for nested scopes#197
Conversation
Prepend instead of append when installing { at: "min" } middleware so
that innermost scope middleware gets interception priority, matching
effection v4-1-alpha's scope.reduce() walk-up semantics.
Before: min = [...min, middleware] — outer scope's min ran first
After: min = [middleware, ...min] — inner scope's min runs first
Ref: taras/executable-markdown-agents#55
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
* ✨ Support any handler type in context-api (sync, constants, operations) Bring context-api to parity with effection v4-1-alpha's API system by allowing API members to be any kind of value — not just Operations. - Sync functions are lifted to Operation-returning functions - Plain constants are lifted to Operations - Middleware type matches the handler's raw signature (sync stays sync) - Added isOperation() runtime guard with native iterable exclusion - Operation check comes before function check in type mapping to prevent misclassification of Operation implementations * 🐛 Fix around() min middleware ordering for nested scopes (#197)
Motivation
When
around()is called with{ at: "min" }in nested scopes, the outer scope's min middleware runs before the inner scope's — breaking the "innermost scope wins" invariant needed for provider/override patterns.The root cause:
min = [...min, middleware]appends the new middleware. Sincecombine()usesreduceRight, the first element in the array runs outermost. Appending makes the inner scope's middleware run closest to the handler, but the outer scope's middleware intercepts the call first — preventing the inner scope from overriding behavior.Discovered in: https://github.com/taras/executable-markdown-agents/pull/55 (vendored fix at commit 6cb693e).
Approach
mod.ts: changedmin = [...min, middleware]tomin = [middleware, ...min]— prepending ensures the most-recently-installed (innermost scope) middleware appears first, giving it interception priority viareduceRightcomposition