utgen

package
v2.3.0-beta41 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 34 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 = 6

Variables

This section is empty.

Functions

func GetCodeLanguage

func GetCodeLanguage(sourceFilePath string) string

func GetPackageName

func GetPackageName(sourceFilePath string) (string, error)

func RunCommand

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

func TrimParentFolder

func TrimParentFolder(path string) string

Types

type AIClient

type AIClient struct {
	Model             string
	APIBase           string
	APIVersion        string
	APIKey            string
	APIServerURL      string
	Auth              service.Auth
	Logger            *zap.Logger
	SessionID         string
	FunctionUnderTest string
}

func NewAIClient

func NewAIClient(genConfig config.UtGen, apiKey, apiServerURL string, auth service.Auth, sessionID string, logger *zap.Logger) *AIClient

func (*AIClient) Call

func (ai *AIClient) Call(ctx context.Context, completionParams CompletionParams, aiRequest AIRequest, stream bool) (string, error)

func (*AIClient) SendCoverageUpdate

func (ai *AIClient) SendCoverageUpdate(ctx context.Context, sessionID string, oldCoverage, newCoverage float64, iterationCount int) error

type AIRequest

type AIRequest struct {
	MaxTokens      int         `json:"maxTokens"`
	Prompt         Prompt      `json:"prompt"`
	SessionID      string      `json:"sessionId"`
	Iteration      int         `json:"iteration"`
	RequestPurpose PurposeType `json:"requestPurpose"`
}

type AIResponse

type AIResponse struct {
	IsSuccess        bool   `json:"isSuccess"`
	Error            string `json:"error"`
	FinalContent     string `json:"finalContent"`
	PromptTokens     int    `json:"promptTokens"`
	CompletionTokens int    `json:"completionTokens"`
	APIKey           string `json:"apiKey"`
}

type Choice

type Choice struct {
	Index        int     `json:"index"`
	FinishReason string  `json:"finish_reason"`
	Message      Message `json:"message"`
	Delta        Delta   `json:"delta"`
}

type CompletionParams

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

type CompletionResponse

type CompletionResponse struct {
	ID      string    `json:"id"`
	Object  string    `json:"object"`
	Created int64     `json:"created"`
	Model   string    `json:"model"`
	Choices []Choice  `json:"choices"`
	Usage   UsageData `json:"usage"`
}

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) ParseCoverageReportJacoco

func (cp *CoverageProcessor) ParseCoverageReportJacoco() (*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 Injector

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

func NewInjectorBuilder

func NewInjectorBuilder(logger *zap.Logger, language string) *Injector

func (*Injector) GetModuleName

func (i *Injector) GetModuleName(sourceFilePath string) (string, string)

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
	AdditionalPrompt       string
	InstalledPackages      []string
	FunctionUnderTest      string
	ImportDetails          string
	ModuleName             string
}

func NewPromptBuilder

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

func (*PromptBuilder) BuildPrompt

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

type PurposeType

type PurposeType string

PurposeType defines the type of purpose for the AI request.

const (
	// TestForFunction represents a purpose type where the request is to test a function.
	TestForFunction PurposeType = "TestForFunction"

	// TestForFile represents a purpose type where the request is to test a file.
	TestForFile PurposeType = "TestForFile"
)

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(
	cfg *config.Config,
	tel Telemetry,
	auth service.Auth,
	logger *zap.Logger,
) (*UnitTestGenerator, error)

func (*UnitTestGenerator) GenerateTests

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

func (*UnitTestGenerator) Start

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

func (*UnitTestGenerator) ValidateTest

func (g *UnitTestGenerator) ValidateTest(generatedTest models.UT, passedTests, noCoverageTest, failedBuild *int, installedPackages []string) (bool, error)

type Usage

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

type UsageData

type UsageData 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