repotest

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package repotest is a contract suite for prompt.FragmentRepository implementations. It is an ordinary package, not a test file, so a repository written outside PromptKit can run the same checks as the ones in runtime/persistence:

func TestFragmentContract(t *testing.T) {
	repotest.RunFragmentRepositoryContract(t, func(t *testing.T, root string) prompt.FragmentRepository {
		return myrepo.New(root)
	})
}

Index

Constants

View Source
const (
	NamedFragment = "contract_named"
	NamedContent  = "Fragment found by name."
)

The fixture a name-only lookup must find. The suite writes it as <root>/fragments/contract_named.yaml and <root>/fragments/contract_named.json before it builds the repository. A repository that does not read fragments from files must hold it some other way; the in-memory one registers it:

repo.RegisterFragment(repotest.NamedFragment, &prompt.Fragment{Content: repotest.NamedContent})

Variables

View Source
var ErrCheckSkipped = errors.New("check skipped on this platform")

ErrCheckSkipped is returned by a check that cannot run on this platform, such as a symlink check where os.Symlink fails. The suite skips it.

Functions

func RunFragmentRepositoryContract

func RunFragmentRepositoryContract(
	t *testing.T, newRepo func(t *testing.T, root string) prompt.FragmentRepository,
)

RunFragmentRepositoryContract checks a FragmentRepository against the contract FragmentResolver relies on:

  • a lookup with no path finds the fragment stored under that name;
  • a relative path resolves against baseDir, so one relative path under two base directories is two fragments;
  • an absolute path loads that file and ignores baseDir;
  • a fragment that does not exist is an error satisfying errors.Is(err, fs.ErrNotExist). FragmentResolver falls back from the prompt's directory to the working directory only on that error;
  • a file that exists but cannot be read or parsed is an error that does not satisfy fs.ErrNotExist, so the resolver reports it rather than looking elsewhere;
  • a relative path may climb only as far as its own leading "../" segments: one that climbs back past that point ("x/../../y") is an error that does not satisfy fs.ErrNotExist, whether or not a file is there. An absolute path is the config's to choose;
  • so is a path whose file is a symlink pointing outside the root, while a symlink that stays inside the root is followed;
  • a baseDir reached through a symlinked directory is that directory: its relative paths, their leading "../" and an absolute link written through the symlinked path all read the files it holds. Where the anchor a path may reach really is is settled once per lookup, and the read stays there;
  • a repository that cannot honor a path (the in-memory one) says so with persistence.ErrFragmentPathUnsupported on every path lookup, and never answers one by name.

newRepo builds the repository over root after the suite has written its fixtures there.

func WriteFixtures

func WriteFixtures(root string) error

WriteFixtures writes the files the checks load under root.

Types

type Check

type Check struct {
	Name string
	Run  func(repo prompt.FragmentRepository, root string) error
}

Check is one clause of the contract. It returns an error describing how the repository broke it, or nil.

func Checks

func Checks() []Check

Checks returns the contract's checks, in the order the suite runs them.

Jump to

Keyboard shortcuts

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