opencodetest

package
v0.120.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 13 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 opencodetest is a FAKE opencode v2 server for muster's tests and browser suite: the routes muster-mirror reads (shaped from upstream's packages/protocol/openapi.json at 6ec5682), HTTP Basic auth with user "opencode", and pair tokens signed the way upstream signs them (packages/server/src/auth.ts), so a token it issues has the real shape and lifetime. Every request is recorded (Requests), which is how tests prove muster-mirror never calls anything else.

Everything it serves is synthetic: tests put sessions and messages in.

Index

Constants

View Source
const TokenTTL = 30 * 24 * time.Hour

TokenTTL is upstream's SESSION_TTL_SECONDS: 30 days.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method string
	Path   string
	// Authorized: it carried a credential the server accepted.
	Authorized bool
}

Request is one request the server received.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server is the fake.

func New

func New(password string) *Server

New starts a fake opencode server whose password is password.

func (*Server) Emit

func (s *Server) Emit(sid, typ string, data map[string]any)

Emit sends an event of type typ for session sid (data gets sessionID) to every open event stream.

func (*Server) FailEvents

func (s *Server) FailEvents(on bool)

FailEvents makes the event stream answer 503 (on) — a server whose stream is down while its REST reads work — and closes none already open.

func (*Server) Issue

func (s *Server) Issue() string

Issue is a token the server accepts, issued at the server's now.

func (*Server) IssueAt

func (s *Server) IssueAt(exp time.Time) string

IssueAt is a token expiring at exp (which may be in the past).

func (*Server) PutMessage

func (s *Server) PutMessage(sid string, m map[string]any)

PutMessage adds message m (a synthetic Session.Message.Info) to session sid, or replaces the one with the same "id" in place — as a streaming assistant message is rewritten — and announces it on the event stream.

func (*Server) PutSession

func (s *Server) PutSession(id, title, parent string)

PutSession adds or replaces a session (by id): a synthetic Session.Info, {"id", "title", "parentID"?, "time": {"created", "updated"}}.

func (*Server) RefuseRedeem

func (s *Server) RefuseRedeem(on bool)

RefuseRedeem makes the code redemption fail (a 401), as an expired code does.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests is every request received so far.

func (*Server) Rotate

func (s *Server) Rotate(password string)

Rotate replaces the server password, which revokes every token it issued (upstream: "rotating the password revokes every session").

func (*Server) Sessions

func (s *Server) Sessions() []string

Sessions is the ids of the sessions put, in order.

func (*Server) SetNow

func (s *Server) SetNow(now func() time.Time)

SetNow sets the server's clock (token issue and expiry).

func (*Server) SetStatus

func (s *Server) SetStatus(sid, status string)

SetStatus sets session sid busy or idle, as session.status announces it.

func (*Server) Subscribers

func (s *Server) Subscribers() int

Subscribers is how many event streams are open.

Jump to

Keyboard shortcuts

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