opencodetest

package
v0.292.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 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.

Sessions and messages are synthetic: tests put them in. Its asks are driven by REAL frames a real server sent (asks.go).

Index

Constants

View Source
const (
	// AbortPermissionSession's turn waited on AbortShellRequest (shell, "ls
	// -la .") when it was interrupted.
	AbortPermissionSession = "ses_e5ce88b59ffevd01THXy0Z6WjF"
	AbortShellRequest      = "per_1a31779020017W8wYt7c7UUj2m"
	// AbortQuestionSession's turn waited on AbortQuestionForm.
	AbortQuestionSession = "ses_e5ce833b5ffeGQb3gjbbeOOQWc"
	AbortQuestionForm    = "frm_1a317d1fb00121QVUp1IrY6yOD"
)

The ids in the abort frames.

View Source
const (
	// FixtureFormSession is the root session the two forms were raised in.
	FixtureFormSession = "ses_e5d55c179ffe6MEUqkUCZbHWA9"
	// FixtureQuestionsForm is a two-question form (a single-select with two
	// options, then a multiselect); FixtureProceedForm a one-question form
	// ("Proceed?": Yes, No).
	FixtureQuestionsForm = "frm_1a2aa3ec2001NmTTM10yDwGseq"
	FixtureProceedForm   = "frm_1a2aaa3d1001lEte0g1lyG1pFi"
	// FixturePermissionSession is the root session whose ruleset asks;
	// FixtureBashRequest its permission request (bash, "rm -rf build").
	FixturePermissionSession = "ses_e5d559cd5ffecrpBJHzHzu6wl9"
	FixtureBashRequest       = "per_1a2aa6345001HPvxtQP9FD941m"
	// FixtureChildSession is a child of FixturePermissionSession (a
	// subagent's); FixtureEditRequest its permission request (edit,
	// src/main.go).
	FixtureChildSession = "ses_e5d518e77ffen4uKUoa3YNdDXi"
	FixtureEditRequest  = "per_1a2ae71b1001G6gXQELgojLFKD"
)

The ids in the fixture frames.

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

TokenTTL is upstream's SESSION_TTL_SECONDS: 30 days.

Variables

This section is empty.

Functions

func AbortFrame added in v0.138.0

func AbortFrame(typ string, n int) string

AbortFrame is the n-th (0-based) abort frame of type typ; it panics when there is none.

func Captured added in v0.160.0

func Captured(name string) json.RawMessage

Captured is one body of testdata/prompt-v2.0.32.json, as the real server sent it (create, getsession, prompt1, prompt1-again, prompt2, prompt-404, prompt-409, commands, messages).

func FixtureFrame added in v0.138.0

func FixtureFrame(typ string, n int) string

FixtureFrame is the n-th (0-based) fixture frame of type typ; it panics when there is none (a test's own mistake).

func PromptFrame added in v0.160.0

func PromptFrame(typ string, n int) string

PromptFrame is the n-th (0-based) captured frame of type typ from testdata/prompt-v2.0.32.sse, verbatim; it panics when there is none.

func SpawnCaptured added in v0.172.0

func SpawnCaptured(name string) json.RawMessage

SpawnCaptured is one body of testdata/spawn-v2.0.32.json (create-model, create-unknown-model, model-openrouter, delete-404).

Types

type Frame added in v0.138.0

type Frame struct {
	Type string
	JSON string
}

Frame is one fixture frame: its type and its JSON, as the server sent it.

func FixtureFrames added in v0.138.0

func FixtureFrames() []Frame

FixtureFrames is every frame of the fixture, in the order it was sent.

type LogEntry added in v0.172.0

type LogEntry struct {
	Op, Session string
	At          time.Time
}

LogEntry is one create, prompt or delete, in the order the fake saw them.

type Model added in v0.172.0

type Model struct {
	ProviderID, ID string
	Disabled       bool
	Context        int64
	NoLimit        bool
}

Model is a model the fake lists (GET /api/model); Disabled lists it with "enabled": false. Context, when above 0, is its limit.context (the context readout's window); NoLimit lists it with no limit at all. Neither: the captured entry's own limit.

type Prompt added in v0.160.0

type Prompt struct {
	Session, ID, Text, Delivery string
}

Prompt is one prompt the fake admitted.

type Reply added in v0.138.0

type Reply struct {
	// Path is the reply route's path; Body its JSON body.
	Path, Body string
}

Reply is one reply the fake received.

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) Creates added in v0.172.0

func (s *Server) Creates() int

Creates is how many sessions POST /api/session created.

func (*Server) DelayFirstPromptAnswer added in v0.172.0

func (s *Server) DelayFirstPromptAnswer(d time.Duration)

DelayFirstPromptAnswer is DelayPromptAnswers for the NEXT prompt POST only: its prompt is admitted at once and its answer comes after d; later posts answer at once (a lost answer whose retry is answered).

func (*Server) DelayPromptAnswers added in v0.160.0

func (s *Server) DelayPromptAnswers(d time.Duration)

DelayPromptAnswers makes every prompt POST admit the prompt at once and answer only after d: a send that LANDED but whose answer is late, as a muster-mirror that timed out sees it. 0 answers at once.

func (*Server) DropStreams added in v0.138.0

func (s *Server) DropStreams()

DropStreams ends every open event stream, as a network drop would; the client reconnects on its own.

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) EmitFrame added in v0.138.0

