supabase-rls-ai-tester
v0.0.1
Published
AI test case generation for RLS policies
Downloads
64
Readme
SupaRAT
Overview
SupaRAT (Supabase Row-Level Security Automated Tester) is a tool that automates the generation and execution of pgTAP test cases for your Supabase Row-Level Security (RLS) policies using AI. It parses existing RLS policies from your Supabase database and generates comprehensive test files to ensure your policies are functioning as intended.
Prerequisites
- pgTAP - Unit testing framework for PostgreSQL
- dbdev - Development environment for database projects
- supabase-test-helpers - Helper functions for testing Supabase policies
- Claude API Key - Required for AI-generated test cases
- Bun - A fast all-in-one JavaScript runtime
- Supabase CLI - Tooling for managing Supabase projects
- Docker - Containerization platform. Docker must be running to use
supabase db test
Environment Variables
Copy the .env.example
file to .env
and fill in the values from the Supabase dashboard and add your Claude API Key:
cp .env.example .env
Update the .env
file with your Supabase database credentials and Claude API Key.
Note: Do not commit your .env
file or any secrets to version control.
Dependency Installation
Install the project dependencies using Bun:
bun install
Getting Started
To run the application and generate the automated test cases, cd into the project directory and run:
bun start
This command will:
- Connect to your Supabase database using the provided credentials.
- Fetch all existing RLS policies.
- Generate pgTAP test files for each policy using Claude AI.
- Save the test files in the
supabase/tests
directory.
Running the Tests
After generating the test cases, you can execute them using the Supabase CLI:
npx supabase db test --linked
The --linked
flag runs the tests against your remote Supabase project instead of a local database. Make sure you have linked your project first using:
supabase link
Note:
You'll need your project's reference ID (or name) and database password from the Supabase dashboard to link your project successfully.
This command runs all SQL test files located in the
supabase/tests
directory.
Contributing
Contributions are welcome! Please open an issue or submit a pull request with your improvements.
License
This project is licensed under the MIT License.