Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jul 6, 2025

Install cucumber, write a first test.
(This showed a flaw in the function definition, which I'll fix in 424)
Factor out some of the functions that call next from roam to ui code.
Added a variable so I could vary the NEXT API endpoint independently of NODE_ENV.

Summary by CodeRabbit

  • New Features

    • Introduced Cucumber-based end-to-end testing for database features, including user stories and acceptance criteria for the roam plugin and content access control.
    • Added utility functions for interacting with Supabase-backed APIs, enabling streamlined creation or retrieval of spaces and platform accounts.
    • Added environment variable support for API root configuration.
    • Added a new stored function to manage platform accounts and space access with enhanced permissions handling.
  • Bug Fixes

    • Improved environment detection and API URL handling for development and production scenarios.
  • Chores

    • Added configuration files for TypeScript, Cucumber, and Prettier to support new testing and code formatting workflows.
    • Updated package dependencies and scripts to enable and format Gherkin feature files and run tests.
  • Refactor

    • Centralized and improved imports and utility functions for Supabase context management.
    • Updated function signatures and argument ordering for database-related operations to enhance consistency.
    • Simplified API input validation and streamlined space creation logic.

@linear
Copy link

linear bot commented Jul 6, 2025

@supabase
Copy link

supabase bot commented Jul 6, 2025

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


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

@maparent
Copy link
Collaborator Author

maparent commented Jul 6, 2025

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

✅ Actions performed

Review triggered.

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

📝 Walkthrough

Walkthrough

This change introduces a new shared module for Supabase context-related API functions, updates their usage in the Roam app, and adds Cucumber-based integration tests for database context creation and content access control. It also enhances environment variable handling, updates type imports, modifies several database function signatures, and adds a new PostgreSQL stored function for account creation in space.

Changes

File(s) Change Summary
apps/roam/scripts/compile.ts Added NEXT_API_ROOT to esbuild environment variable definitions.
apps/roam/src/utils/supabaseContext.ts Replaced local implementations of fetchOrCreateSpaceId and fetchOrCreatePlatformAccount with imports from @repo/ui/lib/supabase/contextFunctions; updated argument structure and imports.
packages/ui/src/lib/supabase/contextFunctions.ts New module with exported async functions fetchOrCreateSpaceId, fetchOrCreatePlatformAccount, and createLoggedInClient for Supabase API interaction and client creation.
packages/ui/src/lib/utils.ts Added IS_DEV constant and nextApiRoot() function for environment-aware API root URL selection.
apps/website/app/api/supabase/space/route.ts Simplified SpaceCreationInput type; updated spaceValidator to validate password length; removed account_id validation and related SpaceAccess creation logic.
packages/database/features/getContext.feature Added Cucumber feature file specifying acceptance criteria for context creation in the database.
packages/database/features/contentAccess.feature Added Cucumber feature file specifying acceptance criteria for content access control by space and user.
packages/database/features/step_definitions/stepdefs.ts New Cucumber step definitions for database initialization, context creation, user simulation, and verification of database state and access control.
packages/database/cucumber.json, packages/database/tsconfig.json Added Cucumber and TypeScript configuration files for test setup.
packages/database/package.json Added test script for Cucumber, new devDependencies for Cucumber and Prettier Gherkin plugin, and Prettier configuration.
packages/database/inputTypes.ts Updated type import path to use alias @repo/database/types.gen.
packages/database/types.gen.ts Reordered and regrouped arguments in several function type declarations in the Database type; added new function create_account_in_space.
packages/database/supabase/migrations/20250710185603_create_account_in_space.sql Added new PostgreSQL stored function create_account_in_space for creating or updating platform accounts linked to spaces with email and editor flags.
packages/database/supabase/schemas/account.sql Added new PostgreSQL stored function create_account_in_space with security definer and conflict handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RoamPlugin
    participant ContextFunctions (@repo/ui)
    participant API Server
    participant Database

    User->>RoamPlugin: Opens plugin
    RoamPlugin->>ContextFunctions: fetchOrCreateSpaceId({password, url, name, platform})
    ContextFunctions->>API Server: POST /space
    API Server->>Database: Create or fetch Space
    Database-->>API Server: Space ID
    API Server-->>ContextFunctions: Space ID
    ContextFunctions-->>RoamPlugin: Space ID

    RoamPlugin->>ContextFunctions: createLoggedInClient(platform, spaceId, password)
    ContextFunctions->>API Server: Authenticate client
    API Server-->>ContextFunctions: Authenticated client

    RoamPlugin->>ContextFunctions: fetchOrCreatePlatformAccount({platform, accountLocalId, name, email, spaceId, password})
    ContextFunctions->>API Server: RPC create_account_in_space
    API Server->>Database: Insert/update PlatformAccount, SpaceAccess, AgentIdentifier
    Database-->>API Server: Account ID
    API Server-->>ContextFunctions: Account ID
    ContextFunctions-->>RoamPlugin: Account ID
Loading

Possibly related PRs


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
packages/database/features/step_definitions/stepdefs.ts (1)

4-4: Verify import path extension.

The import path includes a .ts extension which may not be necessary and could cause issues in some environments.

🧹 Nitpick comments (2)
packages/ui/src/lib/supabase/contextFunctions.ts (1)

56-56: Consider parameterizing the platform value.

The platform is hardcoded as "Roam" but might need to be parameterized for future multi-platform support.

-  platform: "Roam",
+  platform,

And update the function signature to accept platform as a parameter.

packages/database/features/step_definitions/stepdefs.ts (1)

36-38: Address the Space table deletion security issue.

The commented assertion indicates a permissions issue that should be resolved to ensure complete database cleanup.

Would you like me to help create a follow-up issue to address the Space table deletion security configuration?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeb59df and 6b8f5ab.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (11)
  • apps/roam/scripts/compile.ts (1 hunks)
  • apps/roam/src/utils/supabaseContext.ts (2 hunks)
  • packages/database/cucumber.json (1 hunks)
  • packages/database/features/getContext.feature (1 hunks)
  • packages/database/features/step_definitions/stepdefs.ts (1 hunks)
  • packages/database/inputTypes.ts (1 hunks)
  • packages/database/package.json (1 hunks)
  • packages/database/tsconfig.json (1 hunks)
  • packages/database/types.gen.ts (4 hunks)
  • packages/ui/src/lib/supabase/contextFunctions.ts (1 hunks)
  • packages/ui/src/lib/utils.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
packages/database/features/getContext.feature (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:50-63
Timestamp: 2025-06-04T11:41:34.951Z
Learning: In the discourse-graph database, all accounts currently stored are Roam platform accounts, making platform-specific migration logic safe for global operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
packages/database/inputTypes.ts (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer `type` over `interface`
packages/database/cucumber.json (5)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{js,jsx,ts,tsx,json,md,mdx} : Use Prettier with the project's configuration
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: apps/website/eslint.config.mjs:6-13
Timestamp: 2025-06-25T18:11:58.352Z
Learning: In TypeScript ESLint parser options, `parserOptions.project: true` is a valid boolean value that has been supported since version 5.52.0. When set to `true`, it automatically finds the nearest `tsconfig.json` file for each source file being linted, eliminating the need to specify explicit paths like `"./tsconfig.json"`. This is especially useful for monorepos and projects with multiple TypeScript configurations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: apps/website/eslint.config.mjs:6-13
Timestamp: 2025-06-25T18:11:58.352Z
Learning: In TypeScript ESLint parser options, `project: true` is a valid boolean value that has been supported since version 5.52.0. When set to `true`, it automatically finds the nearest tsconfig file, eliminating the need to specify explicit paths like `"./tsconfig.json"`.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer util functions for reusable logic and common operations
packages/database/tsconfig.json (14)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: apps/website/eslint.config.mjs:6-13
Timestamp: 2025-06-25T18:11:58.352Z
Learning: In TypeScript ESLint parser options, `parserOptions.project: true` is a valid boolean value that has been supported since version 5.52.0. When set to `true`, it automatically finds the nearest `tsconfig.json` file for each source file being linted, eliminating the need to specify explicit paths like `"./tsconfig.json"`. This is especially useful for monorepos and projects with multiple TypeScript configurations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/scripts/deploy.ts:0-0
Timestamp: 2025-05-22T23:48:45.450Z
Learning: The database deployment script in packages/database/scripts/deploy.ts requires that the branch is 'main' and pristine (no uncommitted or unpushed changes) before allowing deployment to proceed.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: apps/website/eslint.config.mjs:6-13
Timestamp: 2025-06-25T18:11:58.352Z
Learning: In TypeScript ESLint parser options, `project: true` is a valid boolean value that has been supported since version 5.52.0. When set to `true`, it automatically finds the nearest tsconfig file, eliminating the need to specify explicit paths like `"./tsconfig.json"`.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: PascalCase for components and types
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: UPPERCASE for constants
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer `type` over `interface`
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{js,jsx,ts,tsx,json,md,mdx} : Use Prettier with the project's configuration
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer util functions for reusable logic and common operations
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: camelCase for variables and functions
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Avoid `any` types when possible
apps/roam/src/utils/supabaseContext.ts (9)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.332Z
Learning: Applies to apps/roam/**/* : Use BlueprintJS 3 components and Tailwind CSS for platform-native UI
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.332Z
Learning: Applies to apps/roam/**/* : Use the roamAlphaApi documentation from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.332Z
Learning: Applies to apps/roam/**/* : Use Roam Depot/Extension API documentation from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-25T22:56:17.522Z
Learning: In the Roam discourse-graph system, the existence of the configuration page (identified by DISCOURSE_CONFIG_PAGE_TITLE) and its corresponding UID is a system invariant. The code can safely assume this page will always exist, so defensive null checks are not needed when using `getPageUidByPageTitle(DISCOURSE_CONFIG_PAGE_TITLE)`.
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#226
File: apps/roam/src/components/settings/HomePersonalSettings.tsx:123-149
Timestamp: 2025-06-19T19:43:43.380Z
Learning: The "Fetch Embeddings for nodes" button in HomePersonalSettings.tsx is for testing purposes only, so it doesn't require production-level error handling or user feedback improvements.
packages/ui/src/lib/utils.ts (7)
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer util functions for reusable logic and common operations
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: UPPERCASE for constants
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to {apps/website,packages/ui}/**/*.tsx : Use platform-native UI components first with shadcn/ui as a fallback
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to {apps/website,packages/ui}/**/*.tsx : When refactoring inline styles, use tailwind classes
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/api.mdc:0-0
Timestamp: 2025-06-30T18:58:19.625Z
Learning: You are working on the api routes for Discourse Graph which uses NextJS app router.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to {apps/website,packages/ui}/**/*.tsx : Use Tailwind CSS for styling where possible
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to {apps/website,packages/ui}/**/*.tsx : Maintain visual consistency with the host application's design system
packages/database/package.json (8)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/scripts/deploy.ts:0-0
Timestamp: 2025-05-22T23:48:45.450Z
Learning: The database deployment script in packages/database/scripts/deploy.ts requires that the branch is 'main' and pristine (no uncommitted or unpushed changes) before allowing deployment to proceed.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/obsidian.mdc:0-0
Timestamp: 2025-06-30T18:58:43.737Z
Learning: Applies to apps/obsidian/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Obsidian plugin
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{js,jsx,ts,tsx,json,md,mdx} : Use Prettier with the project's configuration
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: PascalCase for components and types
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: UPPERCASE for constants
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Maintain consistent naming conventions: camelCase for variables and functions
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Prefer util functions for reusable logic and common operations
apps/roam/scripts/compile.ts (1)
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.332Z
Learning: Applies to apps/roam/**/* : Prefer existing dependencies from package.json when adding or using dependencies
packages/database/features/step_definitions/stepdefs.ts (3)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.
packages/database/types.gen.ts (6)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.645Z
Learning: Applies to **/*.{ts,tsx} : Use explicit return types for functions
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/embedding.sql:66-95
Timestamp: 2025-05-20T14:04:19.632Z
Learning: In the `match_embeddings_for_subset_nodes` SQL function in packages/database/supabase/schemas/embedding.sql, the number of results is implicitly limited by the length of the input array parameter `p_subset_roam_uids` since the function filters content using `WHERE c.source_local_id = ANY(p_subset_roam_uids)`.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-07T02:56:57.093Z
Learning: In the discourse-graph project's upsert_content function, null creator_id values are tolerated as an acceptable trade-off, even though they may be annoying, rather than failing the entire operation.
packages/ui/src/lib/supabase/contextFunctions.ts (2)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
🧬 Code Graph Analysis (1)
apps/roam/src/utils/supabaseContext.ts (1)
packages/ui/src/lib/supabase/contextFunctions.ts (2)
  • fetchOrCreatePlatformAccount (41-88)
  • fetchOrCreateSpaceId (8-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: deploy
🔇 Additional comments (27)
packages/database/inputTypes.ts (1)

1-1: Good improvement to import consistency.

Using the workspace-scoped import path @repo/database/types.gen instead of the relative path improves maintainability and follows monorepo best practices.

packages/database/cucumber.json (1)

1-6: Well-structured Cucumber configuration.

The configuration correctly uses ts-node/esm loader for TypeScript support and properly targets the step definitions directory. This follows standard Cucumber practices for TypeScript projects.

packages/database/tsconfig.json (1)

1-13: Appropriate TypeScript configuration for the database package.

The configuration correctly extends the base config and includes the necessary paths for the database package structure, including the new Cucumber test directories. The compiler options are well-suited for this package.

apps/roam/scripts/compile.ts (1)

135-135: Consistent environment variable addition.

The NEXT_API_ROOT environment variable follows the same pattern as the existing environment variables and provides a reasonable fallback to an empty string when undefined.

packages/ui/src/lib/utils.ts (3)

4-4: Necessary TypeScript declaration for process global.

The process global declaration is required for TypeScript when accessing environment variables. The typing is appropriate for the build environment context.


13-13: Clean environment detection constant.

The IS_DEV constant provides a clear abstraction for development environment detection.


15-24: Well-structured API root resolution function.

The nextApiRoot function follows good logic flow:

  1. First checks for explicit NEXT_API_ROOT environment variable
  2. Falls back to appropriate development/production URLs based on environment

This provides flexible API endpoint configuration while maintaining sensible defaults.

packages/database/features/getContext.feature (1)

1-21: Clean and well-structured feature file.

The feature file follows BDD conventions effectively, with clear user story and acceptance criteria. The scenario outline appropriately tests both service and user perspectives for database entity verification.

packages/database/package.json (3)

18-18: Appropriate test script for Cucumber integration.

The test script correctly compiles TypeScript sources before running Cucumber tests, ensuring step definitions are available in the expected directory.


26-29: Well-chosen dependencies for Cucumber testing.

The dependencies are appropriate:

  • @cucumber/cucumber for the testing framework
  • prettier-plugin-gherkin for feature file formatting
  • ts-node-maintained as a reliable fork for TypeScript execution

32-36: Prettier configuration enables Gherkin formatting.

Adding the Gherkin plugin ensures consistent formatting for feature files, improving maintainability.

apps/roam/src/utils/supabaseContext.ts (3)

13-13: Simplified import path for createClient.

The import path has been appropriately simplified by removing the /src segment.


15-18: Successfully centralized context functions.

The refactoring moves API interaction logic to a shared module, improving code reusability and maintainability.


60-74: Updated function call to match new signature.

The fetchOrCreateSpaceId call correctly uses the new object parameter style and explicitly defines the required properties.

packages/ui/src/lib/supabase/contextFunctions.ts (3)

8-39: Well-structured fetchOrCreateSpaceId function.

The function has proper error handling, type validation, and clear parameter structure. The error messages provide helpful context for debugging.


41-88: Robust fetchOrCreatePlatformAccount with email handling.

The function handles both account creation and optional email association. The error handling appropriately logs email association failures without stopping the process.


1-1: Import path extension is intentional and consistent

The .ts extension is used across the codebase for type imports (dozens of occurrences in @repo/database/types.gen.ts), and our build/config setup handles these paths without issue. No change is needed here—please disregard the suggestion to remove the .ts extension.

Likely an incorrect or invalid review comment.

packages/database/features/step_definitions/stepdefs.ts (2)

13-22: Proper Supabase client setup.

The client factory functions correctly configure anonymous and service role clients with appropriate environment variables.


41-57: Well-structured step for simulating user actions.

The step effectively simulates opening the roam plugin by creating platform accounts and spaces using the shared context functions.

packages/database/types.gen.ts (8)

592-595: Confirm correct argument order in compute_arity_local calls

I ran a search for compute_arity_local in TS/JS files and only found its type definition—no call sites were detected. Please ensure that every call (including those in generated code or other languages) matches the updated signature:

  • New order: (lit_content: Json, schema_id: number)
  • Definition location: packages/database/types.gen.ts lines 592–595

575-583: Verify call sites for reordered arguments in alpha_upsert_discourse_nodes

A search in .ts/.js files did not reveal any direct invocations of alpha_upsert_discourse_nodes. Please manually confirm that:

  • All generated clients, resolvers, or other integration layers invoking this proc use the new argument order:
    1. p_nodes
    2. p_space_name
    3. p_user_email
    4. p_user_name

645-654: No action needed: RPC named parameters are order-agnostic

The Supabase RPC call uses an object literal with named parameters, so property order doesn’t matter. The only usage in apps/website/app/api/supabase/sync-task/[fn]/[target]/route.ts correctly passes all keys (s_worker, s_target, s_function, timeout, task_interval).

Likely an incorrect or invalid review comment.


622-635: No action needed: property order in TypeScript return types has no impact
Property reordering in match_content_embeddings’s generated return type won’t affect any code that accesses its properties by name. TypeScript’s structural typing ensures consumers remain compatible, so no changes are required.

Likely an incorrect or invalid review comment.


596-604: No updates needed for end_sync_task calls

All usages invoke supabase.rpc("end_sync_task", { … }) with named parameters in an object, so the order of keys is irrelevant. The only occurrence in the codebase is:

  • apps/website/app/api/supabase/sync-task/[fn]/[target]/[worker]/route.ts

672-691: Verify and update all call sites of upsert_discourse_nodes
I ran a global search (rg -A15 "upsert_discourse_nodes" in .ts/.js) and only found its type definition—no actual invocations. Please ensure you:

  • Search for calls in all client code (including .tsx/.jsx or other languages) that invoke upsert_discourse_nodes and update them to match the new parameter order.
  • Update any tests or scripts that reference this stored procedure.
  • Add or refresh integration tests around this function to catch argument‐order mismatches in the future.

636-644: No action needed: return type property reorder is non-breaking

Verified usages of match_embeddings_for_subset_nodes in the codebase:

  • In apps/website/app/api/supabase/similarity-rank/route.ts, the RPC result is forwarded via createApiResponse without any destructuring or index-based access.
  • No other callers were found that reference properties by position.

Since consumers rely on named fields rather than order, the updated property sequence in the generated type is safe.


668-671: Verify Supabase RPC calls for upsert_content_embedding argument order

I wasn’t able to locate any internal calls to upsert_content_embedding in TS/JS files—please manually check that every RPC invocation (including in .tsx/.jsx or other client code) passes arguments in the new order:

  • model
  • embedding_array
  • content_id

@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from 6b8f5ab to fba1309 Compare July 7, 2025 18:04
@maparent maparent marked this pull request as draft July 8, 2025 12:47
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch 9 times, most recently from 241461b to ccc3044 Compare July 12, 2025 19:28
@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

✅ Actions performed

Review triggered.

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.

@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from 1c50fbc to ccc3044 Compare July 12, 2025 19:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (2)
packages/database/features/contentAccess.feature (1)

30-30: Add missing closing triple quotes.

The code block is missing its closing delimiter.

    And a user logged in space s1 should see 2 Document in the database
+```
packages/database/types.gen.ts (1)

565-605: Review Supabase RPC Call Signatures

Reordering parameters in the generated types won’t break your supabase.rpc calls—RPC binds by named properties, not position. However, a few function signatures have changed and your code must pass the correct named args:

• apps/website/app/api/supabase/sync-task/[fn]/[target]/route.ts
– propose_sync_task now only takes { timeout } but you’re passing { s_target, s_function }. Update the call to match the new signature or restore the missing params.

• apps/website/app/api/supabase/sync-task/[fn]/[target]/[worker]/route.ts
– end_sync_task’s Args include { s_worker, s_status } in addition to { s_target, s_function }. Ensure you supply all required fields.

No other calls are affected by parameter order—supabase.rpc uses object destructuring. Verify each RPC call’s object matches its function’s current Args shape in packages/database/types.gen.ts.

🧹 Nitpick comments (5)
packages/database/features/contentAccess.feature (1)

26-26: Remove duplicate step definition.

This step duplicates line 15 from the Background section. Background steps are automatically executed before each scenario, so this is redundant.

  Scenario Outline: Per-space document access
-    When the user user1 opens the roam plugin in space s1
    Then the database should contain 3 Document
packages/database/supabase/schemas/account.sql (1)

118-118: Consider explicit error handling for invalid space_id.

While STRICT will raise an exception if the space doesn't exist, consider adding explicit validation with a more user-friendly error message.

 BEGIN
+    -- Validate space exists
+    IF NOT EXISTS (SELECT 1 FROM public."Space" WHERE id = space_id_) THEN
+        RAISE EXCEPTION 'Space with id % does not exist', space_id_;
+    END IF;
     SELECT platform INTO platform_ STRICT FROM public."Space" WHERE id = space_id_;
packages/ui/src/lib/supabase/contextFunctions.ts (1)

74-74: Clarify or remove misleading comment.

The comment "account created but not connected, try again" is misleading since this error would indicate the RPC call itself failed, not a partial success.

-  if (result.error) throw Error(result.error.message); // account created but not connected, try again
+  if (result.error) throw Error(result.error.message);
packages/database/features/step_definitions/stepdefs.ts (2)

13-22: Add runtime validation for required environment variables.

The non-null assertions on environment variables could cause runtime errors if they're not set. Consider adding validation to ensure a clearer error message.

 const getAnonymousClient = () =>
+  {
+    if (!process.env.SUPABASE_URL || !process.env.SUPABASE_ANON_KEY) {
+      throw new Error('Missing required environment variables: SUPABASE_URL and SUPABASE_ANON_KEY');
+    }
+    return createClient<Database, "public", Database["public"]>(
+      process.env.SUPABASE_URL,
+      process.env.SUPABASE_ANON_KEY,
+    );
+  }
-  createClient<Database, "public", Database["public"]>(
-    process.env.SUPABASE_URL!,
-    process.env.SUPABASE_ANON_KEY!,
-  );
 const getServiceClient = () =>
+  {
+    if (!process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) {
+      throw new Error('Missing required environment variables: SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY');
+    }
+    return createClient<Database, "public", Database["public"]>(
+      process.env.SUPABASE_URL,
+      process.env.SUPABASE_SERVICE_ROLE_KEY,
+    );
+  }
-  createClient<Database, "public", Database["public"]>(
-    process.env.SUPABASE_URL!,
-    process.env.SUPABASE_SERVICE_ROLE_KEY!,
-  );

96-119: Consider making the platform configurable.

The step hardcodes "Roam" as the platform. For better test coverage, consider parameterizing it to support testing with different platforms.

 When(
-  "the user {word} opens the roam plugin in space {word}",
-  async (userAccountId, spaceName) => {
+  "the user {word} opens the {word} plugin in space {word}",
+  async (userAccountId, platform, spaceName) => {
     // assumption: turbo dev is running. TODO: Make into hooks
     const localRefs: Record<string, any> = world.localRefs || {};
     const spaceId = await fetchOrCreateSpaceId({
       password: SPACE_ANONYMOUS_PASSWORD,
       url: `https://roamresearch.com/#/app/${spaceName}`,
       name: spaceName,
-      platform: "Roam",
+      platform: platform as Platform,
     });
     localRefs[spaceName] = spaceId;
     const userId = await fetchOrCreatePlatformAccount({
-      platform: "Roam",
+      platform: platform as Platform,
       accountLocalId: userAccountId,
       name: userAccountId,
       email: userEmail(userAccountId),
       spaceId,
       password: SPACE_ANONYMOUS_PASSWORD,
     });
     localRefs[userAccountId] = userId;
     world.localRefs = localRefs;
   },
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b8f5ab and ccc3044.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • apps/roam/scripts/compile.ts (1 hunks)
  • apps/roam/src/utils/supabaseContext.ts (3 hunks)
  • apps/website/app/api/supabase/space/route.ts (1 hunks)
  • packages/database/cucumber.json (1 hunks)
  • packages/database/features/contentAccess.feature (1 hunks)
  • packages/database/features/getContext.feature (1 hunks)
  • packages/database/features/step_definitions/stepdefs.ts (1 hunks)
  • packages/database/inputTypes.ts (1 hunks)
  • packages/database/package.json (1 hunks)
  • packages/database/supabase/migrations/20250710185603_create_account_in_space.sql (1 hunks)
  • packages/database/supabase/schemas/account.sql (1 hunks)
  • packages/database/tsconfig.json (1 hunks)
  • packages/database/types.gen.ts (4 hunks)
  • packages/ui/src/lib/supabase/contextFunctions.ts (1 hunks)
  • packages/ui/src/lib/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/database/inputTypes.ts
  • packages/database/tsconfig.json
  • apps/roam/scripts/compile.ts
  • packages/database/cucumber.json
  • packages/ui/src/lib/utils.ts
  • packages/database/package.json
  • apps/roam/src/utils/supabaseContext.ts
  • packages/database/features/getContext.feature
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:37.989Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
packages/database/features/contentAccess.feature (1)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
packages/database/supabase/schemas/account.sql (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
packages/database/supabase/migrations/20250710185603_create_account_in_space.sql (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
packages/ui/src/lib/supabase/contextFunctions.ts (3)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:37.989Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
apps/website/app/api/supabase/space/route.ts (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: apps/website/app/api/supabase/agent_identifier/route.ts:0-0
Timestamp: 2025-06-09T16:54:29.659Z
Learning: In the AgentIdentifier API route (apps/website/app/api/supabase/agent_identifier/route.ts), the trusted field is intentionally optional and should accept undefined values. The validation logic `if (trusted !== undefined && ...)` is designed to allow undefined as expected behavior.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:37.989Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
packages/database/features/step_definitions/stepdefs.ts (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:37.989Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
packages/database/types.gen.ts (10)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-30T18:58:32.668Z
Learning: Applies to **/*.{ts,tsx} : Use explicit return types for functions
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/embedding.sql:66-95
Timestamp: 2025-05-20T14:04:19.632Z
Learning: In the `match_embeddings_for_subset_nodes` SQL function in packages/database/supabase/schemas/embedding.sql, the number of results is implicitly limited by the length of the input array parameter `p_subset_roam_uids` since the function filters content using `WHERE c.source_local_id = ANY(p_subset_roam_uids)`.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.362Z
Learning: Applies to apps/roam/**/* : Use the roamAlphaApi documentation from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-06-30T18:58:53.362Z
Learning: Applies to apps/roam/**/* : Use Roam Depot/Extension API documentation from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:50-63
Timestamp: 2025-06-04T11:41:34.951Z
Learning: In the discourse-graph database, all accounts currently stored are Roam platform accounts, making platform-specific migration logic safe for global operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
🧬 Code Graph Analysis (2)
packages/ui/src/lib/supabase/contextFunctions.ts (3)
packages/database/types.gen.ts (1)
  • Enums (901-914)
packages/ui/src/lib/utils.ts (2)
  • nextApiRoot (15-24)
  • spaceAnonUserEmail (10-11)
packages/ui/src/lib/supabase/client.ts (1)
  • DGSupabaseClient (9-13)
packages/database/features/step_definitions/stepdefs.ts (3)
packages/database/types.gen.ts (1)
  • Database (9-824)
packages/ui/src/lib/supabase/contextFunctions.ts (2)
  • fetchOrCreateSpaceId (12-32)
  • fetchOrCreatePlatformAccount (50-76)
packages/ui/src/lib/utils.ts (1)
  • spaceAnonUserEmail (10-11)
🔇 Additional comments (8)
packages/database/supabase/schemas/account.sql (1)

102-136: Well-implemented idempotent function with proper conflict handling.

The function correctly implements idempotent upserts with proper ON CONFLICT clauses, aligning with the learned best practices for Supabase operations without transaction support.

The use of SECURITY DEFINER is appropriate here as the function needs elevated privileges to manage accounts and access control.

packages/database/supabase/migrations/20250710185603_create_account_in_space.sql (1)

1-34: Migration correctly implements the account creation function.

The migration file properly creates the create_account_in_space function with appropriate security settings and idempotent operations.

apps/website/app/api/supabase/space/route.ts (2)

21-37: Clean refactoring with proper input validation.

The simplified input structure and validation logic is cleaner and more maintainable. Good addition of password length validation.


43-46: Consistent simplification of space creation logic.

The removal of account_id handling aligns well with the new architecture where account creation is handled by the create_account_in_space stored procedure. This separation of concerns improves modularity.

packages/database/features/step_definitions/stepdefs.ts (3)

26-39: Implementation looks good.

The database cleanup step correctly uses the service client and proper error assertions. The commented Space deletion is noted as a known issue to be addressed in another PR.


53-92: Well-designed test data management system.

The implementation elegantly handles relational test data with local references, allowing tests to define relationships between records without knowing database-generated IDs. The use of @ prefix for primary keys and _ prefix for foreign key references is intuitive.


144-144: Use the space's platform instead of hardcoding "Roam".

The anonymous user email generation hardcodes "Roam" as the platform, which may not match the actual platform of the space being tested.

Consider retrieving the platform from the space data:

 Then(
   "a user logged in space {word} should see a {word} in the database",
   async (spaceName, tableName) => {
     const client = getAnonymousClient();
     const spaceId = world.localRefs[spaceName];
+    // TODO: Retrieve platform from space data instead of hardcoding
+    const serviceClient = getServiceClient();
+    const { data: space } = await serviceClient
+      .from("Space")
+      .select("platform")
+      .eq("id", spaceId)
+      .single();
     const loginResponse = await client.auth.signInWithPassword({
-      email: spaceAnonUserEmail("Roam", spaceId),
+      email: spaceAnonUserEmail(space?.platform || "Roam", spaceId),
       password: SPACE_ANONYMOUS_PASSWORD,
     });

Also applies to: 161-161

packages/database/types.gen.ts (1)

588-598: New RPC function properly typed.

The create_account_in_space function signature correctly reflects the database stored procedure for managing platform accounts within spaces.

Comment on lines 18 to 29
const response = await fetch(base_url + "/space", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok)
throw new Error(
`Platform API failed: ${response.status} ${response.statusText} ${await response.text()}`,
);
const space = await response.json();
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 12, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add timeout to prevent hanging requests.

The fetch request has no timeout, which could cause the application to hang indefinitely if the server is unresponsive.

-  const response = await fetch(base_url + "/space", {
+  const controller = new AbortController();
+  const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
+  
+  try {
+    const response = await fetch(base_url + "/space", {
     method: "POST",
     headers: {
       "Content-Type": "application/json",
     },
     body: JSON.stringify(data),
+    signal: controller.signal,
   });
+  } finally {
+    clearTimeout(timeoutId);
+  }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/ui/src/lib/supabase/contextFunctions.ts around lines 18 to 29, the
fetch request lacks a timeout, risking indefinite hanging if the server is
unresponsive. To fix this, implement a timeout mechanism using AbortController
to abort the fetch request if it exceeds a reasonable time limit. Create an
AbortController instance, pass its signal to fetch, and set a timer to call
abort after the timeout duration. Handle the abort error appropriately to
prevent hanging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is probably useful, but we are not yet doing this in the codebase in general. Punting for now, we'll discuss it, do not take this as a learning.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maparent Understood! I acknowledge your decision to defer the timeout implementation. I won't record this as a learning and will respect that this isn't a current pattern in your codebase. Feel free to revisit this when it aligns with your team's priorities.


🧠 Learnings used
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:37.989Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch 2 times, most recently from ee9687e to 653ee04 Compare July 13, 2025 15:59
@maparent maparent changed the base branch from main to ENG-567-refactor-getContext July 13, 2025 16:03
@maparent maparent changed the title Add a basic cucumber test for getContext. ENG-529 Add a basic cucumber test for getContext. Jul 13, 2025
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch 2 times, most recently from 1708d89 to 61dd57c Compare July 13, 2025 16:35
@maparent
Copy link
Collaborator Author

@CodeRabbit: Curious what gave you the idea that the gherkin code needed a delimiter.
The RPC signature reordering is annoying and unfortunate, but this is unstably generated code.
The explicit error handling suggested for create_account_in_space would make for an extra query.

@maparent maparent marked this pull request as ready for review July 13, 2025 16:46
@maparent maparent force-pushed the ENG-567-refactor-getContext branch from 43bea6a to 1fc1fb4 Compare July 14, 2025 02:37
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from c421ebe to 9e3df1e Compare July 14, 2025 02:37
@maparent maparent force-pushed the ENG-567-refactor-getContext branch from 1fc1fb4 to 40f1d66 Compare July 14, 2025 02:43
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from 9e3df1e to 2f9871f Compare July 14, 2025 02:43
Base automatically changed from ENG-567-refactor-getContext to main July 14, 2025 05:03
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch 2 times, most recently from 1cf51da to 2001bdd Compare July 14, 2025 05:19
@maparent
Copy link
Collaborator Author

Re .env: you should use the local one, and turbo dev should be running in parallel.
Ideally, cucumber setup should do the turbo dev, or we should set up a turbo test task that starts dev before running cucumber, but I thought this could be left for later. The point now was just to have infrastructure to test RLS, so manual operation felt adequate.
It will be necessary to revisit that if we want these tests to become part of CI/CD.

Copy link
Contributor

If they aren't going to be part of CI/CD, why not add them to .gitignore and keep them local?

@maparent
Copy link
Collaborator Author

Because

  1. We have not decided to not put them in CI/CD, it's just not in scope yet.
  2. Much more important, I expect others to use this testing infrastructure when working on the database. Keeping it local-only deprives other of testing infrastructure.
  3. The tests are also meant to be part of the forthcoming documentation.

Copy link
Contributor

re: .env
.env is always local. We currently have a .env for each /app but none in root. Is this expected to be in a .env in root? Or in /package/database? Or somewhere else?

@maparent
Copy link
Collaborator Author

Ah, good point on .env. I have put private ones in root, which I manually activate with a source command. I could also source from the app directories. I must say I prefer a global .env approach personally. But given that this is not how turbo does things, it would make sense to add the .env.example files in packages/database. I'll do that if you agree.

Copy link
Contributor

If it is intended for other's to use, instructions on how to use it should be included in this PR. If they are explicitly kept out, that should also be mentioned in the body of the PR, with a link to the task in which it is intended to be completed.

@maparent
Copy link
Collaborator Author

On second thought... Will turbo pick up the packages/database/.env while running the turbo dev from the root? Or will it use apps/website/.env to run website, etc.? I expect the latter. That means environment change (between local and production) could possibly span many directories to be consistent. I'll have to experiment on that.

@maparent
Copy link
Collaborator Author

maparent commented Jul 14, 2025

I'll add testing instructions in #248, aka ENG-520 they will fit better there. Is it enough to say so here? No local will be better after all.

@mdroidian
Copy link
Contributor

I'll add testing instructions in #248, aka ENG-520 they will fit better there. Is it enough to say so here?

Ideally in the body of the PR, as the comments get quite noise.

@maparent
Copy link
Collaborator Author

added to README

@maparent maparent requested a review from mdroidian July 14, 2025 11:55
maparent added 4 commits July 14, 2025 10:48
Factor out some of the functions that call next from roam to ui code.
Also work on a generic way to know the Next endpoint.
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from d73232d to 7b0a113 Compare July 14, 2025 14:49
@maparent maparent force-pushed the ENG-529-minimal-backend-testing branch from 7b0a113 to 87a6a83 Compare July 14, 2025 14:53
@maparent maparent merged commit a47a867 into main Jul 14, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jul 14, 2025
@maparent maparent deleted the ENG-529-minimal-backend-testing branch July 14, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants