test(kanban): prove divergent rebase conflict
req: sync/011
This commit is contained in:
@@ -626,6 +626,116 @@ async fn missing_history_rebase_converges_without_losing_local_intent() -> WebDr
|
||||
.clone();
|
||||
assert_eq!(canonical[2]["title"], "Done");
|
||||
assert_eq!(canonical[2]["cards"], serde_json::json!(["1", "2", "3"]));
|
||||
|
||||
let divergent_server = driver
|
||||
.execute_async(
|
||||
r#"
|
||||
const done = arguments[arguments.length - 1];
|
||||
(async () => {
|
||||
const local = await fetch('/sync/commands?command_id=history%3A3&card_id=2&column=done', { method: 'POST' });
|
||||
const remote = await fetch('/sync/commands?command_id=remote%3A4&card_id=2&column=doing', { method: 'POST' });
|
||||
done({
|
||||
local: { status: local.status, body: await local.json() },
|
||||
remote: { status: remote.status, body: await remote.json() },
|
||||
});
|
||||
})().catch((error) => done({ error: String(error) }));
|
||||
"#,
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.clone();
|
||||
assert_eq!(divergent_server["local"]["status"], 200);
|
||||
assert_eq!(divergent_server["local"]["body"]["serverSequence"], 3);
|
||||
assert_eq!(divergent_server["remote"]["status"], 200);
|
||||
assert_eq!(divergent_server["remote"]["body"]["serverSequence"], 4);
|
||||
assert_eq!(divergent_server["remote"]["body"]["canonicalColumn"], "doing");
|
||||
|
||||
let seeded_conflict = driver
|
||||
.execute_async(
|
||||
r#"
|
||||
const done = arguments[arguments.length - 1];
|
||||
const open = indexedDB.open('hemx-kanban-v1', 1);
|
||||
open.onsuccess = () => {
|
||||
const tx = open.result.transaction('commands', 'readwrite');
|
||||
tx.objectStore('commands').add({
|
||||
id: 'history:3', schemaVersion: 1, actor: 'history', session: 'history-session',
|
||||
causal: 3, kind: 'reorder_card', cardId: '2', eventKind: 'click', key: null,
|
||||
});
|
||||
tx.oncomplete = () => done({ seeded: true });
|
||||
tx.onabort = () => done({ error: tx.error && tx.error.name });
|
||||
};
|
||||
"#,
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.clone();
|
||||
assert_eq!(seeded_conflict["seeded"], true);
|
||||
|
||||
driver.goto(&format!("http://{app_addr}/sync-demo")).await?;
|
||||
wait_until(
|
||||
&driver,
|
||||
"return document.querySelector('[data-kanban-sync]')?.getAttribute('data-sync-phase') === 'conflicted'",
|
||||
)
|
||||
.await?;
|
||||
let conflicted = driver
|
||||
.execute(
|
||||
"const root = document.querySelector('[data-kanban-sync]'); return { phase: root.getAttribute('data-sync-phase'), uploadSequence: root.getAttribute('data-sync-upload-sequence'), snapshotSequence: root.getAttribute('data-sync-snapshot-sequence'), pending: root.getAttribute('data-sync-pending-count'), rebasePending: root.getAttribute('data-sync-rebase-pending-count'), decision: root.getAttribute('data-sync-rebase-decision'), reason: root.getAttribute('data-sync-rebase-reason'), canonicalColumn: root.getAttribute('data-sync-canonical-column'), status: root.querySelector('[role=status]').textContent, error: root.getAttribute('data-sync-error') }",
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.clone();
|
||||
assert_eq!(conflicted["phase"], "conflicted");
|
||||
assert_eq!(conflicted["uploadSequence"], "3");
|
||||
assert_eq!(conflicted["snapshotSequence"], "4");
|
||||
assert_eq!(conflicted["pending"], "1");
|
||||
assert_eq!(conflicted["rebasePending"], "1");
|
||||
assert_eq!(conflicted["decision"], "conflicted");
|
||||
assert_eq!(conflicted["reason"], "canonical-state-diverged");
|
||||
assert_eq!(conflicted["canonicalColumn"], "doing");
|
||||
assert_eq!(
|
||||
conflicted["status"],
|
||||
"Canonical snapshot 4 conflicts with history:3 (canonical-state-diverged); the pending command remains queued."
|
||||
);
|
||||
assert!(conflicted["error"].is_null());
|
||||
assert_eq!(command_count(&driver).await?, 1);
|
||||
let preserved = driver
|
||||
.execute_async(
|
||||
r#"
|
||||
const done = arguments[arguments.length - 1];
|
||||
const open = indexedDB.open('hemx-kanban-v1', 1);
|
||||
open.onsuccess = () => {
|
||||
const tx = open.result.transaction(['commands', 'meta'], 'readonly');
|
||||
const command = tx.objectStore('commands').get('history:3');
|
||||
const cursor = tx.objectStore('meta').get('acknowledgementCursor');
|
||||
const snapshot = tx.objectStore('meta').get('canonicalSnapshot');
|
||||
tx.oncomplete = () => done({ command: command.result, cursor: cursor.result, snapshot: snapshot.result });
|
||||
tx.onabort = () => done({ error: tx.error && tx.error.name });
|
||||
};
|
||||
"#,
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.clone();
|
||||
assert_eq!(preserved["command"]["id"], "history:3");
|
||||
assert_eq!(preserved["cursor"], 2);
|
||||
assert_eq!(preserved["snapshot"]["serverSequence"], 2);
|
||||
|
||||
driver.goto(&format!("http://{app_addr}/")).await?;
|
||||
let divergent_board = driver
|
||||
.execute(
|
||||
"return [...document.querySelectorAll('section.column')].map((column) => ({ title: column.querySelector('h2').textContent, cards: [...column.querySelectorAll('[data-key]')].map((card) => card.dataset.key) }))",
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.clone();
|
||||
assert_eq!(divergent_board[1]["title"], "Doing");
|
||||
assert_eq!(divergent_board[1]["cards"], serde_json::json!(["2"]));
|
||||
assert_eq!(divergent_board[2]["cards"], serde_json::json!(["1", "3"]));
|
||||
Ok(())
|
||||
}
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user