Skip to content
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

test: Add companion ui tests for useChat from upstream #16

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lqhuang
Copy link
Contributor

@lqhuang lqhuang commented Nov 19, 2024

As title said.

What I did:

  1. Fix setData test cases
  2. Fix handler callbacks which due to incorrect use of atom with functions
    • In previous implement, I forgot () => value as atom value would execute directly.
    • Now function is passed into atom with an object (atom({ fn: userFunc }))
  3. Fix dependencies of a useCallback function (in handleSubmit)
  4. Refactor allowEmptySubmit with non-empty input and attachments
  5. Add atomWithReset
    • because state of atoms is out of control for useChat, here I add resettable atoms and <ResetMessageComponent /> (I don't know how to reset out of react context) to clean up all state between each unit test.
    • this is a non-deterministic feature, may remove in the future
    • (remove or not) It depends on how would we actually call useChat in real case.

Preview test state:

 ❯ src/react/use-chat.ui.test.tsx
   ✓ data protocol stream (9)
     ✓ should show streamed response
     × should set stream data
     ✓ setData (2)
       ✓ should set data
       × should clear data
     ✓ should show error response when there is a server error
     ✓ should show error response when there is a streaming error
     ✓ loading state (2)
       ✓ should show loading state
       ✓ should reset loading state on error
     × should invoke onFinish when the stream finishes

Current test state:

 ❯ src/react/use-chat.ui.test.tsx (28) 718ms
   ✓ data protocol stream (9)
     ✓ should show streamed response
     ✓ should set stream data
     ✓ setData (2)
       ✓ should set data
       ✓ should clear data
     ✓ should show error response when there is a server error
     ✓ should show error response when there is a streaming error
     ✓ loading state (2)
       ✓ should show loading state
       ✓ should reset loading state on error
     ✓ should invoke onFinish when the stream finishes
   ✓ text stream (3)
     ✓ should show streamed response
     ✓ should have stable message ids
     ✓ should invoke onFinish when the stream finishes
   ✓ form actions (1)
     ✓ should show streamed response using handleSubmit
   ✓ form actions (with options) (1)
     ✓ allowEmptySubmit
   ✓ prepareRequestBody (1)
     ✓ should show streamed response
   ✓ onToolCall (1)
     ✓ should invoke onToolCall when a tool call is received from the server's response
   ✓ tool invocations (3)
     ✓ should display partial tool call, tool call, and tool result
     ✓ should display partial tool call and tool result (when there is no tool call streaming)
     ✓ should update tool call to result when addToolResult is called
   ✓ maxSteps (2)
     ✓ two steps with automatic tool call (1)
       ✓ should automatically call api when tool call gets executed via onToolCall
     ✓ two steps with error response (1)
       ✓ should automatically call api when tool call gets executed via onToolCall
   ✓ file attachments with data url (2)
     ✓ should handle text file attachment and submission
     ✓ should handle image file attachment and submission
   ✓ file attachments with url (1)
     ✓ should handle image file attachment and submission
   ✓ attachments with empty submit (1)
     ✓ should handle image file attachment and submission
   ✓ should append message with attachments (1)
     ✓ should handle image file attachment and submission
   ✓ reload (1)
     ✓ should show streamed response
   ✓ test sending additional fields during message submission (1)
     ✓ annotations

@lqhuang
Copy link
Contributor Author

lqhuang commented Nov 29, 2024

Ready for review @himself65

@lqhuang lqhuang marked this pull request as ready for review November 29, 2024 07:22
@himself65
Copy link
Member

Thanks for helping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants