utgen

package
v2.2.0-alpha21-rc9 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package utgen is a service that generates unit tests for a given source code file.

Index

Constants

View Source
const ADDITIONAL_INCLUDES_TEXT = `` /* 217-byte string literal not displayed */
View Source
const ADDITIONAL_INSTRUCTIONS_TEXT = `
## Additional Instructions
======
{{.AdditionalInstructions}}
======
`
View Source
const FAILED_TESTS_TEXT = `` /* 250-byte string literal not displayed */
View Source
const MAX_TESTS_PER_RUN = 4

Variables

This section is empty.

Functions

func GetCodeLanguage

func GetCodeLanguage(sourceFilePath string) string

func RunCommand

func RunCommand(command string, cwd string, logger *zap.Logger) (stdout string, stderr string, exitCode int, commandStartTime int64, err error)

Types

type AIClient

type AIClient struct {
	Model      string
	APIBase    string
	APIVersion string
	Logger     *zap.Logger
}

func NewAIClient

func NewAIClient(model, apiBase, apiVersion string, logger *zap.Logger) *AIClient

func (*AIClient) Call

func (ai *AIClient) Call(ctx context.Context, prompt *Prompt, maxTokens int) (string, int, int, error)

type Choice

type Choice struct {
	Delta Delta `json:"delta"`
}

type CompletionParams

type CompletionParams struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	MaxTokens   int       `json:"max_tokens"`
	Stream      bool      `json:"stream"`
	Temperature float32   `json:"temperature"`
}

type Coverage

type Coverage struct {
	Path    string
	Format  string
	Desired float64
	Current float64
	Content string
}

type CoverageProcessor

type CoverageProcessor struct {
	ReportPath string
	SrcPath    string
	Format     string
}

CoverageProcessor handles the processing of coverage reports

func NewCoverageProcessor

func NewCoverageProcessor(reportPath, srcpath, format string) *CoverageProcessor

NewCoverageProcessor initializes a CoverageProcessor object

func (*CoverageProcessor) ParseCoverageReport

func (cp *CoverageProcessor) ParseCoverageReport() (*models.CoverageResult, error)

ParseCoverageReport parses the coverage report based on its type

func (*CoverageProcessor) ParseCoverageReportCobertura

func (cp *CoverageProcessor) ParseCoverageReportCobertura() (*models.CoverageResult, error)

func (*CoverageProcessor) ProcessCoverageReport

func (cp *CoverageProcessor) ProcessCoverageReport(latestTime int64) (*models.CoverageResult, error)

ProcessCoverageReport verifies the report and parses it based on its type

func (*CoverageProcessor) VerifyReportUpdate

func (cp *CoverageProcessor) VerifyReportUpdate(latestTime int64) error

VerifyReportUpdate verifies the coverage report's existence and update time

type Cursor

type Cursor struct {
	Line        int
	Indentation int
}

type Delta

type Delta struct {
	Content string `json:"content"`
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ModelResponse

type ModelResponse struct {
	ID                string   `json:"id"`
	Choices           []Choice `json:"choices"`
	Created           int      `json:"created"`
	Model             string   `json:"model,omitempty"`
	Object            string   `json:"object"`
	SystemFingerprint string   `json:"system_fingerprint,omitempty"`
	Usage             *Usage   `json:"usage,omitempty"`
}

type Prompt

type Prompt struct {
	System string `json:"system"`
	User   string `json:"user"`
}

type PromptBuilder

type PromptBuilder struct {
	Src                    *Source
	Test                   *Test
	CovReportContent       string
	IncludedFiles          string
	AdditionalInstructions string
	Language               string
	Logger                 *zap.Logger
}

func NewPromptBuilder

func NewPromptBuilder(srcPath, testPath, covReportContent, includedFiles, additionalInstructions, language string, logger *zap.Logger) (*PromptBuilder, error)

func (*PromptBuilder) BuildPrompt

func (pb *PromptBuilder) BuildPrompt(file, failedTestRuns string) (*Prompt, error)

type ResponseChunk

type ResponseChunk struct {
	Choices []Choice `json:"choices"`
}

type Service

type Service interface {
	Start(ctx context.Context) error
}

type Source

type Source struct {
	Name         string
	Code         string
	CodeNumbered string
}

type Telemetry

type Telemetry interface {
	GenerateUT()
}

type Test

type Test struct {
	Name         string
	Code         string
	CodeNumbered string
}

type UnitTestGenerator

type UnitTestGenerator struct {
	Files []string
	// contains filtered or unexported fields
}

func NewUnitTestGenerator

func NewUnitTestGenerator(srcPath, testPath, reportPath, cmd, dir, coverageFormat string, desiredCoverage float64, maxIterations int, model string, apiBaseURL string, apiVersion string, _ *config.Config, tel Telemetry, logger *zap.Logger) (*UnitTestGenerator, error)

func (*UnitTestGenerator) GenerateTests

func (g *UnitTestGenerator) GenerateTests(ctx context.Context) (*models.UTDetails, error)

func (*UnitTestGenerator) Start

func (g *UnitTestGenerator) Start(ctx context.Context) error

func (*UnitTestGenerator) ValidateTest

func (g *UnitTestGenerator) ValidateTest(generatedTest models.UT) error

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Directories

Path Synopsis
Package settings provides prompt settings for the test generation
Package settings provides prompt settings for the test generation

Jump to

Keyboard shortcuts

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