Skip to content

test(studio): mock notebook tools - #48952

Merged
charislam merged 1 commit into
masterfrom
feature/notebooks-mock-tools
Aug 12, 2026
Merged

charislam merged 1 commit into
masterfrom
feature/notebooks-mock-tools

Conversation

@charislam

@charislam charislam commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds deterministic list_notebooks/get_notebook fixtures (two seeded notebooks, each with markdown/database/log cells) and stateful in-memory create_notebook/update_notebook mocks to apps/studio/lib/ai/tools/mock-tools.ts, so Braintrust evals can exercise notebook tool calls without a real project.
  • Both write-tool mocks force needsApproval: false, matching the existing execute_sql/deploy_edge_function mock pattern — the eval harness filters out tool-parts in 'approval-requested' state and can never answer an approval gate.
  • All four notebook tools are wrapped from the real getNotebookTools() definitions (only execute/needsApproval overridden), so evals validate the model's arguments against the exact production schemas.
  • Dedupes describeOperationError (previously duplicated between this new mock and notebook-tools.ts) into a single exported describeNotebookOperationError in notebook-operations.ts.

Stacked on #48949 (feature/notebooks-update-tool) — this PR's base branch is that PR, not master, because it reuses update_notebook and the shared error helper that only exist there. Merge #48949 first, then retarget/merge this one.

Test plan

  • `pnpm --filter studio typecheck` passes
  • `pnpm --filter studio test` — all notebook-related suites pass (`mock-tools.test.ts`, `notebook-tools.test.ts`, `data/content/notebooks/*`)
  • `eslint` / `prettier --check` clean on all touched files

Summary by CodeRabbit

  • New Features

    • Added notebook capabilities to mocked AI tools, including listing, viewing, creating, and updating notebooks.
    • Mock notebook changes now persist during interactions, including cell insertion and deletion.
    • Added clear messages for invalid notebook operations and unknown cells.
  • Bug Fixes

    • Improved consistency of notebook operation error messages across tools.
  • Tests

    • Expanded coverage for notebook data, validation, approvals, errors, and isolated tool-call state.

@charislam
charislam requested a review from a team as a code owner August 11, 2026 18:45
@vercel

vercel Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview Aug 12, 2026 1:37pm
studio-staging Ready Ready Preview Aug 12, 2026 1:37pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 12, 2026 1:37pm
design-system Skipped Skipped Aug 12, 2026 1:37pm
docs Skipped Skipped Aug 12, 2026 1:37pm
ui-library Skipped Skipped Aug 12, 2026 1:37pm
zone-www-dot-com Skipped Skipped Aug 12, 2026 1:37pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c1f4cec0-0d7a-47af-bf32-417fb36df58f

📥 Commits

Reviewing files that changed from the base of the PR and between cd4eb45 and 08d643a.

📒 Files selected for processing (2)
  • apps/studio/lib/ai/tools/mock-tools.test.ts
  • apps/studio/lib/ai/tools/mock-tools.ts
 _________________________________________________________________________________________
< If you don't make mistakes, you're not working on hard enough problems. - Frank Wilczek >
 -----------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c1f4cec0-0d7a-47af-bf32-417fb36df58f

📥 Commits

Reviewing files that changed from the base of the PR and between cd4eb45 and 08d643a.

📒 Files selected for processing (2)
  • apps/studio/lib/ai/tools/mock-tools.test.ts
  • apps/studio/lib/ai/tools/mock-tools.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/studio/lib/ai/tools/mock-tools.test.ts
  • apps/studio/lib/ai/tools/mock-tools.ts

📝 Walkthrough

Walkthrough

The change adds shared notebook operation error descriptions and mock notebook tools. The mocks use deterministic fixtures and isolated in-memory stores for listing, retrieval, creation, and cell updates. Tests cover approval behavior, state changes, validation errors, and isolation.

Changes

Notebook tool support

Layer / File(s) Summary
Shared notebook operation error handling
apps/studio/data/content/notebooks/notebook-operations.ts, apps/studio/lib/ai/tools/notebook-tools.ts
Adds describeNotebookOperationError and uses it when notebook updates fail.
In-memory notebook tool implementation
apps/studio/lib/ai/tools/mock-tools.ts
Adds deterministic notebook fixtures, an isolated in-memory store, and mock list, get, create, and update tools.
Mock notebook behavior validation
apps/studio/lib/ai/tools/mock-tools.test.ts
Tests seeded data, approval overrides, creation, cell updates, validation failures, and state isolation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant getMockTools
  participant NotebookTool
  participant MockNotebookStore
  Caller->>getMockTools: create tool set
  getMockTools->>MockNotebookStore: initialize isolated store
  Caller->>NotebookTool: invoke notebook operation
  NotebookTool->>MockNotebookStore: read or update notebook state
  MockNotebookStore-->>NotebookTool: return notebook data or operation error
  NotebookTool-->>Caller: return tool result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding mock notebook tools for Studio tests.
Description check ✅ Passed The description explains the changes, test plan, stacked PR dependency, and additional context, but does not use all template headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/notebooks-mock-tools

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@charislam

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@supabase

supabase Bot commented Aug 11, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/studio/lib/ai/tools/mock-tools.ts (1)

379-380: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider deep-copying the seeded notebooks per store.

createMockNotebookStore puts the exported MOCK_NOTEBOOKS_DATA objects into the Map by reference. Every store therefore shares the same seeded notebook objects. The current code stays safe because replaceCells writes a new object instead of mutating existing. If a later change mutates a notebook or its content.cells in place, state will leak across getMockTools calls and across tests. A per-store clone removes that risk.

♻️ Proposed clone of the seeded fixtures
 function createMockNotebookStore() {
-  const notebooks = new Map(MOCK_NOTEBOOKS_DATA.map((notebook) => [notebook.id, notebook]))
+  const notebooks = new Map(
+    MOCK_NOTEBOOKS_DATA.map((notebook) => [notebook.id, structuredClone(notebook)])
+  )
🤖 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/lib/ai/tools/mock-tools.ts` around lines 379 - 380, Update
createMockNotebookStore so each Map entry is a deep clone of its corresponding
MOCK_NOTEBOOKS_DATA fixture rather than the shared object reference. Preserve
notebook IDs and the existing store behavior while ensuring nested content.cells
state is isolated across getMockTools calls and tests.
🤖 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/lib/ai/tools/mock-tools.ts`:
- Around line 379-380: Update createMockNotebookStore so each Map entry is a
deep clone of its corresponding MOCK_NOTEBOOKS_DATA fixture rather than the
shared object reference. Preserve notebook IDs and the existing store behavior
while ensuring nested content.cells state is isolated across getMockTools calls
and tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f46ebd4-da35-4f71-a3e4-2f7844c903ae

📥 Commits

Reviewing files that changed from the base of the PR and between a282652 and cd4eb45.

📒 Files selected for processing (4)
  • apps/studio/data/content/notebooks/notebook-operations.ts
  • apps/studio/lib/ai/tools/mock-tools.test.ts
  • apps/studio/lib/ai/tools/mock-tools.ts
  • apps/studio/lib/ai/tools/notebook-tools.ts

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  242 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  38 minutes, 36 seconds
commit  08d643a

Flaky tests

Features › rls-policies.spec.ts › RLS Policies › Create RLS Policy › should create an INSERT policy with authenticated role

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Base automatically changed from feature/notebooks-update-tool to master August 12, 2026 13:31
Add deterministic list_notebooks/get_notebook fixtures and stateful
in-memory create_notebook/update_notebook mocks for the AI assistant
eval harness. Dedupe describeOperationError (duplicated between this
mock and notebook-tools.ts) into a single exported
describeNotebookOperationError in notebook-operations.ts.
@charislam
charislam force-pushed the feature/notebooks-mock-tools branch from cd4eb45 to 08d643a Compare August 12, 2026 13:31
@charislam
charislam merged commit b9835e4 into master Aug 12, 2026
44 of 46 checks passed
@charislam
charislam deleted the feature/notebooks-mock-tools branch August 12, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants