Documentation
¶
Overview ¶
Package harness provides scripted fakes for every capkit port. Contract tests instantiate a kit with these fakes so a tool call runs hermetically: no network, no subprocess, no wall clock. Each fake records what it was asked to do, so a test can assert on the request as well as the result.
The fakes satisfy the capkit interfaces structurally; this package therefore imports only the root contract and never a kit.
Index ¶
- Variables
- func Deps() core.Deps
- func MinimalInput(schema json.RawMessage) json.RawMessage
- type Approval
- type Artifacts
- type Audit
- type Binaries
- type Clock
- type CloudSignRequest
- type CloudSigner
- type Completer
- type Engine
- type Evidence
- type Fingerprints
- type HTTP
- type IDs
- type Intel
- type Limiter
- type Logger
- type Ports
- type Process
- type Route
- type Scope
- type Sealer
- type Session
- type Sessions
- func (m *Sessions) Add(s *Session)
- func (m *Sessions) Close(id string) error
- func (m *Sessions) Get(id string) (core.Session, bool)
- func (m *Sessions) List() []core.SessionInfo
- func (m *Sessions) NextID(prefix string) string
- func (m *Sessions) Open(_ context.Context, spec core.SessionSpec) (core.SessionInfo, error)
- type Settings
- type Templates
Constants ¶
This section is empty.
Variables ¶
var DefaultTime = time.Date(2024, 5, 26, 12, 0, 0, 0, time.UTC)
DefaultTime is the clock origin every fixture uses, so signature and timestamp assertions are reproducible.
Functions ¶
func MinimalInput ¶
func MinimalInput(schema json.RawMessage) json.RawMessage
MinimalInput derives a smallest legal input for a tool from its JSON schema: every required property is filled with a type-appropriate sample value. It exists so a contract test can call every registered tool without hand-written fixtures per tool.
Types ¶
type Approval ¶
type Approval struct {
Err error
Requests []core.ApprovalRequest
}
Approval is an approving-by-default core.Approver.
type Artifacts ¶
type Artifacts struct {
// contains filtered or unexported fields
}
Artifacts is an in-memory core.ArtifactStore.
type Audit ¶
type Audit struct {
// contains filtered or unexported fields
}
Audit records every core.AuditEvent it receives.
func (*Audit) Events ¶
func (a *Audit) Events() []core.AuditEvent
Events returns a copy of the recorded events.
type Binaries ¶
type Binaries struct {
Path string
State core.BinaryStatus
Err error
}
Binaries is a scripted core.BinaryManager reporting every binary installed.
type Clock ¶
Clock is a manual clock. Every call to Now advances by Step, so a test that needs distinct timestamps gets them without sleeping.
type CloudSignRequest ¶
type CloudSignRequest struct {
Request core.Request
AccessKey string
SecretKey string
At time.Time
}
CloudSignRequest is one recorded signing request.
type CloudSigner ¶
type CloudSigner struct {
// Signature is the value embedded in the Authorization header.
Signature string
// AccessKey, when set, overrides the credential echoed into the header.
AccessKey string
Err error
// contains filtered or unexported fields
}
CloudSigner is a scripted cloud request signer. It records every request it was asked to sign and stamps a deterministic Authorization header, so a cloud tool can be exercised offline: the test asserts on what would have been sent without ever reaching a vendor API.
It satisfies cloudkit's Signer interface structurally, which keeps this package free of kit imports.
func (*CloudSigner) SignRequest ¶
func (s *CloudSigner) SignRequest(req core.Request, accessKey, secretKey string, now time.Time) (core.Request, error)
SignRequest stamps req with a fake Authorization header and records the call.
func (*CloudSigner) Signed ¶
func (s *CloudSigner) Signed() []CloudSignRequest
Signed returns a copy of every signing request.
type Completer ¶ added in v0.5.0
Completer is a scripted core.Completer. Reply is returned verbatim, so a test can feed a canned model answer — or a malformed one.
type Evidence ¶
Evidence stores every core.Evidence it is handed and returns "<Prefix><n>".
type Fingerprints ¶
type Fingerprints struct {
Result []core.Fingerprint
Err error
}
Fingerprints is a scripted core.FingerprintProvider.
func (*Fingerprints) Fingerprint ¶
func (f *Fingerprints) Fingerprint(context.Context, core.Target) ([]core.Fingerprint, error)
type HTTP ¶
type HTTP struct {
// Default answers any request no route matches.
Default Route
// Routes are checked in order before Default.
Routes []Route
// Queue answers the first len(Queue) calls in order, before Routes and
// Default apply, and is consumed as it is used. It exists for protocol-level
// sequences a route table cannot express — "the invocation does not exist
// yet on the first poll, succeeds on the second" — where the answer depends
// on how many calls came before rather than on the request itself.
Queue []Route
// Err fails every call regardless of routes.
Err error
// contains filtered or unexported fields
}
HTTP is a scripted core.HTTPDoer and core.Fetcher. It answers from a route table, falling back to the default response, and records every request in call order.
func NewHTTPJSON ¶
NewHTTPJSON answers every request with a JSON body.
type IDs ¶
type IDs struct {
// contains filtered or unexported fields
}
IDs is a deterministic core.IDGenerator: the n-th call for a prefix returns "<prefix>-<n>".
type Intel ¶ added in v0.5.0
Intel is a scripted core.IntelStore. It keeps what it was given, so a test can assert the kit handed the host exactly what it claims.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger keeps every line it is given.
type Ports ¶
type Ports struct {
HTTP *HTTP
Fetcher *HTTP
Scope *Scope
Approval *Approval
Limiter *Limiter
Audit *Audit
Evidence *Evidence
Settings *Settings
Sealer Sealer
Logger *Logger
Clock *Clock
IDs *IDs
Process *Process
Artifact *Artifacts
Binaries *Binaries
Fingerprints *Fingerprints
Templates *Templates
Engine *Engine
Sessions *Sessions
Intel *Intel
Completer *Completer
}
Ports is the assembled fake port set. Fields are exposed so a test can swap one fake for a stricter one.
type Process ¶
type Process struct {
Stdout []byte
Stderr []byte
ExitCode int
Err error
// Handler, when set, overrides the preset and answers per spec.
Handler func(core.ProcessSpec) (*core.ProcessResult, error)
// contains filtered or unexported fields
}
Process is a scripted core.ProcessRunner: every Run returns the preset stdout/stderr/exit code and records the spec.
func (*Process) Calls ¶
func (p *Process) Calls() []core.ProcessSpec
Calls returns a copy of every process spec the fake received.
func (*Process) Last ¶
func (p *Process) Last() (core.ProcessSpec, bool)
Last returns the most recent process spec.
func (*Process) Run ¶
func (p *Process) Run(_ context.Context, spec core.ProcessSpec) (*core.ProcessResult, error)
type Route ¶
Route is one scripted HTTP answer. When Match is non-empty only requests whose URL contains it take this route; otherwise it is the fallback.
type Scope ¶
Scope is a permissive-by-default core.ScopeChecker. Denied lists the hosts that must be refused; Err denies everything.
type Sealer ¶
type Sealer struct{ Key byte }
Sealer is a reversible XOR sealer for tests. It is not cryptographic and must never be used outside a test.
type Session ¶
type Session struct {
SessionInfo core.SessionInfo
Stdout string
Stderr string
ExitCode int
Err error
// contains filtered or unexported fields
}
Session is a scripted core.Session: Exec answers with the preset output.
func NewSession ¶
NewSession builds a session for host:22 running as root.
func (*Session) Info ¶
func (s *Session) Info() core.SessionInfo
type Sessions ¶
type Sessions struct {
OpenErr error
// contains filtered or unexported fields
}
Sessions is an in-memory core.SessionManager. NewSessions starts empty; NewSessionsWith pre-registers the given sessions.
func NewSessions ¶
func NewSessions() *Sessions
func NewSessionsWith ¶
NewSessionsWith builds a manager holding the given sessions.
func (*Sessions) List ¶
func (m *Sessions) List() []core.SessionInfo
func (*Sessions) Open ¶
func (m *Sessions) Open(_ context.Context, spec core.SessionSpec) (core.SessionInfo, error)
type Settings ¶
Settings is an in-memory core.Settings.
func NewSettings ¶
func NewSettings() *Settings