tdd

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tdd provides AI-generated acceptance criteria and post-execution test verification for cloop PM tasks.

The workflow is two-phase:

  1. GenerateCriteria (--generate mode): before task execution the AI writes acceptance criteria (criteria.md) and a runnable test script (test.sh) stored under .cloop/tdd/<task-id>/.
  2. RunTests (--verify mode): after task execution the stored test.sh is executed; the exit code and output are used to update TDDStatus on the task and append a result section to the task artifact.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendResultToArtifact

func AppendResultToArtifact(workDir string, task *pm.Task, result TestResult) error

AppendResultToArtifact appends TDD result information to the task artifact file. It is a best-effort operation; errors are returned but callers may ignore them.

func CriteriaPath

func CriteriaPath(workDir string, taskID int) string

CriteriaPath returns the path to the acceptance criteria Markdown file.

func GenerateCriteria

func GenerateCriteria(ctx context.Context, prov provider.Provider, opts provider.Options, task *pm.Task) (string, string, error)

GenerateCriteria calls the AI provider to produce acceptance criteria and a test script for the task. Returns (criteriaMarkdown, shellScript, error).

func GenerateCriteriaPrompt

func GenerateCriteriaPrompt(task *pm.Task) string

GenerateCriteriaPrompt builds the AI prompt that produces acceptance criteria and a runnable test script for the given task.

func SaveCriteria

func SaveCriteria(workDir string, taskID int, criteria, testScript string) error

SaveCriteria writes the criteria.md and test.sh files to .cloop/tdd/<taskID>/. The test script is made executable (0755).

Both files are written atomically (tmp + fsync + rename) so a crash mid-write cannot leave a half-truncated criteria.md (which RunTests would happily exec, producing a misleading verification result) or a partial test.sh that bash would refuse to parse on the next --verify run.

func TDDDir

func TDDDir(workDir string, taskID int) string

TDDDir returns the directory where TDD artifacts for a task are stored.

func TestScriptPath

func TestScriptPath(workDir string, taskID int) string

TestScriptPath returns the path to the runnable test script.

func VerifyPrompt

func VerifyPrompt(task *pm.Task, testOutput string) string

VerifyPrompt builds the AI prompt used to interpret test script output and assign a quality score. It is used in the optional AI-narration step.

Types

type TestResult

type TestResult struct {
	ExitCode int
	Output   string
	Passed   bool
	Elapsed  time.Duration
}

TestResult holds the outcome of running the test script.

func RunTests

func RunTests(workDir string, taskID int) (TestResult, error)

RunTests executes the test script for a task and returns the result. The script is run from workDir so relative paths resolve correctly. Returns an error only when the script cannot be found or started; a non-zero exit code is reported via TestResult.ExitCode, not as an error.

Jump to

Keyboard shortcuts

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