-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add pgTAP testing skill for database test patterns #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ocumentation updates Includes new SKILL.md with detailed testing patterns, helper functions for database management, flow setup, task operations, realtime testing, and timestamp manipulation. Updates schema-dev SKILL.md to reference the new testing resources for improved testing workflows.
|
Merge activity
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
# Add pgTAP Testing Skill for Database Testing Added a new Claude skill for pgTAP testing that provides comprehensive guidance for writing database tests in pgflow. The skill includes: - Complete test structure patterns and examples - Common assertion techniques for database testing - Helper function documentation for test setup and verification - Realtime event testing patterns - Test organization and execution instructions This skill will help developers write effective database tests using the pgTAP framework, with specific focus on pgflow testing patterns. The skill includes a detailed reference of helper functions in a separate markdown file. Also updated the schema-dev skill to reference the new pgTAP testing skill for additional test patterns and helpers.
|
View your CI Pipeline Execution ↗ for commit 7bdc851
☁️ Nx Cloud last updated this comment at |
🔍 Preview Deployment: Website✅ Deployment successful! 🔗 Preview URL: https://pr-298.pgflow.pages.dev 📝 Details:
_Last updated: _ |
| begin; | ||
| select plan(2); | ||
| select pgflow_tests.reset_db(); | ||
| select pgflow_tests.setup_flow('sequential'); | ||
|
|
||
| -- Execute function | ||
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | ||
|
|
||
| -- Test: Check created run | ||
| select results_eq( | ||
| $$ SELECT flow_slug, status from pgflow.runs $$, | ||
| $$ VALUES ('sequential', 'started') $$, | ||
| 'Run should be created with correct status' | ||
| ); | ||
|
|
||
| select finish(); | ||
| rollback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan declares 2 tests but only 1 assertion is present. The results_eq() at line 82-86 is the only assertion. This mismatch will cause the test to fail with "Bad plan. You planned 2 tests but ran 1."
Fix by changing line 74 to:
select plan(1);| begin; | |
| select plan(2); | |
| select pgflow_tests.reset_db(); | |
| select pgflow_tests.setup_flow('sequential'); | |
| -- Execute function | |
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | |
| -- Test: Check created run | |
| select results_eq( | |
| $$ SELECT flow_slug, status from pgflow.runs $$, | |
| $$ VALUES ('sequential', 'started') $$, | |
| 'Run should be created with correct status' | |
| ); | |
| select finish(); | |
| rollback; | |
| begin; | |
| select plan(1); | |
| select pgflow_tests.reset_db(); | |
| select pgflow_tests.setup_flow('sequential'); | |
| -- Execute function | |
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | |
| -- Test: Check created run | |
| select results_eq( | |
| $$ SELECT flow_slug, status from pgflow.runs $$, | |
| $$ VALUES ('sequential', 'started') $$, | |
| 'Run should be created with correct status' | |
| ); | |
| select finish(); | |
| rollback; | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
| begin; | ||
| select plan(3); | ||
| select pgflow_tests.reset_db(); | ||
| select pgflow_tests.setup_flow('sequential'); | ||
|
|
||
| -- Start flow | ||
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | ||
|
|
||
| -- Poll and start task | ||
| select pgflow_tests.read_and_start('sequential'); | ||
|
|
||
| -- Complete task | ||
| select pgflow.complete_task( | ||
| (select run_id from pgflow.runs limit 1), | ||
| 'first', | ||
| 0, | ||
| '{"result": "done"}'::jsonb | ||
| ); | ||
|
|
||
| -- Test: Task completed | ||
| select is( | ||
| (select status from pgflow.step_tasks | ||
| where step_slug = 'first' limit 1), | ||
| 'completed', | ||
| 'Task should be completed' | ||
| ); | ||
|
|
||
| select finish(); | ||
| rollback; | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan declares 3 tests but only 1 assertion is present. The is() at lines 117-122 is the only assertion. This mismatch will cause the test to fail with "Bad plan. You planned 3 tests but ran 1."
Fix by changing line 98 to:
select plan(1);| begin; | |
| select plan(3); | |
| select pgflow_tests.reset_db(); | |
| select pgflow_tests.setup_flow('sequential'); | |
| -- Start flow | |
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | |
| -- Poll and start task | |
| select pgflow_tests.read_and_start('sequential'); | |
| -- Complete task | |
| select pgflow.complete_task( | |
| (select run_id from pgflow.runs limit 1), | |
| 'first', | |
| 0, | |
| '{"result": "done"}'::jsonb | |
| ); | |
| -- Test: Task completed | |
| select is( | |
| (select status from pgflow.step_tasks | |
| where step_slug = 'first' limit 1), | |
| 'completed', | |
| 'Task should be completed' | |
| ); | |
| select finish(); | |
| rollback; | |
| ``` | |
| begin; | |
| select plan(1); | |
| select pgflow_tests.reset_db(); | |
| select pgflow_tests.setup_flow('sequential'); | |
| -- Start flow | |
| select pgflow.start_flow('sequential', '"hello"'::jsonb); | |
| -- Poll and start task | |
| select pgflow_tests.read_and_start('sequential'); | |
| -- Complete task | |
| select pgflow.complete_task( | |
| (select run_id from pgflow.runs limit 1), | |
| 'first', | |
| 0, | |
| '{"result": "done"}'::jsonb | |
| ); | |
| -- Test: Task completed | |
| select is( | |
| (select status from pgflow.step_tasks | |
| where step_slug = 'first' limit 1), | |
| 'completed', | |
| 'Task should be completed' | |
| ); | |
| select finish(); | |
| rollback; | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
| begin; | ||
| select plan(3); | ||
|
|
||
| -- CRITICAL: Create partition before testing realtime | ||
| select pgflow_tests.create_realtime_partition(); | ||
|
|
||
| select pgflow_tests.reset_db(); | ||
| select pgflow.create_flow('sequential'); | ||
| select pgflow.add_step('sequential', 'first'); | ||
|
|
||
| -- Capture run_id in temporary table | ||
| with flow as ( | ||
| select * from pgflow.start_flow('sequential', '{}') | ||
| ) | ||
| select run_id into temporary run_ids from flow; | ||
|
|
||
| -- Test: Event was sent | ||
| select is( | ||
| pgflow_tests.count_realtime_events( | ||
| 'run:started', | ||
| (select run_id from run_ids) | ||
| ), | ||
| 1::int, | ||
| 'Should send run:started event' | ||
| ); | ||
|
|
||
| -- Test: Event payload is correct | ||
| select is( | ||
| (select payload->>'status' | ||
| from pgflow_tests.get_realtime_message( | ||
| 'run:started', | ||
| (select run_id from run_ids) | ||
| )), | ||
| 'started', | ||
| 'Event should have correct status' | ||
| ); | ||
|
|
||
| -- Cleanup | ||
| drop table if exists run_ids; | ||
|
|
||
| select finish(); | ||
| rollback; | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan declares 3 tests but only 2 assertions are present. There are two is() calls at lines 169-176 and 179-187. This mismatch will cause the test to fail with "Bad plan. You planned 3 tests but ran 2."
Fix by changing line 153 to:
select plan(2);| begin; | |
| select plan(3); | |
| -- CRITICAL: Create partition before testing realtime | |
| select pgflow_tests.create_realtime_partition(); | |
| select pgflow_tests.reset_db(); | |
| select pgflow.create_flow('sequential'); | |
| select pgflow.add_step('sequential', 'first'); | |
| -- Capture run_id in temporary table | |
| with flow as ( | |
| select * from pgflow.start_flow('sequential', '{}') | |
| ) | |
| select run_id into temporary run_ids from flow; | |
| -- Test: Event was sent | |
| select is( | |
| pgflow_tests.count_realtime_events( | |
| 'run:started', | |
| (select run_id from run_ids) | |
| ), | |
| 1::int, | |
| 'Should send run:started event' | |
| ); | |
| -- Test: Event payload is correct | |
| select is( | |
| (select payload->>'status' | |
| from pgflow_tests.get_realtime_message( | |
| 'run:started', | |
| (select run_id from run_ids) | |
| )), | |
| 'started', | |
| 'Event should have correct status' | |
| ); | |
| -- Cleanup | |
| drop table if exists run_ids; | |
| select finish(); | |
| rollback; | |
| ``` | |
| begin; | |
| select plan(2); | |
| -- CRITICAL: Create partition before testing realtime | |
| select pgflow_tests.create_realtime_partition(); | |
| select pgflow_tests.reset_db(); | |
| select pgflow.create_flow('sequential'); | |
| select pgflow.add_step('sequential', 'first'); | |
| -- Capture run_id in temporary table | |
| with flow as ( | |
| select * from pgflow.start_flow('sequential', '{}') | |
| ) | |
| select run_id into temporary run_ids from flow; | |
| -- Test: Event was sent | |
| select is( | |
| pgflow_tests.count_realtime_events( | |
| 'run:started', | |
| (select run_id from run_ids) | |
| ), | |
| 1::int, | |
| 'Should send run:started event' | |
| ); | |
| -- Test: Event payload is correct | |
| select is( | |
| (select payload->>'status' | |
| from pgflow_tests.get_realtime_message( | |
| 'run:started', | |
| (select run_id from run_ids) | |
| )), | |
| 'started', | |
| 'Event should have correct status' | |
| ); | |
| -- Cleanup | |
| drop table if exists run_ids; | |
| select finish(); | |
| rollback; | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.

Add pgTAP Testing Skill for Database Testing
Added a new Claude skill for pgTAP testing that provides comprehensive guidance for writing database tests in pgflow. The skill includes:
This skill will help developers write effective database tests using the pgTAP framework, with specific focus on pgflow testing patterns. The skill includes a detailed reference of helper functions in a separate markdown file.
Also updated the schema-dev skill to reference the new pgTAP testing skill for additional test patterns and helpers.