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
- func AbortFrame(typ string, n int) string
- func Captured(name string) json.RawMessage
- func FixtureFrame(typ string, n int) string
- func PromptFrame(typ string, n int) string
- func SpawnCaptured(name string) json.RawMessage
- type Frame
- type LogEntry
- type Model
- type Prompt
- type Reply
- type Request
- type Server
- func (s *Server) Creates() int
- func (s *Server) DelayFirstPromptAnswer(d time.Duration)
- func (s *Server) DelayPromptAnswers(d time.Duration)
- func (s *Server) DropStreams()
- func (s *Server) Emit(sid, typ string, data map[string]any)
- func (s *Server) EmitFrame(frame string)
- func (s *Server) FailCommands(on bool)
- func (s *Server) FailEvents(on bool)
- func (s *Server) HangPromptAnswers(d time.Duration)
- func (s *Server) Issue() string
- func (s *Server) IssueAt(exp time.Time) string
- func (s *Server) Log() []LogEntry
- func (s *Server) PromptPosts() int
- func (s *Server) Prompts() []Prompt
- func (s *Server) PutMessage(sid string, m map[string]any)
- func (s *Server) PutSession(id, title, parent string)
- func (s *Server) PutSessionIn(id, title, parent, dir string)
- func (s *Server) RefusePrompts(on bool)
- func (s *Server) RefuseRedeem(on bool)
- func (s *Server) RefuseReplies(status int)
- func (s *Server) Replies() []Reply
- func (s *Server) Requests() []Request
- func (s *Server) Rotate(password string)
- func (s *Server) SessionModel(sid string) map[string]string
- func (s *Server) Sessions() []string
- func (s *Server) SetCommands(cmds []map[string]string)
- func (s *Server) SetModels(ms ...Model)
- func (s *Server) SetNow(now func() time.Time)
- func (s *Server) SetStatus(sid, status string)
- func (s *Server) SetVersion(v string)
- func (s *Server) Subscribers() int
Constants ¶
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.
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.
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
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
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
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
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
LogEntry is one create, prompt or delete, in the order the fake saw them.
type Model ¶ added in v0.172.0
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 ¶
Server is the fake.
func (*Server) DelayFirstPromptAnswer ¶ added in v0.172.0
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
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 ¶
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
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
FailCommands makes GET /api/command answer 500 (on).
func (*Server) FailEvents ¶
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
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) Log ¶ added in v0.172.0
Log is every create, prompt (admitted or not) and delete, in order.
func (*Server) PromptPosts ¶ added in v0.160.0
PromptPosts is how many prompt POSTs arrived, repeats and refusals too.
func (*Server) Prompts ¶ added in v0.160.0
Prompts is every prompt admitted, in order (a repeat of an id is not one).
func (*Server) PutMessage ¶
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 ¶
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
PutSessionIn is PutSession with the session's location directory dir ("" records none).
func (*Server) RefusePrompts ¶ added in v0.172.0
RefusePrompts makes every prompt POST answer 400, admitting nothing (on).
func (*Server) RefuseRedeem ¶
RefuseRedeem makes the code redemption fail (a 401), as an expired code does.
func (*Server) RefuseReplies ¶ added in v0.138.0
RefuseReplies makes every reply answer status (0: answer normally).
func (*Server) Rotate ¶
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
SessionModel is the model session sid was created with ({providerID, id}), nil for none.
func (*Server) SetCommands ¶ added in v0.160.0
SetCommands replaces the slash commands GET /api/command lists (for a request naming a directory).
func (*Server) SetModels ¶ added in v0.172.0
SetModels sets what GET /api/model lists, each entry shaped as the real server's OpenRouter entry (SpawnCaptured("model-openrouter")).
func (*Server) SetVersion ¶ added in v0.160.0
SetVersion sets what GET /api/info names as the server's version.
func (*Server) Subscribers ¶
Subscribers is how many event streams are open.