-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(cli): tighten response timestamp consistency and tests #5850
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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8370,6 +8370,80 @@ describe('useGeminiStream', () => { | |||||||||
| }); | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| describe('timestamp attachment', () => { | ||||||||||
| it('attaches a numeric timestamp to gemini items via commitItem', async () => { | ||||||||||
| mockSendMessageStream.mockReturnValueOnce( | ||||||||||
| (async function* () { | ||||||||||
| yield { | ||||||||||
| type: ServerGeminiEventType.Content, | ||||||||||
| value: 'Hello world', | ||||||||||
| }; | ||||||||||
| yield { | ||||||||||
| type: ServerGeminiEventType.Finished, | ||||||||||
| value: { | ||||||||||
| reason: undefined, | ||||||||||
| usageMetadata: { totalTokenCount: 1 }, | ||||||||||
| }, | ||||||||||
| }; | ||||||||||
| })(), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const { result } = renderTestHook(); | ||||||||||
|
|
||||||||||
| await act(async () => { | ||||||||||
| await result.current.submitQuery('test'); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| await waitFor(() => { | ||||||||||
| expect(result.current.streamingState).toBe(StreamingState.Idle); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const geminiCalls = mockAddItem.mock.calls.filter( | ||||||||||
| (call: any[]) => call[0]?.type === 'gemini', | ||||||||||
|
Collaborator
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. [Suggestion] Inconsistent
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||
| ); | ||||||||||
| expect(geminiCalls.length).toBeGreaterThanOrEqual(1); | ||||||||||
| const geminiItem = geminiCalls[0][0]; | ||||||||||
| expect(typeof geminiItem.timestamp).toBe('number'); | ||||||||||
| expect(geminiItem.timestamp).toBeGreaterThan(0); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('does not attach timestamp to non-gemini items', async () => { | ||||||||||
| mockSendMessageStream.mockReturnValueOnce( | ||||||||||
| (async function* () { | ||||||||||
| yield { | ||||||||||
| type: ServerGeminiEventType.Content, | ||||||||||
| value: 'response', | ||||||||||
| }; | ||||||||||
| yield { | ||||||||||
| type: ServerGeminiEventType.Finished, | ||||||||||
| value: { | ||||||||||
| reason: undefined, | ||||||||||
| usageMetadata: { totalTokenCount: 1 }, | ||||||||||
| }, | ||||||||||
| }; | ||||||||||
| })(), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const { result } = renderTestHook(); | ||||||||||
|
|
||||||||||
| await act(async () => { | ||||||||||
| await result.current.submitQuery('test'); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| await waitFor(() => { | ||||||||||
| expect(result.current.streamingState).toBe(StreamingState.Idle); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const nonGeminiCalls = mockAddItem.mock.calls.filter( | ||||||||||
| (call: any[]) => call[0]?.type !== 'gemini', | ||||||||||
| ); | ||||||||||
| expect(nonGeminiCalls.length).toBeGreaterThanOrEqual(1); | ||||||||||
| for (const call of nonGeminiCalls) { | ||||||||||
| expect(call[0]).not.toHaveProperty('timestamp'); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| describe('classifyApiError', () => { | ||||||||||
|
|
||||||||||
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.
[Suggestion] The test name says "via commitItem" but the timestamp is actually set by
setPendingHistoryItematuseGeminiStream.ts:1133(which creates the pending item withtimestamp: Date.now()). By the timecommitItemreceives the item,!item.timestampis alreadyfalse, so the guard's value-assignment branch is never exercised.The branch where
commitItemitself assignsDate.now()— when a gemini item arrives without a pre-existing timestamp — is only reachable via the split path atuseGeminiStream.ts:1163(buffer exceedingSTREAM_PENDING_ITEM_MAX_CHARS). No test triggers this path.Consider adding a test that directly invokes
commitItemwith a gemini item lacking a timestamp, or triggers the split path, to validate the guard's assignment branch.— qwen3.7-max via Qwen Code /review