Repository navigation
feat(studio): discriminated snippet union + source-aware writes - #48313
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughSQL editor snippets now support database and logs sources. Source-specific types, sanitization, persistence remapping, state updates, fixture creation, and editor SQL retrieval were updated, with tests covering both ChangesSource-aware snippet creation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/data/content/content-remap.ts (1)
33-42: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winKeep wire payloads separate from the domain union at both boundaries.
Both changes assert API rows as
SnippetWithContentbeforecontent.sqlis converted and/orstatusis added.
apps/studio/data/content/content-remap.ts#L33-L42: validate or type the wire row before remapping.apps/studio/data/content/sql-snippets-query.ts#L52-L52: pass the wire list type to the remapper and produceSnippetWithContent[]only afterwithSavedStatus.As per coding guidelines, avoid
ascasts and parse external data with Zod.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/data/content/content-remap.ts` around lines 33 - 42, Keep wire payloads separate from the domain union at both boundaries: in apps/studio/data/content/content-remap.ts lines 33-42, replace the SnippetWithContent assertion in remapWireSnippet with Zod validation or an appropriate wire-row type before remapping; in apps/studio/data/content/sql-snippets-query.ts line 52, pass the wire list type to the remapper and only produce SnippetWithContent[] after withSavedStatus, avoiding `as` casts throughout.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/studio/data/content/content-remap.ts`:
- Around line 33-42: Keep wire payloads separate from the domain union at both
boundaries: in apps/studio/data/content/content-remap.ts lines 33-42, replace
the SnippetWithContent assertion in remapWireSnippet with Zod validation or an
appropriate wire-row type before remapping; in
apps/studio/data/content/sql-snippets-query.ts line 52, pass the wire list type
to the remapper and only produce SnippetWithContent[] after withSavedStatus,
avoiding `as` casts throughout.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 18f64415-6295-47b3-9c29-ba33799ca96f
📒 Files selected for processing (18)
apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.tsapps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsxapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/SQLEditor/usePrettifyQuery.tsapps/studio/data/content/content-id-query.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.tsapps/studio/data/content/sql-folders-query.tsapps/studio/data/content/sql-snippets-query.tsapps/studio/state/sql-editor/sql-editor-rules.test.tsapps/studio/state/sql-editor/sql-editor-rules.tsapps/studio/state/sql-editor/sql-editor-save-scheduler.test.tsapps/studio/state/sql-editor/sql-editor-save.test.tsapps/studio/state/sql-editor/sql-editor-state.test.tsapps/studio/state/sql-editor/sql-editor-state.tsapps/studio/tests/lib/sql-editor-test-utils.tsx
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › database.spec.ts › Database Enumerated Types › CRUD operations works as expected Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
c939c88 to
e987da5
Compare
Make SnippetWithContent a discriminated union on `type` (sql →
SqlSnippets.Content, log_sql → LogSqlSnippets.Content, report →
content?: never) so database and logs SQL brands can never cross execution
paths. Source-aware writes: `setSql` brands per snippet type,
`buildUpsertPayload` persists the snippet's own type, and
`createSqlSnippetSkeletonV2({ source })` emits the matching type + content
shape cast-free. New `querySource.ts` exposes `SqlSnippetSource` +
`getSnippetSource`; `seedSnippet` gains a `source` arg. Concentrate the
wire->domain assertion in a single `remapWireSnippet` boundary helper so the
content query/mutation call sites are cast-free.
PR 3 of the SQL-editor query-source stack. No user-visible change (no entry
points yet). Green on typecheck, lint:ratchet, and test:studio.
0db771a to
66b10a8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/data/content/sql-snippets-query.ts`:
- Line 52: Validate the API payload before remapping in the query flow
containing remapSqlContentFields. Replace the unsafe data.data cast with the
appropriate Zod wire-schema parse, or use an existing validating fetcher, and
pass the parsed SnippetWithContent[] result to remapSqlContentFields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 972fe4cc-5329-4f59-9abe-eed9811b4a06
📒 Files selected for processing (18)
apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.tsapps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsxapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/SQLEditor/usePrettifyQuery.tsapps/studio/data/content/content-id-query.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.tsapps/studio/data/content/sql-folders-query.tsapps/studio/data/content/sql-snippets-query.tsapps/studio/state/sql-editor/sql-editor-rules.test.tsapps/studio/state/sql-editor/sql-editor-rules.tsapps/studio/state/sql-editor/sql-editor-save-scheduler.test.tsapps/studio/state/sql-editor/sql-editor-save.test.tsapps/studio/state/sql-editor/sql-editor-state.test.tsapps/studio/state/sql-editor/sql-editor-state.tsapps/studio/tests/lib/sql-editor-test-utils.tsx
🚧 Files skipped from review as they are similar to previous changes (15)
- apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts
- apps/studio/state/sql-editor/sql-editor-save.test.ts
- apps/studio/components/interfaces/SQLEditor/querySource.ts
- apps/studio/state/sql-editor/sql-editor-save-scheduler.test.ts
- apps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsx
- apps/studio/data/content/content-upsert-mutation.ts
- apps/studio/data/content/content-id-query.ts
- apps/studio/state/sql-editor/sql-editor-state.test.ts
- apps/studio/state/sql-editor/sql-editor-rules.test.ts
- apps/studio/data/content/content-remap.ts
- apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
- apps/studio/tests/lib/sql-editor-test-utils.tsx
- apps/studio/data/content/sql-folders-query.ts
- apps/studio/state/sql-editor/sql-editor-state.ts
- apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts
| const snippets = remapSqlContentFields( | ||
| data.data as unknown as Array<Snippet & { content?: SqlSnippets.Content }> | ||
| ) | ||
| const snippets = remapSqlContentFields(data.data as unknown as SnippetWithContent[]) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Validate the wire response before remapping.
Line 52 uses as unknown as SnippetWithContent[], so the discriminated union is only enforced at compile time. Parse the API payload with the appropriate Zod wire schema before calling remapSqlContentFields, or use a fetcher that performs this validation.
As per coding guidelines, external data should be parsed with Zod instead of bypassed with TypeScript casts.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/studio/data/content/sql-snippets-query.ts` at line 52, Validate the API
payload before remapping in the query flow containing remapSqlContentFields.
Replace the unsafe data.data cast with the appropriate Zod wire-schema parse, or
use an existing validating fetcher, and pass the parsed SnippetWithContent[]
result to remapSqlContentFields.
Source: Coding guidelines
Braintrust eval report
|
Stacked on #48305.
What
PR 3 of the stacked SQL-editor query-source series (Database vs Logs). Stacked on the PR 2 branch
charislam/log-sql-content-shape.Turns
SnippetWithContentinto a discriminated union ontypeand makes all snippet writes source-aware:data/content/sql-folders-query.ts:SnippetWithContentis now{ type: 'sql'; content?: SqlSnippets.Content } | { type: 'log_sql'; content?: LogSqlSnippets.Content } | { type: 'report'; content?: never }.reportis kept (the content endpoints' wire type carries it) but has no SQL content — its body isDashboards.Content, loaded through the separateContentunion.setSqlbrands per type (untrustedLogSqlvsuntrustedSql).buildUpsertPayloadpersistssnippet.type(no longer hardcoded'sql').createSqlSnippetSkeletonV2({ source })emits the matching type + content shape with theas anycast removed.components/interfaces/SQLEditor/querySource.ts:SqlSnippetSource+getSnippetSource.seedSnippettest helper gains asourcearg.remapWireSnippetboundary helper incontent-remap.tsconcentrates the single wire->domain assertion, socontent-id-query/content-upsert-mutationcall sites are cast-free (noas unknown as).updateSnippetno longer acceptstype(source is immutable); db-only editor read paths narrow awaylog_sql.Why
Impossible-states-impossible typing: a snippet's brand follows its content type, so logs SQL and database SQL can never cross execution paths. No behavior change for existing database snippets.
Testing
Summary by CodeRabbit