testutil

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package testutil provides shared testing utilities for the pasture test suite.

LoadFixtures reads a named YAML fixture from the caller's testdata/ directory and unmarshals it into the supplied target value. Tests that rely on this function will fail immediately (via require) if the fixture file is missing or malformed, keeping test failures actionable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoldenUnifiedDBPath added in v0.0.5

func GoldenUnifiedDBPath(t *testing.T) string

GoldenUnifiedDBPath returns a per-test copy of a pre-migrated unified pasture.db. The golden source is built once per test binary through the real production opener, then copied byte-for-byte for each test that opts in.

func GoleakOptions added in v0.0.5

func GoleakOptions() []goleak.Option

func LoadFixtures

func LoadFixtures(t *testing.T, name FixtureName, target any)

LoadFixtures reads testdata/<name>.yaml relative to the current working directory (the package under test) and unmarshals the contents into target.

It calls t.Helper() so that failure lines point to the caller, and uses require (not assert) so that the test stops immediately on infrastructure failures rather than proceeding with a zero-value target.

Parameters:

  • t: the active *testing.T (must not be nil).
  • name: one of the FixtureName constants — determines the file path.
  • target: a non-nil pointer that yaml.Unmarshal will populate.

Failure modes (both call t.FailNow via require):

  • The fixture file does not exist at testdata/<name>.yaml.
  • The YAML content cannot be unmarshalled into target.

func OpenGoldenTaskTracker added in v0.0.5

func OpenGoldenTaskTracker(t *testing.T) (protocol.TaskTracker, string)

OpenGoldenTaskTracker opens a copied golden database with migrations explicitly disabled. Migration tests should not use this helper.

func SetEnv added in v0.0.5

func SetEnv(t *testing.T, key, value string)

SetEnv sets an environment variable for the duration of the test and restores the previous value during cleanup.

func SetHermeticEnv added in v0.0.5

func SetHermeticEnv(prefix string) (func(), error)

SetHermeticEnv points HOME and XDG_DATA_HOME at a temporary directory tree for a package-level test run.

Before redirecting HOME it resolves and pins GOCACHE and GOPATH to their effective values (via "go env"). This prevents subprocess go builds inside audit crash tests and cmd/pasture TestMain from resolving GOCACHE/GOPATH through the redirected (throwaway) HOME, which would produce a cold build-cache and module-cache hit on every run. GOCACHE and GOPATH are typically unset in the Nix dev shell, so os.Getenv("GOCACHE") is a no-op; only the toolchain's own resolution gives the real paths.

Sharing the content-addressed build and module caches does not weaken test isolation: per-test SQLite databases remain isolated via --db flags and t.TempDir(); only HOME and XDG_* dirs are redirected for hermeticity.

The returned cleanup function restores all four variables (GOCACHE, GOPATH, HOME, XDG_DATA_HOME) to their original state and removes the temp dir.

func UnsetEnv added in v0.0.5

func UnsetEnv(t *testing.T, key string)

UnsetEnv removes an environment variable for the duration of the test and restores the previous value during cleanup.

Types

type AcceptanceStore added in v0.0.5

type AcceptanceStore struct {
	Path    string
	Tracker protocol.TaskTracker
}

func OpenAcceptanceStore added in v0.0.5

func OpenAcceptanceStore(t *testing.T) *AcceptanceStore

OpenAcceptanceStore creates a file-backed store through the production opener. Callers seed it through Tracker APIs; this helper intentionally exposes no SQL.

func (*AcceptanceStore) Close added in v0.0.5

func (s *AcceptanceStore) Close(t *testing.T)

func (*AcceptanceStore) Reopen added in v0.0.5

func (s *AcceptanceStore) Reopen(t *testing.T)

type FixtureName

type FixtureName string

FixtureName is a typed string that identifies a YAML fixture file stored under the calling package's testdata/ directory. Using a named type instead of a plain string prevents accidental string literals at call sites.

const (
	// ContentBlock is used by S2–S3 tests (message/content-block scenarios).
	ContentBlock FixtureName = "content_block"

	// CLISmoke is used by S4–S5 tests (CLI smoke / handler scenarios).
	CLISmoke FixtureName = "cli_smoke"

	// ValidateBeforeOpen is used by the pasture CLI tests asserting that invalid
	// epoch/signal/session/slice/phase invocations are rejected by argument
	// validation before the durable database is opened.
	ValidateBeforeOpen FixtureName = "validate_before_open"

	// RunAgentSession is used by S5–S6 tests (Temporal workflow scenarios).
	RunAgentSession FixtureName = "run_agent_session"

	// ConfigLoading is used by S3 tests (config loading scenarios).
	ConfigLoading FixtureName = "config_loading"

	// CodegenMarkers is used by S3 codegen tests (marker parsing scenarios).
	CodegenMarkers FixtureName = "markers"

	// CodegenContext is used by S2 codegen tests (context injection scenarios).
	CodegenContext FixtureName = "context"

	// CodegenAgents is used by S6 codegen tests (agent definition generation scenarios).
	CodegenAgents FixtureName = "agents"

	// CodegenSkills is used by S4 codegen tests (SKILL.md generation scenarios).
	CodegenSkills FixtureName = "skills"

	// CodegenSchema is used by S5 codegen tests (schema.xml generation scenarios).
	CodegenSchema FixtureName = "schema"
)

Jump to

Keyboard shortcuts

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