plan

package
v2.8.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package plan provides the model for the test plan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintSplitSummary

func PrintSplitSummary(w io.Writer, p TestPlan)

PrintSplitSummary writes a human-readable summary of the resolved test plan to w (typically os.Stderr). At parallelism > 1 it uses per-format TimingMetadata to break down known vs unknown cases. At parallelism == 1 the server skips per-format timing data due to performance reasons, so it falls back to the plan-level KnownTimingsRatio. Skipped for fallback plans, or when neither signal is available.

Types

type FormatTimingMetadata

type FormatTimingMetadata struct {
	// MedianDuration is the median of historical timings used to backfill
	// cases without history. Nil when no history existed at all.
	MedianDuration *float64 `json:"median_duration"`
	// DefaultDuration is the assumed duration when no history exists at all.
	DefaultDuration float64 `json:"default_duration"`
}

FormatTimingMetadata is the timing data for a single case format (file-scoped or example-scoped). All durations are in milliseconds and may be fractional (the server-side median can be the mean of two middle values).

type Task

type Task struct {
	NodeNumber int `json:"node_number"`
	// When splitting by file, this tests array is essentially an array of test files.
	// When splitting by example, this array is an array of proper test cases.
	// See comment above, we plan to split TestCase into two types or clarify its usage.
	Tests []TestCase `json:"tests"`
}

Task represents the task for the given node.

type TestCase

type TestCase struct {
	EstimatedDuration int            `json:"estimated_duration,omitempty"`
	Format            TestCaseFormat `json:"format,omitempty"`
	Identifier        string         `json:"identifier,omitempty"`
	Name              string         `json:"name,omitempty"`
	// Path is the path of the individual test or test file that the test runner can interpret.
	// For example:
	// In RSpec, the path can be a test file like `user_spec.rb` or an individual test id like `user_spec.rb[1,2]`.
	// In Jest, the path is a test file like `src/components/Button.spec.tsx`.
	// In pytest, the path can be a test file like `test_hello.py` or a node id like `test_hello.py::TestHello::test_greet`
	// In go test, the path can only be package name like "example.com/foo/bar".
	Path  string `json:"path"`
	Scope string `json:"scope,omitempty"`
	// TimingSampleSize is the number of historical executions/runs behind this
	// case's EstimatedDuration. For file-scoped cases this is distinct runs,
	// for example-scoped cases this is raw executions. Defaults to 0 when no
	// history is available or the field is missing on older/cached plans.
	TimingSampleSize int `json:"timing_sample_size,omitempty"`
}

TestCase currently can represent a single test case or a single test file (when used as output of test plan API). TODO: it's best if we split this into two types.

type TestCaseFormat

type TestCaseFormat string
const (
	TestCaseFormatFile    TestCaseFormat = "file"
	TestCaseFormatExample TestCaseFormat = "example"
)

type TestPlan

type TestPlan struct {
	Identifier   string           `json:"identifier"`
	Parallelism  int              `json:"parallelism"`
	Experiment   string           `json:"experiment"`
	Tasks        map[string]*Task `json:"tasks"`
	Fallback     bool
	MutedTests   []TestCase `json:"muted_tests,omitempty"`
	SkippedTests []TestCase `json:"skipped_tests,omitempty"`
	// TimingMetadata describes the historical timing data the server used to
	// build this plan. Nil when missing (e.g. error plans, plans cached before
	// the server began emitting it).
	TimingMetadata *TimingMetadata `json:"timing_metadata,omitempty"`
	// KnownTimingsRatio is the fraction (0.0–1.0) of cases that had historical
	// timing data when the plan was built. Used to summarise plans where
	// per-format timing metadata is not emitted (e.g. parallelism == 1).
	KnownTimingsRatio *float64 `json:"known_timings_ratio,omitempty"`
}

TestPlan represents the entire test plan.

func CreateFallbackPlan

func CreateFallbackPlan(files []string, parallelism int) TestPlan

CreateFallbackPlan creates a fallback test plan for the given tests and parallelism. It distributes test cases evenly across the tasks using deterministic algorithm.

type TimingMetadata

type TimingMetadata struct {
	File    *FormatTimingMetadata `json:"file,omitempty"`
	Example *FormatTimingMetadata `json:"example,omitempty"`
}

TimingMetadata describes the historical timing data the server used to build the test plan, broken down per case format. Either key may be omitted when the plan contains no cases of that format (or when parallelism is 1 and no timings were fetched).

Jump to

Keyboard shortcuts

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