fakes

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package fakes provides httptest servers standing in for the three network boundaries of decision-backed kb flows: the OpenRouter decisions endpoint (Jev), OpenRouter chat completions (generation) and Firecrawl scrape. Tests use them to exercise real vault flows without the network (spec §17).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dist

func Dist(probs map[string]float64) any

Dist builds a choice answer from an explicit distribution; missing options get 0 and the argmax becomes the choice.

func Level

func Level(level int) any

Level builds a score answer concentrated on one level.

func Noul

func Noul(p float64) any

Noul builds a noul answer.

func Pick

func Pick(option string, p float64) any

Pick builds a choice answer giving option p and spreading the rest evenly over the question's other options (the fake fills the distribution).

Types

type Call

type Call struct {
	Model     string
	State     json.RawMessage
	Questions map[string]Question
}

Call is one decoded decisions request.

func (Call) StateString

func (c Call) StateString() string

StateString returns the raw JSON state as text (for substring rules).

type DecideFunc

type DecideFunc func(call Call, q Question) any

DecideFunc answers one question of a call. Returning nil falls back to the server default (noul 0.05; choice picks the exit option `none`, `unknown`, `other` or `different` when present, else the first option; score 0).

type Firecrawl

type Firecrawl struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Firecrawl is a fake Firecrawl server. Point [firecrawl].api_url at URL.

func NewFirecrawl

func NewFirecrawl(scrape ScrapeFunc) *Firecrawl

NewFirecrawl starts a fake Firecrawl server.

func (*Firecrawl) Requests

func (f *Firecrawl) Requests() []ScrapeRequest

Requests returns a copy of every scrape request received.

type GenRequest

type GenRequest struct {
	Model      string
	SchemaName string
	System     string
	Prompt     string
}

GenRequest is one recorded generation request.

type GenerateFunc

type GenerateFunc func(schemaName, system, prompt string) any

GenerateFunc answers one generation request: schema name and the user prompt; it returns the JSON object to place in the message content.

type OpenRouter

type OpenRouter struct {
	*httptest.Server

	CostPerCall float64
	// contains filtered or unexported fields
}

OpenRouter is a fake OpenRouter serving /alpha/decisions and /v1/chat/completions. Point [openrouter].api_url at URL.

func NewOpenRouter

func NewOpenRouter(decide DecideFunc, generate GenerateFunc) *OpenRouter

NewOpenRouter starts a fake OpenRouter. Close it with t.Cleanup(srv.Close).

func (*OpenRouter) Calls

func (f *OpenRouter) Calls() []Call

Calls returns a copy of every decisions request received.

func (*OpenRouter) GenCalls

func (f *OpenRouter) GenCalls() []GenRequest

GenCalls returns a copy of every generation request received.

func (*OpenRouter) QuestionCount

func (f *OpenRouter) QuestionCount(prefix string) int

QuestionCount counts received questions whose id starts with prefix.

func (*OpenRouter) SetDecide

func (f *OpenRouter) SetDecide(decide DecideFunc)

SetDecide replaces the decide rule.

func (*OpenRouter) SetGenerate

func (f *OpenRouter) SetGenerate(generate GenerateFunc)

SetGenerate replaces the generate rule.

type Question

type Question struct {
	ID           string
	Type         string
	Instructions any
	Criteria     any
}

Question is one decoded question from a decisions request.

func (Question) Levels

func (q Question) Levels() int

Levels returns the number of score levels.

func (Question) Options

func (q Question) Options() []string

Options returns the option names of a choice question in sorted order.

type ScrapeFunc

type ScrapeFunc func(req ScrapeRequest) ScrapeResponse

ScrapeFunc answers one scrape request.

type ScrapeRequest

type ScrapeRequest struct {
	URL             string   `json:"url"`
	Formats         []string `json:"formats"`
	MaxAge          *int64   `json:"maxAge,omitempty"`
	WaitFor         *int64   `json:"waitFor,omitempty"`
	OnlyMainContent *bool    `json:"onlyMainContent,omitempty"`
}

ScrapeRequest is one decoded Firecrawl /v2/scrape request.

type ScrapeResponse

type ScrapeResponse struct {
	Markdown   string
	Title      string
	SourceURL  string
	StatusCode int
	// SiteName is returned as metadata.ogSiteName when set.
	SiteName string
}

ScrapeResponse is what the fake returns for one scrape.

Jump to

Keyboard shortcuts

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