rules

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rules provides natural language business rule processing

Package rules provides natural language business rule processing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BusinessRule

type BusinessRule struct {
	ID          string   `yaml:"id" json:"id"`
	Description string   `yaml:"description" json:"description"`
	Category    string   `yaml:"category" json:"category"`     // authorization, data_access, workflow, validation
	Priority    string   `yaml:"priority" json:"priority"`     // critical, high, medium, low
	Scope       []string `yaml:"scope" json:"scope"`           // Endpoint patterns this rule applies to
	Actor       string   `yaml:"actor" json:"actor"`           // Who is performing the action
	Action      string   `yaml:"action" json:"action"`         // What action is being performed
	Resource    string   `yaml:"resource" json:"resource"`     // What resource is being accessed
	Constraint  string   `yaml:"constraint" json:"constraint"` // Natural language constraint
	Tags        []string `yaml:"tags,omitempty" json:"tags,omitempty"`
}

BusinessRule represents a natural language business rule

func (*BusinessRule) MatchesEndpoint

func (rule *BusinessRule) MatchesEndpoint(method, path string) bool

MatchesEndpoint checks if a rule applies to an endpoint

type ExpectedResult

type ExpectedResult struct {
	Success        bool     `json:"success"`
	StatusCode     int      `json:"status_code,omitempty"`
	StatusCodes    []int    `json:"status_codes,omitempty"` // Multiple acceptable codes
	ContainsData   bool     `json:"contains_data,omitempty"`
	ErrorMessage   string   `json:"error_message,omitempty"`
	MustNotContain []string `json:"must_not_contain,omitempty"`
	MustContain    []string `json:"must_contain,omitempty"`
}

ExpectedResult defines expected test outcomes

type Extraction

type Extraction struct {
	Name   string `json:"name"`
	From   string `json:"from"` // body, header, cookie
	Path   string `json:"path"`
	SaveAs string `json:"save_as"`
}

Extraction defines what to extract from a response

type RuleParser

type RuleParser struct{}

RuleParser parses business rules from YAML

func NewRuleParser

func NewRuleParser() *RuleParser

NewRuleParser creates a new rule parser

func (*RuleParser) Parse

func (p *RuleParser) Parse(data []byte) (*RuleSet, error)

Parse parses rules from YAML data

func (*RuleParser) ParseFile

func (p *RuleParser) ParseFile(filePath string) (*RuleSet, error)

ParseFile parses rules from a YAML file

type RuleSet

type RuleSet struct {
	Name        string         `yaml:"name" json:"name"`
	Description string         `yaml:"description" json:"description"`
	Version     string         `yaml:"version" json:"version"`
	Rules       []BusinessRule `yaml:"rules" json:"rules"`
}

RuleSet represents a collection of business rules

func (*RuleSet) GetRulesByCategory

func (rs *RuleSet) GetRulesByCategory(category string) []BusinessRule

GetRulesByCategory returns rules filtered by category

func (*RuleSet) GetRulesByPriority

func (rs *RuleSet) GetRulesByPriority(priority string) []BusinessRule

GetRulesByPriority returns rules filtered by priority

func (*RuleSet) GetRulesForEndpoint

func (rs *RuleSet) GetRulesForEndpoint(method, path string) []BusinessRule

GetRulesForEndpoint returns rules that apply to an endpoint

type RuleTestCase

type RuleTestCase struct {
	RuleID         string         `json:"rule_id"`
	Description    string         `json:"description"`
	SetupSteps     []TestStep     `json:"setup_steps"`
	ActionStep     TestStep       `json:"action_step"`
	ExpectedResult ExpectedResult `json:"expected_result"`
	Actors         []TestActor    `json:"actors"`
	Tags           []string       `json:"tags"`
}

RuleTestCase represents a test case generated from a rule

type RuleTranslator

type RuleTranslator struct {
	// contains filtered or unexported fields
}

RuleTranslator translates business rules to test cases

func NewRuleTranslator

func NewRuleTranslator(provider llm.Provider) *RuleTranslator

NewRuleTranslator creates a new rule translator

func (*RuleTranslator) TranslateRules

func (rt *RuleTranslator) TranslateRules(ctx context.Context, rules []BusinessRule, endpoints []types.Endpoint) ([]RuleTestCase, error)

TranslateRules translates business rules to test cases

type TestActor

type TestActor struct {
	Name     string `json:"name"`
	Role     string `json:"role"`
	AuthType string `json:"auth_type"`
	Token    string `json:"token,omitempty"`
}

TestActor represents an actor in the test

type TestStep

type TestStep struct {
	Name        string                 `json:"name"`
	Method      string                 `json:"method"`
	Endpoint    string                 `json:"endpoint"`
	Actor       string                 `json:"actor"`
	Headers     map[string]string      `json:"headers,omitempty"`
	Body        map[string]interface{} `json:"body,omitempty"`
	QueryParams map[string]string      `json:"query_params,omitempty"`
	Extract     []Extraction           `json:"extract,omitempty"`
}

TestStep represents a step in a test case

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL