utgen

package
v2.3.0-beta29 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 31 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
	APIKey       string
	APIServerURL string
	Auth         service.Auth
	Logger       *zap.Logger
	SessionID    string
}

func NewAIClient

func NewAIClient(model, apiBase, apiVersion, apiKey, apiServerURL string, auth service.Auth, sessionID string, logger *zap.Logger) *AIClient

func (*AIClient) Call

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

func (*AIClient) SendCoverageUpdate

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

type AIRequest

type AIRequest struct {
	MaxTokens int    `json:"maxTokens"`
	Prompt    Prompt `json:"prompt"`
	SessionID string `json:"sessionId"`
}

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

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
}

func NewPromptBuilder

func NewPromptBuilder(srcPath, testPath, covReportContent, includedFiles, additionalInstructions, language, additionalPrompt 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(
	cfg *config.Config,
	tel Telemetry,
	auth service.Auth,
	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, passedTests, noCoverageTest, failedBuild *int, installedPackages []string) 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