mock

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mock provides a deterministic offline provider for CI and testing. It returns scripted responses based on prompt substring or hash matching, without making any network calls.

Index

Constants

View Source
const (
	ProviderName = "mock"
	DefaultModel = "mock-model"
	// DefaultResponse is returned when no rule matches and no default is configured.
	DefaultResponse = "TASK_DONE"
)

Variables

This section is empty.

Functions

func HashPrompt

func HashPrompt(prompt string) string

HashPrompt is exported for use in tests and tooling that generate response files.

Types

type Provider

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

Provider is a deterministic mock provider that never makes network calls.

func New

func New(responsesFile string) *Provider

New creates a mock provider that reads scripted responses from responsesFile. When a call to Complete() provides opts.WorkDir, that directory is used to locate the responses file; otherwise it falls back to auto-detecting .cloop/mock_responses.yaml in the current directory. If responsesFile is empty, the default path .cloop/mock_responses.yaml is used.

func NewWithWorkDir

func NewWithWorkDir(responsesFile, workDir string) *Provider

NewWithWorkDir creates a mock provider with an explicit fallback workDir. Use this when callers (e.g. pm.Decompose) do not pass opts.WorkDir.

func (*Provider) Complete

func (p *Provider) Complete(_ context.Context, prompt string, opts provider.Options) (*provider.Result, error)

Complete returns a scripted response without any network calls. Rules in the responses file are checked in order; the first match wins. If no rule matches, the configured default (or DefaultResponse) is returned.

func (*Provider) DefaultModel

func (p *Provider) DefaultModel() string

func (*Provider) Name

func (p *Provider) Name() string

type ResponseRule

type ResponseRule struct {
	// Substring, if non-empty, matches when the prompt contains this string (case-sensitive).
	Substring string `yaml:"substring"`
	// Hash, if non-empty, matches when the SHA-256 hex digest of the prompt equals this value.
	// Use this for exact, deterministic matching independent of substring.
	Hash string `yaml:"hash"`
	// Response is the canned output returned when this rule matches.
	Response string `yaml:"response"`
}

ResponseRule maps a prompt pattern to a canned response.

type ResponsesConfig

type ResponsesConfig struct {
	// Rules are evaluated in order; the first match wins.
	Rules []ResponseRule `yaml:"rules"`
	// Default is returned when no rule matches. Defaults to "TASK_DONE".
	Default string `yaml:"default"`
}

ResponsesConfig is the structure of the mock_responses.yaml file.

Jump to

Keyboard shortcuts

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