hosttest

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package hosttest provides shared test doubles for wiring an in-process host.Service in end-to-end tests: a stub backend manager standing in for the real opencode/claude process boundary, and a throwaway git repo factory. Everything else in such tests (host service, mux, store, daemonclient) is real.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGitRepo

func InitGitRepo(t *testing.T) string

InitGitRepo creates a git repo with an "origin" remote so host.workDirFor accepts a LocalPath at (or inside) it.

Types

type StubBackend

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

StubBackend is a programmable agent.SessionBackend that records what the host dispatched to it, so wire-level tests can assert the translation without mocking yet another struct.

func (*StubBackend) Abort

func (b *StubBackend) Abort(context.Context) error

func (*StubBackend) Aborted

func (b *StubBackend) Aborted() bool

Aborted reports whether Abort was dispatched.

func (*StubBackend) Events

func (b *StubBackend) Events() <-chan agent.Event

func (*StubBackend) Fork

func (b *StubBackend) Fork(_ context.Context, msgID string) (agent.ForkResult, error)

func (*StubBackend) ForkedMessageID

func (b *StubBackend) ForkedMessageID() string

ForkedMessageID returns the message id from the most recent Fork.

func (*StubBackend) LastSendOpts

func (b *StubBackend) LastSendOpts() agent.SendMessageOpts

LastSendOpts returns the options from the most recent Send or OpenAndSend dispatch.

func (*StubBackend) Messages

func (*StubBackend) Open

func (b *StubBackend) Open(context.Context) error

func (*StubBackend) OpenAndSend

func (b *StubBackend) OpenAndSend(_ context.Context, opts agent.SendMessageOpts) error

func (*StubBackend) OpenAndSendCalled

func (b *StubBackend) OpenAndSendCalled() bool

OpenAndSendCalled reports whether the host dispatched the initial prompt via OpenAndSend.

func (*StubBackend) PendingPermissions

func (b *StubBackend) PendingPermissions() []agent.PermissionData

PendingPermissions implements agent.PendingPermissionsReporter.

func (*StubBackend) PermissionReply

func (b *StubBackend) PermissionReply() (called bool, permissionID string, allow bool)

PermissionReply returns whether RespondPermission was called and with which permission id and verdict.

func (*StubBackend) PushEvent

func (b *StubBackend) PushEvent(evt agent.Event)

PushEvent injects an event into the backend's events channel as if the agent emitted it. Drops the event if Stop has been called so test goroutines that race the service's Cleanup don't panic on send-to-closed-channel (and don't trip the race detector).

func (*StubBackend) QuestionReply

func (b *StubBackend) QuestionReply() (called bool, requestID string, answers []agent.QuestionAnswer, reject bool)

QuestionReply returns whether RespondQuestion was called and with which request id, answers, and reject flag.

func (*StubBackend) RespondPermission

func (b *StubBackend) RespondPermission(_ context.Context, permissionID string, allow bool, _ string) error

func (*StubBackend) RevertedMessageID

func (b *StubBackend) RevertedMessageID() string

RevertedMessageID returns the message id from the most recent Revert.

func (*StubBackend) Send

func (*StubBackend) SessionID

func (b *StubBackend) SessionID() string

func (*StubBackend) SetExternalID

func (b *StubBackend) SetExternalID(id string)

SetExternalID overrides what SessionID() returns going forward. Tests use this to mimic opencode's late-binding behavior — the real session ID isn't known until Open completes.

func (*StubBackend) SetPendingPermissions

func (b *StubBackend) SetPendingPermissions(perms ...agent.PermissionData)

SetPendingPermissions primes the parked-permission snapshot, as if the agent had requested them and no decision landed yet.

func (*StubBackend) SetStatus

func (b *StubBackend) SetStatus(s agent.SessionStatus)

SetStatus overrides what Status() returns going forward.

func (*StubBackend) Status

func (b *StubBackend) Status() agent.SessionStatus

func (*StubBackend) Stop

func (b *StubBackend) Stop() error

type StubBackendManager

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

StubBackendManager spawns a StubBackend on every CreateBackend. Last() returns the most recently created backend so tests can inspect what it received (e.g. did handleCreateSession actually dispatch the initial prompt via OpenAndSend?).

func (*StubBackendManager) CreateBackend

func (*StubBackendManager) DiscoverSessions

func (m *StubBackendManager) DiscoverSessions(_ context.Context, _ string) ([]agent.SessionSnapshot, error)

DiscoverSessions implements agent.SessionDiscoverer with the seeded snapshots, regardless of seedDir.

func (*StubBackendManager) Init

func (m *StubBackendManager) Init(_ context.Context, _ func() ([]string, error)) error

func (*StubBackendManager) Last

func (m *StubBackendManager) Last() *StubBackend

Last returns the backend created by the most recent CreateBackend call, or nil if none has been created yet.

func (*StubBackendManager) SetDiscoverSnapshots

func (m *StubBackendManager) SetDiscoverSnapshots(snaps []agent.SessionSnapshot)

SetDiscoverSnapshots seeds what DiscoverSessions returns — the stand-in for a backend's on-disk session archive.

func (*StubBackendManager) Shutdown

func (m *StubBackendManager) Shutdown()

Jump to

Keyboard shortcuts

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