Documentation
¶
Overview ¶
Package conformance is the tool route conformance suite of the SDK (ADR-0029 §5, cases T1–T11), for the tests of anything that is a bmaexecutor.ToolRoute: the SDK's LocalToolRoute and PlatformToolRoute, and the route of a brain or hands of your own.
A brain must not be able to tell which route its calls took: the same refusals with the same error codes, the same three outcomes (executed, not_forwarded, unknown), the same texts, at most one run per call id, the same cancel and epoch behavior. RunToolRouteConformance runs one set of cases against the route a Factory builds:
func TestMyRoute(t *testing.T) {
conformance.RunToolRouteConformance(t, func(t *testing.T, toolPolicy map[string]string) *conformance.Rig {
// build your route and the levers the cases need
})
}
PlatformFactory builds the SDK's PlatformToolRoute against the contract double of the platform's tool gateway (package gatewaystub), with hands of your choosing (CoreHands runs the calls in a Core; the example hand does that). Run it to check that your hands are what the gateway expects.
The package depends on the SDK's public interface and on package testing only. It is for tests: production code must not import it (the SDK checks its own, see arch_test.go). Its cases start POSIX commands, so it is not built on Windows.
Index ¶
- Constants
- func CoreHands(t *testing.T, turn context.Context, core *bmaexecutor.Core, workspace string) gatewaystub.Hands
- func DefaultHands(t *testing.T, turn context.Context) (gatewaystub.Hands, string)
- func EffectivePolicy(overrides map[string]string) map[string]string
- func RunToolRouteConformance(t *testing.T, factory Factory)
- type Factory
- type HandsFunc
- type Rig
Constants ¶
const ( SessionID = "sesn_t1" TurnID = "turn_1" )
The ids a Rig's route must be bound to. A Factory derives the approval id of a call from them (bmaexecutor.ApprovalID).
Variables ¶
This section is empty.
Functions ¶
func CoreHands ¶
func CoreHands(t *testing.T, turn context.Context, core *bmaexecutor.Core, workspace string) gatewaystub.Hands
CoreHands are hands that run every call in a Core, in workspace, through a LocalToolRoute that allows every tool (the gateway has already decided). They are what the SDK's own hands do for a call, so a platform route in front of them must answer as the local route does. The call's SyncWait is not applied.
func DefaultHands ¶
DefaultHands are a Core of their own in a temporary directory, with the workspace "hands" in it (CoreHands).
func EffectivePolicy ¶
EffectivePolicy is the permission of every tool in the default permission mode (bash, write and edit ask; read, glob and grep allow) with overrides applied: the policy a Factory's route and a gateway double must enforce.
func RunToolRouteConformance ¶
RunToolRouteConformance runs T1–T11 against the routes factory builds, one subtest per case. Call it from a Test function, once per route (wrap it in t.Run to name the route).
Types ¶
type Factory ¶
Factory builds a Rig for one case. toolPolicy overrides the default permission of tools (allow, ask or deny): without an override bash, write and edit are ask and read, glob and grep are allow. The rig's route must enforce the result, and everything it creates must be removed with t.
func PlatformFactory ¶
PlatformFactory is the Factory of the SDK's PlatformToolRoute against the gateway double, with the hands hands makes. nil hands: a Core of its own in a temporary directory (DefaultHands). With your own hands it checks that they are what the platform's gateway needs: the same results as the SDK's local hands for the same calls.
type HandsFunc ¶
HandsFunc makes the hands behind the gateway double for one case: the machine that runs a call that passed the gateway's checks, and the directory its tools work in (the Rig's Workspace). turn ends when the turn is canceled.
type Rig ¶
type Rig struct {
// Workspace is the directory the tools run in (the hands' working
// directory) on this machine: the cases look at the files the tools leave
// there, and at its parent for escapes.
Workspace string
// Route is the route of the current turn (SessionID, TurnID). The cases ask
// for it before every call, so Restart and Supersede may replace it.
Route func() bmaexecutor.ToolRoute
// Approve records the user's answer ("allow" or "deny") to the permission
// interaction of a call, asked under bmaexecutor.ApprovalID(SessionID,
// TurnID, callID) for tool and input, and makes the route present it.
Approve func(callID, tool string, input map[string]any, decision string)
// Restart is an executor (and brain process) restart in the middle of the
// turn: nothing in memory survives, what the route keeps on disk or the
// platform keeps does. Route then returns a route of the same turn.
Restart func()
// MarkStarted: the call was submitted to the hands and the process died
// before the result was saved.
MarkStarted func(callID string)
// Supersede starts a newer epoch of the turn; routes handed out before are
// stale and Route returns the newer one.
Supersede func()
// CancelTurn is the user's cancel of the turn: calls in flight end and
// their process groups are killed.
CancelTurn func()
// HandsOffline makes the hands unreachable (and reachable again). Nil when
// the hands cannot be somewhere else (they are in the same process): T11 is
// then not run. There is no other exemption.
HandsOffline func(offline bool)
}
Rig is one route under test, with the levers the platform and the machine have: the user's answer to a permission, an executor restart, a newer brain epoch, a turn cancel, hands that are offline.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gatewaystub is a contract double of the platform's execute-only tool gateway (ADR-0005) and of the hands behind it, for tests of brains, of hands and of the SDK's tool routes.
|
Package gatewaystub is a contract double of the platform's execute-only tool gateway (ADR-0005) and of the hands behind it, for tests of brains, of hands and of the SDK's tool routes. |