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 FixtureFrame(typ string, n int) string
- type Frame
- type Reply
- type Request
- type Server
- func (s *Server) DropStreams()
- func (s *Server) Emit(sid, typ string, data map[string]any)
- func (s *Server) EmitFrame(frame string)
- func (s *Server) FailEvents(on bool)
- func (s *Server) Issue() string
- func (s *Server) IssueAt(exp time.Time) string
- func (s *Server) PutMessage(sid string, m map[string]any)
- func (s *Server) PutSession(id, title, parent string)
- 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) Sessions() []string
- func (s *Server) SetNow(now func() time.Time)
- func (s *Server) SetStatus(sid, status 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 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).
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 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) 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) 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) 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"}}.
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) Subscribers ¶
Subscribers is how many event streams are open.