Skip to content

keelgate.testing

Stability of each symbol (stable or provisional) is listed in the API contract. Narrative and semantics are in the integration contract.

Fakes and fixtures Keelgate ships for downstream projects' CI.

Importing this package never imports pytest. The fixtures live in keelgate.testing.plugin, which pytest loads through an entry point.

FakeLLM

A scripted, deterministic LLMClient for tests.

Replies come from a script, in order or indexed by call number (so a restarted process continues the script). Records every request it receives.

GovernedHarness dataclass

A wired gateway plus the handles a test needs to drive and inspect it.

grant

grant(
    capabilities: Iterable[str] | None = None,
    *,
    tenant: str | None = None,
    max_cost: float = 100.0,
    ttl: timedelta = timedelta(hours=1),
) -> str

A signed grant token. Default: every capability of every registered tool.

ManualClock

A clock that only moves when told to. Callable, so it plugs in wherever a clock does.

Reply dataclass

One scripted model turn: text, tool calls, or both.

ScriptExhaustedError

Bases: AssertionError

The code under test made more LLM calls than the script has replies for.

StaticPolicyEngine

A scripted :class:~keelgate.policy.PolicyEngine. Unlisted tools are DENIED.

rules maps a tool name to a :class:Decision. Every input it sees is kept in inputs so a test can assert what the policy was asked. As in production, the gateway consults policy for PROPOSE and WRITE tools only; READ tools are gated by the grant alone.

allow_all classmethod

allow_all() -> StaticPolicyEngine

Allow every action. For tests only; never a production policy.

UnofferedToolError

Bases: AssertionError

The script asked for a tool that the request did not offer.

build_governed_harness

build_governed_harness(
    tools: Iterable[Tool] = (),
    *,
    engine: PolicyEngine | None = None,
    clock: ManualClock | None = None,
    tenant_id: str = "tenant-1",
    agent_id: str = "agent-1",
) -> GovernedHarness

Build the stack. engine defaults to a DENY-everything static policy.