Testing Utilities
The @zakardo/testing package provides comprehensive testing utilities for Zakardo applications.
Installation
Section titled “Installation”pnpm add -D @zakardo/testingTest Runtime
Section titled “Test Runtime”Create a fully wired runtime for integration tests:
import { createTestRuntime } from '@zakardo/testing';
const runtime = await createTestRuntime({ capabilities: [myCapability], implementations: { 'my_cap': myCapFn }, policies: [myPolicy],});
// Use runtime for tests...
await runtime.shutdown();Test Helpers
Section titled “Test Helpers”import { testCapability, testPlan, testPolicy } from '@zakardo/testing';
// Test a capabilityconst result = await testCapability(myCapFn, { name: 'Alice' });expect(result.output.id).toBeDefined();expect(result.error).toBeUndefined();
// Test plan validationconst planResult = testPlan(myPlan, runtime);expect(planResult.valid).toBe(true);
// Test policy evaluationconst policyResult = testPolicy(runtime, 'my_capability');expect(policyResult.allowed).toBe(true);Custom Vitest Matchers
Section titled “Custom Vitest Matchers”import { expect } from 'vitest';import { zakardoMatchers } from '@zakardo/testing';
expect.extend(zakardoMatchers);
// Plan matchersexpect(plan).toContainCapability('contacts_create');expect(plan).toHaveStepCount(3);
// Training matchersexpect(result).toHaveVerdict('PASS');expect(run).toHavePassRate(0.9);
// Output matchersexpect(output).toMatchSubset({ name: 'Alice' });Factory Functions
Section titled “Factory Functions”import { createTestCapability, createTestPlanIR, createTestTrainingDataset, createMockCapabilityImpl,} from '@zakardo/testing';
const cap = createTestCapability({ name: 'my_cap' });const plan = createTestPlanIR({ steps: [...] });const dataset = createTestTrainingDataset({ cases: [...] });const mock = createMockCapabilityImpl({ defaultOutput: { id: '123' } });