beads/issue_roles_external_test.go
Julian Knutsen 3eab445b0a
Add issueops.GraphCounter: how many edges, in one named direction (ga-itny5) (#5485)
* Add issueops.GraphCounter: how many edges, in one named direction (ga-itny5)

The graph counts are the last read on the storage surface with no role behind
them. `storage.DoltStorage` publishes CountDependents, CountDependencies and
CountDependentsByStatus as three methods that differ only in a direction and a
narrowing, and every one of them is a raw method a front door can call with no
decorator, no probe and no plane story. This is their facade.

ONE METHOD, AND THE DIRECTION IS IN THE REQUEST. The raw seam spells the
direction in the METHOD NAME, which is the one thing a request field can get
wrong, so `EdgeCountRequest.Direction` is REQUIRED and an empty one is
ErrValidation before anything is read — including for a request that names no
ids at all, which is otherwise the empty answer EdgeReader gives. There is no
`both`: the two numbers are over different edge sets, summing them
double-counts an edge between two requested anchors, and a paired answer would
make Status — which narrows by a row only the inbound direction has — govern
half an answer silently. internal/workapi's detail assembly already makes two
calls for the pair today, so nothing pays a round trip it was not paying.

STATUS IS INBOUND-ONLY AND SAYS SO RATHER THAN BEING IGNORED. Narrowing by
status means joining the far end of an edge to the row holding its status, and
an OUTBOUND edge's far end may be a row this database does not hold — an
"external:" reference or a foreign-repository id, both of which
DependencyEditor accepts. A status filter there would silently drop every
dangling edge, which is the class of edge EdgeReader exists to return verbatim.
The raw seam has the same asymmetry: CountDependentsByStatus exists and
CountDependenciesByStatus does not.

A MISSING ANCHOR IS A FLAG, NOT ErrNotFound. 0 is the common answer — most
issues have no edges in at least one direction — so an id typo would never
surface, and a batch that failed on one absent id would discard the answers for
the ids that were found. That is EdgeReader's rule, and it is what forces the
existence probe and the tally into ONE transaction.

WHAT IS EXCLUDED, since the never-append rule makes each one a decision. The
COMMENT count is genuinely consumed — `bd show` prints it beside the two edge
counts — and is still out: a comment has no direction, no type and no far end,
so every field of the request below IDs would be meaningless to it. CountEvents
has no caller in the tree at all and follows the journal. GetDependencyCounts
is expressible as two calls with Types set to the blocking type, and naming it
as a method would have added a map-shaped answer no wire operation can carry.

THREE LEGS, ONE BODY. All three reach issueops.ExecuteEdgeCount — the two
stores wrap it in their own read transaction, the unit of work reaches it
through the domain repository, whose runner publishes exactly the DBTX method
set — so the contract header says one reading plus two engine checks and three
wrapper checks, not "three backends agree". Validation moved INSIDE that body
for the same reason: with one body there is no second implementation for a
per-leg check to belong to.

FACADE ONLY. No HTTP operation: the wire half follows in the graph-counts wire
slice per the program's council gating. No `bd` command either, and that is the
larger of the two decisions — the numbers are printed today through
internal/workapi's detail seam, which an HTTP handler shares, so moving it is a
change with its own parity argument. Both absences are written into the leaf
doc beside the promises, as VersionReconciler writes down its absent HTTP half
and BatchApplier its absent CLI.

Contract: 14 cases, wired on all three legs. Mutation-checked — a constant
count reddens 7 including both per-direction cases, ignoring the direction
reddens the 4 inbound ones, and dropping the ephemeral plane reddens the 2
cross-plane ones. The pure halves (the request vocabulary, the missing-anchor
rule, the SQL shape) are pinned without a database beside the body.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Review: reattach the Importer note, cite the collision, size the id list

Three corrections, none behavioral.

The four-line note about Importer's uow-only accessor was left stranded above
the GraphCounter row by this slice's insertion, where it asserted three things
that are false of it: GraphCounter IS a storage.DoltStorage accessor, a
store-built backend CAN fill its field, and importer_contract.go's header says
nothing about it. Moved back onto the row it describes.

"Nothing in this contract's reach can produce one" reads too easily as "it
cannot happen". A cross-table id collision is real and constructed:
TestDependentRecordsCrossTableCollision seeds one logical edge into both
dependency tables and names the two production paths that make them — a wisp
promoted to durable, and two Dolt clones merged. The leaf now cites it and says
what this role promises against it (the sum) versus what
CountDependentRecords' question is (the distinct total).

And EdgeCountRequest.IDs says out loud that it carries no size cap, which
EdgeReadRequest.IDs also does not: the bound belongs to the wire operation,
where the request arrives from somewhere else and the cost of an unbounded one
is a stranger's. ApplyBatchRequest.Items makes the same split explicitly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Review Sim <ci@beads.test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 11:29:32 -07:00

786 lines
30 KiB
Go

package beads_test
import (
"errors"
"reflect"
"testing"
"github.com/steveyegge/beads"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/dolt"
"github.com/steveyegge/beads/internal/telemetry"
)
// TestReadyClaimerLayersHooksOutsideTelemetry pins the decorator order the
// claim accessor produces against the order cmd/bd assembles the chain in
// (storage_chain.go: telemetry first, hooks outermost), the same property
// TestIssueLifecycleLayersHooksOutsideTelemetry pins for the write role. A
// blind delegation at either decorator would still satisfy Storage and would
// still compile.
func TestReadyClaimerLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
claimer, err := storage.NewHookFiringStore(instrumented, nil).ReadyClaimer()
if err != nil {
t.Fatalf("ReadyClaimer() error = %v", err)
}
if got := reflect.TypeOf(claimer).String(); got != "*storage.hookReadyClaimer" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
// TestBatchCloserLayersHooksOutsideTelemetry is the same pin for the
// close-many role.
func TestBatchCloserLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
closer, err := storage.NewHookFiringStore(instrumented, nil).BatchCloser()
if err != nil {
t.Fatalf("BatchCloser() error = %v", err)
}
if got := reflect.TypeOf(closer).String(); got != "*storage.hookBatchCloser" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
// TestReadyClaimerExposesTypedUnsupportedError pins the typed error a backend
// returns when it cannot serve the role, reachable through the public alias
// without importing internal/storage.
func TestReadyClaimerExposesTypedUnsupportedError(t *testing.T) {
claimer, err := (*dolt.DoltStore)(nil).ReadyClaimer()
if claimer != nil {
t.Fatalf("ReadyClaimer() claimer = %T, want nil", claimer)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("ReadyClaimer() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestBatchCloserExposesTypedUnsupportedError(t *testing.T) {
closer, err := (*dolt.DoltStore)(nil).BatchCloser()
if closer != nil {
t.Fatalf("BatchCloser() closer = %T, want nil", closer)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("BatchCloser() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestBatchCreatorLayersHooksOutsideTelemetry is the same pin for the
// create-many role.
func TestBatchCreatorLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
creator, err := storage.NewHookFiringStore(instrumented, nil).BatchCreator()
if err != nil {
t.Fatalf("BatchCreator() error = %v", err)
}
if got := reflect.TypeOf(creator).String(); got != "*storage.hookBatchCreator" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
func TestBatchCreatorExposesTypedUnsupportedError(t *testing.T) {
creator, err := (*dolt.DoltStore)(nil).BatchCreator()
if creator != nil {
t.Fatalf("BatchCreator() creator = %T, want nil", creator)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("BatchCreator() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestDependencyEditorLayersHooksOutsideTelemetry is the same decorator-order
// pin for the edge-write role.
func TestDependencyEditorLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
editor, err := storage.NewHookFiringStore(instrumented, nil).DependencyEditor()
if err != nil {
t.Fatalf("DependencyEditor() error = %v", err)
}
if got := reflect.TypeOf(editor).String(); got != "*storage.hookDependencyEditor" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
// TestBatchApplierLayersHooksOutsideTelemetry is the same pin for the
// apply-many role, and it has more to lose than its siblings: this decorator is
// the one place four hook vocabularies fire from one call, so an accessor that
// stopped wrapping would silently drop on_create, on_update AND on_close for
// every plan a caller applies.
func TestBatchApplierLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
applier, err := storage.NewHookFiringStore(instrumented, nil).BatchApplier()
if err != nil {
t.Fatalf("BatchApplier() error = %v", err)
}
if got := reflect.TypeOf(applier).String(); got != "*storage.hookBatchApplier" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
func TestBatchApplierExposesTypedUnsupportedError(t *testing.T) {
applier, err := (*dolt.DoltStore)(nil).BatchApplier()
if applier != nil {
t.Fatalf("BatchApplier() applier = %T, want nil", applier)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("BatchApplier() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestCommenterLayersHooksOutsideTelemetry is the same pin for the comment
// role.
func TestCommenterLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
commenter, err := storage.NewHookFiringStore(instrumented, nil).Commenter()
if err != nil {
t.Fatalf("Commenter() error = %v", err)
}
if got := reflect.TypeOf(commenter).String(); got != "*storage.hookCommenter" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
// TestMetadataCASLayersHooksOutsideTelemetry is the same pin for the
// conditional metadata write, and it is the answer the OTHER destructive-ish
// write roles do not give: a swap that lands names a bead and moves a column,
// which is on_update — a hook the vocabulary publishes and a row a script can
// still read back — so this decorator wraps rather than recursing the way
// Sweeper and Deleter do.
func TestMetadataCASLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
cas, err := storage.NewHookFiringStore(instrumented, nil).MetadataCAS()
if err != nil {
t.Fatalf("MetadataCAS() error = %v", err)
}
if got := reflect.TypeOf(cas).String(); got != "*storage.hookMetadataCAS" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
func TestMetadataCASExposesTypedUnsupportedError(t *testing.T) {
cas, err := (*dolt.DoltStore)(nil).MetadataCAS()
if cas != nil {
t.Fatalf("MetadataCAS() surface = %T, want nil", cas)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("MetadataCAS() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestReleaserLayersHooksOutsideTelemetry is the same pin for the claim
// release. It gives the same answer the metadata swap does and for the same
// reason: a release moves assignee and status, which is on_update — a hook the
// vocabulary publishes and a row a script can still read back — so this
// decorator wraps rather than recursing the way Sweeper and Deleter do.
func TestReleaserLayersHooksOutsideTelemetry(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
releaser, err := storage.NewHookFiringStore(instrumented, nil).Releaser()
if err != nil {
t.Fatalf("Releaser() error = %v", err)
}
if got := reflect.TypeOf(releaser).String(); got != "*storage.hookReleaser" {
t.Fatalf("outer layer = %s, want the hook wrapper", got)
}
}
func TestReleaserExposesTypedUnsupportedError(t *testing.T) {
releaser, err := (*dolt.DoltStore)(nil).Releaser()
if releaser != nil {
t.Fatalf("Releaser() surface = %T, want nil", releaser)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Releaser() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestIssueRelationsKeepsTelemetryOutermost is the READ role's version of the
// pin, and it is deliberately the other answer: the hook decorator adds no
// layer to a read, so the outermost thing a caller gets is the instrumented
// surface. A wrapper appearing here would mean a hook layer landed on a path
// with nothing to fire.
func TestIssueRelationsKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
relations, err := storage.NewHookFiringStore(instrumented, nil).IssueRelations()
if err != nil {
t.Fatalf("IssueRelations() error = %v", err)
}
if got := reflect.TypeOf(relations).String(); got != "*telemetry.instrumentedIssueRelations" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestDependencyEditorExposesTypedUnsupportedError(t *testing.T) {
editor, err := (*dolt.DoltStore)(nil).DependencyEditor()
if editor != nil {
t.Fatalf("DependencyEditor() editor = %T, want nil", editor)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("DependencyEditor() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestCommenterExposesTypedUnsupportedError(t *testing.T) {
commenter, err := (*dolt.DoltStore)(nil).Commenter()
if commenter != nil {
t.Fatalf("Commenter() commenter = %T, want nil", commenter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Commenter() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestIssueRelationsExposesTypedUnsupportedError(t *testing.T) {
relations, err := (*dolt.DoltStore)(nil).IssueRelations()
if relations != nil {
t.Fatalf("IssueRelations() relations = %T, want nil", relations)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("IssueRelations() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestCounterKeepsTelemetryOutermost is the READ answer for the reason
// TestIssueRelationsKeepsTelemetryOutermost gives: counting fires no completion
// hooks, so the hook decorator adds no layer.
func TestCounterKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
counter, err := storage.NewHookFiringStore(instrumented, nil).Counter()
if err != nil {
t.Fatalf("Counter() error = %v", err)
}
if got := reflect.TypeOf(counter).String(); got != "*telemetry.instrumentedCounter" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
// TestWorkspaceConfigKeepsTelemetryOutermost is the first place in this file
// where the read answer is given for a role that WRITES.
//
// The hook decorator's vocabulary is on_create / on_update / on_close and every
// one of them hands a hook script an ISSUE. A settings write changes the
// workspace rather than a bead, so there is nothing to hand one — and the
// legacy config verbs this decorator inherits fire nothing either.
func TestWorkspaceConfigKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
settings, err := storage.NewHookFiringStore(instrumented, nil).WorkspaceConfig()
if err != nil {
t.Fatalf("WorkspaceConfig() error = %v", err)
}
if got := reflect.TypeOf(settings).String(); got != "*telemetry.instrumentedWorkspaceConfig" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
// TestMemoriesKeepsTelemetryOutermost is the settings role's answer for the
// second plane that rides in the config table.
//
// Remember and Forget WRITE, so the reflex is to expect the hook wrapper here.
// The hook vocabulary is what decides it: on_create, on_update and on_close each
// hand a script an ISSUE, and a remembered insight is not one. There is no
// on_remember to fire and inventing one is a hook proposal, not a role commit.
// See internal/storage/hook_memories.go.
func TestMemoriesKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
memories, err := storage.NewHookFiringStore(instrumented, nil).Memories()
if err != nil {
t.Fatalf("Memories() error = %v", err)
}
if got := reflect.TypeOf(memories).String(); got != "*telemetry.instrumentedMemories" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
// TestMemoriesExposesTypedUnsupportedError pins the typed refusal a backend
// gives when it cannot serve the memory role, reachable through the public
// alias without importing internal/storage.
func TestMemoriesExposesTypedUnsupportedError(t *testing.T) {
memories, err := (*dolt.DoltStore)(nil).Memories()
if memories != nil {
t.Fatalf("Memories() memories = %T, want nil", memories)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Memories() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestVersionReconcilerKeepsTelemetryOutermost is the settings role's reason
// plus one this role has on its own: it runs from PersistentPreRun on every
// startup, so a hook wrapper here would run a user's script before every
// command — including the ones that go on to fail on their own arguments —
// with no bead to hand it.
func TestVersionReconcilerKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
reconciler, err := storage.NewHookFiringStore(instrumented, nil).VersionReconciler()
if err != nil {
t.Fatalf("VersionReconciler() error = %v", err)
}
if got := reflect.TypeOf(reconciler).String(); got != "*telemetry.instrumentedVersionReconciler" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
// TestBootstrapperKeepsTelemetryOutermost has a reason that is neither the
// settings role's nor the version marker's. A bootstrap writes, and loudly —
// it is what turns a database into a workspace — but this decorator's hook
// vocabulary is issue-shaped and a bootstrap names no issue; and on a workspace
// this new, `bd init` has not installed .beads/hooks/ yet, so a hook fired here
// would run whatever the previous project in that directory left behind. See
// internal/storage/hook_bootstrapper.go.
func TestBootstrapperKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
bootstrapper, err := storage.NewHookFiringStore(instrumented, nil).Bootstrapper()
if err != nil {
t.Fatalf("Bootstrapper() error = %v", err)
}
if got := reflect.TypeOf(bootstrapper).String(); got != "*telemetry.instrumentedBootstrapper" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
// TestInitVerifierKeepsTelemetryOutermost is the ordinary read-role pin: reads
// fire no hooks, so the hook decorator recurses and the telemetry wrapper is
// what a caller holds.
func TestInitVerifierKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
verifier, err := storage.NewHookFiringStore(instrumented, nil).InitVerifier()
if err != nil {
t.Fatalf("InitVerifier() error = %v", err)
}
if got := reflect.TypeOf(verifier).String(); got != "*telemetry.instrumentedInitVerifier" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestBootstrapperExposesTypedUnsupportedError(t *testing.T) {
bootstrapper, err := (*dolt.DoltStore)(nil).Bootstrapper()
if bootstrapper != nil {
t.Fatalf("Bootstrapper() bootstrapper = %T, want nil", bootstrapper)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Bootstrapper() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestInitVerifierExposesTypedUnsupportedError(t *testing.T) {
verifier, err := (*dolt.DoltStore)(nil).InitVerifier()
if verifier != nil {
t.Fatalf("InitVerifier() verifier = %T, want nil", verifier)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("InitVerifier() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestVersionReconcilerExposesTypedUnsupportedError(t *testing.T) {
reconciler, err := (*dolt.DoltStore)(nil).VersionReconciler()
if reconciler != nil {
t.Fatalf("VersionReconciler() reconciler = %T, want nil", reconciler)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("VersionReconciler() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestWorkspaceConfigExposesTypedUnsupportedError(t *testing.T) {
settings, err := (*dolt.DoltStore)(nil).WorkspaceConfig()
if settings != nil {
t.Fatalf("WorkspaceConfig() settings = %T, want nil", settings)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("WorkspaceConfig() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestStatsReporterKeepsTelemetryOutermost is the READ answer again: reporting
// fires no completion hooks, so the hook decorator recurses.
func TestStatsReporterKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
reporter, err := storage.NewHookFiringStore(instrumented, nil).StatsReporter()
if err != nil {
t.Fatalf("StatsReporter() error = %v", err)
}
if got := reflect.TypeOf(reporter).String(); got != "*telemetry.instrumentedStatsReporter" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestStatsReporterExposesTypedUnsupportedError(t *testing.T) {
reporter, err := (*dolt.DoltStore)(nil).StatsReporter()
if reporter != nil {
t.Fatalf("StatsReporter() reporter = %T, want nil", reporter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("StatsReporter() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestCycleDetectorKeepsTelemetryOutermost is the READ answer again: a cycle
// sweep fires no completion hooks, so the hook decorator adds no layer.
func TestCycleDetectorKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
detector, err := storage.NewHookFiringStore(instrumented, nil).CycleDetector()
if err != nil {
t.Fatalf("CycleDetector() error = %v", err)
}
if got := reflect.TypeOf(detector).String(); got != "*telemetry.instrumentedCycleDetector" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestCycleDetectorExposesTypedUnsupportedError(t *testing.T) {
detector, err := (*dolt.DoltStore)(nil).CycleDetector()
if detector != nil {
t.Fatalf("CycleDetector() detector = %T, want nil", detector)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("CycleDetector() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestEdgeReaderKeepsTelemetryOutermost is the READ answer again: reading edges
// fires no completion hooks, so the hook decorator adds no layer.
func TestEdgeReaderKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
edges, err := storage.NewHookFiringStore(instrumented, nil).EdgeReader()
if err != nil {
t.Fatalf("EdgeReader() error = %v", err)
}
if got := reflect.TypeOf(edges).String(); got != "*telemetry.instrumentedEdgeReader" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestEdgeReaderExposesTypedUnsupportedError(t *testing.T) {
edges, err := (*dolt.DoltStore)(nil).EdgeReader()
if edges != nil {
t.Fatalf("EdgeReader() reader = %T, want nil", edges)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("EdgeReader() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestBlockingAnnotatorKeepsTelemetryOutermost is the READ answer again:
// annotating a page fires no completion hooks, so the hook decorator adds no
// layer.
func TestBlockingAnnotatorKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
annotator, err := storage.NewHookFiringStore(instrumented, nil).BlockingAnnotator()
if err != nil {
t.Fatalf("BlockingAnnotator() error = %v", err)
}
if got := reflect.TypeOf(annotator).String(); got != "*telemetry.instrumentedBlockingAnnotator" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestBlockingAnnotatorExposesTypedUnsupportedError(t *testing.T) {
annotator, err := (*dolt.DoltStore)(nil).BlockingAnnotator()
if annotator != nil {
t.Fatalf("BlockingAnnotator() annotator = %T, want nil", annotator)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("BlockingAnnotator() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestTreeWalkerKeepsTelemetryOutermost is the READ answer again: a tree walk
// fires no completion hooks, so the hook decorator adds no layer.
func TestTreeWalkerKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
walker, err := storage.NewHookFiringStore(instrumented, nil).TreeWalker()
if err != nil {
t.Fatalf("TreeWalker() error = %v", err)
}
if got := reflect.TypeOf(walker).String(); got != "*telemetry.instrumentedTreeWalker" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestTreeWalkerExposesTypedUnsupportedError(t *testing.T) {
walker, err := (*dolt.DoltStore)(nil).TreeWalker()
if walker != nil {
t.Fatalf("TreeWalker() walker = %T, want nil", walker)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("TreeWalker() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestGraphCounterKeepsTelemetryOutermost is the READ answer again: counting
// edges fires no completion hooks, so the hook decorator adds no layer.
func TestGraphCounterKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
counter, err := storage.NewHookFiringStore(instrumented, nil).GraphCounter()
if err != nil {
t.Fatalf("GraphCounter() error = %v", err)
}
if got := reflect.TypeOf(counter).String(); got != "*telemetry.instrumentedGraphCounter" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestGraphCounterExposesTypedUnsupportedError(t *testing.T) {
counter, err := (*dolt.DoltStore)(nil).GraphCounter()
if counter != nil {
t.Fatalf("GraphCounter() counter = %T, want nil", counter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("GraphCounter() error = %v, want *beads.ErrUnsupported", err)
}
}
func TestCounterExposesTypedUnsupportedError(t *testing.T) {
counter, err := (*dolt.DoltStore)(nil).Counter()
if counter != nil {
t.Fatalf("Counter() counter = %T, want nil", counter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Counter() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestReadyCounterKeepsTelemetryOutermost is the READ answer again: sizing the
// ready set fires no completion hooks, so the hook decorator adds no layer.
func TestReadyCounterKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
counter, err := storage.NewHookFiringStore(instrumented, nil).ReadyCounter()
if err != nil {
t.Fatalf("ReadyCounter() error = %v", err)
}
if got := reflect.TypeOf(counter).String(); got != "*telemetry.instrumentedReadyCounter" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestReadyCounterExposesTypedUnsupportedError(t *testing.T) {
counter, err := (*dolt.DoltStore)(nil).ReadyCounter()
if counter != nil {
t.Fatalf("ReadyCounter() counter = %T, want nil", counter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("ReadyCounter() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestQuerierKeepsTelemetryOutermost is the READ answer again: a query fires no
// completion hooks, so the hook decorator adds no layer.
func TestQuerierKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
querier, err := storage.NewHookFiringStore(instrumented, nil).Querier()
if err != nil {
t.Fatalf("Querier() error = %v", err)
}
if got := reflect.TypeOf(querier).String(); got != "*telemetry.instrumentedQuerier" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestQuerierExposesTypedUnsupportedError(t *testing.T) {
querier, err := (*dolt.DoltStore)(nil).Querier()
if querier != nil {
t.Fatalf("Querier() querier = %T, want nil", querier)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Querier() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestSweeperKeepsTelemetryOutermost is a WRITE role that answers the way the
// reads do: there is no on_delete hook to fire
// (internal/storage/hook_sweeper.go), so the hook decorator adds no layer.
// Pinning it here is what keeps that a decision rather than a wrapper someone
// forgot to write.
func TestSweeperKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
sweeper, err := storage.NewHookFiringStore(instrumented, nil).Sweeper()
if err != nil {
t.Fatalf("Sweeper() error = %v", err)
}
if got := reflect.TypeOf(sweeper).String(); got != "*telemetry.instrumentedSweeper" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestSweeperExposesTypedUnsupportedError(t *testing.T) {
sweeper, err := (*dolt.DoltStore)(nil).Sweeper()
if sweeper != nil {
t.Fatalf("Sweeper() sweeper = %T, want nil", sweeper)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Sweeper() error = %v, want *beads.ErrUnsupported", err)
}
}
// TestDeleterKeepsTelemetryOutermost is the second write role to answer the way
// the reads do: there is no on_delete hook to fire
// (internal/storage/hook_deleter.go), so the hook decorator adds no layer.
func TestDeleterKeepsTelemetryOutermost(t *testing.T) {
t.Setenv("BD_OTEL_STDOUT", "true")
instrumented, ok := telemetry.WrapStorage(&dolt.DoltStore{}).(*telemetry.InstrumentedStorage)
if !ok {
t.Fatal("WrapStorage() did not create InstrumentedStorage")
}
deleter, err := storage.NewHookFiringStore(instrumented, nil).Deleter()
if err != nil {
t.Fatalf("Deleter() error = %v", err)
}
if got := reflect.TypeOf(deleter).String(); got != "*telemetry.instrumentedDeleter" {
t.Fatalf("outer layer = %s, want the telemetry wrapper unwrapped by the hook decorator", got)
}
}
func TestDeleterExposesTypedUnsupportedError(t *testing.T) {
deleter, err := (*dolt.DoltStore)(nil).Deleter()
if deleter != nil {
t.Fatalf("Deleter() deleter = %T, want nil", deleter)
}
var unsupported *beads.ErrUnsupported
if !errors.As(err, &unsupported) {
t.Fatalf("Deleter() error = %v, want *beads.ErrUnsupported", err)
}
}