copilottest

package
v0.7.14-dev.8 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package copilottest is a fake Copilot CLI server mode for tests: the JSON-RPC 2.0 server of `copilot --headless --stdio`, framed by Content-Length, in the shapes Copilot CLI 1.0.95 answers with (recorded against the real binary with no account) and copilot-sdk go/v1.0.19 names. It asks for the session's token at session.create, as the real one does, then plays a scripted turn per session.send, and lists its Models to session.model.list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is the server's side of one session, for a Turn to play on.

func (*Conn) Ask

func (c *Conn) Ask(method string, params map[string]any) map[string]any

Ask sends a request the driver does not serve, and returns its answer.

func (*Conn) AskPermission

func (c *Conn) AskPermission(requestID string, request map[string]any) map[string]any

AskPermission sends a permission.requested event for request and waits for the driver's decision.

func (*Conn) AskToken

func (c *Conn) AskToken(reason string) map[string]any

AskToken asks the driver for a token, as Copilot CLI does (reason initial or refresh), and returns its answer: the result, or {"error": …}.

func (*Conn) Event

func (c *Conn) Event(typ string, data any)

Event sends one session event.

func (*Conn) ToolCall

func (c *Conn) ToolCall(callID, tool string) string

ToolCall plays a gateway tool call as Copilot CLI 1.0.95 makes it: its start, the approval asked, and its completion when approved. The permission request names the tool with its server's prefix ("gateway-fs_read"). It returns the decision's kind.

type Server

type Server struct {
	// CreateError fails session.create with this message, after the token
	// callback (GitHub refusing the token, an organization's policy).
	CreateError string
	// Abort plays a session.abort on c after its answer; nil only answers it.
	Abort func(c *Conn)
	// Turn plays one session.send on c; nil answers "Hello." and goes idle.
	Turn func(c *Conn, prompt string)
	// Models is session.model.list's list, each entry a model as Copilot
	// CLI lists it (copilot-sdk go/rpc/zrpc.go Model: id, name, billing,
	// policy); nil lists none.
	Models []map[string]any
	// Stored are the session ids session.resume finds, as a COPILOT_HOME
	// kept from an earlier process holds them; any other is "not found".
	Stored []string
	// ResumeError fails session.resume with this message whatever the id
	// (an organization's policy).
	ResumeError string
	// Compact is session.history.compact's result; nil answers the method
	// as unhandled, as a release that does not serve it would.
	Compact map[string]any

	// Resume is session.resume's params, as the driver sent them.
	Resume map[string]any
	// Create is session.create's params, as the driver sent them.
	Create map[string]any
	// Options is session.options.update's params.
	Options map[string]any
	// Tokens are the callback's answers (the token's result object, or
	// the error), in order.
	Tokens []map[string]any
	// Decisions are the permission decisions the driver applied, by
	// request id.
	Decisions map[string]map[string]any
	// Methods are the methods the driver called, in order.
	Methods []string
	// contains filtered or unexported fields
}

Server is one fake Copilot CLI process.

func (*Server) Resumed

func (s *Server) Resumed() map[string]any

Resumed is session.resume's params, as the driver sent them; nil when it sent none.

func (*Server) Serve

func (s *Server) Serve(r io.Reader, w io.Writer) error

Serve plays the server on r (the driver's writes) and w (what the driver reads) until r ends.

func (*Server) Snapshot

func (s *Server) Snapshot() (create, options map[string]any, tokens []map[string]any, decisions map[string]map[string]any, methods []string)

Snapshot is what the server saw, copied.

Jump to

Keyboard shortcuts

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