Repository navigation
refactor(studio): derive notebook diff entries - #49109
Conversation
The AI Assistant can create and edit notebooks behind an approval gate, but there is no way to show the user what they are approving. Rendering a diff needs the operations resolved into annotated cell positions, not just the resulting cells. Introduce `deriveNotebookDiff`, which resolves an ordered list of operations into one annotated entry per cell position (unchanged, added, removed, replaced, moved). `applyNotebookOperations` becomes a thin projection over its result, so there is a single interpreter of notebook operations and the diff a user approves cannot disagree with the cells that get written. The existing tests pass untouched, which is the evidence that the projection is faithful. Notes on the annotations: - `removed` entries stay in the position the cell used to hold so the list reads as a diff. This does not perturb insert-anchor arithmetic: prior inserts still sit contiguously after their anchor. - Moves that cancel out are downgraded to `unchanged`, since two moves can anchor on each other and leave every cell where it started. Badging those as moved would make the preview lie. - `fromIndex` is the cell's position in the original notebook rather than in the shifted working order, so "was #3" means what a reader expects. Also fix a latent bug this made visible: replacing a cell dropped its id, so `[replace cell-2, insert after cell-2]` failed with a spurious `unknown_cell_id`. A replacement holds the same position, so the old id is still a meaningful anchor. Anchoring and targeting are now separate lookups — a replaced cell can be anchored on but is never a legitimate target, which the conflict pre-pass already guaranteed and the types now enforce.
|
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review. 📝 WalkthroughWalkthroughNotebook operations now derive an annotated diff for unchanged, added, removed, replaced, and moved cells. ChangesNotebook diff processing
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The PR derives notebook diff entries and preserves replaced-cell anchors while keeping cell application behavior aligned; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › clicking broadcast message shows detail panel Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
awaseem
left a comment
There was a problem hiding this comment.
Not sure if the comments are needed in the operation functions. Can remove them
Reviewer feedback on PR 1 of the notebook-diff stack: the doc comments added alongside deriveNotebookDiff were unnecessary. Removes them; no behavior change (all 29 existing tests still pass unmodified).
Braintrust eval report
|
## Summary Stacked on #49109 (PR 1 — `deriveNotebookDiff`). This is PR 3 of the notebook approval-preview stack: a pure presentational component that renders the cell-level diff for a proposed notebook create/update, for use in the assistant approval UI (wired in a later PR). - `NotebookPreview` — header summary (`"6 cells"` for create, `"+2 −1 ~1 ↕1"` for update) + entry list + "Show N more cells" for long notebooks. - `NotebookPreviewCell` — dispatches per entry tag: `unchanged`/`removed`/`moved` collapse to a muted badge row; `added` renders source via `CodeBlock` (with a max-height/expand toggle); `replaced` renders a `DiffEditor` diff, plus a before → after metadata line when only `database_identifier`/`time_range` changed (SQL/text identical). - `NotebookPreview.utils` — pure helpers (labels, source/metadata extraction, language mapping, summary formatting), unit tested. - **Safety property**: cell content only ever renders through `CodeBlock`/`DiffEditor` (literal source), never through a markdown renderer — agent-authored text can't trigger image loads or link navigation before the user approves. Covered by an adversarial test (``, `[y](evil)`, `<img onerror>` → zero `img`/`[href]`/`[src]` DOM nodes). - Adds `'markdown'` as a supported `CodeBlock` language (small, additive change to `packages/ui-patterns`). Towards FE-4143 ## Test plan - [x] `pnpm --filter studio test` — NotebookPreview suite (21 tests) passes - [x] `pnpm --filter studio exec eslint components/interfaces/Explorer/NotebookPreview` — clean - [x] `pnpm --filter studio exec tsc --noEmit` — no new errors - [x] `pnpm exec prettier --check` — clean <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added notebook previews showing create and update summaries. * Displayed added, removed, moved, unchanged, and replaced cells with metadata and source diffs. * Added expandable previews with truncation and a “Show more cells” option. * Added Markdown syntax highlighting to code blocks. * **Bug Fixes** * Safely render adversarial agent-authored Markdown as literal content. * **Tests** * Added comprehensive coverage for notebook previews, summaries, metadata, formatting, and truncation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
While testing the operation compositions introduced here, I found two cases that still reproduce on current master with focused Vitest regressions: Both involve interactions between individually supported operations. I’m not sure whether the resulting diff behavior is intentional, so I filed them separately for confirmation. |
|
Thanks for catching these and putting together such clear Vitest repros @anp0429! Both are legit issues in
|
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Refactor, plus one bug fix.
Groundwork for showing the user a preview of what they are approving when the AI Assistant creates or edits a notebook. No UI in this PR.
Towards FE-4143
What is the current behavior?
applyNotebookOperationsresolves an ordered list of notebook operations into the resulting cells and nothing else. Rendering a diff for the approval gate needs to know what happened to each cell position, not just where things landed, so there is no way to build the preview on top of it.Separately, replacing a cell dropped its id, so
[replace cell-2, insert after cell-2]failed with a spuriousunknown_cell_id.What is the new behavior?
deriveNotebookDiffresolves operations into one annotated entry per cell position (unchanged,added,removed,replaced,moved).applyNotebookOperationsbecomes a thin projection over its result, so there is a single interpreter of notebook operations and the diff a user approves cannot disagree with the cells that get written. The pre-existing tests pass untouched, which is the evidence that the projection is faithful.Notes on the annotations:
removedentries stay in the position the cell used to hold so the list reads as a diff. This does not perturb insert-anchor arithmetic: prior inserts still sit contiguously after their anchor.unchanged, since two moves can anchor on each other and leave every cell where it started. Badging those as moved would make the preview lie.fromIndexis the cell's position in the original notebook rather than in the shifted working order, sowas #3means what a reader expects.A replaced cell now stays addressable as an anchor. Anchoring and targeting are separate lookups: a replaced cell can be anchored on, but is never a legitimate target.
Summary by CodeRabbit
New Features
Bug Fixes