testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: CC0-1.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil supplies deterministic fixtures for Taskronin tests. Production packages must not import it.

Index

Constants

View Source
const DefaultNow = "2026-10-28 10:00"

DefaultNow is the catalog's default local instant.

View Source
const Password = "correct horse battery"

Password is the one fixed test password permitted by A§13.1.

Variables

View Source
var Zone = mustZone()

Zone is the catalog's America/Denver civil time zone.

Functions

func AI

func AI() domain.Actor

AI returns the catalog's AI actor with the MCP mutation limit.

func After

func After(id domain.TaskID) func(*service.AddTaskIn)

After places a new task immediately after id in the global task order.

func Before

func Before(id domain.TaskID) func(*service.AddTaskIn)

Before places a new task immediately before id in the global task order.

func BlockAt

func BlockAt(span string) func(*service.AddTaskIn)

BlockAt places a new task in a catalog span; an omitted date means the scenario's today.

func Bottom

func Bottom() func(*service.AddTaskIn)

Bottom places a new task at the bottom of the global task order.

func Clock

func Clock(t testing.TB, local string) *clock.Fake

Clock constructs a fake clock at a catalog instant.

func D

func D(s string) civil.Date

D parses an ISO date or a month-day shorthand in 2026, panicking on bad fixtures.

func DeferTo

func DeferTo(m string) func(*service.AddTaskIn)

DeferTo sets an AddTask input's defer moment from a catalog date and optional time.

func Due

func Due(m string) func(*service.AddTaskIn)

Due sets an AddTask input's due moment from a catalog date and optional time.

func Golden

func Golden(t testing.TB, name string, got []byte)

Golden compares got with testdata/golden/<name>.golden, relative to the calling package's working directory. Pass -update to rewrite the fixture.

func Local

func Local(t testing.TB, s string) time.Time

Local parses a catalog wall time or UTC ISO instant; wall-time gaps move forward.

func Meta

Meta constructs a unique canonical test request for the given caller and generation.

func Moment

func Moment(s string) domain.Moment

Moment parses a catalog date with an optional HH:MM minute.

func Now

func Now() func(*service.AddTaskIn)

Now places a new task at the top, focuses it and records any interruption.

func Owner

func Owner() domain.Actor

Owner returns the trusted CLI owner actor.

func RequireCode

func RequireCode(t testing.TB, err error, want domain.Code)

RequireCode fails unless err is a domain error with the expected code.

func Service

func Service(t testing.TB, opts ...SvcOpt) (*service.Service, *clock.Fake)

Service constructs a service with the catalog clock, policies and isolated storage.

func Store

func Store(t testing.TB) *store.Store

Store creates a migrated, bootstrapped database and checks FTS and structural invariants during cleanup.

func StoreNoCheck

func StoreNoCheck(t testing.TB) *store.Store

StoreNoCheck creates a store without cleanup checks for deliberate corruption tests.

func TokenActor

func TokenActor(name string, sc domain.Scopes) domain.Actor

TokenActor returns an API actor with the supplied token name and scopes.

func Top

func Top() func(*service.AddTaskIn)

Top places a new task at the top of the global task order.

Types

type Scenario

type Scenario struct {
	T     testing.TB
	Svc   *service.Service
	Clock *clock.Fake
	Store *store.Store
	Actor domain.Actor
	Last  *service.OpResult
}

Scenario holds a service fixture and the actor for fluent catalog operations.

func NewScenario

func NewScenario(t testing.TB, opts ...SvcOpt) *Scenario

NewScenario constructs an isolated fixture acting as the owner.

func (*Scenario) Add

func (s *Scenario) Add(title string, mods ...func(*service.AddTaskIn)) domain.TaskID

Add captures a task after applying the supplied input modifiers.

func (*Scenario) As

func (s *Scenario) As(a domain.Actor) *Scenario

As returns a shallow copy acting as a, retaining the shared fixture.

func (*Scenario) At

func (s *Scenario) At(when string) *Scenario

At moves the shared fake clock to a catalog instant.

func (*Scenario) Backlog

func (s *Scenario) Backlog() []domain.TaskID

Backlog independently queries open, undeleted, undeferred tasks without reasons.

func (*Scenario) Block

func (s *Scenario) Block(task domain.TaskID, span string) domain.BlockID

Block schedules a task using its current precondition; an omitted date means today.

func (*Scenario) BlockExpect

func (s *Scenario) BlockExpect(id domain.BlockID) domain.Expect

BlockExpect returns the block's current version in the live database generation.

func (*Scenario) BlockState

func (s *Scenario) BlockState(id domain.BlockID) string

