# testkit/crashtest

> Package crashtest supplies deterministic failure injection and an independent event-log checker for durability tests.

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/testkit/crashtest (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
import "github.com/barevoidco/zelk/core/testkit/crashtest"
```

Package crashtest supplies deterministic failure injection and an independent event-log checker for durability tests. It never drives the production reducer.


## Variables

```go
var ErrDead = errors.New("simulated process death")
```

ErrDead marks a driver boundary lost to a simulated process death.


## Check

```go
func Check(evs []event.Event) error
```

Check validates E2–E4 independently of loop.Step. Incomplete logs are valid: open attempts keep their reservation and retryable effects may remain open.


## CheckBatches

```go
func CheckBatches(batches [][]event.Event) error
```

CheckBatches verifies O1/C4: observations cannot outlive their closing record in an atomic append group. Each supplied batch must represent one append.


## Intent

```go
func Intent(evs []event.Event, id string, attempt int) error
```

Intent verifies C3 at the instant of dispatch using the surviving log, so a test can prove action never precedes an acknowledged intent.


## Barrier

```go
type Barrier struct {
	Entered chan struct{}
	Release chan struct{}
	// contains filtered or unexported fields
}
```

Barrier announces entry and blocks dispatch until released or cancelled. The caller owns the goroutine using Wait and must join it during teardown.


### NewBarrier

```go
func NewBarrier() *Barrier
```

NewBarrier returns a dispatch barrier with owned channels.


### Barrier.Wait

```go
func (b *Barrier) Wait(ctx context.Context) error
```

Wait announces dispatch and waits for explicit release or cancellation.


## Boundary

```go
type Boundary string
```

Boundary selects how the chosen append fails.

```go
const (
	Before          Boundary = "before"
	After           Boundary = "after"
	AmbiguousLanded Boundary = "ambiguous_landed"
	AmbiguousAbsent Boundary = "ambiguous_absent"
	Conflict        Boundary = "conflict"
	ReadFailure     Boundary = "read_failure"
	// CancelRead and LeaseRead invoke OnRead while resolving a landed ambiguity.
	CancelRead Boundary = "cancelled_read"
	LeaseRead  Boundary = "lease_lost_read"
)
```

The injected append outcomes.


## Log

```go
type Log struct {
	// OnRead injects cancellation or authority loss during ambiguity resolution.
	OnRead func() error

	store.LogStore
	At       int
	Boundary Boundary
	Batches  [][]event.Event
	// contains filtered or unexported fields
}
```

Log fails exactly the At-th append. After a simulated death it never blocks and every operation fails. Base is the surviving durable backing store. Configure it before use; inspect Batches only after its driver has joined.


### Log.Adopt

```go
func (l *Log) Adopt(ctx context.Context, session string, t lease.Token) (uint64, error)
```

Adopt fails after death rather than consulting surviving state.


### Log.Append

```go
func (l *Log) Append(ctx context.Context, session string, seq uint64, t lease.Token, evs ...event.Event) error
```

Append injects the selected boundary, preserving atomic writes in the base.


### Log.Read

```go
func (l *Log) Read(ctx context.Context, session string, from uint64) iter.Seq2[event.Event, error]
```

Read fails after death or when an ambiguous read-back is faulted.
