fakeopencode

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 28 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 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

View Source
const Version = "2.3.0"

Version is the OpenCode version the stand-in plays.

Variables

This section is empty.

Functions

func CheckTransfer

func CheckTransfer(b []byte) (dropped []string, err error)

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

func Export(file, sid string) ([]byte, error)

Export is `opencode session export <id>` on the database at file: the session as OpenCode 2.3.0 prints it.

func Import

func Import(file string, transfer []byte, dir string, now time.Time) (string, error)

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 Main

func Main(p Proc) int

Main runs the stand-in and returns its exit code.

func MessageID

func MessageID(t time.Time) string

func Open

func Open(file string) (*sql.DB, error)

Open opens (or makes) an OpenCode 2.3.0 database at file.

func SessionID

func SessionID(t time.Time) string

SessionID and MessageID mint ids as OpenCode does at t.

func VersionLine

func VersionLine(v string) string

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.

Jump to

Keyboard shortcuts

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