BlockState returns the catalog tuple {status, source, slipped, cancel}.

func (*Scenario) BlockView

func (s *Scenario) BlockView(id domain.BlockID) domain.BlockView

BlockView returns the current block view through GetBlock.

func (*Scenario) Ctx

func (s *Scenario) Ctx() context.Context

Ctx returns the test's context.

func (*Scenario) Defer

func (s *Scenario) Defer(id domain.TaskID, moment string)

Defer places a task at a defer moment, or clears its defer when moment is empty.

func (*Scenario) Delete

func (s *Scenario) Delete(id domain.TaskID)

Delete tombstones a task using its current precondition.

func (*Scenario) DeleteEntry

func (s *Scenario) DeleteEntry(id domain.EntryID)

DeleteEntry tombstones an entry using its current precondition.

func (*Scenario) Done

func (s *Scenario) Done(id domain.TaskID, mods ...func(*service.CompleteIn))

Done completes a task using its current precondition and input modifiers.

func (*Scenario) Drop

func (s *Scenario) Drop(id domain.TaskID)

Drop closes an open task using its current precondition.

func (*Scenario) EditEntry

func (s *Scenario) EditEntry(id domain.EntryID, mods ...func(*service.UpdateEntryIn))

EditEntry edits an entry using its current precondition and input modifiers.

func (*Scenario) EntryExpect

func (s *Scenario) EntryExpect(id domain.EntryID) domain.Expect

EntryExpect returns the entry's current version in the live database generation.

func (*Scenario) EventKeys

func (s *Scenario) EventKeys(op domain.OpID) []string

EventKeys returns compact entity/action labels with IDs, triage reasons and derivation.

func (*Scenario) Events

func (s *Scenario) Events(op domain.OpID) []domain.Event

Events returns an operation's persisted events in event order.

func (*Scenario) Exec

func (s *Scenario) Exec(query string, args ...any)

Exec runs raw fixture SQL only for scenarios explicitly permitting it.

func (*Scenario) Expect

func (s *Scenario) Expect(id domain.TaskID) domain.Expect

Expect returns the task's current version in the live database generation.

func (*Scenario) Focus

func (s *Scenario) Focus() domain.Focus

Focus returns the persisted singleton focus without triggering reconcile.

func (*Scenario) Interruptions

func (s *Scenario) Interruptions(date string) []domain.Interruption

Interruptions returns live interruptions on a catalog date.

func (*Scenario) Log

func (s *Scenario) Log(task domain.TaskID, text, date string) domain.EntryID

Log records untimed work; task 0 means standalone and date "" means today.

func (*Scenario) LogAt

func (s *Scenario) LogAt(task domain.TaskID, text, date, at string) domain.EntryID

LogAt records work with an optional HH:MM time; task 0 is standalone, date "" is today.

func (*Scenario) MarkManual

func (s *Scenario) MarkManual(id domain.TaskID)

MarkManual requests manual triage using the task's current precondition.

func (*Scenario) Meta

func (s *Scenario) Meta() service.Meta

Meta returns a fresh request for the current actor and database generation.

func (*Scenario) MetaWith

func (s *Scenario) MetaWith(key, body string) service.Meta

MetaWith returns a request with an explicit idempotency key and canonical body.

func (*Scenario) Must

func (s *Scenario) Must(r *service.OpResult, err error) *service.OpResult

Must requires success and remembers the latest fluent operation result.

func (*Scenario) Op

func (s *Scenario) Op(id domain.OpID) domain.OpRecord

Op loads a persisted operation.

func (*Scenario) OpCount

func (s *Scenario) OpCount() int

OpCount counts all operations in the fixture.

func (*Scenario) Outcome

func (s *Scenario) Outcome(b domain.BlockID, o domain.UserOutcome)

Outcome sets a block's outcome policy using its current precondition.

func (*Scenario) Place

func (s *Scenario) Place(id domain.TaskID, how domain.PlaceHow, ref ...domain.TaskID)

Place acknowledges triage and positions a task using its current precondition.

func (*Scenario) Reasons

func (s *Scenario) Reasons(id domain.TaskID) []domain.TriageReason

Reasons returns a task's triage reasons in descending priority order.

func (*Scenario) Reblock

func (s *Scenario) Reblock(b domain.BlockID, span string) domain.BlockID

Reblock reschedules a block and returns the resulting planned block's ID.

func (*Scenario) Reconcile

func (s *Scenario) Reconcile()

Reconcile applies pending time-dependent transitions at the current fake instant.

func (*Scenario) Redo

func (s *Scenario) Redo() *service.OpResult

Redo reapplies the current actor's newest redo entry with a fresh request key.

func (s *Scenario) Relink(id domain.EntryID, task domain.TaskID)

Relink changes an entry's task using its current precondition; task 0 is standalone.

func (*Scenario) Reopen

func (s *Scenario) Reopen(id domain.TaskID, removeEntry bool)

Reopen reopens a task, optionally tombstoning its completion entry.

func (*Scenario) Revert

func (s *Scenario) Revert(op domain.OpID) *service.OpResult

Revert reverses an operation using the current actor and a fresh request key.

func (*Scenario) SeqFloor

func (s *Scenario) SeqFloor(table string, next int64)

SeqFloor raises a table's sequence so its next row ID is at least next.

func (*Scenario) SetDue

func (s *Scenario) SetDue(id domain.TaskID, moment string)

SetDue sets a task's due moment, or clears it when moment is empty.

func (*Scenario) SetFocus

func (s *Scenario) SetFocus(task domain.TaskID, interrupt bool)

SetFocus focuses task, or clears focus when task is zero.

func (*Scenario) Slips

func (s *Scenario) Slips(id domain.TaskID) (lifetime, sinceTriage int)

Slips returns lifetime and unacknowledged slip counts from the task view.

func (*Scenario) Stack

func (s *Scenario) Stack(actor string, which store.Stack) []domain.OpID

Stack returns the actor's stack from bottom to top.

func (*Scenario) StateDigest

func (s *Scenario) StateDigest() string

StateDigest returns deterministic live user state, excluding bookkeeping clocks, versions and sequences. Task order is represented by IDs rather than rank values.

func (*Scenario) Task

func (s *Scenario) Task(id domain.TaskID) domain.TaskView

Task returns the current task view through GetTask.

func (*Scenario) Unblock

func (s *Scenario) Unblock(b domain.BlockID)

Unblock ends a planned block using its current precondition.

func (*Scenario) Undelete

func (s *Scenario) Undelete(id domain.TaskID)

Undelete restores a task using its current precondition.

func (*Scenario) UndeleteEntry

func (s *Scenario) UndeleteEntry(id domain.EntryID)

UndeleteEntry restores an entry using its current precondition.

func (*Scenario) Undo

func (s *Scenario) Undo() *service.OpResult

Undo reverses the current actor's newest undo entry with a fresh request key.

func (*Scenario) Update

func (s *Scenario) Update(id domain.TaskID, mods ...func(*service.UpdateTaskIn))

Update edits a task using its current precondition and input modifiers.

type Server

type Server struct {
	Client          *client.Client
	Clock           *clock.Fake
	Svc             *service.Service
	DataDir, Socket string
	Paths           config.Paths
	WebURL          string
	Log             *SyncBuffer
	// contains filtered or unexported fields
}

Server is a real, restartable socket server with isolated data and fake time.

func StartServer

func StartServer(t testing.TB, opts ...ServerOpt) *Server

StartServer initializes real data and starts Run, waiting for its health endpoint. It changes environment variables and must not be used by parallel tests.

func (*Server) Start

func (s *Server) Start(t testing.TB)

Start runs the same initialized data again and captures its new service.

func (*Server) Stop

func (s *Server) Stop()

Stop cancels Run and waits without abandoning its drain. Repeated calls are safe.

func (*Server) TokenClient

func (s *Server) TokenClient(t testing.TB, name string, scopes domain.Scopes, perHour int, channel string) *client.Client

TokenClient mints a scoped token through the service and writes its private file.

type ServerOpt

type ServerOpt func(*serverOpts)

ServerOpt configures a StartServer fixture.

func InitOnly

func InitOnly() ServerOpt

InitOnly creates the instance without running the server.

func WithClock

func WithClock(local string) ServerOpt

WithClock selects the initial catalog wall time.

func WithConfig

func WithConfig(f func(*config.Server)) ServerOpt

WithConfig changes effective server configuration before initialization.

func WithMCPToken

func WithMCPToken() ServerOpt

WithMCPToken initializes the default MCP token as well as the owner token.

func WithWeb

func WithWeb() ServerOpt

WithWeb enables plain loopback HTTP on an ephemeral port when an adapter exists.

type SvcOpt

type SvcOpt func(*service.Options)

SvcOpt changes a service fixture's options before construction.

type SyncBuffer

type SyncBuffer struct {
	// contains filtered or unexported fields
}

SyncBuffer is a goroutine-safe log sink.

func (*SyncBuffer) String

func (b *SyncBuffer) String() string

func (*SyncBuffer) Write

func (b *SyncBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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