Repository navigation
feat(studio): log_sql content shape + remap content.sql to unchecked_sql - #48305
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. |
📝 WalkthroughWalkthroughLog SQL snippets now use branded ChangesLog SQL content handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant LogsExplorer
participant upsertContent
participant API
participant contentRemap
LogsExplorer->>upsertContent: submit branded log SQL
upsertContent->>contentRemap: unmap unchecked_sql
contentRemap->>API: send content.sql
API-->>contentRemap: return content.sql
contentRemap-->>upsertContent: remap to unchecked_sql
upsertContent-->>LogsExplorer: return branded log SQL
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
|
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › start/stop listening button works Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/components/interfaces/SQLEditor/MoveQueryModal.tsx (1)
139-141: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression test for the SQL-content fallback path.
Cover a snippet without in-memory content, verify
getSqlSnippetByIdsuppliesunchecked_sql, and assert the move request sends API-facingcontent.sql.As per coding guidelines: Include relevant tests by default using Vitest and MSW with
customRenderandaddAPIMock.Also applies to: 158-158
🤖 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/components/interfaces/SQLEditor/MoveQueryModal.tsx` around lines 139 - 141, In the MoveQueryModal test coverage, add a Vitest regression test for a snippet missing in-memory content that mocks getSqlSnippetById via MSW to return unchecked_sql, then verifies the move request sends that value as API-facing content.sql. Use the existing customRender and addAPIMock helpers and cover the fallback path around getSqlSnippetById.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/components/interfaces/SQLEditor/MoveQueryModal.tsx`:
- Around line 139-141: In the MoveQueryModal test coverage, add a Vitest
regression test for a snippet missing in-memory content that mocks
getSqlSnippetById via MSW to return unchecked_sql, then verifies the move
request sends that value as API-facing content.sql. Use the existing
customRender and addAPIMock helpers and cover the fallback path around
getSqlSnippetById.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 220e2f66-3322-4de6-93e3-2d4754014cbe
📒 Files selected for processing (11)
apps/studio/components/interfaces/SQLEditor/MoveQueryModal.tsxapps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.test.tsxapps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.tsxapps/studio/components/interfaces/Settings/Logs/RecentQueriesItem.tsxapps/studio/components/ui/EditorPanel/EditorPanel.tsxapps/studio/data/content/content-remap.test.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.test.tsapps/studio/pages/project/[ref]/logs/explorer/index.tsxapps/studio/pages/project/[ref]/logs/explorer/recent.tsxapps/studio/types/userContent.ts
Client-side rename only — the wire format is unchanged (the API still stores/returns `content.sql`); this moves the frontend field to the branded `unchecked_sql`, matching SqlSnippets.Content: - types/userContent.ts: LogSqlSnippets.Content's plain `sql: string` becomes `unchecked_sql: UntrustedLogSqlFragment`. - data/content/content-remap.ts: extend remap/unmap to `log_sql`, branding per type (untrustedLogSql for logs, untrustedSql for database) and never mixing brands. Defensive unmap: content missing `unchecked_sql` is never clobbered with `sql: undefined`; a residual raw `sql` field (a missed save-path rename) throws in development to surface the bug loudly. - Update the legacy Logs Explorer consumers to the branded field: the explorer save/update paths, SavedQueriesItem, RecentQueriesItem, and the recent-queries page. - Removing `sql` from LogSqlSnippets.Content forced two db-only write sites to stop leaning on it: EditorPanel now saves `unchecked_sql`, and MoveQueryModal switches to the SQL-editor-specific getSqlSnippetById so its content is typed as SqlSnippets.Content with no narrowing/casting. Tests: - content-remap: log_sql remap/unmap round-trip with the logs brand; the defensive-unmap no-op (prod) and dev throw. - content-upsert-mutation: a log_sql payload reaches the wire as a plain `content.sql` and the response remaps back to `unchecked_sql`.
The recent-queries list is backed by localStorage, which bypasses the API remap boundary, so entries written before the rename still carry a raw `sql` field. Introduce useRecentLogSqlSnippets: a shared hook that reads the `project-content-<ref>-recent-log-sql` store, brands any legacy `sql` into `unchecked_sql` on read (healing storage on the next write), and always surfaces the branded `LogSqlSnippets.Content` shape to consumers. The explorer page and the recent-queries page both use it. Unit tests cover the normalizer's legacy, already-branded, and empty cases.
c939c88 to
e987da5
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.ts (1)
41-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid unmeasured
useMemohere.This is a small normalization map, and no memoized consumer requiring referential stability is shown. Return the mapped value directly unless profiling or a memoized child justifies the memoization.
As per coding guidelines,
useMemoshould be reserved for measured expense or required referential stability.🤖 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/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.ts` around lines 41 - 44, Remove the unnecessary useMemo wrapper around the snippets calculation in the recent log SQL snippets hook, returning stored.map(normalizeRecentLogSqlSnippet) directly. Remove any now-unused useMemo import while preserving the existing normalization behavior.Source: Coding guidelines
apps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.test.ts (1)
24-36: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd coverage for entries containing both fields.
The implementation promises that
unchecked_sqlwins when legacysqlremains present, but no test exercises that migration state.Suggested test
+ it('prefers unchecked_sql when both fields are present', () => { + const result = normalizeRecentLogSqlSnippet({ + content_id: 'b', + schema_version: '1', + sql: 'select legacy', + unchecked_sql: untrustedLogSql(SQL), + }) + + expect(result.unchecked_sql).toEqual(untrustedLogSql(SQL)) + expect(result).not.toHaveProperty('sql') + })🤖 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/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.test.ts` around lines 24 - 36, Add a test alongside the existing normalizeRecentLogSqlSnippet cases that supplies both legacy sql and branded unchecked_sql fields, then assert the result retains unchecked_sql, excludes sql, and preserves the other entry properties.
🤖 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/pages/project/`[ref]/logs/explorer/recent.tsx:
- Around line 35-36: Update the key on the RecentQueriesItem mapping to use the
stable unique item.content_id identifier instead of item.unchecked_sql,
preserving the existing recent query rendering behavior.
---
Nitpick comments:
In
`@apps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.test.ts`:
- Around line 24-36: Add a test alongside the existing
normalizeRecentLogSqlSnippet cases that supplies both legacy sql and branded
unchecked_sql fields, then assert the result retains unchecked_sql, excludes
sql, and preserves the other entry properties.
In `@apps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.ts`:
- Around line 41-44: Remove the unnecessary useMemo wrapper around the snippets
calculation in the recent log SQL snippets hook, returning
stored.map(normalizeRecentLogSqlSnippet) directly. Remove any now-unused useMemo
import while preserving the existing normalization behavior.
🪄 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: 818f6643-f3e6-4c7c-97b7-364f0197adf5
📒 Files selected for processing (13)
apps/studio/components/interfaces/SQLEditor/MoveQueryModal.tsxapps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.test.tsxapps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.tsxapps/studio/components/interfaces/Settings/Logs/RecentQueriesItem.tsxapps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.test.tsapps/studio/components/interfaces/Settings/Logs/useRecentLogSqlSnippets.tsapps/studio/components/ui/EditorPanel/EditorPanel.tsxapps/studio/data/content/content-remap.test.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.test.tsapps/studio/pages/project/[ref]/logs/explorer/index.tsxapps/studio/pages/project/[ref]/logs/explorer/recent.tsxapps/studio/types/userContent.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- apps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.test.tsx
- apps/studio/pages/project/[ref]/logs/explorer/index.tsx
- apps/studio/components/ui/EditorPanel/EditorPanel.tsx
- apps/studio/components/interfaces/Settings/Logs/RecentQueriesItem.tsx
- apps/studio/data/content/content-remap.ts
- apps/studio/types/userContent.ts
- apps/studio/components/interfaces/Settings/Logs/Logs.SavedQueriesItem.tsx
- apps/studio/data/content/content-remap.test.ts
- apps/studio/data/content/content-upsert-mutation.test.ts
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 `SnippetWithContent` into a discriminated union on `type` and makes all snippet writes source-aware: - `data/content/sql-folders-query.ts`: `SnippetWithContent` is now `{ type: 'sql'; content?: SqlSnippets.Content } | { type: 'log_sql'; content?: LogSqlSnippets.Content } | { type: 'report'; content?: never }`. `report` is kept (the content endpoints' wire type carries it) but has no SQL content — its body is `Dashboards.Content`, loaded through the separate `Content` union. - `setSql` brands per type (`untrustedLogSql` vs `untrustedSql`). - `buildUpsertPayload` persists `snippet.type` (no longer hardcoded `'sql'`). - `createSqlSnippetSkeletonV2({ source })` emits the matching type + content shape with the `as any` cast removed. - New `components/interfaces/SQLEditor/querySource.ts`: `SqlSnippetSource` + `getSnippetSource`. - `seedSnippet` test helper gains a `source` arg. - New `remapWireSnippet` boundary helper in `content-remap.ts` concentrates the single wire->domain assertion, so `content-id-query` / `content-upsert-mutation` call sites are cast-free (no `as unknown as`). - Collateral: query result types aligned to the union; `updateSnippet` no longer accepts `type` (source is immutable); db-only editor read paths narrow away `log_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 - \`pnpm typecheck\` — clean - \`pnpm --filter studio run lint:ratchet\` — no new warnings - \`pnpm test:studio\` (data/content, SQLEditor, state/sql-editor) — passing, including new tests for \`getSnippetSource\`, source-aware \`setSql\`, type-aware \`buildUpsertPayload\`, and both skeleton shapes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added source-aware creation for SQL editor snippets, including log-based SQL snippets. * Introduced backend source mapping so log snippets are treated as log_sql. * **Bug Fixes** * Improved SQL retrieval/prettification so log snippets no longer use the wrong fallback content. * Ensured log snippets are sanitized and preserve correct type, content, identifiers, and statuses during save/upsert flows. * **Tests** * Expanded unit and integration coverage for log snippet creation, source mapping, editing, prettification, and upsert payloads. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
What
PR 2 of 9 in the SQL-editor query-source (Database vs Logs) stack.
Base:
charislam/snippet-source-typing(#48301) — this is a stacked PR; review/merge that one first.Client-side rename only — the wire format is unchanged (the platform API still stores and returns
content.sql). This moves the frontendLogSqlSnippets.Contentfield to the brandedunchecked_sql, matchingSqlSnippets.Content, and hardens the remap boundary so the rename can't silently drop saved query text.Changes
types/userContent.ts—LogSqlSnippets.Content's plainsql: stringbecomesunchecked_sql: UntrustedLogSqlFragment(the brand added in PR 1). Shape kept minimal:{ content_id, unchecked_sql, schema_version }.data/content/content-remap.ts— extendremapSqlContentField/unmapSqlContentFieldtolog_sql, branding per type (untrustedLogSqlfor logs,untrustedSqlfor database) and never mixing brands. Defensive unmap: content missingunchecked_sqlis never clobbered withsql: undefined; a residual rawsqlfield (a missed save-path rename) throws in development to surface the bug loudly, while production no-ops safely.SavedQueriesItem,RecentQueriesItem, and the recent-queries page.LogSqlSnippets.Content.sql:EditorPanelnow savesunchecked_sql, andMoveQueryModalswitches to the SQL-editor-specificgetSqlSnippetByIdso its content is typed asSqlSnippets.Content— no narrowing or casting.Tests
log_sqlremap/unmap round-trip with the logs brand; the defensive-unmap no-op (prod) and dev throw.log_sqlpayload reaches the wire as a plaincontent.sqland the response remaps back tounchecked_sql(the data-loss-critical round-trip shared by both explorer save-new andSavedQueriesItemupdate).Verification
pnpm --filter studio run typecheck✓pnpm --filter studio run lint:ratchet✓ (no new warnings)pnpm test:studiofordata/content+Settings/Logs— 139 passing ✓Nothing is user-visible yet — logs snippet entry points arrive later in the stack behind the
sqlEditorLogsSourceflag.Summary by CodeRabbit
Bug Fixes
unchecked_sql(branded as untrusted) consistently when creating, editing, moving, and reopening queries, with correct remapping to/from the API boundary.Tests
log_sqlremap/upsert request/response behavior.