Documentation
¶
Overview ¶
Package fakeopencode is the stand-in OpenCode 2.3.0 the tests (and the test bundle) run in place of the real one. It keeps sessions in a SQLite database with OpenCode's own schema, where OpenCode keeps it, and answers what hopsesh asks OpenCode: --version, debug paths, service status, service get|set|unset port, session list|export|import|delete, auth list and the HTTP API calls hopsesh makes through `opencode api`, the way OpenCode 2.3.0 does (agents/opencode/testdata/2.3.0 holds what the real one printed).
It has no model and no server. Its background service is make-believe: stopped unless $FAKE_OPENCODE_SERVICE is "running" (or a URL), or a command started it, which OpenCode does for any command but `run`, `service`, `debug paths` and --version when no --standalone is given; the stand-in then records the start in its state folder and in $FAKE_AGENT_LOG ("opencode: started the background service"), so a test can check that hopsesh never starts it. A port `service set port` set (in {config}/service.json, as OpenCode keeps it) is the started service's; setting or unsetting it stops the service registered in the state folder, which the stand-in logs ("opencode: stopped the background service").
An import decodes the transfer with OpenCode's schemas (decode.go): a wrong shape is a Bad Request, and members the schemas do not declare are dropped.
Every call is appended to $FAKE_AGENT_LOG as "opencode <args>". Other variables: $FAKE_OPENCODE_VERSION (the program's version, default 2.3.0), $FAKE_OPENCODE_SERVICE_VERSION (the running service's, default the program's), $FAKE_OPENCODE_ACTIVE (session ids with a turn running in the background service, comma-separated; their rows claim the turn, and a private server lists none), and $FAKE_OPENCODE_AUTH (what `auth list --format json` prints, default []), $FAKE_OPENCODE_TOOL (the shell command a `run -s <id>` turn's model calls: the turn plays hopsesh's plugin, plugin.go), and $FAKE_OPENCODE_FAIL ("session import", for example: that command fails, changing nothing, as a program that died would).
Index ¶
- Constants
- func CheckTransfer(b []byte) (dropped []string, err error)
- func Export(file, sid string) ([]byte, error)
- func Import(file string, transfer []byte, dir string, now time.Time) (string, error)
- func Main(p Proc) int
- func MessageID(t time.Time) string
- func Open(file string) (*sql.DB, error)
- func SessionID(t time.Time) string
- func VersionLine(v string) string
- type Proc
Constants ¶
const Version = "2.3.0"
Version is the OpenCode version the stand-in plays.
Variables ¶
This section is empty.
Functions ¶
func CheckTransfer ¶
CheckTransfer reports whether OpenCode 2.3.0 would import the transfer b (an error saying why not), and the members its import would drop.
func Export ¶
Export is `opencode session export <id>` on the database at file: the session as OpenCode 2.3.0 prints it.
func Import ¶
Import imports a transfer (OpenCode's export: {info, messages}) into the database at file, in dir, as `opencode session import <file> --directory <dir>` does with OpenCode 2.3.0, and returns the session's id. demoseed and the test kit use it.
func VersionLine ¶
VersionLine is what `opencode --version` prints for a version.
Types ¶
type Proc ¶
type Proc struct {
Args []string
Dir string // the working folder
Getenv func(string) (string, bool) // its environment (nil: the process's)
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Now func() time.Time // nil: the clock
// ReadFile and Stat reach the files a command names (an import's file, a folder):
// nil, this machine's. A test of a fake machine passes its own.
ReadFile func(string) ([]byte, error)
Stat func(string) (os.FileInfo, error)
}
Proc is one run of the stand-in.