Documentation
¶
Overview ¶
Package planetest is the money peer a billing test bills against: commerce's half of the internal plane, on a real socket, recording every debit that crosses.
THE DEBIT LEFT HTTP. It used to be a JSON POST to commerce's /v1/billing/usage, and metering.Usage.Ref — the ledger's idempotency key — is tagged `json:"-"` so that no request body anywhere can set it. json.Marshal therefore dropped it and every split-deploy debit reached the ledger anonymous, which broke the exactly-once contract the same client holds on its co-resident path. The debit now crosses the plane, where the act's name is a field of its own.
The fakes in the app packages still answer the balance READ over HTTP, because that is where it still happens. They receive the usage DEBIT here.
IT IS ONE PACKAGE RATHER THAN A COPY PER CALLER, for the reason iamtest states and this file then proved: nine packages hand-rolled a usage counter against the HTTP body, the debit moved to the plane, and all nine kept counting an endpoint nothing calls any more. Every one of them reported zero debits and every one of them was asserting its own fixture. One recorder means the next time the wire moves, it moves in one place and the tests that depend on it fail loudly instead of quietly passing.
OBSERVING HERE GRANTS NOTHING. The socket is a per-test temp dir the test itself owns; no deployment binds or reads it.
Index ¶
Constants ¶
const Workdir = "/mnt/data"
Workdir is where a fake sandbox keeps its files — the same directory the real `exec` class uses, because the code tool tells the model to persist artifacts there and a test against a different one would prove nothing about the contract.
Variables ¶
This section is empty.
Functions ¶
func Cents ¶
Cents reads a crossed amount as whole cents — the unit a fee constant is written in. Use Micros for a per-screen or per-token price, which is finer than a cent and would truncate to zero here.
func Micros ¶
Micros reads a crossed amount as micro-USD (1e6 = $1) — finer than a cent, because per-token charges are.
The amount crosses as an EXACT decimal, so this is a rescale and never a rounding: the old HTTP body had to choose between a cents field and a micros field, and the reader had to guess which one was set.
Types ¶
type Commerce ¶
type Commerce struct {
// contains filtered or unexported fields
}
Commerce records every debit that reaches the money plane.
func Serve ¶
Serve binds the peer's socket and returns the recorder. Every test that expects a debit calls it, and it must be called BEFORE the client makes one — an unbound socket is plane.ErrNoPeer, which reads in a failure message as "the meter never fired" rather than "nobody was listening".
func ServeWith ¶
ServeWith is Serve plus an observer, for a peer that keeps a running balance rather than only a count. The observer runs INSIDE the handler, so the debit has landed by the time the op answers — which is what lets a gate that reads afterwards see it.
func (*Commerce) Body ¶
Body is the last debit rendered in the shape commerce's ledger row takes: the same field names the HTTP body used, so an assertion written against the old wire keeps asserting the same FACTS about the same debit.
It is a projection for reading, never a thing the code under test produces — the crossing is typed. Amount is in CENTS, which is what the callers compare against their fee constants; anything finer is in Micros.
func (*Commerce) Count ¶
Count is how many debits have landed. Debits are fire-and-forget, so callers poll it — see Wait.
type Pod ¶
Pod is one fake sandbox: its files, and the two clocks the shell commands a caller actually sends depend on — a file's mtime, and the marker a run stamps for itself.
type Program ¶
type Program func(id string, argv []string) (stdout, stderr string, exit int, wrote map[string][]byte)
Program is what a run DOES: what it printed, whether it failed, and the files it left behind (keyed by path relative to Workdir). Nil means a run that printed nothing and wrote nothing.
type Sandboxes ¶
type Sandboxes struct {
// Run is the program every leased sandbox executes. Assign it before the call
// under test; it is read under the peer's own lock.
Run Program
// OnLease observes the ORG each lease was taken for — the caller's plane
// identity, which is the only thing a cross-tenant test can assert on. A
// sandbox id says nothing about whose it is; this says exactly that.
OnLease func(org string)
// contains filtered or unexported fields
}
Sandboxes is the peer. Set Run to give the fake pods a program; leave it nil and every run is a silent success.
func ServeSandboxes ¶
ServeSandboxes binds the sandboxes peer's socket and returns it. It shares the test's ONE runtime directory (see runtimeDir), so a test may serve this and the commerce peer together.
func (*Sandboxes) Args ¶
Args is the argument vector the most recent PROGRAM was given — what followed `sh -c <line> sh`. It is how a test checks that a caller's args reached the program and not, say, the compiler that built it.
func (*Sandboxes) Lines ¶
Lines is every shell line the peer was asked to run, in order, for a test that asserts on what was SENT rather than only on what came back.
func (*Sandboxes) Live ¶
Live is how many leases the peer still holds. A code-interpreter session legitimately outlives its run; a function invoke must leave none.