* feat(http): bd blocked over bd serve (blocked.list) through issueops.BlockedLister
`bd blocked` refused against an HTTP workspace: it called the legacy
GetBlockedIssues, which the HTTP backend stubs as unsupported. It now runs
one role on every route, and bd serve publishes that role.
- Role: issueops.BlockedLister.ListBlocked(BlockedRequest{ParentID, Labels,
LabelsAny, ExcludeLabels}) -> BlockedResult{Items}. One body,
internal/storage/issueops.ExecuteListBlockedInTx over the unchanged
GetBlockedIssuesInTx; labels normalized in the role (BlockedFilter);
Items never nil and in a total order (priority, created_at desc, id).
- Legs: DoltStore (read tx), EmbeddedDoltStore (read conn), uow (read unit
of work through the use case's GetBlockedIssues, so the
external-dependency uow decorator applies). Census: storage.DoltStorage
gains BlockedLister(); HookFiringStore passes it through (a read),
telemetry wraps it, uow.notifyingProvider, externaldeps.uowProvider and
httpapi.timedProvider build it.
- externaldeps.Store.BlockedLister is built over its own GetBlockedIssues,
so local `bd blocked` output is unchanged. Over a remote store it takes
the server's listing when the server advertises
policy.external_dependencies, else decorates the server's listing here
through EdgeReader and BatchGetter (decorateBlocked, factored out of
GetBlockedIssues).
- Wire: GET /v0/beads/blocked (listBlockedIssues; parent, label,
label_any, exclude_label) answering BlockedPage {items, has_more} with
the new x-go-type-pinned BlockedIssue schema, behind the new
blocked.list token. apigen and the wire-shape golden regenerated; the
golden diff is additive only, so wire_revision stays 2.
Config.BlockedLister is a required role, wired in bd serve.
- Client: httpclient.Store.BlockedLister dials through Store.dispatch, so
an older server is refused BEFORE the dial with *wire.CapabilityError
naming blocked.list. The legacy Store.GetBlockedIssues rides the role
(page and row cap applied to its answer) and leaves the unsupported
shell. Divergence ledger row F-blocked retired.
- CLI: `bd blocked` takes BlockedLister() from the store on the direct
routes and from the provider's BlockedListerSource on the proxied route;
runBlockedProxiedServer is deleted. --json output is the same rows in
the same order, [] when empty.
Tests: backend/conformance RunBlockedLister (10 cases: direct blocker,
child attributed to its blocked parent, closed blocker, wisp plane, pinned
status, parent filter, label filters with normalization, order, empty
slice, request not mutated) on dolt, embedded, uow and the served HTTP
client; httpapi handler tests (mapping, unknown/repeated params,
projection, capability); httpclient stub tests (pre-dial refusal naming
the token, encoding, projection, legacy door paging); skew and vocabulary
counts; TestE2E_BlockedOverHTTP (served `bd blocked --json` equals the
local command's after mapping ids and timestamps, member order included,
external blocker named, older-server refusal with no dial); corpus
gc-blocked re-marked and gc-blocked-parent added, both pending until the
reference server advertises blocked.list.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(blocked): pin server-side external decoration, refuse has_more, serve the legacy door over http
Review fixes for the blocked.list slice.
- Server-side external decoration is now pinned on the compositions bd
serve answers from. TestWrapUOWProviderBlockedListerNamesExternalBlockers
lists through the wrapped unit-of-work provider's own BlockedLister
accessor (the bd serve provider path) and requires an external-only row
and a mixed row to carry their external: refs; building that lister over
the inner provider fails it. TestServedBlockedListerCarriesExternalRefs-
WhenTheServerEnforces serves the store-shaped composition
(externaldeps.Store.BlockedLister, policy advertised) and requires the
operation's own answer, through the undecorated client role, to carry the
refs, and the client's decorated chain to return it unchanged; serving
the inner store's lister fails it.
- The client refuses an answer reporting has_more with the new typed
httpclient.TruncatedListingError instead of returning a short listing:
the operation has no cursor, and a caller reads a missing row as
unblocked. The legacy door inherits it.
- externaldeps.Store.GetBlockedIssues over an http store reads the extra
sources through the served roles (EdgeReader, BatchGetter) instead of the
raw GetIssuesByIDs / GetDependencyRecordsForIssues the http backend
refuses, and the decoration skips the source read when there is nothing
to load. The legacy door on the CLI chain (bd mol stale, the wisp
commands) now answers over http in both policy modes;
TestServedLegacyGetBlockedIssuesThroughTheDecorator pins it, paging
included. bd ready --explain still refuses on its other raw reads; the
CHANGELOG says so.
- Docs: the spec and the retired F-blocked ledger row state that the
listing is unpaged, bounded by the client's 32 MiB response limit
(refused, never read in part), and that has_more is refused.
- Contract: new cases for waits-for and conditional-blocks blockers, no
type exclusions (gate, epic), and a stale flag with no nameable blocker
(on the legs that can write the column: dolt, embedded; skipped
elsewhere with the reason). Order seeds explicit created_at values with
five rows tied on priority and created_at, two of them wisps, so only the
id tiebreak orders them; dropping the tiebreak now fails every run.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* feat(blocked): bd blocked --flags, the blocked flag per id from stdin
`bd blocked --flags [--json]` reads ids from stdin, one per line (blank
lines and repeats ignored), and prints the blocked flag bd holds for each:
with --json, [{"id","is_blocked"}] in the order the ids were first given,
omitting an id that names no row on either plane, [] for no input. It is
the readiness column a consumer otherwise had to read with `bd sql`, so no
such consumer needs a local-only command.
It is the FLAG, not the listing: `bd blocked` narrows the stored flag to
rows it can name a blocker for, and --flags does not, so a row whose flag
is set with no nameable blocker reads true here and is absent from the
listing. Where the external-dependency policy applies, an unsatisfied
external: blocker sets the flag, as it keeps the row out of `bd ready`.
One library entry on every route: issueops.BlockedFlags over the route's
BlockingAnnotator (the store's accessor on dolt, embedded and HTTP, the
provider's on the proxied route). Over HTTP that is listBlockingAnnotations
with is_blocked behind dependencies.blocking.isBlocked; a server without
that token is refused before the dial, naming it. No wire change. The
listing's filter flags are refused with --flags rather than ignored.
Tests: TestE2E_BlockedFlagsOverHTTP (served JSON equals the local command's
after mapping ids to titles, unknown id omitted, repeat collapsed, [] on
empty stdin, filters refused; a stale-flagged row with no blocker reads
true and is absent from `bd blocked --json`, which fails if --flags is
derived from the listing; an older server's handshake refused naming the
token with no dial); TestProxiedServerBlocked/flags_reads_ids_from_stdin on
the proxied route; corpus gc-blocked-flags, pending until the reference
server advertises the token. CHANGELOG entry.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* feat(blocked): bd blocked --flags --raw, the stored is_blocked column
`bd blocked --flags --raw [--json]` answers the stored is_blocked column
for each id read from stdin, exactly what reading is_blocked from the issues
and wisps tables returns, without the external-dependency policy: a row
blocked only by an unsatisfied external: ref reads false (the policy-aware
--flags reads true), and a stale flag reads true either way. Same output
shape as --flags. This lets a consumer move off a `bd sql` read of the
column with no change in what it reads. The default --flags is unchanged.
The role is taken from beneath every decorator: storage.UnwrapStore on the
direct routes, uow.UnwrapProvider on the proxied route. Over HTTP the
innermost store is the http client, whose annotation read is the server's
answer: against a server that does not advertise
policy.external_dependencies that answer is the column, and --raw is
served. A server that advertises it decorates the flag it answers, the v0
wire has no member asking it for the column, and the decorated flag cannot
be turned back into the column client-side, so --raw against such a server
is refused before the annotation read, naming the token, rather than
answered with the decorated flag. --raw without --flags is refused.
Tests: TestE2E_BlockedFlagsOverHTTP/raw_is_the_stored_column (served --raw
equals local --raw; the externally-blocked-only row reads true with --flags
and false with --raw on both; locally blocked rows agree; a stale-flagged
row reads true in both modes; --raw without --flags exits 1; a server
advertising the policy refuses --raw with no annotation request);
TestProxiedServerBlocked/flags_raw_is_the_stored_column; corpus
gc-blocked-flags-raw (pending until the reference server advertises
dependencies.blocking.isBlocked). Routing --raw through the decorated
annotator fails the e2e. CHANGELOG entry.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(changelog): bd blocked --flags --raw is for the local and proxied routes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(blocked): give the e2e gate-kid its own priority; document --flags answers closed ids
TestE2E_BlockedOverHTTP seeded gate-parent and gate-kid at one priority, so
when both landed in the same second their order fell to the generated ids,
which differ between the local and the served workspace: the comparison
failed intermittently. gate-kid now has its own priority. Ten runs on the
embedded lane pass.
bd blocked --flags answers a closed id too, with its stored flag; a SQL read
of the column filtered on status <> 'closed' leaves it out. Said in the
command's doc and the CHANGELOG.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(blocked): apply label filters to external-only blocked rows
The external-dependency policy appends a row blocked only by an
unsatisfied external: ref after the label query has run, so --label,
--label-any and --exclude-label never judged it: bd blocked and
GET /v0/beads/blocked listed it whatever its labels, on every route.
Both decorators now filter those rows by the request's labels. The uow
decorator reads them through GetMany, chunked at MaxGetManyIDs, so their
labels are hydrated; GetIssuesByIDs left them empty, which also printed
them unlabelled on the proxied route.
Review fixes (adopt-pr apply-fixes, iteration 1):
- major #1: label filters on external-only rows in the store and uow
decorators, with absence-asserting arms in the unit, served httpclient
(server- and client-enforced policy), e2e and proxied tiers; the spec
and the role doc say such rows are narrowed like every other row.
- minor #2: the policy.external_dependencies token prose names the
blocked listing (spec, routes.go, regenerated types.gen.go).
- minor #6: SERVE_RUNBOOK and the allowUnlimited comment record the
blocked listing's unbounded whole-set answer and why.
- minor #10: BlockedLister telemetry-outermost and typed-unsupported pins
beside the ReadyCounter pair, plus the externaldeps wrap pin.
- nit #9: F-blocked names --flags --raw's refusal against a server that
applies the policy (ledger.go and the regenerated ledger doc).
- nit #11: the remote BlockedLister no longer builds a local lister it
then discards.
Review fixes (adopt-pr apply-fixes, iteration 2; the review approved at
940 with one minor and two nits, none gating):
- minor (the --flags refusal list was unpinned): the new
TestBlockedFlagsRefusesEveryListingFilter pins blockedFlagFilterFlags
to the flags blockedCmd registers, in both directions. Every
registered flag except --flags and --raw must be refused, and every
entry must name a registered flag. The test walks Flags() rather than
LocalFlags(), so it does not merge the root's persistent flags into
blockedCmd, and it skips inherited root flags and cobra's --help.
Mutants:
- four fail it: a new filter flag left off the list, a dropped
entry, a misspelled entry, and --raw added to the list;
- a simulated earlier in-process run (merged root flags plus --help)
stays green, and fails once either skip is removed.
- nit (the remote branch's span): the remote BlockedLister comment now
says why that lister is not wrapped again. The inner lister already
carries telemetry's span, so wrapping would nest a second span of the
same name. The comment also says what runs outside that span.
- nit (duplicated order comparator): left as is. finishBlockedIssues
predates this PR, so merging the two sorts would refactor existing
code with no review pass left after this one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
398 lines
14 KiB
Go
398 lines
14 KiB
Go
//go:build cgo
|
|
|
|
// Contributed by gascity from bd-enterprise (internal/enterprise/httpstore/served_test.go@49d1df2f6)
|
|
// to OSS beads under the MIT license.
|
|
|
|
package httpclient
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/httpapi"
|
|
"github.com/steveyegge/beads/internal/httpapi/apigen"
|
|
"github.com/steveyegge/beads/internal/httpclient/wire"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/storage/embeddeddolt"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// The served-surface composition: the http client, a real in-process `bd serve`,
|
|
// and the embedded-Dolt reference store the server serves.
|
|
//
|
|
// This is the shape composition_test.go specifies, stood up. Behavior parity for
|
|
// this backend cannot be proved by bare RunAll — its Factory contract wants a
|
|
// write-ready store and its cases seed through raw CreateIssue/SetConfig, both of
|
|
// which this backend refuses — so the per-role fixture contracts are run instead,
|
|
// with their SEED HANDLES BOUND TO THE REFERENCE STORE and only the subject role
|
|
// bound to the client. A fixture that seeded through the client would prove the
|
|
// client agrees with itself.
|
|
//
|
|
// ONE STORE AND ONE SERVER FOR THE WHOLE PACKAGE, which is the unit-of-work
|
|
// wiring's arrangement rather than the embedded one's. Every contract case here
|
|
// scopes its own query — by label, by exact id, or by a query expression naming
|
|
// its own label — precisely so several of them can share one database, and a
|
|
// store per case would cost half a second each for nothing. It also makes the
|
|
// composition harder rather than easier: a filter this client dropped would come
|
|
// back carrying another case's rows.
|
|
|
|
// servedIssuePrefix is the id namespace every fixture below sub-namespaces. It
|
|
// is not the workspace's `issue_prefix`, which the reference store sets for
|
|
// itself; explicit-id creates do not check one against the other.
|
|
const servedIssuePrefix = "http"
|
|
|
|
type servedComposition struct {
|
|
// reference is the store the server serves. It is the seed handle and the
|
|
// dual-run oracle, and it is NEVER the subject of a contract.
|
|
reference *embeddeddolt.EmbeddedDoltStore
|
|
dataDir string
|
|
database string
|
|
baseURL string
|
|
// client is the http store under test.
|
|
client *Store
|
|
}
|
|
|
|
var (
|
|
compositionOnce sync.Once
|
|
compositionEnv *servedComposition
|
|
compositionErr error
|
|
compositionStop func()
|
|
)
|
|
|
|
// TestMain owns the composition's lifetime: one embedded database and one bound
|
|
// listener for the package, torn down after the last case.
|
|
func TestMain(m *testing.M) {
|
|
code := m.Run()
|
|
if compositionStop != nil {
|
|
compositionStop()
|
|
}
|
|
if servedTemplateDir != "" {
|
|
_ = os.RemoveAll(servedTemplateDir)
|
|
}
|
|
os.Exit(code)
|
|
}
|
|
|
|
func composition(t *testing.T) *servedComposition {
|
|
t.Helper()
|
|
compositionOnce.Do(func() { compositionEnv, compositionStop, compositionErr = startServedComposition() })
|
|
if compositionErr != nil {
|
|
t.Fatalf("stand up the served composition: %v", compositionErr)
|
|
}
|
|
return compositionEnv
|
|
}
|
|
|
|
func startServedComposition() (*servedComposition, func(), error) {
|
|
ctx := context.Background()
|
|
root, err := os.MkdirTemp("", "httpstore-served-")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
cleanups := []func(){func() { _ = os.RemoveAll(root) }}
|
|
stop := func() {
|
|
for i := len(cleanups) - 1; i >= 0; i-- {
|
|
cleanups[i]()
|
|
}
|
|
}
|
|
fail := func(err error) (*servedComposition, func(), error) {
|
|
stop()
|
|
return nil, nil, err
|
|
}
|
|
|
|
const database = "httpstore"
|
|
beadsDir := filepath.Join(root, ".beads")
|
|
reference, err := embeddeddolt.Open(ctx, beadsDir, database, "main")
|
|
if err != nil {
|
|
return fail(fmt.Errorf("open the embedded reference store: %w", err))
|
|
}
|
|
cleanups = append(cleanups, func() { _ = reference.Close() })
|
|
if err := reference.SetConfig(ctx, "issue_prefix", servedIssuePrefix); err != nil {
|
|
return fail(fmt.Errorf("identify the reference workspace: %w", err))
|
|
}
|
|
if err := reference.Commit(ctx, "bd init"); err != nil {
|
|
return fail(fmt.Errorf("commit the reference workspace: %w", err))
|
|
}
|
|
|
|
cfg, err := serveRoles(reference)
|
|
if err != nil {
|
|
return fail(err)
|
|
}
|
|
cfg.Addr = "127.0.0.1:0"
|
|
cfg.Stdout = io.Discard
|
|
cfg.Stderr = io.Discard
|
|
srv, err := httpapi.Listen(cfg)
|
|
if err != nil {
|
|
return fail(fmt.Errorf("bind the in-process bd serve: %w", err))
|
|
}
|
|
serveCtx, cancelServe := context.WithCancel(context.Background())
|
|
done := make(chan struct{})
|
|
go func() { defer close(done); _ = srv.Serve(serveCtx) }()
|
|
cleanups = append(cleanups, func() { cancelServe(); <-done })
|
|
|
|
base, err := url.Parse("http://" + srv.Addr())
|
|
if err != nil {
|
|
return fail(err)
|
|
}
|
|
transport, err := wire.New(base, nil, wire.Options{})
|
|
if err != nil {
|
|
return fail(fmt.Errorf("build the wire client: %w", err))
|
|
}
|
|
|
|
return &servedComposition{
|
|
reference: reference,
|
|
dataDir: filepath.Join(beadsDir, "embeddeddolt"),
|
|
database: database,
|
|
baseURL: base.String(),
|
|
client: New(Target{BaseURL: base}, servedWire{transport}, nil),
|
|
}, stop, nil
|
|
}
|
|
|
|
// serveRoles takes the whole role set off the reference store's own accessors.
|
|
//
|
|
// httpapi.Listen requires ALL of them together — a server missing one would
|
|
// bind, answer every other route, and fail that one with a nil dereference on a
|
|
// live server — and it refuses a hook-firing role. These come off a raw store
|
|
// with no decorators, so there is nothing to unwrap.
|
|
func serveRoles(store storage.DoltStorage) (httpapi.Config, error) {
|
|
var cfg httpapi.Config
|
|
var err error
|
|
if cfg.Reader, err = store.IssueReader(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Claimer, err = store.IssueClaimer(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.ReadyClaimer, err = store.ReadyClaimer(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Releaser, err = store.Releaser(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Lifecycle, err = store.IssueLifecycle(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Settings, err = store.WorkspaceConfig(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Stats, err = store.StatsReporter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.CycleDetector, err = store.CycleDetector(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.EdgeReader, err = store.EdgeReader(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.GraphCounter, err = store.GraphCounter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Relations, err = store.IssueRelations(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Commenter, err = store.Commenter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BlockingAnnotator, err = store.BlockingAnnotator(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.TreeWalker, err = store.TreeWalker(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.ReadyCounter, err = store.ReadyCounter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Counter, err = store.Counter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Querier, err = store.Querier(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Sweeper, err = store.Sweeper(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Deleter, err = store.Deleter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BatchCreator, err = store.BatchCreator(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BatchCloser, err = store.BatchCloser(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.DependencyEditor, err = store.DependencyEditor(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.MetadataCAS, err = store.MetadataCAS(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BatchApplier, err = store.BatchApplier(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Memories, err = store.Memories(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BatchGetter, err = store.BatchGetter(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.LeaseReclaimer, err = store.LeaseReclaimer(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.Heartbeater, err = store.Heartbeater(); err != nil {
|
|
return cfg, err
|
|
}
|
|
if cfg.BlockedLister, err = store.BlockedLister(); err != nil {
|
|
return cfg, err
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
// servedWire adapts *wire.Client onto the store's transport seam.
|
|
//
|
|
// It exists here rather than in the package because the production adapter is
|
|
// the ACTIVATION path's — `bd connect` resolves a target, builds the credential
|
|
// ladder and registers the dialer — and inventing half of it here would be a
|
|
// second wiring for that bead to reconcile. What the seam actually needs from
|
|
// the transport is Preflight and Do, and *wire.Client satisfies both verbatim;
|
|
// only the handshake accessor is shaped differently, because the store caches
|
|
// the ContextResponse and the client caches the gated Snapshot around it.
|
|
type servedWire struct{ *wire.Client }
|
|
|
|
func (w servedWire) ServerContext(ctx context.Context) (*apigen.ContextResponse, error) {
|
|
snap, err := w.Client.Handshake(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &snap.Context, nil
|
|
}
|
|
|
|
// tamperedClient is a second client onto the same server whose outbound
|
|
// requests are rewritten on the way out.
|
|
//
|
|
// It exists to produce RED evidence: a composition that could not tell a
|
|
// correctly encoded request from a subtly wrong one would pass every test in
|
|
// this package while shipping a client that answers the wrong question. The
|
|
// tamper runs after the encoder and before the transport, which is exactly
|
|
// where a hand-written encoder's mistakes live.
|
|
func (c *servedComposition) tamperedClient(t *testing.T, tamper func(*wire.Request)) *Store {
|
|
t.Helper()
|
|
base, err := url.Parse(c.baseURL)
|
|
if err != nil {
|
|
t.Fatalf("parse the composition base URL: %v", err)
|
|
}
|
|
transport, err := wire.New(base, nil, wire.Options{})
|
|
if err != nil {
|
|
t.Fatalf("build a second wire client: %v", err)
|
|
}
|
|
return New(Target{BaseURL: base}, tamperedWire{WireClient: servedWire{transport}, tamper: tamper}, nil)
|
|
}
|
|
|
|
type tamperedWire struct {
|
|
WireClient
|
|
tamper func(*wire.Request)
|
|
}
|
|
|
|
func (w tamperedWire) Do(ctx context.Context, req wire.Request, out any) error {
|
|
w.tamper(&req)
|
|
return w.WireClient.Do(ctx, req, out)
|
|
}
|
|
|
|
// seedIssue is the seed handle every fixture binds: the REFERENCE store's own
|
|
// create, never the client's. The client refuses CreateIssue outright, so this
|
|
// is not merely a convention here — it is the only thing that can seed at all.
|
|
func (c *servedComposition) seedIssue(ctx context.Context, issue *types.Issue, actor string) error {
|
|
return c.reference.CreateIssue(ctx, issue, actor)
|
|
}
|
|
|
|
func (c *servedComposition) seedDependency(ctx context.Context, dep *types.Dependency, actor string) error {
|
|
return c.reference.AddDependencyWithOptions(ctx, dep, actor, storage.DependencyAddOptions{EmitEvent: true})
|
|
}
|
|
|
|
func (c *servedComposition) seedComment(ctx context.Context, issueID, author, text string) error {
|
|
_, err := c.reference.AddIssueComment(ctx, issueID, author, text)
|
|
return err
|
|
}
|
|
|
|
func (c *servedComposition) seedPromotion(ctx context.Context, id, actor string) error {
|
|
return c.reference.PromoteFromEphemeral(ctx, id, actor)
|
|
}
|
|
|
|
// queryScalar is the composition's raw-row hook: a single-row query against the
|
|
// REFERENCE store, which is where the rows a contract seeded actually live.
|
|
//
|
|
// It opens its own SQL handle per call, exactly as the per-case harness does
|
|
// (served_harness_test.go states the measurement): a handle held for the life of
|
|
// the composition and a live server on the same database deadlock, and the
|
|
// symptom is a hung run rather than a failing one.
|
|
//
|
|
// It exists because a count or a listing cannot tell a row it EXCLUDED from a
|
|
// row that was never seeded — both surfaces hide it — so the cases that assert
|
|
// an exclusion read the stored row directly.
|
|
func (c *servedComposition) queryScalar(ctx context.Context, query string, args []any, dest ...any) error {
|
|
db, cleanup, err := embeddeddolt.OpenSQL(ctx, c.dataDir, c.database, "main")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() { _ = cleanup() }()
|
|
return db.QueryRowContext(ctx, query, args...).Scan(dest...)
|
|
}
|
|
|
|
// countHistory reads the reference branch's commit log. The client cannot
|
|
// observe history at all — v0 publishes no history surface — so the
|
|
// writes-nothing cases would otherwise skip themselves, which is the one thing
|
|
// they exist to prevent.
|
|
func (c *servedComposition) countHistory(ctx context.Context) (int, error) {
|
|
var entries int
|
|
if err := c.queryScalar(ctx, "SELECT COUNT(*) FROM dolt_log", nil, &entries); err != nil {
|
|
return 0, err
|
|
}
|
|
return entries, nil
|
|
}
|
|
|
|
// fixture binds the composition into the shell's servedFixture shape, which
|
|
// re-checks the one invariant that cannot be read off a wiring later: the seed
|
|
// handle is not the subject.
|
|
func (c *servedComposition) fixture(t *testing.T) servedFixture {
|
|
t.Helper()
|
|
return newServedFixture(t, c.reference, c.client, c.baseURL)
|
|
}
|
|
|
|
// bind is how every case below reaches its role: through servedFixture.bindRole,
|
|
// which returns the accessor's error UNCHANGED. A contract wired before its role
|
|
// bead lands therefore FAILS rather than skips — refusals are owned by
|
|
// RunUnsupportedContract, not by skipped conformance cases.
|
|
func bindRole[T any](t *testing.T, f servedFixture, accessor func(*Store) (T, error)) T {
|
|
t.Helper()
|
|
var role T
|
|
if err := f.bindRole(func(s *Store) error {
|
|
var err error
|
|
role, err = accessor(s)
|
|
return err
|
|
}); err != nil {
|
|
t.Fatalf("binding the role against the http client: %v", err)
|
|
}
|
|
return role
|
|
}
|
|
|
|
// assertServedRefusal is the shape a parked case's refusal must still have: the
|
|
// contract cannot run, but the REFUSAL is itself a promise — it names a field,
|
|
// it classifies as unsupported, and it is not a silent drop.
|
|
func assertServedRefusal(t *testing.T, what string, err error, field string) {
|
|
t.Helper()
|
|
var unsup *storage.ErrUnsupported
|
|
if !errors.As(err, &unsup) {
|
|
t.Fatalf("%s = %v, want a typed *storage.ErrUnsupported", what, err)
|
|
}
|
|
var inexpressible *InexpressibleError
|
|
if !errors.As(err, &inexpressible) {
|
|
t.Fatalf("%s = %v, want an *InexpressibleError carrying its ledger row", what, err)
|
|
}
|
|
if inexpressible.Refused.Row.Field != field {
|
|
t.Errorf("%s refused over %q, want the refusal to name %q", what, inexpressible.Refused.Row.Field, field)
|
|
}
|
|
}
|