func (s *Server) EmitFrame(frame string)

EmitFrame sends frame (an event's JSON, as the server sends it) verbatim to every open event stream, and keeps the pending lists in step: an asked or created frame adds its ask, a replied or cancelled one removes it.

func (*Server) FailCommands added in v0.160.0

func (s *Server) FailCommands(on bool)

FailCommands makes GET /api/command answer 500 (on).

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) HangPromptAnswers added in v0.172.0

func (s *Server) HangPromptAnswers(d time.Duration)

HangPromptAnswers is DelayPromptAnswers for EVERY prompt POST, a repeat of an id included (DelayPromptAnswers answers a repeat at once): a server that admits and never answers in time.

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) Log added in v0.172.0

func (s *Server) Log() []LogEntry

Log is every create, prompt (admitted or not) and delete, in order.

func (*Server) PromptPosts added in v0.160.0

func (s *Server) PromptPosts() int

PromptPosts is how many prompt POSTs arrived, repeats and refusals too.

func (*Server) Prompts added in v0.160.0

func (s *Server) Prompts() []Prompt

Prompts is every prompt admitted, in order (a repeat of an id is not one).

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"}}, whose location directory is /srv/fixture.

func (*Server) PutSessionIn added in v0.251.0

func (s *Server) PutSessionIn(id, title, parent, dir string)

PutSessionIn is PutSession with the session's location directory dir ("" records none).

func (*Server) RefusePrompts added in v0.172.0

func (s *Server) RefusePrompts(on bool)

RefusePrompts makes every prompt POST answer 400, admitting nothing (on).

func (*Server) RefuseRedeem

func (s *Server) RefuseRedeem(on bool)

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

func (*Server) RefuseReplies added in v0.138.0

func (s *Server) RefuseReplies(status int)

RefuseReplies makes every reply answer status (0: answer normally).

func (*Server) Replies added in v0.138.0

func (s *Server) Replies() []Reply

Replies is every reply received so far.

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) SessionModel added in v0.172.0

func (s *Server) SessionModel(sid string) map[string]string

SessionModel is the model session sid was created with ({providerID, id}), nil for none.

func (*Server) Sessions

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

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

func (*Server) SetCommands added in v0.160.0

func (s *Server) SetCommands(cmds []map[string]string)

SetCommands replaces the slash commands GET /api/command lists (for a request naming a directory).

func (*Server) SetModels added in v0.172.0

func (s *Server) SetModels(ms ...Model)

SetModels sets what GET /api/model lists, each entry shaped as the real server's OpenRouter entry (SpawnCaptured("model-openrouter")).

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) SetVersion added in v0.160.0

func (s *Server) SetVersion(v string)

SetVersion sets what GET /api/info names as the server's version.

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