Tools and Pipelines
Test tool handlers and deterministic pipeline workflow code.
Tools and pipelines usually contain the highest-value unit tests because they hold application behavior that should work before a model is involved.
Test Tools Directly
Tools are application functions with schemas. Test expected product states without involving a model:
const result = await lookupOrder.call({ orderId: "A-100" });
expect(result).toEqual({
status: "shipped",
carrier: "DHL",
});Also test invalid input and permission failures at the tool boundary. Do not rely on prompts to enforce product permissions.
Test Expected Product States
Prefer explicit results for expected conditions:
await expect(lookupOrder.call({ orderId: "missing" })).resolves.toEqual({
status: "not_found",
});Throw only when the workflow should fail or be retried. That keeps tool behavior easier to assert from agents, pipelines, and Studio.
Test Pipelines as Workflow Code
Pipeline steps are ordinary functions. Keep deterministic steps small enough to test before adding model calls:
const pipeline = new PipelineBuilder<string>()
.step((input) => input.trim())
.step((input) => ({ query: input, limit: 5 }))
.build();
await expect(pipeline.run(" refund policy ")).resolves.toEqual({
query: "refund policy",
limit: 5,
});Test Batch Behavior
Use batch(...) tests when concurrency, ordering, or failure behavior matters:
const results = await pipeline.batch(["one", "two"], {
concurrency: 2,
});
expect(results).toHaveLength(2);Keep model-backed pipeline stages in narrower integration tests. Deterministic preprocessing, branching, and result formatting should stay covered by fast tests.
