Documentation
¶
Overview ¶
Package aitest provides a reusable ai.Executor harness for tests, extracted from the pattern in pkg/ai/fixtures_test.go.
NewHarness builds an ai.Executor with option-based subsystem wiring:
- SeedPatients, SeedAppointments — preload storetest.ResourceStore
- WithSearch, WithViews, WithCore, WithValidator — optional integrations
- AllowPatientRead, AllowPatientSearch, AllowPatientSummaryView, etc. — policy flags
- ApprovalGranted, WriteRequiresApproval — approval flow controls
- At, NewFixedClock — deterministic time helpers
Exported fakes implement ai.AuditLogger, ai.ApprovalHook, ai.Deidentifier, and ai.ModelAdapter for direct assertion on tool access, approval calls, and de-id.
Harness exposes Resources, Search, Views, Core, Policy, Audit, Approval, Deid, Model, Executor, and Clock so tests can assert both executor behavior and side effects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FakeApprovalHook ¶
type FakeApprovalHook struct {
Approved bool
Token string
Store *ai.MemoryApprovalStore
Calls []ai.ApprovalRequest
// contains filtered or unexported fields
}
FakeApprovalHook returns a configured approval result.
func (*FakeApprovalHook) RequestApproval ¶
func (h *FakeApprovalHook) RequestApproval(ctx context.Context, req ai.ApprovalRequest) (*ai.ApprovalResult, error)
type FakeAuditLogger ¶
type FakeAuditLogger struct {
Records []ai.AuditRecord
Tools int
Models int
// contains filtered or unexported fields
}
FakeAuditLogger records tool and model audit events on separate methods.
func (*FakeAuditLogger) LogModelInvoke ¶
func (a *FakeAuditLogger) LogModelInvoke(_ context.Context, rec ai.AuditRecord) error
func (*FakeAuditLogger) LogToolAccess ¶
func (a *FakeAuditLogger) LogToolAccess(_ context.Context, rec ai.AuditRecord) error
type FakeDeidentifier ¶
type FakeDeidentifier struct {
Called bool
}
FakeDeidentifier is a no-op deidentifier that reports one removed field.
func (*FakeDeidentifier) Deidentify ¶
func (d *FakeDeidentifier) Deidentify(_ context.Context, req ai.DeidentifyRequest) (any, []string, error)
type FakeModelAdapter ¶
type FakeModelAdapter struct {
AdapterName string
}
FakeModelAdapter returns deterministic model responses.
func (*FakeModelAdapter) Invoke ¶
func (a *FakeModelAdapter) Invoke(_ context.Context, req ai.ModelRequest) (*ai.ModelResponse, error)
func (*FakeModelAdapter) Name ¶
func (a *FakeModelAdapter) Name() string
type FixedClock ¶
type FixedClock struct {
// contains filtered or unexported fields
}
FixedClock returns a pinned time from Now().
func NewFixedClock ¶
func NewFixedClock(t time.Time) *FixedClock
NewFixedClock constructs a fixed clock at t.
func (*FixedClock) Now ¶
func (c *FixedClock) Now() time.Time
type Harness ¶
type Harness struct {
Resources *storetest.ResourceStore
Search *search.Service
Views *view.Executor
Core *core.ResourceService
Policy *ai.AllowListPolicy
Audit *FakeAuditLogger
Approval *FakeApprovalHook
Deid *FakeDeidentifier
Model *FakeModelAdapter
Executor *ai.Executor
Clock *FixedClock
}
Harness wires an ai.Executor with optional search, views, core, and policy fakes.
type Options ¶
type Options struct {
SeedPatients bool
SeedAppointments bool
WithSearch bool
WithViews bool
WithCore bool
WithValidator bool
AllowPatientRead bool
AllowPatientSearch bool
AllowPatientSummaryView bool
AllowAppointmentsView bool
AllowPatientWrite bool
WriteRequiresApproval bool
ApprovalGranted bool
FixedTime time.Time
}
Options configures which subsystems the harness enables.