Help us shape the future of Go! Take the 2026 Go Developer Survey

fakesock

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package fakesock is the fake inbox socket of plan 9.5: a unix-domain server standing in for a Claude Code session's `CLAUDE_CODE_MESSAGING_SOCKET`, so the socket poster (6.7, U-17, U-19, U-20) and later the watcher can be tested against a real socket with no Claude process anywhere near.

It records, per accepted connection, every physical line it read: the auth lines separately from the user frames, plus the lines that were neither (A.2 says the real harness silently drops those, so a test can prove nothing malformed was ever sent). It can Stall — accept and never read, so a write deadline fires — CloseAtOnce, or Abandon its listener while leaving the socket file in place so a dial gets ECONNREFUSED.

The socket lives under os.MkdirTemp("/tmp", "bsk"), never t.TempDir(): macOS caps sun_path at 103 bytes and a t.TempDir path is already about 91 of them (7.3). The socket file is chmodded to 0600 like the real one. Everything is torn down in a Cleanup: held and live connections are closed first, otherwise the reader wait would hang the package.

Index

Constants

View Source
const OverlongLine = "<line dropped: over 1 MiB>"

OverlongLine is recorded in Invalid for a line the reader dropped as longer than protocol.MaxLineBytes.

View Source
const SocketName = "inbox.sock"

SocketName is the file name inside the server's private directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// Auth holds the token of every valid auth line, in order.
	Auth []string
	// Frames holds the content of every valid user line, in order.
	Frames []string
	// Invalid holds every line that was neither, verbatim (an over-long
	// line is recorded as OverlongLine).
	Invalid []string
	// Lines is how many physical lines were read, valid or not.
	Lines int
	// Held reports a connection accepted while stalled: never read.
	Held bool
	// Done reports that the peer closed and the reader finished.
	Done bool
}

A Connection is the snapshot of one accepted connection.

type Server

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

A Server is one fake inbox socket.

func New

func New(tb testing.TB) *Server

New starts a server and registers its teardown with tb.Cleanup.

func (*Server) Abandon

func (s *Server) Abandon()

Abandon closes the listener but leaves the socket file in place, so a dial finds a socket nobody listens on: ECONNREFUSED.

func (*Server) Accepted

func (s *Server) Accepted() int

Accepted is how many connections the listener has accepted so far, held and closed-at-once ones included. A refused pre-check shows as zero (U-19).

func (*Server) Close

func (s *Server) Close()

Close stops the listener, closes every held and live connection, waits for the readers, and removes the private directory. Safe to call more than once; New registers it as a Cleanup.

func (*Server) CloseAtOnce

func (s *Server) CloseAtOnce(on bool)

CloseAtOnce makes every connection accepted from now on be closed immediately, before anything is read.

func (*Server) Connections

func (s *Server) Connections() []Connection

Connections snapshots every accepted connection in acceptance order.

func (*Server) Dir

func (s *Server) Dir() string

Dir is the private directory holding the socket.

func (*Server) Frames

func (s *Server) Frames() []string

Frames is every user-line content recorded so far, across connections, in arrival order.

func (*Server) Path

func (s *Server) Path() string

Path is the socket path.

func (*Server) Stall

func (s *Server) Stall(on bool)

Stall makes every connection accepted from now on be held and never read. Connections already being read are unaffected; held connections stay held until Close.

func (*Server) WaitAccepted

func (s *Server) WaitAccepted(n int, timeout time.Duration)

WaitAccepted polls until at least n connections have been accepted.

func (*Server) WaitDone

func (s *Server) WaitDone(n int, timeout time.Duration)

WaitDone polls until at least n connections have been read to EOF.

func (*Server) WaitFrames

func (s *Server) WaitFrames(n int, timeout time.Duration) []string

WaitFrames polls until at least n frames have been recorded and returns them. timeout is a hang catcher, never a performance bound: on expiry it fails tb and returns what it has.

Jump to

Keyboard shortcuts

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