testrun

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testrun detects the project test framework, runs tests, and pipes failures to the AI provider for root-cause diagnosis and fix suggestions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiagnosePrompt

func DiagnosePrompt(fw *Framework, failures []TestFailure, taskContext string) string

DiagnosePrompt builds the AI prompt for analyzing test failures.

func FixPrompt

func FixPrompt(fw *Framework, diags []Diagnosis, summary string) string

FixPrompt builds the task-add description for the --fix remediation task.

func FormatReport

func FormatReport(r *Report) string

FormatReport renders a human-readable test report.

func WriteReportArtifact

func WriteReportArtifact(workDir string, taskID int, report *Report) (string, error)

WriteReportArtifact persists the test report to .cloop/tasks/<taskID>-test-report.md. If taskID is 0 the filename is test-report-<timestamp>.md.

Types

type Diagnosis

type Diagnosis struct {
	TestName    string `json:"test_name"`
	RootCause   string `json:"root_cause"`
	FixStrategy string `json:"fix_strategy"`
}

Diagnosis is the AI-generated root-cause + fix strategy for one failure.

type Framework

type Framework struct {
	Name    string   // human-readable name, e.g. "go test", "pytest"
	Command []string // executable + args, e.g. ["go", "test", "./..."]
	Lang    string   // "go", "python", "node", "rust", "shell"
}

Framework describes a detected test framework and how to run it.

func Detect

func Detect(workDir string) (*Framework, error)

Detect probes workDir for known project files and returns the best matching Framework. It checks in priority order:

  1. Go (go.mod)
  2. Rust (Cargo.toml)
  3. Python (pytest via pyproject.toml / setup.cfg / requirements / .py files)
  4. Node with vitest (package.json + vitest)
  5. Node with jest (package.json + jest)
  6. Node with npm test (package.json fallback)

type Report

type Report struct {
	Framework string
	Passed    int
	Failed    int
	Skipped   int
	Diagnoses []Diagnosis
	RawOutput string
	AISummary string
}

Report is the final output of the test command.

func Diagnose

func Diagnose(ctx context.Context, prov provider.Provider, opts provider.Options, result *Result, taskContext string) (*Report, error)

Diagnose calls the AI provider to analyze the test failures and returns a Report.

type Result

type Result struct {
	Framework Framework
	Passed    int
	Failed    int
	Skipped   int
	Failures  []TestFailure
	RawOutput string // combined stdout + stderr
	ExitCode  int
}

Result holds the combined output and counts from a test run.

func Run

func Run(ctx context.Context, workDir string, fw *Framework) (*Result, error)

Run executes the framework's test command in workDir and returns a Result. A non-zero exit code is not an error — it is reflected in Result.ExitCode.

type TestFailure

type TestFailure struct {
	Name    string // test function/case name
	Message string // failure output excerpt (stacktrace, assertion)
}

TestFailure holds the details of a single failing test.

Jump to

Keyboard shortcuts

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