-
Notifications
You must be signed in to change notification settings - Fork 46.2k
feat(platform): Add file upload to copilot chat [SECRT-1788] #12220
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
91e6723
feat(platform): Add file upload to copilot chat [SECRT-1788]
ntindle 727d7a1
Merge branch 'dev' into ntindle/file-upload
ntindle 41eccad
fix(platform): Address PR review feedback for file upload feature
ntindle 6c3cc6b
Merge branch 'ntindle/file-upload' of https://github.com/Significant-…
ntindle c15e425
fix(platform): Address second-round review feedback
ntindle 4aa8eb5
feat(frontend): Purple user file cards + restore attachments on refresh
ntindle 6d828d1
feat(frontend): Add drag-and-drop file upload to copilot chat
ntindle d69165e
Merge remote-tracking branch 'origin/dev' into ntindle/file-upload
ntindle d40f013
fix(frontend): Fix centered file chips in new InputGroup layout
ntindle afb4b4c
refactor(platform): Remove file type extension filtering
ntindle 263d21a
dx(infra): Add .nvmrc for Node 22
ntindle 00005bf
test(backend): Add virus scan rejection test for file uploads
ntindle d29eea6
fix(frontend): Remove placeholder text leak and fix filename regex in…
ntindle 74f0506
fix(frontend): Merge dev and fix empty-message guards for file-only s…
ntindle 9d2245a
fix(platform): Pass file_ids in direct transport, add extensionless u…
ntindle 9aa032e
fix(frontend): Bypass Vercel proxy for file uploads to avoid 4.5 MB p…
ntindle 8d3b95d
fix(backend): Fix chat route test mock targets after import hoisting
ntindle 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 @@ | ||
| 22 |
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
160 changes: 160 additions & 0 deletions
160
autogpt_platform/backend/backend/api/features/chat/routes_test.py
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,160 @@ | ||
| """Tests for chat route file_ids validation and enrichment.""" | ||
|
|
||
| import fastapi | ||
| import fastapi.testclient | ||
| import pytest | ||
| import pytest_mock | ||
|
|
||
| from backend.api.features.chat import routes as chat_routes | ||
|
|
||
| app = fastapi.FastAPI() | ||
| app.include_router(chat_routes.router) | ||
|
|
||
| client = fastapi.testclient.TestClient(app) | ||
|
|
||
| TEST_USER_ID = "3e53486c-cf57-477e-ba2a-cb02dc828e1a" | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_app_auth(mock_jwt_user): | ||
| from autogpt_libs.auth.jwt_utils import get_jwt_payload | ||
|
|
||
| app.dependency_overrides[get_jwt_payload] = mock_jwt_user["get_jwt_payload"] | ||
| yield | ||
| app.dependency_overrides.clear() | ||
|
|
||
|
|
||
| # ---- file_ids Pydantic validation (B1) ---- | ||
|
|
||
|
|
||
| def test_stream_chat_rejects_too_many_file_ids(): | ||
| """More than 20 file_ids should be rejected by Pydantic validation (422).""" | ||
| response = client.post( | ||
| "/sessions/sess-1/stream", | ||
| json={ | ||
| "message": "hello", | ||
| "file_ids": [f"00000000-0000-0000-0000-{i:012d}" for i in range(21)], | ||
| }, | ||
| ) | ||
| assert response.status_code == 422 | ||
|
|
||
|
|
||
| def _mock_stream_internals(mocker: pytest_mock.MockFixture): | ||
| """Mock the async internals of stream_chat_post so tests can exercise | ||
| validation and enrichment logic without needing Redis/RabbitMQ.""" | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes._validate_and_get_session", | ||
| return_value=None, | ||
| ) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.append_and_save_message", | ||
| return_value=None, | ||
| ) | ||
| mock_registry = mocker.MagicMock() | ||
| mock_registry.create_session = mocker.AsyncMock(return_value=None) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.stream_registry", | ||
| mock_registry, | ||
| ) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.enqueue_copilot_turn", | ||
| return_value=None, | ||
| ) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.track_user_message", | ||
| return_value=None, | ||
| ) | ||
|
|
||
|
|
||
| def test_stream_chat_accepts_20_file_ids(mocker: pytest_mock.MockFixture): | ||
| """Exactly 20 file_ids should be accepted (not rejected by validation).""" | ||
| _mock_stream_internals(mocker) | ||
| # Patch workspace lookup as imported by the routes module | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.get_or_create_workspace", | ||
| return_value=type("W", (), {"id": "ws-1"})(), | ||
| ) | ||
| mock_prisma = mocker.MagicMock() | ||
| mock_prisma.find_many = mocker.AsyncMock(return_value=[]) | ||
| mocker.patch( | ||
| "prisma.models.UserWorkspaceFile.prisma", | ||
| return_value=mock_prisma, | ||
| ) | ||
|
|
||
| response = client.post( | ||
| "/sessions/sess-1/stream", | ||
| json={ | ||
| "message": "hello", | ||
| "file_ids": [f"00000000-0000-0000-0000-{i:012d}" for i in range(20)], | ||
| }, | ||
| ) | ||
| # Should get past validation — 200 streaming response expected | ||
| assert response.status_code == 200 | ||
|
|
||
|
|
||
| # ---- UUID format filtering ---- | ||
|
|
||
|
|
||
| def test_file_ids_filters_invalid_uuids(mocker: pytest_mock.MockFixture): | ||
| """Non-UUID strings in file_ids should be silently filtered out | ||
| and NOT passed to the database query.""" | ||
| _mock_stream_internals(mocker) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.get_or_create_workspace", | ||
| return_value=type("W", (), {"id": "ws-1"})(), | ||
| ) | ||
|
|
||
| mock_prisma = mocker.MagicMock() | ||
| mock_prisma.find_many = mocker.AsyncMock(return_value=[]) | ||
| mocker.patch( | ||
| "prisma.models.UserWorkspaceFile.prisma", | ||
| return_value=mock_prisma, | ||
| ) | ||
|
|
||
| valid_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| client.post( | ||
| "/sessions/sess-1/stream", | ||
| json={ | ||
| "message": "hello", | ||
| "file_ids": [ | ||
| valid_id, | ||
| "not-a-uuid", | ||
| "../../../etc/passwd", | ||
| "", | ||
| ], | ||
| }, | ||
| ) | ||
|
|
||
| # The find_many call should only receive the one valid UUID | ||
| mock_prisma.find_many.assert_called_once() | ||
| call_kwargs = mock_prisma.find_many.call_args[1] | ||
| assert call_kwargs["where"]["id"]["in"] == [valid_id] | ||
|
|
||
|
|
||
| # ---- Cross-workspace file_ids ---- | ||
|
|
||
|
|
||
| def test_file_ids_scoped_to_workspace(mocker: pytest_mock.MockFixture): | ||
| """The batch query should scope to the user's workspace.""" | ||
| _mock_stream_internals(mocker) | ||
| mocker.patch( | ||
| "backend.api.features.chat.routes.get_or_create_workspace", | ||
| return_value=type("W", (), {"id": "my-workspace-id"})(), | ||
| ) | ||
|
|
||
| mock_prisma = mocker.MagicMock() | ||
| mock_prisma.find_many = mocker.AsyncMock(return_value=[]) | ||
| mocker.patch( | ||
| "prisma.models.UserWorkspaceFile.prisma", | ||
| return_value=mock_prisma, | ||
| ) | ||
|
|
||
| fid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| client.post( | ||
| "/sessions/sess-1/stream", | ||
| json={"message": "hi", "file_ids": [fid]}, | ||
| ) | ||
|
|
||
| call_kwargs = mock_prisma.find_many.call_args[1] | ||
| assert call_kwargs["where"]["workspaceId"] == "my-workspace-id" | ||
| assert call_kwargs["where"]["isDeleted"] is False |
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.