Repository navigation
test(agent): cover tab open/switch/close/remount subscription lifetime (FE-2158) #17531
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
e5c7585
c6c445d
8714384
5a9c641
3c36af2
66e899c
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 | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,12 +27,32 @@ import type { GraphOperation } from './graphOperations' | |||||||||||||||||||||||||||||||||||||||||||||
| import type { BatchOutcome, OpSenderDeps } from './opSender' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const bridgeState = vi.hoisted(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const liveSubscriptions = new Map<object, Set<string>>() | ||||||||||||||||||||||||||||||||||||||||||||||
| let maxLiveSubscriptions = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| const countLiveSubscriptions = () => | ||||||||||||||||||||||||||||||||||||||||||||||
| [...liveSubscriptions.values()].reduce( | ||||||||||||||||||||||||||||||||||||||||||||||
| (count, workflows) => count + workflows.size, | ||||||||||||||||||||||||||||||||||||||||||||||
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| class FakeBridge extends EventTarget { | ||||||||||||||||||||||||||||||||||||||||||||||
| subscribe = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| unsubscribe = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| subscribe = vi.fn((workflowId: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| // A bridge retargets its single subscription; concurrency is measured | ||||||||||||||||||||||||||||||||||||||||||||||
| // across bridge instances, not across its historical workflow ids. | ||||||||||||||||||||||||||||||||||||||||||||||
| liveSubscriptions.set(this, new Set([workflowId])) | ||||||||||||||||||||||||||||||||||||||||||||||
| maxLiveSubscriptions = Math.max( | ||||||||||||||||||||||||||||||||||||||||||||||
| maxLiveSubscriptions, | ||||||||||||||||||||||||||||||||||||||||||||||
| countLiveSubscriptions() | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| unsubscribe = vi.fn(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| liveSubscriptions.delete(this) | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| resubscribe = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| reconcile = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| destroy = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| destroy = vi.fn(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| liveSubscriptions.delete(this) | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| sendHumanOps = vi.fn() | ||||||||||||||||||||||||||||||||||||||||||||||
| subscribedWorkflowId: string | null = 'wf-1' | ||||||||||||||||||||||||||||||||||||||||||||||
| lastSequence = 41 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -45,7 +65,14 @@ const bridgeState = vi.hoisted(() => { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||
| FakeBridge, | ||||||||||||||||||||||||||||||||||||||||||||||
| current: null as InstanceType<typeof FakeBridge> | null | ||||||||||||||||||||||||||||||||||||||||||||||
| current: null as InstanceType<typeof FakeBridge> | null, | ||||||||||||||||||||||||||||||||||||||||||||||
| get maxLiveSubscriptions() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return maxLiveSubscriptions | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| resetLiveSubscriptions() { | ||||||||||||||||||||||||||||||||||||||||||||||
| liveSubscriptions.clear() | ||||||||||||||||||||||||||||||||||||||||||||||
| maxLiveSubscriptions = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+75
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. P2: Part of removing the live-subscription tracker (comment on lines 30-55). Only line 275 and line 560 read these members.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -245,6 +272,7 @@ describe('useAgentCrdtFollower', () => { | |||||||||||||||||||||||||||||||||||||||||||||
| useAgentPanelStore().enabled = true | ||||||||||||||||||||||||||||||||||||||||||||||
| sessionStorage.clear() | ||||||||||||||||||||||||||||||||||||||||||||||
| bridgeState.current = null | ||||||||||||||||||||||||||||||||||||||||||||||
| bridgeState.resetLiveSubscriptions() | ||||||||||||||||||||||||||||||||||||||||||||||
|
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. P2: Part of removing the live-subscription tracker (comment on lines 30-55).
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| clientState.transport = null | ||||||||||||||||||||||||||||||||||||||||||||||
| projectionState.applyFrame | ||||||||||||||||||||||||||||||||||||||||||||||
| .mockReset() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -480,6 +508,58 @@ describe('useAgentCrdtFollower', () => { | |||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| it('FE-2158: one follower retargets across a tab switch and releases across remount', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
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. P2: Once the unmount and remount phase goes (comment on lines 540-560), this test covers one thing no other test does: a follower whose tab went inactive on wf-a retargets to wf-b when wf-b becomes bound and active. The name should say that. The flag-revocation and total-teardown tests already cover "releases across remount".
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| // AgentPanelRoot.vue creates a SINGLE follower and drives it with the | ||||||||||||||||||||||||||||||||||||||||||||||
| // reactive boundWorkflowId / isBoundWorkflowActive. Exercising the switch | ||||||||||||||||||||||||||||||||||||||||||||||
| // as two mounted followers would leave a broken direct A-to-B retarget | ||||||||||||||||||||||||||||||||||||||||||||||
| // green, because no one follower would ever change workflow. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+512
to
+515
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. P3: This comment argues for the test's design. That belongs in the PR description, and the code below doesn't need it. It also names
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| const { unmount, workflowId, isTargetActive, status } = | ||||||||||||||||||||||||||||||||||||||||||||||
| mountFollower('wf-a') | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(bridge().subscribe).toHaveBeenLastCalledWith('wf-a') | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+516
to
+518
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. P3: Line 518 repeats "subscribes immediately to a bound workflow and reports it in status" (line 406), and both go through the same immediate watcher.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| isTargetActive.value = false | ||||||||||||||||||||||||||||||||||||||||||||||
| await nextTick() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| workflowId.value = 'wf-b' | ||||||||||||||||||||||||||||||||||||||||||||||
| isTargetActive.value = true | ||||||||||||||||||||||||||||||||||||||||||||||
| await nextTick() | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(bridge().subscribe).toHaveBeenLastCalledWith('wf-b') | ||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // A frame for the workflow this follower just left must be counted and | ||||||||||||||||||||||||||||||||||||||||||||||
| // dropped, never applied to the newly bound graph. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+528
to
+529
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. P3: The assertions already say this. It also describes a path that only exists with the fake. The real
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| dispatchFrame('doc_update', { workflowId: 'wf-a', seq: 99 }) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(status().outcomes.applied).toBe(0) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(status().outcomes.skipped).toBeGreaterThan(0) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(projectionState.applyFrame).not.toHaveBeenCalled() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+531
to
+534
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. P3: None of these lines add anything once line 538 asserts which frame was applied (suggestion there).
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Control: the retarget really did bind B, so the filter above | ||||||||||||||||||||||||||||||||||||||||||||||
| // discriminated on workflow id rather than having gone silent. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+535
to
+536
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. P3: With one assertion on the applied frame (suggestion below), the code itself makes the control explicit.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| dispatchFrame('doc_update', { workflowId: 'wf-b', seq: 1 }) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(status().outcomes.applied).toBe(1) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(projectionState.applyFrame).toHaveBeenCalledTimes(1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+538
to
+539
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. P3: Both lines count the same event, and neither checks which frame was applied. I made
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const staleBridge = bridge() | ||||||||||||||||||||||||||||||||||||||||||||||
| unmount() | ||||||||||||||||||||||||||||||||||||||||||||||
| await nextTick() | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(staleBridge.unsubscribe).toHaveBeenCalled() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| staleBridge.dispatchEvent( | ||||||||||||||||||||||||||||||||||||||||||||||
| new CustomEvent('doc_update', { | ||||||||||||||||||||||||||||||||||||||||||||||
| detail: { workflowId: 'wf-b', seq: 2 } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(projectionState.applyFrame).toHaveBeenCalledTimes(1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const remounted = mountFollower('wf-b') | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(bridge()).not.toBe(staleBridge) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(bridge().subscribe).toHaveBeenCalledExactlyOnceWith('wf-b') | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| dispatchFrame('doc_update', { workflowId: 'wf-b', seq: 2 }) | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(projectionState.applyFrame).toHaveBeenCalledTimes(2) | ||||||||||||||||||||||||||||||||||||||||||||||
| remounted.unmount() | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(bridgeState.maxLiveSubscriptions).toBeLessThanOrEqual(1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+540
to
+560
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. P2: Existing tests already catch everything this unmount and remount phase catches, and line 544 checks a different event than its position suggests.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| it('FE-1902: persists a binding only once the server confirms it', () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const { unmount } = mountFollower('wf-1') | ||||||||||||||||||||||||||||||||||||||||||||||
| expect(persistedRecord()).toBeNull() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
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.
P2: The live-subscription tracker has no failure case of its own. FE-2158 runs in order (unmount happens before the remount), so two bridges can only be subscribed at once if teardown skips
bridge.destroy(). Two existing tests already fail on that. When I deleted() => bridge.destroy(),from the teardown list, "starts on flag delivery and stops synchronously on revocation" (line 343) and "tears down totally on unmount" (line 2232) both failed, with or without line 560. The fake also cannot represent one bridge subscribed to wf-a and wf-b, becausesubscribereplaces the bridge's entry, so everySethere holds at most one id. Making the fake'sdestroyinert does fail FE-2158, but that shows the tracker works, not that the composable does.This restores the base
FakeBridge. The matching edits are on lines 68-75 and 275 and inside the comment on 540-560 (line 560). They also remove theMap<object, Set<string>>, the arrowcountLiveSubscriptions, and the comment that explains both.