-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(events): deduplicate ConversationStateUpdateEvent definition #249
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
Open
VascoSch92
wants to merge
3
commits into
main
Choose a base branch
from
vasco/dedupe-conversation-state-update-event
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,76 @@ | ||
| import { HttpClient } from '../client/http-client'; | ||
| import { RemoteState } from '../conversation/remote-state'; | ||
| import { ConversationStateUpdateEvent } from '../events/types'; | ||
|
|
||
| const originalFetch = global.fetch; | ||
|
|
||
| /** A fetch mock that fails the test if the network is touched. */ | ||
| function makeStateWithNoNetwork(): { state: RemoteState; fetchMock: jest.Mock } { | ||
| const fetchMock = jest | ||
| .fn() | ||
| .mockRejectedValue(new Error('network should not be called')) as jest.Mock; | ||
| global.fetch = fetchMock as typeof fetch; | ||
| const client = new HttpClient({ baseUrl: 'http://example.com' }); | ||
| return { state: new RemoteState(client, 'abc'), fetchMock }; | ||
| } | ||
|
|
||
| describe('RemoteState.updateStateFromEvent with the canonical ConversationStateUpdateEvent', () => { | ||
| afterEach(() => { | ||
| global.fetch = originalFetch; | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('applies a __full_state__ snapshot event and serves it from cache', async () => { | ||
| const { state, fetchMock } = makeStateWithNoNetwork(); | ||
|
|
||
| // Uses the deduplicated type from events/types: BaseEvent shape (id/timestamp) | ||
| // plus the optional previous_value field that the old local copy lacked. | ||
| const event: ConversationStateUpdateEvent = { | ||
| id: 'evt-1', | ||
| kind: 'ConversationStateUpdateEvent', | ||
| timestamp: '2024-01-01T00:00:00Z', | ||
| source: 'agent', | ||
| key: '__full_state__', | ||
| value: { full_state: { execution_status: 'running', persistence_dir: '/data/abc' } }, | ||
| previous_value: undefined, | ||
| }; | ||
|
|
||
| await state.updateStateFromEvent(event); | ||
|
|
||
| await expect(state.getExecutionStatus()).resolves.toBe('running'); | ||
| await expect(state.getPersistenceDir()).resolves.toBe('/data/abc'); | ||
| expect(fetchMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('applies a single-key update event', async () => { | ||
| const { state } = makeStateWithNoNetwork(); | ||
|
|
||
| const event: ConversationStateUpdateEvent = { | ||
| id: 'evt-2', | ||
| kind: 'ConversationStateUpdateEvent', | ||
| timestamp: '2024-01-01T00:00:00Z', | ||
| key: 'execution_status', | ||
| value: 'idle', | ||
| }; | ||
|
|
||
| await state.updateStateFromEvent(event); | ||
| await expect(state.getExecutionStatus()).resolves.toBe('idle'); | ||
| }); | ||
|
|
||
| it('routes ConversationStateUpdateEvent through createStateUpdateCallback', async () => { | ||
| const { state } = makeStateWithNoNetwork(); | ||
| const callback = state.createStateUpdateCallback(); | ||
|
|
||
| callback({ | ||
| id: 'evt-3', | ||
| kind: 'ConversationStateUpdateEvent', | ||
| timestamp: '2024-01-01T00:00:00Z', | ||
| key: 'execution_status', | ||
| value: 'finished', | ||
| } as ConversationStateUpdateEvent); | ||
|
|
||
| // The callback dispatches asynchronously; allow the microtask queue to drain. | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| await expect(state.getExecutionStatus()).resolves.toBe('finished'); | ||
| }); | ||
| }); |
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.
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.