toolkittest

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 15 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 toolkittest is the conformance kit a tool runs from its own tests:

func TestConformance(t *testing.T) {
	toolkittest.Run(t, toolkittest.Suite{
		New: func(t testing.TB) toolkittest.Fixture {
			reg, store := newRegistry()
			return toolkittest.Fixture{Registry: reg, State: store.Snapshot}
		},
		Options: options(),
		Cases: map[string]toolkittest.Case{
			"note.delete": {Input: map[string]any{"id": "n1"}, Args: []string{"note", "n1", "delete"}},
		},
	})
}

It checks that cli.Validate accepts the command tree (which rejects an operation flag that a root flag such as --version would swallow), that the metadata is schema-valid, that MCP tools/list and the OpenAPI document match the registry, that every surface returns the same output for the same input, that destructive operations refuse to apply without confirm on the CLI, HTTP and MCP, and that writes only preview without apply. An operation with CLIImmediate is checked to apply on the CLI without --apply and preview with --dry-run, while HTTP and MCP still preview without apply. An operation with CLIConfirmed is checked to apply on the CLI without --yes, while HTTP and MCP still refuse to apply it without confirm. HTTP and MCP calls leave out a case's cli-only inputs, and when a case sets one, the kit checks that HTTP and MCP refuse it with cli_only and change nothing while the CLI accepts it. All calls are in-process, with no network or credentials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMCPTools

func CheckMCPTools(t testing.TB, reg *op.Registry, tools []*sdk.Tool)

CheckMCPTools checks that tools, from any MCP transport, are exactly the registry's MCP operations, with the registry's input schemas, effect annotations and CLIImmediate and CLIConfirmed _meta.

func CheckMetadata

func CheckMetadata(t testing.TB, doc []byte)

CheckMetadata validates a metadata document against toolkit.metadata.v1.

func CheckOpenAPI

func CheckOpenAPI(t testing.TB, reg *op.Registry, doc []byte)

CheckOpenAPI checks that an OpenAPI document has exactly one POST path per operation, with the registry's input and output schemas, effect, CLIImmediate and CLIConfirmed.

func ErrorCode

func ErrorCode(body []byte) string

ErrorCode returns error.code from a CLI, HTTP or MCP error body, or "".

func MCPClient

func MCPClient(t testing.TB, reg *op.Registry, auth op.Authorizer) *sdk.ClientSession

MCPClient connects an in-memory MCP client to reg's tools. A nil auth means op.DenyWrites, the served default.

func Run

func Run(t *testing.T, s Suite)

Run runs every conformance check as a subtest.

func SameJSON

func SameJSON(a, b []byte) bool

SameJSON reports whether two JSON documents are equal by value.

Types

type Case

type Case struct {
	// Input is the wire input without apply and confirm. It may set
	// cli-only inputs: HTTP and MCP calls leave them out, except in the
	// check that they are refused.
	Input map[string]any
	// Args select the same call on the CLI, without --apply, --dry-run, --yes
	// or --json.
	Args []string
}

Case is one call of an operation, expressed for every surface.

type Fixture

type Fixture struct {
	Registry *op.Registry
	// State returns a JSON-encodable snapshot of the backend. The kit compares
	// snapshots to prove that previews and refused calls change nothing, and
	// that an applied call does change something.
	State func() any
}

Fixture is one fresh registry over a fresh fake backend.

type Suite

type Suite struct {
	// New returns a fresh fixture. Each check gets its own.
	New func(t testing.TB) Fixture
	// Options are the tool's toolkit options. Authorizer is ignored: the kit
	// tests the default and an allow-all authorizer explicitly.
	Options toolkit.Options
	// Cases maps operation names to a call. Every write and destructive
	// operation needs one. A read case adds a parity check.
	Cases map[string]Case
}

Suite describes a tool for Run.

Jump to

Keyboard shortcuts

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