From e8f318316fb1879b9531f5da4ce6891d057e561f Mon Sep 17 00:00:00 2001 From: Karel Bourgois Date: Wed, 30 Sep 2026 01:56:23 +0200 Subject: [PATCH] feat(count): `--include-ephemeral`, the plane knob `bd count` never had (#6240) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(count): --include-ephemeral, the plane knob `bd count` never had `bd count` can admit the wisps table only through `--include-infra`, which makes four changes at once. This adds the flag that makes just the first one, mirroring the `--include-ephemeral` that `bd list` gained in #6098. ## Why the plane is unreachable on its own The write path routes on STORAGE CLASS, not type — dolt's `useWispsTable` is `Ephemeral || NoHistory || WispType != "" || IsInfraType`. So a `no_history` task lives in the wisps TABLE while remaining ordinary durable work, and a default `bd count` never sees it. Recovering it today means `--include-infra`, which this repo's own doc calls "FOUR changes at once and not one": it admits the plane, drops the infra-type exclusions, changes the template treatment, and reconciles cardinality with `bd list --all`. Its template exclusion then silently drops template rows of the named type — so a caller who wanted the plane trades one silent undercount for another. `ListRequest.IncludeEphemeral` has been the narrow answer on the listing side since #5476, and #6098 gave it a CLI flag. `CountRequest` had no equivalent field at all. This is the missing half of that pair. ## The change - `issueops.CountRequest.IncludeEphemeral` — the plane knob alone: exactly the first of `IncludeInfra`'s four changes, with none of the other three. - `internal/workapi/count.go` — one line, `} else if !in.IncludeEphemeral {`. - `cmd/bd/count.go` — flag registration, matching `bd list`'s wording. - `internal/httpapi` — `include_ephemeral` on `countIssues`, in the spec; the generated `types.gen.go` is `make api-gen` output, not hand-edited. Unset, the count is durable-plane only: the historical answer, unchanged. Every default is untouched. It does NOT promise a count and a listing agree. They already differ on TEMPLATES without this flag and still do with it — a count includes template rows unless `IncludeInfra` excludes them, a listing excludes them unless `IncludeTemplates` admits them. That predates this and is unchanged by it; only `IncludeInfra` sets out to reconcile cardinality, and it pays with three changes beyond the plane. ## Verification ok github.com/steveyegge/beads/internal/workapi ok github.com/steveyegge/beads/internal/httpapi ok github.com/steveyegge/beads/issueops --- PASS: TestEmbeddedCountIncludeEphemeral (39.71s) --- PASS: TestCountIncludeInfraFlagShape --- PASS: TestParseCountRequestCarriesEveryFilterFlag `TestEmbeddedCountIncludeEphemeral` was run with `BEADS_TEST_EMBEDDED_DOLT=1` and really executed — 39.71s, not a skip. The default fast tier would have skipped it and reported `ok`. `make api-gen` reproduces `types.gen.go` byte-for-byte from the spec hunk, so the two cannot drift apart in review. `go build ./...`, `go vet` and `gofmt` clean. Claude-Session: https://claude.ai/code/session_01X1jMLQTSrCwtzFRS1xeUC6 * count: reframe the comments for this repo, not the fork they came from Review on #6240 (bee-ghosttrack): five comment blocks were written from the fork's point of view and become false once merged here — "belongs upstream", "the half that still has to go upstream", "the fork's old wide default", and "upstream's default" meaning the current default. Find-and-replace, as asked: the reasoning is kept, only the frame of reference changes. "upstream's default" -> "the default before this change"; the bd list sibling "landed in #6098"; the infra-type divergence is "pinned, not fixed, here" with the reason; the embedded test's fork-maintenance history is replaced by what it actually pins. No code changes. * build(bazel): list the two test files this PR adds in their go_test srcs Maintainer review fixes for #6240, review iteration 1. The synthesis and the quality scorecard both returned approve with no required changes; this commit takes the one minor whose subject is the PR's own added files. Taken: - Change Impact / Blast Radius (minor, gate impact minor). The PR adds cmd/bd/count_include_ephemeral_embedded_test.go and internal/workapi/count_skipwisps_test.go, but neither was listed in its package's explicit go_test srcs, so the PR's own assertions were invisible to `bazel test`. Both rows are now listed. Gazelle's verdict, not a hand-guess: `make bazel-sync` was run (bazel 9.2.0 is available here) and it produced exactly these two entries. Its full output also rewrote 12 other BUILD.bazel files -- pre-existing base drift from other PRs' files, plus dep/select churn -- which is out of scope for this PR, so the generated result was reverted and only the two rows this PR is responsible for were re-applied, at the slots gazelle chose. Both srcs lists remain sorted with no duplicates (cmd/bd bd_test 637 entries, internal/workapi workapi_test 24 entries). The cgo build tag on count_include_ephemeral_embedded_test.go does not exempt it: the repo lists tag-gated *_embedded_test.go files anyway (99 of the 101 in cmd/bd are listed, and the sampled ones are simultaneously listed and tagged). Declined: - Test Evidence Quality (nit, gate impact none). The filing lane itself marked it optional and explicitly said not to gate on it, and its own reasoning holds: internal/storage/dolt/counts.go and internal/storage/embeddeddolt/counts.go both delegate to the same issueops.CountIssuesInTx, differing only in transaction acquisition. Validation: go build ./... and CGO_ENABLED=1 go vet on cmd/bd, internal/workapi and issueops all clean; go test ./internal/workapi/ ./issueops/ ok. No production code changed -- the commit is two generated-list rows. Co-Authored-By: Claude Opus 5 --------- Co-authored-by: Gas City Adopt-PR Co-authored-by: Claude Opus 5 --- cmd/bd/BUILD.bazel | 1 + cmd/bd/count.go | 16 +++ cmd/bd/count_filter_test.go | 52 +++---- .../count_include_ephemeral_embedded_test.go | 79 ++++++++++ internal/httpapi/apigen/types.gen.go | 5 + internal/httpapi/count_test.go | 7 +- internal/httpapi/reads.go | 3 +- internal/httpapi/spec/openapi.v0.yaml | 17 +++ internal/workapi/BUILD.bazel | 1 + internal/workapi/count.go | 2 +- internal/workapi/count_skipwisps_test.go | 136 ++++++++++++++++++ issueops/counter.go | 23 +++ 12 files changed, 313 insertions(+), 29 deletions(-) create mode 100644 cmd/bd/count_include_ephemeral_embedded_test.go create mode 100644 internal/workapi/count_skipwisps_test.go diff --git a/cmd/bd/BUILD.bazel b/cmd/bd/BUILD.bazel index efec9749f..96143f6ac 100644 --- a/cmd/bd/BUILD.bazel +++ b/cmd/bd/BUILD.bazel @@ -589,6 +589,7 @@ go_test( "cook_test.go", "count_embedded_test.go", "count_filter_test.go", + "count_include_ephemeral_embedded_test.go", "count_proxied_integration_test.go", "cpu_profile_test.go", "create_atomic_test.go", diff --git a/cmd/bd/count.go b/cmd/bd/count.go index c6c568236..01f3d7d04 100644 --- a/cmd/bd/count.go +++ b/cmd/bd/count.go @@ -33,6 +33,7 @@ Examples: bd count --by-label # Group count by label bd count --assignee alice --by-status # Count alice's issues by status bd count --include-infra # Count issues + wisps tier (matches 'bd list --include-infra --all' cardinality) + bd count --type task --include-ephemeral # Count tasks in the durable AND wisps tiers `, SilenceUsage: true, SilenceErrors: true, @@ -91,6 +92,7 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun noLabels, _ := cmd.Flags().GetBool("no-labels") includeInfra, _ := cmd.Flags().GetBool("include-infra") metadataFieldFlags, _ := cmd.Flags().GetStringArray("metadata-field") + includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral") request := issueops.CountRequest{ Status: status, @@ -107,6 +109,8 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun NoAssignee: noAssignee, NoLabels: noLabels, IncludeInfra: includeInfra, + + IncludeEphemeral: includeEphemeral, } if len(metadataFieldFlags) > 0 { request.MetadataFields = make(map[string]string, len(metadataFieldFlags)) @@ -296,6 +300,18 @@ func registerCountFlags(cmd *cobra.Command) { // `bd list --include-infra --all`. cmd.Flags().Bool("include-infra", false, "Include infrastructure beads and the wisps tier (matches 'bd list --include-infra --all' cardinality)") + // The plane knob alone: admits the wisps tier WITHOUT lifting any type + // exclusion, which --include-infra cannot do (it bundles four changes, and + // its template exclusion silently drops template rows of a named type). + // + // The sibling on `bd list` landed in #6098 (cmd/bd/list.go); the name and + // the help text deliberately follow its shape so the two halves of the + // pair read alike. The trailing clause is the one addition: on `bd count` + // the wider `--include-infra` sits right beside this flag and advertises + // cardinality matching, so the contrast has to be legible in `--help` and + // not only in this comment. + cmd.Flags().Bool("include-ephemeral", false, "Include ephemeral wisp-plane rows in the count (normally hidden), without lifting type exclusions") + // Grouping flags cmd.Flags().Bool("by-status", false, "Group count by status") cmd.Flags().Bool("by-priority", false, "Group count by priority") diff --git a/cmd/bd/count_filter_test.go b/cmd/bd/count_filter_test.go index 89fd9ed01..d943e1ac5 100644 --- a/cmd/bd/count_filter_test.go +++ b/cmd/bd/count_filter_test.go @@ -70,6 +70,7 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) { "priority-min": "0", "priority-max": "4", "include-infra": "true", + "include-ephemeral": "true", } { if err := flags.Flags().Set(flag, value); err != nil { t.Fatalf("set --%s=%s: %v", flag, value, err) @@ -96,31 +97,32 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) { } priority, min, max := 1, 0, 4 want := issueops.CountRequest{ - Status: "closed", - IssueType: "bug", - Assignee: "alice", - Priority: &priority, - PriorityMin: &min, - PriorityMax: &max, - Labels: []string{"alpha", "beta"}, - LabelsAny: []string{"gamma"}, - TitleSearch: "needle", - IDFilter: "bd-1,bd-2", - TitleContains: "tc", - DescContains: "dc", - NotesContains: "nc", - CreatedAfter: day(1), - CreatedBefore: day(2), - UpdatedAfter: day(3), - UpdatedBefore: day(4), - ClosedAfter: day(5), - ClosedBefore: day(6), - EmptyDesc: true, - NoAssignee: true, - NoLabels: true, - MetadataFields: map[string]string{"team": "platform"}, - HasMetadataKey: "audit_ref", - IncludeInfra: true, + Status: "closed", + IssueType: "bug", + Assignee: "alice", + Priority: &priority, + PriorityMin: &min, + PriorityMax: &max, + Labels: []string{"alpha", "beta"}, + LabelsAny: []string{"gamma"}, + TitleSearch: "needle", + IDFilter: "bd-1,bd-2", + TitleContains: "tc", + DescContains: "dc", + NotesContains: "nc", + CreatedAfter: day(1), + CreatedBefore: day(2), + UpdatedAfter: day(3), + UpdatedBefore: day(4), + ClosedAfter: day(5), + ClosedBefore: day(6), + EmptyDesc: true, + NoAssignee: true, + NoLabels: true, + MetadataFields: map[string]string{"team": "platform"}, + HasMetadataKey: "audit_ref", + IncludeInfra: true, + IncludeEphemeral: true, } if !reflect.DeepEqual(request, want) { t.Errorf("parseCountRequest built\n %#v\nwant\n %#v", request, want) diff --git a/cmd/bd/count_include_ephemeral_embedded_test.go b/cmd/bd/count_include_ephemeral_embedded_test.go new file mode 100644 index 000000000..d2b45bed7 --- /dev/null +++ b/cmd/bd/count_include_ephemeral_embedded_test.go @@ -0,0 +1,79 @@ +//go:build cgo + +package main + +import ( + "os" + "testing" +) + +// TestEmbeddedCountIncludeEphemeral covers the plane knob end to end, on the +// same fixture shape TestEmbeddedCountIncludeInfra uses. +// +// It is a SEPARATE file rather than a subtest of that function on purpose: +// TestEmbeddedCountIncludeInfra pins the existing --include-infra contract and +// is left byte-for-byte untouched, so a reader can see at a glance that this +// flag changed nothing it asserts. +// +// The distinction being pinned: --include-infra bundles four changes (see +// issueops.CountRequest.IncludeInfra) and its template exclusion silently drops +// template rows of the named type. --include-ephemeral admits the plane and +// nothing else. +func TestEmbeddedCountIncludeEphemeral(t *testing.T) { + if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" { + t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests") + } + t.Parallel() + + bd := buildEmbeddedBD(t) + dir, _, _ := bdInit(t, bd, "--prefix", "ie") + + // 3 durable tasks (one closed), 2 no_history tasks, 1 ephemeral task. + bdCreate(t, bd, dir, "durable task one", "--type", "task") + bdCreate(t, bd, dir, "durable task two", "--type", "task") + closed := bdCreate(t, bd, dir, "durable task closed", "--type", "task") + bdClose(t, bd, dir, closed.ID) + bdCreate(t, bd, dir, "nohistory task one", "--type", "task", "--no-history") + bdCreate(t, bd, dir, "nohistory task two", "--type", "task", "--no-history") + bdCreate(t, bd, dir, "ephemeral task", "--type", "task", "--ephemeral") + + countOf := func(args ...string) int { + t.Helper() + m := bdCountJSON(t, bd, dir, args...) + return int(m["count"].(float64)) + } + + t.Run("default stays durable-only", func(t *testing.T) { + if got := countOf("--type", "task"); got != 3 { + t.Errorf("bd count --type task = %d, want 3 (the default before this change, unchanged)", got) + } + }) + + t.Run("include-ephemeral reaches the wisps tier", func(t *testing.T) { + if got := countOf("--type", "task", "--include-ephemeral"); got != 6 { + t.Errorf("bd count --type task --include-ephemeral = %d, want 6 "+ + "(3 durable + 2 no_history + 1 ephemeral)", got) + } + }) + + t.Run("count and list read the same plane", func(t *testing.T) { + // The property is that both reach the wisps tier under the flag — NOT + // that the two numbers are equal. A count includes template rows and a + // listing does not, with or without this flag (see + // issueops.CountRequest.IncludeEphemeral), and this fixture has no + // templates only because it does not need any. Asserting raw equality + // here would pass by accident and break the day someone adds one. + durable := len(bdListJSON(t, bd, dir, + "--type", "task", "--status", "all", "--limit", "0")) + withPlane := len(bdListJSON(t, bd, dir, + "--type", "task", "--include-ephemeral", "--status", "all", "--limit", "0")) + if withPlane-durable != 3 { + t.Errorf("list gained %d rows from the plane, want 3 (2 no_history + 1 ephemeral)", + withPlane-durable) + } + if got := countOf("--type", "task", "--include-ephemeral") - countOf("--type", "task"); got != 3 { + t.Errorf("count gained %d rows from the plane, want 3 — count and list "+ + "must admit the same tier even where their totals differ", got) + } + }) +} diff --git a/internal/httpapi/apigen/types.gen.go b/internal/httpapi/apigen/types.gen.go index f97f80034..870046d99 100644 --- a/internal/httpapi/apigen/types.gen.go +++ b/internal/httpapi/apigen/types.gen.go @@ -2363,6 +2363,11 @@ type CountIssuesParams struct { // MetadataField Top-level metadata equality filter as `key=value`, split on the first `=`. Repeatable. An invalid key is a 400. MetadataField *[]string `form:"metadata_field,omitempty" json:"metadata_field,omitempty"` + // IncludeEphemeral Admit the EPHEMERAL PLANE — the wisps table — and nothing else. Exactly the first of `include_infra`'s four changes, with none of the other three: no type exclusion is taken off, so a row whose TYPE a default count already excludes stays excluded. + // + // It exists because there was no way to ask for that one thing. The write path routes on STORAGE CLASS, not type, so a `no_history` bead lives in the wisps table while remaining ordinary durable work. Reaching it needed `include_infra`, which also drops template rows of the named type — one silent undercount traded for another. + IncludeEphemeral *bool `form:"include_ephemeral,omitempty" json:"include_ephemeral,omitempty"` + // HasMetadataKey Only issues carrying this top-level metadata key. HasMetadataKey *string `form:"has_metadata_key,omitempty" json:"has_metadata_key,omitempty"` diff --git a/internal/httpapi/count_test.go b/internal/httpapi/count_test.go index 4c4c515ec..92af3f5c1 100644 --- a/internal/httpapi/count_test.go +++ b/internal/httpapi/count_test.go @@ -116,6 +116,7 @@ func TestCountForwardsEveryDocumentedParameter(t *testing.T) { "metadata_field": {"team=platform", "env=prod"}, "has_metadata_key": {"audit_ref"}, "include_infra": {"true"}, + "include_ephemeral": {"true"}, }.Encode()) if resp.StatusCode != http.StatusOK { t.Fatalf("status = %d, want 200: %s", resp.StatusCode, readAll(t, resp)) @@ -166,7 +167,8 @@ func TestCountForwardsEveryDocumentedParameter(t *testing.T) { MetadataFields: map[string]string{"team": "platform", "env": "prod"}, HasMetadataKey: "audit_ref", - IncludeInfra: true, + IncludeInfra: true, + IncludeEphemeral: true, } if !reflect.DeepEqual(got[0], want) { t.Errorf("request = %+v\nwant %+v", got[0], want) @@ -571,7 +573,7 @@ func TestCountGroupEnumMatchesTheRolesVocabulary(t *testing.T) { // The other two are already mechanical: TestCountParametersMatchTheHandler ties // the parameter names to the DOCUMENT, and TestCountForwardsEveryDocumentedParameter // ties each parameter's VALUE to the field it lands in. Neither can see a role -// field that no parameter reaches — a 25th filter added to CountRequest and left +// field that no parameter reaches — a 26th filter added to CountRequest and left // unpublished turns nothing red, and the wire silently stops being able to ask // a question the role can answer. That is the failure this map closes, and it is // the one that matters for an HTTP-backed store: it is how the wire becomes @@ -605,6 +607,7 @@ var countFieldForParameter = map[string]string{ "metadata_field": "MetadataFields", "has_metadata_key": "HasMetadataKey", "include_infra": "IncludeInfra", + "include_ephemeral": "IncludeEphemeral", } // TestEveryCountRequestFieldIsPublished: the role publishes 25 filters and the diff --git a/internal/httpapi/reads.go b/internal/httpapi/reads.go index 13da51856..1afbb122d 100644 --- a/internal/httpapi/reads.go +++ b/internal/httpapi/reads.go @@ -224,7 +224,8 @@ func countFilters(q *query) issueops.CountRequest { // infra type to the ephemeral tier — is four decisions the role makes // from the WORKSPACE's own infra vocabulary, which is a config load this // handler must never perform. - IncludeInfra: q.boolean("include_infra"), + IncludeInfra: q.boolean("include_infra"), + IncludeEphemeral: q.boolean("include_ephemeral"), } } diff --git a/internal/httpapi/spec/openapi.v0.yaml b/internal/httpapi/spec/openapi.v0.yaml index 24f30e574..bbc9130df 100644 --- a/internal/httpapi/spec/openapi.v0.yaml +++ b/internal/httpapi/spec/openapi.v0.yaml @@ -1977,6 +1977,23 @@ paths: type: array items: type: string + - name: include_ephemeral + in: query + description: >- + Admit the EPHEMERAL PLANE — the wisps table — and nothing else. + Exactly the first of `include_infra`'s four changes, with none of + the other three: no type exclusion is taken off, so a row whose TYPE + a default count already excludes stays excluded. + + + It exists because there was no way to ask for that one thing. The + write path routes on STORAGE CLASS, not type, so a `no_history` bead + lives in the wisps table while remaining ordinary durable work. + Reaching it needed `include_infra`, which also drops template rows of + the named type — one silent undercount traded for another. + schema: + type: boolean + default: false - name: has_metadata_key in: query description: Only issues carrying this top-level metadata key. diff --git a/internal/workapi/BUILD.bazel b/internal/workapi/BUILD.bazel index 53633c13d..9372bab7c 100644 --- a/internal/workapi/BUILD.bazel +++ b/internal/workapi/BUILD.bazel @@ -39,6 +39,7 @@ go_test( name = "workapi_test", srcs = [ "bootstrap_test.go", + "count_skipwisps_test.go", "count_test.go", "delete_test.go", "detail_test.go", diff --git a/internal/workapi/count.go b/internal/workapi/count.go index 8d82b5413..00fd466a7 100644 --- a/internal/workapi/count.go +++ b/internal/workapi/count.go @@ -105,7 +105,7 @@ func BuildCountFilter(in issueops.CountRequest, cfg ListConfig) (types.IssueFilt if in.IncludeInfra { applyCountIncludeInfra(&filter, in.IssueType, cfg) - } else { + } else if !in.IncludeEphemeral { filter.SkipWisps = true } return filter, nil diff --git a/internal/workapi/count_skipwisps_test.go b/internal/workapi/count_skipwisps_test.go new file mode 100644 index 000000000..4727860f9 --- /dev/null +++ b/internal/workapi/count_skipwisps_test.go @@ -0,0 +1,136 @@ +package workapi + +import ( + "testing" + + "github.com/steveyegge/beads/issueops" +) + +// TestBuildCountFilter_IncludeEphemeral pins the plane knob on the count side. +// +// The wisps TABLE holds no_history beads (ephemeral = 0) alongside true wisps +// (ephemeral = 1), and the write path routes on STORAGE CLASS, not type — so a +// no_history task lives there while remaining ordinary durable work. A count +// that names a type therefore has to be able to reach that table, and until +// IncludeEphemeral existed the only way was IncludeInfra, which ALSO drops +// template rows of the named type: one silent undercount traded for another. +// +// The default before this change must stay byte-identical: durable plane only. +func TestBuildCountFilter_IncludeEphemeral(t *testing.T) { + cfg := ListConfig{} + + cases := []struct { + name string + in issueops.CountRequest + wantSkipWisps bool + }{ + { + name: "unfiltered count stays durable-only", + in: issueops.CountRequest{}, + wantSkipWisps: true, + }, + { + name: "a named type alone stays durable-only (the default before this change)", + in: issueops.CountRequest{IssueType: "task"}, + wantSkipWisps: true, + }, + { + name: "--include-ephemeral admits the plane", + in: issueops.CountRequest{IncludeEphemeral: true}, + wantSkipWisps: false, + }, + { + name: "--include-ephemeral with a named type admits the plane", + in: issueops.CountRequest{IssueType: "task", IncludeEphemeral: true}, + wantSkipWisps: false, + }, + { + name: "--include-infra still admits the plane on its own", + in: issueops.CountRequest{IssueType: "task", IncludeInfra: true}, + wantSkipWisps: false, + }, + } + + for _, tt := range cases { + t.Run(tt.name, func(t *testing.T) { + filter, err := BuildCountFilter(tt.in, cfg) + if err != nil { + t.Fatalf("BuildCountFilter: %v", err) + } + if filter.SkipWisps != tt.wantSkipWisps { + t.Errorf("SkipWisps = %v, want %v", filter.SkipWisps, tt.wantSkipWisps) + } + }) + } +} + +// TestCountAndListPlaneAgreement pins how count and list decide the PLANE for +// the same request — including the ONE case where they disagree. +// +// The name is not "AgreeOnThePlane" because they do not always agree, and a +// test that claimed they did would be asserting a property the code lacks. For +// an INFRA type they diverge: list reads the plane (applyTypeSuppressions +// exempts infra types) while count does not, so `bd count --type agent` answers +// 0 where `bd list --type agent` returns rows. +// +// That divergence predates the flag — the count arm is a bare `else { +// SkipWisps = true }`, so it answers 0 for an infra type with or without this +// change. It is pinned here, not fixed: the fix is a separate decision about +// what naming an infra type should admit, and this change deliberately alters +// nothing about the default arm. +// +// It asserts the ABSOLUTE expected value as well as the agreement. Agreement +// alone is satisfied by a regression that turns the flag into a no-op on BOTH +// builders, which is exactly the drift this exists to catch. +// +// It deliberately says nothing about the two answers being equal in ROWS: a +// count includes templates and a listing does not, with or without this flag. +// See issueops.CountRequest.IncludeEphemeral. +func TestCountAndListPlaneAgreement(t *testing.T) { + // CustomTypes admits "agent" into the workspace vocabulary (BuildListFilter + // rejects a type it does not know), and the default InfraSet already treats + // it as infra. Without the vocabulary the builders return an error and the + // infra cases below prove nothing. + cfg := ListConfig{CustomTypes: []string{"agent", "role", "message"}} + + for _, tt := range []struct { + name string + issueType string + includeEphemeral bool + wantCountSkip bool + wantAgree bool + }{ + {"default", "", false, true, true}, + {"named type", "task", false, true, true}, + {"include-ephemeral", "", true, false, true}, + {"named type + include-ephemeral", "task", true, false, true}, + // The known divergence. list reads the plane for an infra type, count + // does not; --include-ephemeral recovers count. + {"infra type diverges", "agent", false, true, false}, + {"infra type + include-ephemeral", "agent", true, false, true}, + } { + t.Run(tt.name, func(t *testing.T) { + listFilter, err := BuildListFilter(issueops.ListRequest{ + IssueType: tt.issueType, IncludeEphemeral: tt.includeEphemeral, + }, cfg) + if err != nil { + t.Fatalf("BuildListFilter: %v", err) + } + countFilter, err := BuildCountFilter(issueops.CountRequest{ + IssueType: tt.issueType, IncludeEphemeral: tt.includeEphemeral, + }, cfg) + if err != nil { + t.Fatalf("BuildCountFilter: %v", err) + } + if countFilter.SkipWisps != tt.wantCountSkip { + t.Errorf("count SkipWisps = %v, want %v", countFilter.SkipWisps, tt.wantCountSkip) + } + agree := listFilter.SkipWisps == countFilter.SkipWisps + if agree != tt.wantAgree { + t.Errorf("list SkipWisps=%v count SkipWisps=%v (agree=%v), want agree=%v — "+ + "a change to either builder alone lands here", + listFilter.SkipWisps, countFilter.SkipWisps, agree, tt.wantAgree) + } + }) + } +} diff --git a/issueops/counter.go b/issueops/counter.go index 53780573e..9886c0657 100644 --- a/issueops/counter.go +++ b/issueops/counter.go @@ -129,6 +129,29 @@ type CountRequest struct { // the historical `bd count` answer, kept exactly so a scripted caller reads // the same number it read yesterday. IncludeInfra bool + + // IncludeEphemeral admits the EPHEMERAL PLANE — the wisps TABLE — and + // admits nothing else. It is the plane knob on its own: exactly the first + // of IncludeInfra's four changes, with none of the other three. + // + // It exists because there was no way to ask for that one thing. The write + // path routes on STORAGE CLASS, not type (dolt's useWispsTable is + // `Ephemeral || NoHistory || WispType != "" || IsInfraType`), so a + // no_history task lives in the wisps table while remaining ordinary durable + // work. Counting it needed IncludeInfra, which ALSO drops template rows of + // the named type — a silent undercount traded for a silent undercount. + // + // Same meaning as ListRequest.IncludeEphemeral (see issueops/reader.go): + // both admit the same PLANE under the same filters. It does NOT promise the + // two answers are equal — a count and a listing already differ on TEMPLATES + // without this flag, and still do with it. A count includes template rows + // unless IncludeInfra excludes them; a listing excludes them unless + // IncludeTemplates admits them. That predates this field and is unchanged by + // it; only IncludeInfra sets out to reconcile cardinality, and it pays for + // that with three changes beyond the plane. + // + // Unset, the count is durable-plane only: the historical answer, unchanged. + IncludeEphemeral bool } // CountResult is the cardinality of the matching set.