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 ¶
- func InitGitRepo(t *testing.T) string
- type StubBackend
- func (b *StubBackend) Abort(context.Context) error
- func (b *StubBackend) Aborted() bool
- func (b *StubBackend) Events() <-chan agent.Event
- func (b *StubBackend) Fork(_ context.Context, msgID string) (agent.ForkResult, error)
- func (b *StubBackend) ForkedMessageID() string
- func (b *StubBackend) LastSendOpts() agent.SendMessageOpts
- func (*StubBackend) Messages(context.Context) ([]agent.MessageData, error)
- func (b *StubBackend) Open(context.Context) error
- func (b *StubBackend) OpenAndSend(_ context.Context, opts agent.SendMessageOpts) error
- func (b *StubBackend) OpenAndSendCalled() bool
- func (b *StubBackend) PendingPermissions() []agent.PermissionData
- func (b *StubBackend) PermissionReply() (called bool, permissionID string, allow bool)
- func (b *StubBackend) PushEvent(evt agent.Event)
- func (b *StubBackend) QuestionReply() (called bool, requestID string, answers []agent.QuestionAnswer, reject bool)
- func (b *StubBackend) RespondPermission(_ context.Context, permissionID string, allow bool, _ string) error
- func (b *StubBackend) RevertedMessageID() string
- func (b *StubBackend) Send(_ context.Context, opts agent.SendMessageOpts) error
- func (b *StubBackend) SessionID() string
- func (b *StubBackend) SetExternalID(id string)
- func (b *StubBackend) SetPendingPermissions(perms ...agent.PermissionData)
- func (b *StubBackend) SetStatus(s agent.SessionStatus)
- func (b *StubBackend) Status() agent.SessionStatus
- func (b *StubBackend) Stop() error
- type StubBackendManager
- func (m *StubBackendManager) CreateBackend(_ context.Context, _ agent.BackendInvocation) (agent.SessionBackend, error)
- func (m *StubBackendManager) DiscoverSessions(_ context.Context, _ string) ([]agent.SessionSnapshot, error)
- func (m *StubBackendManager) Init(_ context.Context, _ func() ([]string, error)) error
- func (m *StubBackendManager) Last() *StubBackend
- func (m *StubBackendManager) SetDiscoverSnapshots(snaps []agent.SessionSnapshot)
- func (m *StubBackendManager) Shutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitGitRepo ¶
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) 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) Messages(context.Context) ([]agent.MessageData, 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 (*StubBackend) RevertedMessageID ¶
func (b *StubBackend) RevertedMessageID() string
RevertedMessageID returns the message id from the most recent Revert.
func (*StubBackend) Send ¶
func (b *StubBackend) Send(_ context.Context, opts agent.SendMessageOpts) error
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 (m *StubBackendManager) CreateBackend(_ context.Context, _ agent.BackendInvocation) (agent.SessionBackend, error)
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) 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()