Fix #1901: share_cube_with_user passes swapped args to _validate_cube_access — fails for ev#1903
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1901: share_cube_with_user passes swapped args to _validate_cube_access — fails for ev#1903Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
share_cube_with_user(cube_id, target_user_id) called _validate_cube_access(cube_id, target_user_id), but the validator signature is (user_id, cube_id). The cube_id therefore landed in the user_id slot and _validate_user_exists raised "User '<cube_id>' does not exist or is inactive" for every well-formed call, making the API unusable. The in-code comment "Validate current user has access to this cube" already documented the correct intent: the sharing user (self.user_id) must have access to the cube being shared, not the target. Switch the call to self._validate_cube_access(self.user_id, cube_id). The target user's existence is independently checked on the next line via validate_user(target_user_id), so that path is unchanged. Add regression tests in tests/mem_os/test_memos_core.py that pin down: - validate_user_cube_access is consulted with (self.user_id, cube_id), - add_user_to_cube is called with (target_user_id, cube_id) on success, - a missing target raises "Target user '<id>' does not exist". Closes #1901
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed, 36 skipped). memos_local_plugin/smoke: 0 passed, 1 skipped, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s Branch: |
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.
Description
Fixes #1901:
MOSCore.share_cube_with_userwas broken for every well-formed call. The method calledself._validate_cube_access(cube_id, target_user_id), but the validator's signature is(user_id, cube_id). The cube UUID therefore landed in theuser_idslot and the first line of the validator (_validate_user_exists) raisedValueError: User '<cube_id>' does not exist or is inactivefor every invocation, making the share API completely unusable inb60616d/ PyPIMemoryOS==2.0.17.The in-code comment "Validate current user has access to this cube" already documented the correct intent: the sharing user (
self.user_id) — not the target — must own the cube being shared. The fix is a one-line change insrc/memos/mem_os/core.py:self._validate_cube_access(self.user_id, cube_id). The target user's existence is independently checked on the next line viavalidate_user(target_user_id), which is unchanged.Added three regression tests in
tests/mem_os/test_memos_core.py::TestShareCubeWithUser: (1) the happy path assertsvalidate_user_cube_accessis called with(self.user_id, cube_id)andadd_user_to_cubewith(target_user_id, cube_id); (2) the current user lacking cube access raises aValueErrorreferencing the current user (not the cube id); (3) a missing target user raises"Target user '<id>' does not exist". All three tests fail before the fix and pass after. Full mem_os test suite passes (28/28).ruff checkandruff format --checkare clean on both changed files.Related Issue (Required): Fixes #1901
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.
Reviewer Checklist