Repository navigation
test(agent-crdt): characterize malformed follower updates #16664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
69feefe
8a639ff
d21772c
8b5c4a7
4568a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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('throws for a truncated update without dispatching an event or incrementing updatesApplied', () => { | ||
| const follower = new FollowerDoc() | ||
| const onUpdate = vi.fn() | ||
| follower.addEventListener('update', onUpdate) | ||
|
|
||
| expect(() => follower.applyRemoteUpdate(Uint8Array.of(0))).toThrow( | ||
| 'Unexpected end of array' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Nit — Matching
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left as-is: the exact decoder error is part of this narrow characterization. Matching any thrown error would let an unrelated regression satisfy the test.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but this is still a form of change-detector. |
||
| ) | ||
|
|
||
| expect(onUpdate).not.toHaveBeenCalled() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left as-is: this test makes no atomicity claim. It characterizes counters and events for a deterministic first-decode rejection; partial-apply behavior needs separate targeted coverage. |
||
| expect(follower.updatesApplied).toBe(0) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium — This test pins propagation as the contract for malformed remote updates, but the production caller (
LayoutFollowerBridge.onDocUpdate) advanceslastSeqbefore callingapplyRemoteUpdateand wraps it in no try/catch, so a single corrupt frame throws out of the socket listener while the gap detector now believes the follower is caught up — noreportError(), no resubscribe, and silent divergence for the rest of the session. Consider pinning containment plus recovery (catch, report, resubscribe) instead, or at minimum not baking the throwing behaviour in as intended. Raised by 4 of 8 reviewers (claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case, gemini-3.1-pro adversarial, gpt-5.6-sol-max adversarial).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deferred to #16869: recovery requires a production bridge change plus bridge-level coverage. This PR remains a characterization of the current
FollowerDocpropagation contract.