-
Notifications
You must be signed in to change notification settings - Fork 15
refactor(appkit): own asUser OBO wrapping in Plugin proxy #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MarioCadenas
wants to merge
1
commit into
main
Choose a base branch
from
mario/refactor-asuser-proxy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+626
−98
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review: PR #385 — refactor(appkit): own asUser OBO wrapping in Plugin proxy
Context
PR #385 moves OBO-side
exports()wrapping out ofAppKit#wrapWithAsUserand intoPlugin.asUser's proxy. The cross-fileUSER_CONTEXT_SYMBOLbridge is removed, and two inline Proxy literals (real OBO + dev fallback) collapse into a single_createAsUserProxy(wrapCall)factory. A 26-test file covering proxy mechanics is added.Scope: 4 files changed in
packages/appkit/— context/index.ts, core/appkit.ts, plugin/plugin.ts, plugin/tests/asUser-proxy.test.ts (new)Reviewers dispatched: correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, kieran-typescript, reliability, api-contract
Review Findings
P2 — Moderate
packages/appkit/src/plugin/plugin.ts:52isPlainObjectimplementation. Identical logic exists atplugin.ts:52(module function) andappkit.ts:180(static method). Two sources of truth for the same check — if logic needs to change, both must be updated independently.manual -> humanpackages/appkit/src/plugin/plugin.ts:65wrapExportFunctionsmutates input object in-place. Currently safe becauseexports()returns a fresh object per call, but fragile if a plugin ever caches the result. The docstring says "Mutates and returns" but thewrapnaming suggests a non-mutating operation.advisory -> humanpackages/appkit/src/plugin/plugin.ts:75wrapExportFunctions. Recursive descent into nested plain objects has no cycle detection. Extremely unlikely with real plugin exports (shallow structures,isPlainObjectrejects arrays/class instances), but undocumented limitation.advisory -> humanP3 — Low
packages/appkit/src/plugin/plugin.ts:70Object.hasOwn()check.Object.keys()on line 69 already returns only own enumerable keys, so thehasOwnguard on line 70 can never be true — dead code.safe_auto -> review-fixerPre-existing (not introduced by this PR)
packages/appkit/src/core/appkit.ts:172(plugin as any).asUser(req).exports()cast loses type safety. Pre-existing pattern — the old code also used(plugin as any)withUSER_CONTEXT_SYMBOL.Testing Gaps
exports()returning non-plain, non-function values (Map, Set, Array as top-level return) — the fallthrough atplugin.ts:502is uncoveredplugin.exports()throws duringwrapWithAsUserwrapExportFunctionsandisPlainObjecthave no isolated unit tests (only tested indirectly through proxy integration)Coverage Notes
docs/solutions/directory exists — no institutional learnings to surfaceVerdict: Ready to merge (with optional improvements)
The core refactoring is sound — consolidating two Proxy literals into
_createAsUserProxy(wrapCall)is a clear improvement that eliminates the cross-fileUSER_CONTEXT_SYMBOLbridge. The 26-test file is thorough and well-organized, covering real OBO, dev fallback, exports interception, async propagation, concurrent user isolation, and boundary cases.No P0 or P1 issues found in the PR's committed changes. The findings below are improvements, not blockers.
Improvement Plan
Fix 1: Remove redundant
Object.hasOwn()check (P3)File:
packages/appkit/src/plugin/plugin.ts:70Remove the dead
if (!Object.hasOwn(exports, key)) continue;guard sinceObject.keys()on line 69 already returns only own enumerable keys.Optional improvements (not blocking merge)
Deduplicate
isPlainObject— Extract to a shared utility (e.g.packages/appkit/src/utils.ts) or haveplugin.tsimportAppKit.isPlainObjectfromappkit.ts. Both files (plugin.ts:52andappkit.ts:180) have identical implementations.Add test for non-plain-object top-level exports — Add a test case where
exports()returns a Map or Array as the top-level value, verifying it's returned as-is without wrapping (theplugin.ts:502fallthrough path).Add test for mixed async/sync exports — Verify that an exports object with both async and sync functions preserves their semantics when wrapped.
Verification
After making changes: