-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(copilot): stream file edits into the live collaborative Y.Doc (keep embedded view collaborative) #6108
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
Merged
waleedlatif1
merged 14 commits into
realtime-rooms
from
feat/copilot-stream-into-collab-doc
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9b6fce6
feat(copilot): stream file edits into the live collaborative Y.Doc
waleedlatif1 8340290
fix(copilot): order + gate streaming live-doc merges; fast collab fir…
waleedlatif1 3dc1378
test(copilot): cover streaming file edits into the live collaborative…
waleedlatif1 4226987
fix(collab-doc): coordinate live-doc merge ordering in one place; clo…
waleedlatif1 68acab6
fix(copilot): address review — order merges, exclude update, gate thr…
waleedlatif1 63a4681
fix(collab-doc): reject stale durable merges at the relay (cross-proc…
waleedlatif1 46212f3
fix(copilot): match durable path — detect markdown by MIME type + nam…
waleedlatif1 b0753ad
test(copilot): assert throttle follow-through after an in-flight merg…
waleedlatif1 e9622e9
fix(collab-doc): order streaming merges by streamedAt so a late snaps…
waleedlatif1 6986b74
refactor(collab-doc): tidy merge-order docs + relay order object; cov…
waleedlatif1 8a7bca4
fix(collab-doc): order streaming merges by causal base version, not w…
waleedlatif1 d95070f
fix(collab-doc): derive streaming baseVersion as contentUpdatedAt ?? …
waleedlatif1 3a5ffbd
fix(collab-doc): fail-closed on a streaming snapshot with no baseVersion
waleedlatif1 16fa747
docs(collab-doc): document the accepted concurrent-independent-stream…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| * | ||
| * Multi-replica (store-enabled) coverage for the copilot live-merge stale-check. The main | ||
| * `file-doc.test.ts` runs with the store DISABLED (single-replica fallback); this file mocks an ENABLED | ||
| * store so the cross-process branch of `mergeMarkdownIntoRoom` — staleness against the SHARED synced | ||
| * version under the merge lock, and `recordVersion` writing `setSyncedVersion` — is exercised directly. | ||
| * The enabled merge path reads its base from the shared store (not an in-memory room), so no JOIN/seed | ||
| * is needed: calling `applyMarkdownToLiveFileDoc` against the fake store drives the branch on its own. | ||
| */ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import * as Y from 'yjs' | ||
|
|
||
| const { mockFetchFileDocMerge } = vi.hoisted(() => ({ | ||
| mockFetchFileDocMerge: vi.fn(), | ||
| })) | ||
|
|
||
| /** | ||
| * A minimal ENABLED store: in-memory monotonic synced version (mirrors SET_VERSION_IF_NEWER_SCRIPT), a | ||
| * non-null stream state so the merge has a base, and no-op locks/publish. Only the surface the | ||
| * store-enabled merge path touches is implemented. | ||
| */ | ||
| const fakeStore = { | ||
| enabled: true, | ||
| versions: new Map<string, number>(), | ||
| acquireMergeSlot: vi.fn(async () => 'token'), | ||
| releaseMergeSlot: vi.fn(async () => {}), | ||
| getStreamState: vi.fn(async () => new Uint8Array([1])), | ||
| publishAndWait: vi.fn(async () => {}), | ||
| getSyncedVersion: vi.fn(async (name: string) => fakeStore.versions.get(name) ?? null), | ||
| setSyncedVersion: vi.fn(async (name: string, version: number) => { | ||
| fakeStore.versions.set(name, Math.max(fakeStore.versions.get(name) ?? 0, version)) | ||
| }), | ||
| } | ||
|
|
||
| vi.mock('@sim/platform-authz/rooms', () => ({ authorizeRoom: vi.fn() })) | ||
|
|
||
| vi.mock('@/handlers/file-doc-app', () => ({ | ||
| fetchFileDocSeed: vi.fn(), | ||
| fetchFileDocMerge: mockFetchFileDocMerge, | ||
| fetchFileDocPersist: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/handlers/file-doc-store', () => ({ | ||
| getFileDocStore: () => fakeStore, | ||
| REDIS_ORIGIN: Symbol('redis'), | ||
| REDIS_SNAPSHOT_ORIGIN: Symbol('redis-snapshot'), | ||
| })) | ||
|
|
||
| import { applyMarkdownToLiveFileDoc } from '@/handlers/file-doc' | ||
|
|
||
| const ROOM_NAME = 'workspace-file-doc:file-1' | ||
|
|
||
| describe('applyMarkdownToLiveFileDoc — multi-replica (store-enabled) ordering', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| fakeStore.versions.clear() | ||
| fakeStore.acquireMergeSlot.mockResolvedValue('token') | ||
| fakeStore.getStreamState.mockResolvedValue(new Uint8Array([1])) | ||
| mockFetchFileDocMerge.mockResolvedValue(Y.encodeStateAsUpdate(new Y.Doc())) | ||
| }) | ||
|
|
||
| it('drops a stale-base streaming snapshot against the SHARED synced version and never records it', async () => { | ||
| // A durable write (e.g. a concurrent human save on another process) records the shared synced version. | ||
| expect(await applyMarkdownToLiveFileDoc('file-1', '# durable', { version: 100 })).toBe( | ||
| 'applied' | ||
| ) | ||
| expect(fakeStore.setSyncedVersion).toHaveBeenCalledWith(ROOM_NAME, 100) | ||
| mockFetchFileDocMerge.mockClear() | ||
|
|
||
| // A streaming snapshot built from an older base (50) than the SHARED synced version is stale — | ||
| // rejected under the lock before any diff is built, so it can't clobber the durable write. | ||
| expect( | ||
| await applyMarkdownToLiveFileDoc('file-1', '# stale-base stream', { baseVersion: 50 }) | ||
| ).toBe('stale') | ||
| expect(mockFetchFileDocMerge).not.toHaveBeenCalled() | ||
|
|
||
| // A streaming snapshot whose base is the current shared version applies (nothing newer to clobber)... | ||
| expect( | ||
| await applyMarkdownToLiveFileDoc('file-1', '# current-base stream', { baseVersion: 100 }) | ||
| ).toBe('applied') | ||
| // ...but is never recorded: a later durable write at 150 still applies. | ||
| expect(await applyMarkdownToLiveFileDoc('file-1', '# durable again', { version: 150 })).toBe( | ||
| 'applied' | ||
| ) | ||
| expect(fakeStore.setSyncedVersion).toHaveBeenCalledWith(ROOM_NAME, 150) | ||
| // setSyncedVersion fired only for the two durable writes, never for a streaming snapshot. | ||
| expect(fakeStore.setSyncedVersion).toHaveBeenCalledTimes(2) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.