-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: copilot breaking change introduced in 2.8.5 #2647
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
+381
−135
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b31aa6d
fix: add default value for optional session init parameters
asvishnyakov c5846cf
fix: check thread existence
asvishnyakov 4e3c712
test: refactor related tests
asvishnyakov bd9599f
Merge branch 'main' into fix/2641
asvishnyakov 91870ce
chore: fix linting issue
asvishnyakov 66c4d93
test: fix e2e ACL test
asvishnyakov bae9ec7
revert: remove temporary skip from tests
asvishnyakov 49b3b66
test: fix data layer e2e test
asvishnyakov 68c0b98
test: remove unnecessary as: we need interception itself, not it's re…
asvishnyakov 0ae9751
style: fix liting error
asvishnyakov b73d40d
test: fix after review
asvishnyakov 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
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,52 @@ | ||
| import os | ||
| from uuid import uuid4 | ||
|
|
||
| import chainlit as cl | ||
| from chainlit.auth import create_jwt | ||
| from chainlit.server import _authenticate_user, app | ||
| from chainlit.user import User | ||
| from fastapi import Request, Response | ||
|
|
||
| os.environ["CHAINLIT_AUTH_SECRET"] = "SUPER_SECRET" # nosec B105 | ||
| os.environ["CHAINLIT_CUSTOM_AUTH"] = "true" | ||
|
|
||
|
|
||
| @app.get("/auth/custom") | ||
| async def custom_auth(request: Request) -> Response: | ||
| user_id = str(uuid4()) | ||
|
|
||
| user = User(identifier=user_id, metadata={"role": "user"}) | ||
| response = await _authenticate_user(request, user) | ||
|
|
||
| return response | ||
|
|
||
|
|
||
| @app.get("/auth/token") | ||
| async def custom_token_auth() -> Response: | ||
| user_id = str(uuid4()) | ||
|
|
||
| user = User(identifier=user_id, metadata={"role": "admin"}) | ||
| response = create_jwt(user) | ||
|
|
||
| return response | ||
|
|
||
|
|
||
| catch_all_route = None | ||
| for route in app.routes: | ||
| if route.path == "/{full_path:path}": | ||
| catch_all_route = route | ||
|
|
||
| if catch_all_route: | ||
| app.routes.remove(catch_all_route) | ||
| app.routes.append(catch_all_route) | ||
|
|
||
|
|
||
| @cl.on_chat_start | ||
| async def on_chat_start(): | ||
| user = cl.user_session.get("user") | ||
| await cl.Message(f"Hello {user.identifier}").send() | ||
|
|
||
|
|
||
| @cl.on_message | ||
| async def on_message(msg: cl.Message): | ||
| await cl.Message(content=f"Echo: {msg.content}").send() |
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,130 @@ | ||
| import { loadCopilotScript, mountCopilotWidget, openCopilot, submitMessage } from '../../support/testUtils'; | ||
|
|
||
| function login() { | ||
| return cy.request({ | ||
| method: 'GET', | ||
| url: '/auth/custom', | ||
| followRedirect: false | ||
| }) | ||
| } | ||
|
|
||
| function getToken() { | ||
| return cy.request({ | ||
| method: 'GET', | ||
| url: '/auth/token', | ||
| followRedirect: false | ||
| }) | ||
| } | ||
|
|
||
| function shouldShowGreetingMessage() { | ||
| it('should show greeting message', () => { | ||
| cy.get('.step').should('exist'); | ||
| cy.get('.step').should('contain', 'Hello'); | ||
| }); | ||
| } | ||
|
|
||
| function shouldSendMessageAndRecieveAnswer() { | ||
| it('should send message and receive answer', () => { | ||
| cy.get('.step').should('contain', 'Hello'); | ||
|
|
||
| const testMessage = 'Test message from custom auth'; | ||
| submitMessage(testMessage); | ||
|
|
||
| cy.get('.step').should('contain', 'Echo:'); | ||
| cy.get('.step').should('contain', testMessage); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| describe('Custom Auth', () => { | ||
| describe('when unauthenticated', () => { | ||
| beforeEach(() => { | ||
| cy.intercept('GET', '/user').as('user'); | ||
| }); | ||
|
|
||
| it('should attempt to and not have permission to access /user', () => { | ||
asvishnyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cy.wait('@user').then((interception) => { | ||
| expect(interception.response.statusCode).to.equal(401); | ||
| }); | ||
| }); | ||
|
|
||
| it('should redirect to login dialog', () => { | ||
| cy.location('pathname').should('eq', '/login'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('authenticating via custom endpoint', () => { | ||
| beforeEach(() => { | ||
| login().then((response) => { | ||
| expect(response.status).to.equal(200); | ||
| // Verify cookie is set in response headers | ||
| expect(response.headers).to.have.property('set-cookie'); | ||
| const cookies = Array.isArray(response.headers['set-cookie']) | ||
| ? response.headers['set-cookie'] | ||
| : [response.headers['set-cookie']]; | ||
| expect(cookies[0]).to.contain('access_token'); | ||
| }); | ||
| }); | ||
|
|
||
| const shouldBeLoggedIn = () => { | ||
| it('should not be on /login', () => { | ||
| cy.location('pathname').should('not.contain', '/login'); | ||
| }); | ||
|
|
||
| shouldShowGreetingMessage(); | ||
| }; | ||
|
|
||
| shouldBeLoggedIn(); | ||
|
|
||
| it('should request and have access to /user', () => { | ||
asvishnyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cy.intercept('GET', '/user').as('user'); | ||
| cy.wait('@user').then((interception) => { | ||
| expect(interception.response.statusCode).to.equal(200); | ||
| }); | ||
| }); | ||
|
|
||
| shouldSendMessageAndRecieveAnswer(); | ||
|
|
||
| describe('after reloading', () => { | ||
| beforeEach(() => { | ||
| cy.reload(); | ||
| }); | ||
|
|
||
| shouldBeLoggedIn(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Copilot Token', { includeShadowDom: true }, () => { | ||
| beforeEach(() => { | ||
| cy.location('pathname').should('eq', '/login'); | ||
|
|
||
| loadCopilotScript(); | ||
| }); | ||
|
|
||
| describe('when unauthenticated', () => { | ||
| it('should throw error about missing authentication token', () => { | ||
| mountCopilotWidget(); | ||
| openCopilot(); | ||
| cy.get('#chainlit-copilot-chat').should('contain', 'No authentication token provided.'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('authenticating via custom endpoint', () => { | ||
| beforeEach(() => { | ||
| getToken().then((response) => { | ||
| expect(response.status).to.equal(200); | ||
|
|
||
| const accessToken = response.body | ||
| expect(accessToken).to.not.be.null; | ||
|
|
||
| mountCopilotWidget({ accessToken }); | ||
| openCopilot(); | ||
| }); | ||
| }) | ||
|
|
||
| shouldShowGreetingMessage(); | ||
|
|
||
| shouldSendMessageAndRecieveAnswer(); | ||
| }); | ||
| }); | ||
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.