aitest

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

func At

func At(year int, month time.Month, day, hour, min, sec int) time.Time

At returns a UTC time for deterministic AI harness tests.

func URLValues

func URLValues(params map[string]string) url.Values

URLValues converts a param map to url.Values for search tests.

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 (*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
	SearchIndex   *storetest.SearchStore // populated when WithSearch; updated atomically with Core writes
	SearchIndexer search.Indexer         // same indexer wired into Core when WithSearch && WithCore
	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.

func NewHarness

func NewHarness(t *testing.T, opts Options) *Harness

NewHarness builds an AI executor harness for tests.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL