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 ¶
- func CheckMCPTools(t testing.TB, reg *op.Registry, tools []*sdk.Tool)
- func CheckMetadata(t testing.TB, doc []byte)
- func CheckOpenAPI(t testing.TB, reg *op.Registry, doc []byte)
- func ErrorCode(body []byte) string
- func MCPClient(t testing.TB, reg *op.Registry, auth op.Authorizer) *sdk.ClientSession
- func Run(t *testing.T, s Suite)
- func SameJSON(a, b []byte) bool
- type Case
- type Fixture
- type Suite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckMCPTools ¶
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 ¶
CheckMetadata validates a metadata document against toolkit.metadata.v1.
func CheckOpenAPI ¶
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 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.
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.