Skip to content

Add safe edit mode#2

Draft
marcus-pousette wants to merge 1 commit into
codex/lazy-undo-historyfrom
codex/safe-edit-mode
Draft

Add safe edit mode#2
marcus-pousette wants to merge 1 commit into
codex/lazy-undo-historyfrom
codex/safe-edit-mode

Conversation

@marcus-pousette

Copy link
Copy Markdown
Owner

Summary

Stacked on cybersemics#175.

This PR adds a conservative edit mode for the undo/redo helper API introduced in cybersemics#175.

  • Adds mode: 'force' | 'safe' to edits.undo(...) and edits.redo(...).
  • Keeps force as the default behavior from History-derived undo plans cybersemics/treecrdt#175.
  • Adds safe mode, which checks that the current visible state still matches the captured edit's post-state before writing undo/redo ops.
  • Throws EditConflictError and writes no operations when safe mode detects a changed visible state.
  • Adds conformance coverage for safe-mode rejection and for imported-op undo/redo using safe mode.

Semantics

force is git-revert-style behavior: always append inverse operations, even if that overwrites a later change to the same visible field.

safe is the conservative collaborative behavior: reject before writing if another local or remote edit changed the same visible node state after the edit was captured.

This PR intentionally keeps the policy in the TypeScript edits helper. The backend history.invert(...) trait remains responsible only for deriving inverse plans.

Verification

  • pnpm -C packages/treecrdt-ts run build
  • pnpm -C packages/treecrdt-engine-conformance run build
  • pnpm -C packages/treecrdt-sqlite-node exec vitest run tests/conformance.test.ts
  • pnpm -C packages/treecrdt-wa-sqlite exec vitest run tests/node-client.test.ts

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.

1 participant