Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix vault merge e2e test (#1404)

Leendert de Borst55d907f26c91
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index 18bc1f427..0978a36b3 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -16,7 +16,7 @@
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:e2e": "playwright test",
- "test:e2e:headed": "playwright test --headed",
+ "test:e2e:build": "npm run build:chrome && playwright test",
"lint": "eslint src",
"lint:custom": "eslint",
"lint:fix": "eslint src --fix",
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index 47ddb1fe3..555c15f81 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -449,17 +449,27 @@ export async function handleGetEncryptionKeyDerivationParams(
* Upload the vault to the server.
*/
export async function handleUploadVault(
- message: any
+ message: { vaultBlob: string; baseRevisionNumber?: number }
) : Promise<messageVaultUploadResponse> {
try {
/*
* Store the new vault blob in local: storage with pending sync flag.
- * The uploadNewVaultToServer will clear this on success.
+ * If a baseRevisionNumber is provided (e.g., after a merge), update it atomically.
+ * The uploadNewVaultToServer will clear hasPendingSync on success.
*/
- await storage.setItems([
- { key: 'local:encryptedVault', value: message.vaultBlob },
- { key: 'local:hasPendingSync', value: true }
- ]);
+ if (message.baseRevisionNumber !== undefined) {
+ // Store vault, pending sync flag, and revision number atomically
+ await storage.setItems([
+ { key: 'local:encryptedVault', value: message.vaultBlob },
+ { key: 'local:hasPendingSync', value: true },
+ { key: 'local:vaultRevisionNumber', value: message.baseRevisionNumber }
+ ]);
+ } else {
+ await storage.setItems([
+ { key: 'local:encryptedVault', value: message.vaultBlob },
+ { key: 'local:hasPendingSync', value: true }
+ ]);
+ }
// Create new sqlite client which will use the new vault blob.
const sqliteClient = await createVaultSqliteClient();
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
index 3088d86ed..fe184741d 100644
--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
@@ -187,11 +187,12 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
/*
* Upload the merged vault to server.
- * Use the server's revision as our current revision since we just fetched it.
+ * Pass the server's revision as our base revision since we just fetched and merged with it.
*/
onStatus?.(t('common.uploadingVault'));
const uploadResponse = await sendMessage('UPLOAD_VAULT', {
- vaultBlob: mergedEncryptedVault
+ vaultBlob: mergedEncryptedVault,
+ baseRevisionNumber: statusResponse.vaultRevision
}, 'background') as VaultUploadResponse;
if (uploadResponse.success && uploadResponse.status === 0) {
diff --git a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
index 722d4878e..a44d5771d 100644
--- a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
+++ b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
@@ -109,6 +109,10 @@ test.describe.serial('5. Vault Merge', () => {
await clientB.popup.getByRole('button', { name: 'Vault' }).click();
await navigateToAddCredentialForm(clientB.popup);
+
+ // Take screenshots of both clients on the add form
+ await clientA.popup.screenshot({ path: 'tests/screenshots/5.1-client-a-add-form.png' });
+ await clientB.popup.screenshot({ path: 'tests/screenshots/5.1-client-b-add-form.png' });
});
test('5.2 Client A should create a credential and sync', async () => {
@@ -139,8 +143,6 @@ test.describe.serial('5. Vault Merge', () => {
const popup = clientB.popup;
- await popup.waitForTimeout(555555);
-
// Enter the item name
await popup.fill('input#itemName', credentialNameB);
@@ -154,11 +156,6 @@ test.describe.serial('5. Vault Merge', () => {
await popup.fill('input#login\\.username', '[email protected]');
await popup.fill('input#login\\.password', 'ClientBPassword456!');
- // Take screenshot before saving
- await popup.screenshot({ path: 'tests/screenshots/5.3-client-b-form-filled.png' });
-
- await popup.waitForTimeout(555555);
-
// Click Save button
await popup.click('button:has-text("Save")');
@@ -166,8 +163,7 @@ test.describe.serial('5. Vault Merge', () => {
// 1. Navigation to item details page (success)
// 2. Navigation back to vault list (merge happened, redirected)
// 3. Stay on form with error (sync conflict)
- // Use a longer timeout and check for any of these states
- await popup.waitForTimeout(555555);
+ await popup.waitForTimeout(100);
// Take a screenshot to see current state
await popup.screenshot({ path: 'tests/screenshots/5.3-client-b-after-save.png' });
@@ -180,7 +176,7 @@ test.describe.serial('5. Vault Merge', () => {
await popup.getByRole('button', { name: 'Vault' }).click();
// Wait for the credentials list to load
- await popup.waitForTimeout(2000);
+ await popup.waitForTimeout(100);
// Take a screenshot first to see what's there
await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-vault-state.png' });
@@ -194,23 +190,12 @@ test.describe.serial('5. Vault Merge', () => {
const hasBothCredentials = await clientBCredential.isVisible().catch(() => false);
if (hasBothCredentials) {
- // Both credentials exist - merge worked correctly!
- await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-merged-vault-success.png' });
-
- // Check the item count shows 2 items
+ // Both credentials exist: merge worked correctly!
const itemsText = popup.locator('text=/\\(2 items\\)/');
await expect(itemsText).toBeVisible({ timeout: 5000 });
} else {
- // Only Client A's credential exists - merge overwrote local changes
- // This is a known limitation - take screenshot for debugging
- await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-merge-overwrote-local.png' });
-
- // For now, we'll accept this behavior but log it
- console.warn('MERGE LIMITATION: Client B local changes were lost during merge');
-
- // The test passes but documents the current behavior
- const itemsText = popup.locator('text=/\\(1 items?\\)/');
- await expect(itemsText).toBeVisible({ timeout: 5000 });
+ // Only Client A's credential exists: merge logic failed
+ throw new Error('Merge logic failed');
}
});