Repository navigation
ref(attachments): Choose attachment storage in one place - #2324
Merged
Merged
Conversation
Runtime entry points called createVercelAttachmentStorage() directly in four places. Route them through createAttachmentStorage() in chat/attachments/storage.ts so a later change can add another provider without editing each caller. The function still returns the Vercel Blob adapter. Runtime behavior does not change. Co-Authored-By: Thomas Jiang <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
createAttachmentStorage() now takes a provider and switches on it. Chat config holds attachmentStorage.provider, which is always vercel-blob for now. Runtime entry points pass that value, so a later provider only adds a config value and a switch case. Runtime behavior does not change.
thomasjiangcy
approved these changes
Oct 29, 2026
thomasjiangcy
added a commit
that referenced
this pull request
Oct 29, 2026
This is the second step toward local object storage, after #2324. It adds an S3 adapter for attachment storage, and a `versitygw` S3-compatible server in `compose.yaml` and CI to test it. **What changes** - `chat/attachments/s3.ts`: a new adapter that implements `AttachmentStorage` with three requests. `put` is a PUT, `get` is a GET (a 404 returns `null`), and `delete` sends one DELETE for each key (a 404 counts as deleted). It signs requests with `aws4fetch` and uses path-style URLs (`<endpoint>/<bucket>/<key>`), so it works with local S3 servers and with AWS S3. The stored `storage_provider` value is `s3`. - `chat/attachments/config.ts`: new. It reads `JUNIOR_ATTACHMENT_STORAGE_PROVIDER` and switches to the provider module for its settings. `s3.ts` owns `S3StorageConfig` and reads the `JUNIOR_S3_*` settings itself: - `JUNIOR_ATTACHMENT_STORAGE_PROVIDER`: `vercel-blob` (the default) or `s3` - `JUNIOR_S3_ENDPOINT`, `JUNIOR_S3_BUCKET`, `JUNIOR_S3_ACCESS_KEY_ID`, `JUNIOR_S3_SECRET_ACCESS_KEY`: required for `s3` - `JUNIOR_S3_REGION`: optional, defaults to `us-east-1` An invalid provider or a missing S3 setting fails at config load, the same way an invalid `JUNIOR_DATABASE_DRIVER` does. - `createAttachmentStorage()` now takes the whole `attachmentStorage` config, not only the provider name, and switches to the S3 adapter for `s3`. The four entry points pass `getChatConfig().attachmentStorage`. - I moved the attachment storage types and parsing out of `chat/config.ts` and into `chat/attachments/`. Provider-specific settings stay in their provider module. `chat/config.ts` stays under the 1,000-line limit. - Key safety: the adapter rejects keys with `.` or `..` segments. URL parsing removes them (also in `%2e` form), so a filename like `../../artifacts/x.png` could otherwise write or delete an object outside the attachment prefix. - Tests: `compose.yaml` and the Junior test CI job get an `s3` service (`versity/versitygw:v1.10.0`, host port 7072). `tests/integration/attachment-s3-storage.test.ts` runs against it: it stores an attachment with symbols in the filename, serves it from the attachment API, deletes it during garbage collection, rejects a path-traversal filename without changing the target object, and checks that rejected credentials fail without showing the key. Run it locally with `docker compose up -d s3`. - Docs: new rows in `reference/config-and-env.md` and an update to the attachments `README.md`. - Dependency: `aws4fetch@^1.0.20`, added as a direct dependency. It was already in the lockfile as an optional peer of `unstorage`. pnpm also rewrote two unrelated snapshot lines in `pnpm-lock.yaml`. **Behavior:** nothing changes unless `JUNIOR_ATTACHMENT_STORAGE_PROVIDER=s3` is set. Vercel Blob stays the default. **Error messages:** S3 errors give only the operation and HTTP status, for example `S3 put failed with status 403`. Object keys and S3 error bodies can contain user filenames, so the messages leave them out. **Checks run** - `tsc --noEmit` and the full root `pnpm lint`: file length, migration metadata, test architecture, oxlint, depcruise, ast-grep, and package lint. - `vitest run`: the config tests (with four new cases), the artifact, retention, send-files, and load-attachment tests, and every test that uses `readChatConfig`. Against the local compose Postgres, 300 tests passed. - `tests/integration/attachment-s3-storage.test.ts` against the compose `versitygw` service: 3 passed. Without the dot-segment check, the traversal case fails because the target object is overwritten. - Earlier manual check against a real `versitygw` v1.10.0 container, with a scratch test that I did not commit: - put, get, and delete for a key with spaces, `é`, `+`, `#`, and `?`; the file appeared on disk - an empty object - a missing key returns `null` - deleting a missing key succeeds - wrong credentials raise errors that do not show the key - `publishImage` and the public artifact route work end to end with real SQL **Notes** - `response.body.cancel()` hangs under the test MSW interceptor. The adapter reads small response bodies to the end instead. The S3 integration test runs under the same interceptor. - Local env defaults for S3 are not in this PR. <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CCUMX7ET0%3A1793248918.684709 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CCUMX7ET0%3A1793248918.684709) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CCUMX7ET0%3A1793248918.684709/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[email protected]>
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Runtime entry points called
createVercelAttachmentStorage()directly in four places:app.ts,api.ts,handlers/artifacts.ts, andhandlers/retention.ts. This change sends all four through one function,createAttachmentStorage(provider)inchat/attachments/storage.ts.attachmentStorage.providerfield. Its type isAttachmentStorageProviderinchat/config.ts. The value is alwaysvercel-blobfor now, and no env var sets it yet.createAttachmentStorage(provider)switches on the provider.vercel-blobreturns the existing Vercel Blob adapter.getChatConfig().attachmentStorage.provider.Runtime behavior does not change. The
AttachmentStorageinterface, the adapter, and the storedstorage_providervalue (vercel-blob) stay the same.This is the first small step toward local object storage in
compose.yaml, next to Postgres and Redis. To add an S3-compatible provider later, add a value toAttachmentStorageProvider, read it from env inreadChatConfig, and add a switch case. Callers will not need to change.The attachments
README.mdnow namescreateAttachmentStorage(provider)as the place where a provider maps to its adapter.Checks run
tsc --noEmitfor@sentry/juniorpnpm --filter @sentry/junior lint(oxlint and depcruise)pnpm ast-grep:lint, plus the file-length checkvitest runon the artifact, retention, send-files, and load-attachment tests, plus every test that usesreadChatConfig: 13 files, 223 tests passed, against the local compose PostgresI did not add tests. The change does not add behavior, and the tests above already cover the storage paths through the test adapter.
--
View Junior Session [Sentry]