internal: incomplete vault systems behind feature flag (#2340)

This commit is contained in:
Mo
2023-06-30 09:01:56 -05:00
committed by GitHub
parent d16e401bb9
commit b032eb9c9b
638 changed files with 20321 additions and 4813 deletions

View File

@@ -1,5 +1,5 @@
/* eslint-disable no-undef */
import { BaseItemCounts } from '../lib/Applications.js'
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
import * as Factory from '../lib/factory.js'
import { createSyncedNoteWithTag } from '../lib/Items.js'
import * as Utils from '../lib/Utils.js'
@@ -16,7 +16,7 @@ describe('online conflict handling', function () {
beforeEach(async function () {
localStorage.clear()
this.expectedItemCount = BaseItemCounts.DefaultItems
this.expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
this.context = await Factory.createAppContextWithFakeCrypto('AppA')
await this.context.launch()
@@ -64,7 +64,7 @@ describe('online conflict handling', function () {
it('components should not be duplicated under any circumstances', async function () {
const payload = createDirtyPayload(ContentType.Component)
const item = await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
this.expectedItemCount++
@@ -91,7 +91,7 @@ describe('online conflict handling', function () {
it('items keys should not be duplicated under any circumstances', async function () {
const payload = createDirtyPayload(ContentType.ItemsKey)
const item = await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
this.expectedItemCount++
await this.application.syncService.sync(syncOptions)
/** First modify the item without saving so that
@@ -118,7 +118,7 @@ describe('online conflict handling', function () {
// create an item and sync it
const note = await Factory.createMappedNote(this.application)
this.expectedItemCount++
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
await this.application.syncService.sync(syncOptions)
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
@@ -128,11 +128,11 @@ describe('online conflict handling', function () {
const dirtyValue = `${Math.random()}`
/** Modify nonsense first to get around strategyWhenConflictingWithItem with previousRevision check */
await this.application.itemManager.changeNote(note, (mutator) => {
await this.application.mutator.changeNote(note, (mutator) => {
mutator.title = 'any'
})
await this.application.itemManager.changeNote(note, (mutator) => {
await this.application.mutator.changeNote(note, (mutator) => {
// modify this item locally to have differing contents from server
mutator.title = dirtyValue
// Intentionally don't change updated_at. We want to simulate a chaotic case where
@@ -238,7 +238,7 @@ describe('online conflict handling', function () {
it('should duplicate item if saving a modified item and clearing our sync token', async function () {
let note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
await this.application.syncService.sync(syncOptions)
this.expectedItemCount++
@@ -279,11 +279,11 @@ describe('online conflict handling', function () {
it('should handle sync conflicts by not duplicating same data', async function () {
const note = await Factory.createMappedNote(this.application)
this.expectedItemCount++
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
await this.application.syncService.sync(syncOptions)
// keep item as is and set dirty
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
// clear sync token so that all items are retrieved on next sync
this.application.syncService.clearSyncPositionTokens()
@@ -295,10 +295,10 @@ describe('online conflict handling', function () {
it('clearing conflict_of on two clients simultaneously should keep us in sync', async function () {
const note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
this.expectedItemCount++
await this.application.mutator.changeAndSaveItem(
await this.application.changeAndSaveItem(
note,
(mutator) => {
// client A
@@ -311,7 +311,7 @@ describe('online conflict handling', function () {
// client B
await this.application.syncService.clearSyncPositionTokens()
await this.application.itemManager.changeItem(
await this.application.mutator.changeItem(
note,
(mutator) => {
mutator.mutableContent.conflict_of = 'bar'
@@ -329,10 +329,10 @@ describe('online conflict handling', function () {
it('setting property on two clients simultaneously should create conflict', async function () {
const note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
this.expectedItemCount++
await this.application.mutator.changeAndSaveItem(
await this.application.changeAndSaveItem(
note,
(mutator) => {
// client A
@@ -369,12 +369,12 @@ describe('online conflict handling', function () {
const note = await Factory.createMappedNote(this.application)
const originalPayload = note.payloadRepresentation()
this.expectedItemCount++
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
await this.application.syncService.sync(syncOptions)
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
// client A
await this.application.itemManager.setItemToBeDeleted(note)
await this.application.mutator.setItemToBeDeleted(note)
await this.application.syncService.sync(syncOptions)
this.expectedItemCount--
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
@@ -387,10 +387,10 @@ describe('online conflict handling', function () {
deleted: false,
updated_at: Factory.yesterday(),
})
await this.application.itemManager.emitItemsFromPayloads([mutatedPayload], PayloadEmitSource.LocalChanged)
await this.application.mutator.emitItemsFromPayloads([mutatedPayload], PayloadEmitSource.LocalChanged)
const resultNote = this.application.itemManager.findItem(note.uuid)
expect(resultNote.uuid).to.equal(note.uuid)
await this.application.itemManager.setItemDirty(resultNote)
await this.application.mutator.setItemDirty(resultNote)
await this.application.syncService.sync(syncOptions)
// We expect that this item is now gone for good, and a duplicate has not been created.
@@ -400,7 +400,7 @@ describe('online conflict handling', function () {
it('if server says not deleted but client says deleted, keep server state', async function () {
const note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
this.expectedItemCount++
// client A
@@ -426,7 +426,7 @@ describe('online conflict handling', function () {
it('should create conflict if syncing an item that is stale', async function () {
let note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
await this.application.syncService.sync(syncOptions)
note = this.application.items.findItem(note.uuid)
expect(note.dirty).to.equal(false)
@@ -462,7 +462,7 @@ describe('online conflict handling', function () {
it('creating conflict with exactly equal content should keep us in sync', async function () {
const note = await Factory.createMappedNote(this.application)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
this.expectedItemCount++
await this.application.syncService.sync(syncOptions)
@@ -505,7 +505,7 @@ describe('online conflict handling', function () {
for (const note of this.application.itemManager.getDisplayableNotes()) {
/** First modify the item without saving so that
* our local contents digress from the server's */
await this.application.itemManager.changeItem(note, (mutator) => {
await this.application.mutator.changeItem(note, (mutator) => {
mutator.text = '1'
})
@@ -530,18 +530,18 @@ describe('online conflict handling', function () {
const payload1 = Factory.createStorageItemPayload(ContentType.Tag)
const payload2 = Factory.createStorageItemPayload(ContentType.UserPrefs)
this.expectedItemCount -= 1 /** auto-created user preferences */
await this.application.itemManager.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
await this.application.mutator.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
this.expectedItemCount += 2
let tag = this.application.itemManager.getItems(ContentType.Tag)[0]
let userPrefs = this.application.itemManager.getItems(ContentType.UserPrefs)[0]
expect(tag).to.be.ok
expect(userPrefs).to.be.ok
tag = await this.application.itemManager.changeItem(tag, (mutator) => {
tag = await this.application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(userPrefs)
})
await this.application.itemManager.setItemDirty(userPrefs)
await this.application.mutator.setItemDirty(userPrefs)
userPrefs = this.application.items.findItem(userPrefs.uuid)
expect(this.application.itemManager.itemsReferencingItem(userPrefs).length).to.equal(1)
@@ -599,7 +599,7 @@ describe('online conflict handling', function () {
*/
let tag = await Factory.createMappedTag(this.application)
let note = await Factory.createMappedNote(this.application)
tag = await this.application.mutator.changeAndSaveItem(
tag = await this.application.changeAndSaveItem(
tag,
(mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(note)
@@ -608,7 +608,7 @@ describe('online conflict handling', function () {
undefined,
syncOptions,
)
await this.application.itemManager.setItemDirty(note)
await this.application.mutator.setItemDirty(note)
this.expectedItemCount += 2
await this.application.syncService.sync(syncOptions)
@@ -663,18 +663,18 @@ describe('online conflict handling', function () {
const baseTitle = 'base title'
/** Change the note */
const noteAfterChange = await this.application.itemManager.changeItem(note, (mutator) => {
const noteAfterChange = await this.application.mutator.changeItem(note, (mutator) => {
mutator.title = baseTitle
})
await this.application.sync.sync()
/** Simulate a dropped response by reverting the note back its post-change, pre-sync state */
const retroNote = await this.application.itemManager.emitItemFromPayload(noteAfterChange.payload)
const retroNote = await this.application.mutator.emitItemFromPayload(noteAfterChange.payload)
expect(retroNote.serverUpdatedAt.getTime()).to.equal(noteAfterChange.serverUpdatedAt.getTime())
/** Change the item to its final title and sync */
const finalTitle = 'final title'
await this.application.itemManager.changeItem(note, (mutator) => {
await this.application.mutator.changeItem(note, (mutator) => {
mutator.title = finalTitle
})
await this.application.sync.sync()
@@ -708,7 +708,7 @@ describe('online conflict handling', function () {
errorDecrypting: true,
dirty: true,
})
await this.application.itemManager.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
await this.application.mutator.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
/**
* Retrieve this note from the server by clearing sync token
@@ -758,7 +758,7 @@ describe('online conflict handling', function () {
email: Utils.generateUuid(),
password: Utils.generateUuid(),
})
await newApp.itemManager.emitItemsFromPayloads(priorData.map((i) => i.payload))
await newApp.mutator.emitItemsFromPayloads(priorData.map((i) => i.payload))
await newApp.syncService.markAllItemsAsNeedingSyncAndPersist()
await newApp.syncService.sync(syncOptions)
expect(newApp.payloadManager.invalidPayloads.length).to.equal(0)
@@ -786,7 +786,7 @@ describe('online conflict handling', function () {
password: password,
})
Factory.handlePasswordChallenges(newApp, password)
await newApp.mutator.importData(backupFile, true)
await newApp.importData(backupFile, true)
expect(newApp.itemManager.getDisplayableTags().length).to.equal(1)
expect(newApp.itemManager.getDisplayableNotes().length).to.equal(1)
await Factory.safeDeinit(newApp)
@@ -801,7 +801,7 @@ describe('online conflict handling', function () {
await createSyncedNoteWithTag(this.application)
const tag = this.application.itemManager.getDisplayableTags()[0]
const note2 = await Factory.createMappedNote(this.application)
await this.application.mutator.changeAndSaveItem(tag, (mutator) => {
await this.application.changeAndSaveItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(note2)
})
let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
@@ -821,7 +821,7 @@ describe('online conflict handling', function () {
password: password,
})
Factory.handlePasswordChallenges(newApp, password)
await newApp.mutator.importData(backupFile, true)
await newApp.importData(backupFile, true)
const newTag = newApp.itemManager.getDisplayableTags()[0]
const notes = newApp.items.referencesForItem(newTag)
expect(notes.length).to.equal(2)
@@ -855,7 +855,7 @@ describe('online conflict handling', function () {
},
dirty: true,
})
await this.application.itemManager.emitItemFromPayload(modified)
await this.application.mutator.emitItemFromPayload(modified)
await this.application.sync.sync()
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
await this.sharedFinalAssertions()
@@ -879,7 +879,7 @@ describe('online conflict handling', function () {
dirty: true,
})
this.expectedItemCount++
await this.application.itemManager.emitItemFromPayload(modified)
await this.application.mutator.emitItemFromPayload(modified)
await this.application.sync.sync()
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
await this.sharedFinalAssertions()
@@ -911,7 +911,7 @@ describe('online conflict handling', function () {
dirty: true,
})
this.expectedItemCount++
await this.application.itemManager.emitItemFromPayload(modified)
await this.application.mutator.emitItemFromPayload(modified)
await this.application.sync.sync()
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
await this.sharedFinalAssertions()