From 69feefef798ae22f8cca814c8d21c96d9e32ef3f Mon Sep 17 00:00:00 2001 From: bymyself Date: Wed, 2 Sep 2026 14:42:02 +0000 Subject: [PATCH 1/3] test(agent-crdt): characterize malformed follower updates --- .../extensions/agent/crdt/followerDoc.test.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/workbench/extensions/agent/crdt/followerDoc.test.ts diff --git a/src/workbench/extensions/agent/crdt/followerDoc.test.ts b/src/workbench/extensions/agent/crdt/followerDoc.test.ts new file mode 100644 index 00000000000..2380458b14c --- /dev/null +++ b/src/workbench/extensions/agent/crdt/followerDoc.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it, vi } from 'vitest' +import * as Y from 'yjs' + +import { FollowerDoc } from './followerDoc' + +describe('FollowerDoc.applyRemoteUpdate', () => { + it('applies a valid host update', () => { + const host = new Y.Doc() + host.getMap('nodes').set('1', { type: 'LoadImage' }) + const update = Y.encodeStateAsUpdate(host) + const follower = new FollowerDoc() + const onUpdate = vi.fn() + follower.addEventListener('update', onUpdate) + + follower.applyRemoteUpdate(update) + + expect(follower.doc.getMap('nodes').toJSON()).toEqual({ + '1': { type: 'LoadImage' } + }) + expect(follower.updatesApplied).toBe(1) + expect(onUpdate).toHaveBeenCalledOnce() + }) + + it('propagates a malformed Yjs update without recording it', () => { + const follower = new FollowerDoc() + const onUpdate = vi.fn() + follower.addEventListener('update', onUpdate) + + expect(() => follower.applyRemoteUpdate(Uint8Array.of(0))).toThrow( + 'Unexpected end of array' + ) + + expect(onUpdate).not.toHaveBeenCalled() + expect(follower.updatesApplied).toBe(0) + }) +}) From d21772ca5355e62380fc081dc7dddce3fc0a2e27 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 21 Sep 2026 12:25:06 -0700 Subject: [PATCH 2/3] Update src/workbench/extensions/agent/crdt/followerDoc.test.ts Co-authored-by: Alexander Brown --- src/workbench/extensions/agent/crdt/followerDoc.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/followerDoc.test.ts b/src/workbench/extensions/agent/crdt/followerDoc.test.ts index 2380458b14c..29a7d376e29 100644 --- a/src/workbench/extensions/agent/crdt/followerDoc.test.ts +++ b/src/workbench/extensions/agent/crdt/followerDoc.test.ts @@ -21,7 +21,9 @@ describe('FollowerDoc.applyRemoteUpdate', () => { expect(onUpdate).toHaveBeenCalledOnce() }) - it('propagates a malformed Yjs update without recording it', () => { +it( + 'throws for a truncated update without dispatching an event or incrementing updatesApplied', + () => { const follower = new FollowerDoc() const onUpdate = vi.fn() follower.addEventListener('update', onUpdate) From 8b5c4a7c9dd9717e678c0a85b84435b6b546c0cf Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 21 Sep 2026 19:30:36 +0000 Subject: [PATCH 3/3] [automated] Apply ESLint and Oxfmt fixes --- src/workbench/extensions/agent/crdt/followerDoc.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/followerDoc.test.ts b/src/workbench/extensions/agent/crdt/followerDoc.test.ts index 29a7d376e29..62e022ba952 100644 --- a/src/workbench/extensions/agent/crdt/followerDoc.test.ts +++ b/src/workbench/extensions/agent/crdt/followerDoc.test.ts @@ -21,9 +21,7 @@ describe('FollowerDoc.applyRemoteUpdate', () => { expect(onUpdate).toHaveBeenCalledOnce() }) -it( - 'throws for a truncated update without dispatching an event or incrementing updatesApplied', - () => { + it('throws for a truncated update without dispatching an event or incrementing updatesApplied', () => { const follower = new FollowerDoc() const onUpdate = vi.fn() follower.addEventListener('update', onUpdate)