Creating Rules and Workflows
Core Agent enables you to create powerful rules and workflows that provide system-level guidance and automate repetitive tasks. Rules act as persistent context and preferences, while workflows define step-by-step processes for common operations.
Understanding Rules
Rules allow you to provide PostQode with system-level guidance that persists across conversations and projects. Think of them as a way to encode your team's standards, preferences, and best practices.
Global Rules vs Workspace Rules
Global Rules
- Scope: Apply to all projects and conversations
- Purpose: Organization-wide standards and preferences
- Examples: Coding standards, security guidelines, documentation requirements
- Persistence: Available across all workspaces and projects
Workspace Rules
- Scope: Apply only to the current workspace/project
- Purpose: Project-specific guidelines and conventions
- Examples: Project architecture, team conventions, environment configurations
- Persistence: Available only within the specific workspace
Rule Categories
Coding Standards Rules
# Example: JavaScript Coding Standards
name: javascript-coding-standards
type: global
category: coding-standards
description: JavaScript coding standards and best practices
rules:
- name: variable-naming
description: Use camelCase for variables and functions
example: "const userName = 'john'; function getUserData() {}"
- name: function-documentation
description: All functions must have JSDoc comments
example: |
/**
* Calculates user age based on birth date
* @param {Date} birthDate - User's birth date
* @returns {number} Age in years
*/
function calculateAge(birthDate) { ... }
- name: error-handling
description: Always use try-catch for async operations
example: |
try {
const data = await fetchUserData();
return data;
} catch (error) {
console.error('Failed to fetch user data:', error);
throw error;
}
Testing Standards Rules
# Example: Test Case Standards
name: test-case-standards
type: workspace
category: testing
description: Standards for test case creation and maintenance
rules:
- name: test-naming
description: Test names should be descriptive and follow Given-When-Then pattern
example: "Given user is logged in, When user clicks logout, Then user is redirected to login page"
- name: test-data
description: Use realistic test data that mimics production scenarios
requirements:
- No hardcoded production data
- Use data generators for large datasets
- Include edge cases and boundary values
- name: test-independence
description: Each test case must be independent and self-contained
requirements:
- No dependencies between test cases
- Each test creates its own test data
- Proper cleanup after test execution
Security Guidelines Rules
# Example: Security Testing Rules
name: security-testing-guidelines
type: global
category: security
description: Security testing requirements and guidelines
rules:
- name: authentication-testing
description: All authentication mechanisms must be thoroughly tested
requirements:
- Test token expiration and refresh
- Test unauthorized access attempts
- Validate session management
- Test password policies
- name: data-protection
description: Ensure sensitive data is properly protected
requirements:
- No sensitive data in test logs
- Encrypt sensitive test data
- Mask PII in test reports
- Secure test data storage
- name: api-security
description: API security testing requirements
requirements:
- Test input validation and sanitization
- Test SQL injection prevention
- Test XSS protection
- Validate HTTPS enforcement
Understanding Workflows
Workflows define a series of steps to guide PostQode through repetitive tasks. They can be invoked using /workflow-name in the chat interface.
Workflow Types
Development Workflows
- Code Review Process - Automated code review checklist and validation
- Feature Development - Step-by-step feature implementation process
- Bug Fix Process - Systematic approach to bug investigation and resolution
- Deployment Process - Automated deployment and validation steps
Testing Workflows
- Test Suite Creation - Automated test suite generation and organization
- Test Execution - Comprehensive test execution and reporting
- Test Data Management - Test data creation, maintenance, and cleanup
- Regression Testing - Automated regression test execution and analysis
Documentation Workflows
- API Documentation - Automated API documentation generation and validation
- Test Documentation - Test plan and test case documentation creation
- Release Notes - Automated release notes generation from commits and issues
Creating Custom Rules
Rule File Structure
# Global Rule Example
name: api-testing-standards
type: global
category: api-testing
description: Standards for API testing and validation
version: 1.0
author: QA Team
created: 2024-01-15
updated: 2024-03-20
context: |
These rules define the standards for API testing across all projects.
They ensure consistent testing practices and comprehensive coverage.
rules:
- name: endpoint-testing
description: Every API endpoint must have comprehensive test coverage
requirements:
- Test all HTTP methods (GET, POST, PUT, DELETE)
- Validate request/response schemas
- Test authentication and authorization
- Test error handling (4xx, 5xx responses)
- Performance testing for critical endpoints
- name: test-data-management
description: API test data must be properly managed
requirements:
- Use realistic test data
- Implement data cleanup after tests
- Avoid dependencies on external data
- Use data factories for consistent data generation
- name: documentation
description: API tests must be well documented
requirements:
- Clear test descriptions and purposes
- Document test data requirements
- Include examples of expected responses
- Maintain test case traceability to requirements
examples:
- name: user-registration-test
description: Example of comprehensive user registration API test
code: |
// Test user registration with valid data
test('POST /api/users - Create user with valid data', async () => {
const userData = {
username: 'testuser',
email: '[email protected]',
password: 'SecurePass123'
};
const response = await request(app)
.post('/api/users')
.send(userData)
.expect(201);
expect(response.body).toHaveProperty('id');
expect(response.body.email).toBe(userData.email);
expect(response.body).not.toHaveProperty('password');
});
enforcement:
- trigger: test-case-creation
action: validate-against-standards
- trigger: code-review
action: check-compliance
Workspace Rule Example
# Workspace-Specific Rule
name: ecommerce-testing-conventions
type: workspace
category: project-specific
description: Testing conventions specific to the e-commerce project
context: |
This project uses a microservices architecture with the following services:
- User Service (authentication, user management)
- Product Service (catalog, inventory)
- Order Service (cart, checkout, orders)
- Payment Service (payment processing)
rules:
- name: service-testing
description: Each microservice must have dedicated test suites
requirements:
- Unit tests for business logic
- Integration tests for service interactions
- Contract tests for API boundaries
- End-to-end tests for user journeys
- name: test-environment
description: Test environment configuration standards
requirements:
- Use Docker containers for service isolation
- Mock external dependencies (payment gateways, email services)
- Use test databases with realistic data volumes
- Implement service health checks
- name: performance-criteria
description: Performance requirements for the e-commerce platform
requirements:
- API response time < 200ms for 95% of requests
- Page load time < 3 seconds
- Support 1000 concurrent users
- Database query time < 100ms average
test-data:
users:
- type: customer
count: 100
attributes: [name, email, address, payment_method]
- type: admin
count: 5
attributes: [name, email, permissions]
products:
- type: physical
count: 500
attributes: [name, price, category, inventory, images]
- type: digital
count: 100
attributes: [name, price, category, download_url]
Creating Custom Workflows
Workflow File Structure
# API Testing Workflow
name: api-testing-workflow
description: Comprehensive API testing workflow
version: 1.0
category: testing
tags: [api, automation, testing]
parameters:
- name: api_spec_path
description: Path to API specification file
type: string
required: true
- name: test_environment
description: Target test environment
type: string
default: staging
options: [dev, staging, production]
- name: test_types
description: Types of tests to execute
type: array
default: [functional, security, performance]
options: [functional, security, performance, load]
steps:
- name: environment-setup
description: Set up test environment and dependencies
actions:
- validate_api_specification: "{{api_spec_path}}"
- configure_test_environment: "{{test_environment}}"
- setup_test_data: "realistic_dataset"
- initialize_test_tools: ["postman", "newman", "k6"]
- name: test-generation
description: Generate test cases from API specification
actions:
- analyze_api_spec: "{{api_spec_path}}"
- generate_positive_tests: "all_endpoints"
- generate_negative_tests: "error_scenarios"
- generate_security_tests: "auth_and_validation"
- create_performance_tests: "load_scenarios"
- name: test-execution
description: Execute generated test suites
parallel: true
actions:
- run_functional_tests:
suite: "api_functional_suite"
environment: "{{test_environment}}"
timeout: 300
- run_security_tests:
suite: "api_security_suite"
environment: "{{test_environment}}"
timeout: 600
- run_performance_tests:
suite: "api_performance_suite"
environment: "{{test_environment}}"
duration: 900
- name: result-analysis
description: Analyze test results and generate reports
actions:
- collect_test_results: "all_suites"
- generate_coverage_report: "api_endpoints"
- analyze_performance_metrics: "response_times"
- identify_failed_tests: "detailed_analysis"
- create_summary_report: "executive_summary"
- name: notification-and-cleanup
description: Send notifications and clean up test environment
actions:
- send_test_report:
recipients: ["[email protected]", "[email protected]"]
format: "html_with_attachments"
- update_test_dashboard: "real_time_metrics"
- cleanup_test_data: "preserve_logs"
- archive_test_results: "30_day_retention"
conditions:
- name: critical_failure
condition: "failed_tests > 0 AND severity == 'critical'"
actions:
- send_alert: "immediate_notification"
- create_jira_ticket: "high_priority"
- block_deployment: true
- name: performance_degradation
condition: "avg_response_time > 500ms"
actions:
- send_alert: "performance_team"
- generate_performance_report: "detailed_analysis"
- recommend_optimizations: true
rollback:
- name: test_failure_cleanup
description: Clean up if tests fail catastrophically
actions:
- restore_test_environment: "previous_state"
- cleanup_partial_data: "all_test_artifacts"
- send_failure_notification: "ops_team"
Test Suite Creation Workflow
name: test-suite-creation
description: Automated test suite creation from requirements
version: 1.0
category: test-automation
parameters:
- name: requirements_source
description: Source of requirements (document, jira, figma)
type: string
required: true
- name: test_types
description: Types of tests to generate
type: array
default: [functional, integration, ui]
- name: coverage_target
description: Target test coverage percentage
type: number
default: 85
steps:
- name: requirement-analysis
description: Analyze requirements and extract testable scenarios
actions:
- load_requirements: "{{requirements_source}}"
- extract_user_stories: "acceptance_criteria"
- identify_test_scenarios: "positive_negative_edge"
- map_requirements_to_tests: "traceability_matrix"
- name: test-case-generation
description: Generate comprehensive test cases
actions:
- generate_functional_tests:
scenarios: "user_journeys"
coverage: "{{coverage_target}}"
- generate_integration_tests:
scenarios: "system_interactions"
focus: "api_endpoints"
- generate_ui_tests:
scenarios: "user_interface"
browsers: ["chrome", "firefox", "safari"]
- generate_test_data:
type: "realistic_datasets"
volume: "medium"
- name: test-organization
description: Organize tests into logical suites
actions:
- create_test_suites:
structure: "feature_based"
priority: "risk_based"
- setup_test_dependencies: "execution_order"
- configure_test_environments: "isolated_execution"
- create_test_documentation: "comprehensive_guides"
- name: validation-and-review
description: Validate generated tests and prepare for review
actions:
- validate_test_completeness: "coverage_analysis"
- check_test_quality: "best_practices"
- generate_review_report: "test_suite_summary"
- prepare_execution_plan: "phased_rollout"
outputs:
- test_suites: "organized_by_feature"
- test_data: "csv_and_json_formats"
- documentation: "test_plans_and_guides"
- execution_scripts: "automation_ready"
- coverage_report: "requirements_traceability"
Workflow Invocation
Using Workflows in Chat
# Invoke API testing workflow
/api-testing-workflow api_spec_path="./specs/user-api.yaml" test_environment="staging"
# Invoke test suite creation workflow
/test-suite-creation requirements_source="./docs/user-stories.md" coverage_target=90
# Invoke with interactive parameter selection
/api-testing-workflow
# PostQode will prompt for required parameters
Workflow Chaining
name: complete-testing-pipeline
description: End-to-end testing pipeline with multiple workflows
version: 1.0
workflow_chain:
- workflow: test-suite-creation
parameters:
requirements_source: "{{requirements_path}}"
coverage_target: 85
- workflow: api-testing-workflow
parameters:
api_spec_path: "{{api_spec}}"
test_environment: "staging"
depends_on: test-suite-creation
- workflow: performance-testing
parameters:
load_profile: "normal_usage"
duration: 600
depends_on: api-testing-workflow
- workflow: security-testing
parameters:
scan_type: "comprehensive"
compliance: ["OWASP", "GDPR"]
depends_on: api-testing-workflow
Best Practices
Rule Creation Guidelines
✅ Effective Rule Creation:
├── Be specific and actionable
├── Include clear examples and code snippets
├── Define enforcement mechanisms
├── Regular review and updates
├── Version control for rule changes
└── Team collaboration on rule definitions
Workflow Design Principles
💡 Workflow Optimization:
├── Break complex processes into manageable steps
├── Use parameters for flexibility and reusability
├── Implement proper error handling and rollback
├── Include validation and quality checks
├── Provide clear progress indicators
└── Enable parallel execution where possible
Rules and workflows with Core Agent provide powerful automation and consistency, enabling teams to encode their best practices and automate repetitive processes for improved efficiency and quality.