Skip to content
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

fix: write own device info when creating and adding projects #297

Merged
merged 21 commits into from
Oct 11, 2023

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Oct 2, 2023

Closes #289

exposes a $setOwnDeviceInfo() method on MapeoProject, which is used by the MapeoManager when calling createProject(), acceptProject(), and setDeviceInfo()

@achou11 achou11 requested a review from gmaclennan October 2, 2023 20:56
@achou11 achou11 force-pushed the 289/project-device-info-init branch from 98255f1 to 2fd8cb5 Compare October 2, 2023 21:00
src/mapeo-project.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
@achou11 achou11 force-pushed the 289/project-device-info-init branch from 2fd8cb5 to 669bda5 Compare October 2, 2023 21:19
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be done the "other way around", e.g. it is the responsibility of the MapeoManager class when it creates or adds a project to call project.setDeviceInfo().

As currently written, if we release a future version that allows non-device-owners to change their device info, and a device is running this older version, we will get an loop where the device would keep automatically changing it back.

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on "deviceId". Can talk it through if helpful

src/mapeo-project.js Outdated Show resolved Hide resolved
src/mapeo-project.js Outdated Show resolved Hide resolved
@achou11 achou11 changed the title fix: write device info to projects when instatiating fix: write own device info when creating and adding projects Oct 3, 2023
Comment on lines 224 to 226
if (deviceInfo.name) {
await project.$setOwnDeviceInfo({ name: deviceInfo.name })
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if this is desired behavior or not. keeping this means that one should call manager.setDeviceInfo() before adding or creating a project. Otherwise, attempting to use the $member namespace causes issues.

Comment on lines 377 to 380
if (deviceInfo.name) {
const project = await this.getProject(projectPublicId)
await project.$setOwnDeviceInfo({ name: deviceInfo.name })
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same concern as previously stated regarding needing to call manager.setDeviceInfo() first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found that there was a lot of overlap between the tests here and in various other places (both e2e + unit). It was getting harder to update this because of the trickiness with mocking the various contructor parameters, and felt like i was re-implementing a bad version of MapeoManager + MapeoProject. Decided that moving this to e2e to specifically test the $member namespace made more sense (see test-e2e/members.js)

Comment on lines 36 to 37
// TODO: Fails. Needs MemberApi.invite() to be updated to write device info record of invited peer
test('getting others after invite', { todo: true }, async (t) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test fails to run due to some additional work needed in the MemberApi implementation, namely saving the saving the invited member's device info when they accept.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • DeviceInfo and CoreOwnership records need to be written by the invited peer
  • The invitor needs to write the Role record
  • They need to sync after invite so each gets these records

@achou11 achou11 requested a review from gmaclennan October 3, 2023 19:55
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think actually the member namespace needs to be able to handle a device not having a name, and also no code ownership record existing for a device. It's possible that after an invite, the invite or writes the role record (so the device appears as a member) but sync does not complete, so no device info or code ownership record is received from the invited device. The api then needs to have name as optional, and we need to have a fallback in the UX - maybe just show the device ID (we haven't planned out device IDs yet - there was a discussion somewhere about it, I think base-32 of the truncated device key, maybe hashed too. That can be a separate issue.

@achou11
Copy link
Member Author

achou11 commented Oct 5, 2023

a note that this is waiting on #326 in order to update the MemberApi implementation to handle what is described in #297 (review)

@achou11 achou11 requested a review from gmaclennan October 9, 2023 21:07
@achou11 achou11 deleted the 289/project-device-info-init branch October 11, 2023 15:24
gmaclennan added a commit that referenced this pull request Oct 20, 2023
* main:
  feat: NamespaceSyncState improvements (#339)
  chore: update better-sqlite3 to 8.7.0 (#337)
  chore: update @mapeo/crypto to latest (#336)
  fix: write own device info when creating and adding projects (#297)
  Feat: add DataStore.writeRaw method (#334)
  feat: Add NamespaceSyncState (#313)
  chore: run CI on PRs against any branch (#330)
  feat: add capabilities.getAll() (#326)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Save relevant device info when initially creating/adding a project
2 participants