feat(count): Counter scope — ParentID, NoParent, ExcludeTypes, ExcludeStatus (issues.count.scope) (#7199)

* feat(httpapi): wire-shape signal — wire_revision, floor header, golden digest, param tokens

S0 of the HTTP role-parity program: give a client a single place to learn
whether this build's wire shape has moved under it, and give CI a gate that
catches an undocumented move.

- GET /v0/beads/context reports wire_revision (bumps only on a non-additive
  response-shape change) and min_client_wire_revision. An optional
  Bd-Wire-Revision request header lets a client declare the revision it was
  built for; checkWireRevision refuses a declared revision below the floor
  with 400 invalid_argument/reason=wire_revision_unsupported and a
  min_wire_revision field, on every route but /healthz (wireRevisionExempt) —
  including the identity handshake, where catching the mismatch is cheapest.
  Absent header is today's behavior; malformed value is invalid_value, never
  wire_revision_unsupported. The floor lives in Server.minClientWireRevision
  (defaulting to the MinClientWireRevision constant) so a test can raise it.
- internal/httpapi/wireshape: a golden digest over every response's every
  content-type schema (including application/problem+json) across the whole
  spec, keyed by schema+member. TestWireShapeDigest fails closed when a
  member's JSON name or type changes without wire_revision bumping to match;
  regenerate with `go run ./internal/httpapi/wireshape/cmd/gendigest`.
- GET /v0/beads/issues' `sort` parameter now carries the issues.listSort
  capability token, the same convention `capabilities` entries use.
  TestNewParameterOnExistingOperationHasABehaviorToken requires every new
  parameter on an existing operation to carry one, checked against a
  write-once grandfather baseline (testdata/pretoken_parameters.json) of
  parameters that predate the rule; TestUntokenedParameterRuleFires proves
  the checker itself against a synthetic fixture.
- Docs: engdocs/design/bd-serve-v0.md gets a "The wire-shape signal" section;
  CHANGELOG.md gets an Added entry.

Live-mutated and reverted three RED demonstrations during development:
retyping api_version in the spec failed TestWireShapeDigest; short-circuiting
checkWireRevision's floor comparison failed
TestWireRevisionBelowFloorRefusesEveryEnforcedRoute; adding an untokened
query parameter to listIssues failed
TestNewParameterOnExistingOperationHasABehaviorToken. All three now pass
against the unmutated tree.

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

* fix(httpapi): rename issues.listSort to issues.list.sort, harden token rule

Opus review of 12c5144ca (HIGH-1, MEDIUM-5):

- Rename the capability token issues.listSort -> issues.list.sort to match
  bd-enterprise's client (httpstore/wire/handshake.go:121, DESIGN.txt S4e),
  and widen capabilityToken to accept an optional third segment.
- untokenedParameters() now requires the extracted token to be one
  Capabilities() actually serves, not just backtick-shaped text. This
  catches real false positives that existed in the spec already
  (workapi.DefaultReadyLimit, status.custom) which only shape-matched the
  old regex; they're added to the pretoken baseline as genuinely
  pre-existing untokened parameters.
- Extend the rule to request body members (new
  testdata/pretoken_request_body_members.json baseline) and exempt
  brand-new operations via a frozen testdata/pretoken_operations.json
  snapshot.
- Add TestPretokenBaselinesNeverGrow pinning all three baseline sizes so
  a future change can't hand-add an exemption instead of a token.
- Update spec prose for the widened rule scope.

go test ./internal/httpapi/... and the reviewer's pmut.py all pass as
expected: plain/bogus modes go RED, reuse (real-but-unrelated token) stays
green, matching the review's literal ask ("a token must be one advertised
by Capabilities()").

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

* fix(wireshape): close four digest-coverage gaps, add gendigest write guard

Opus review of 12c5144ca (HIGH-2, MEDIUM-4). The digest only tracked
Type/Format/Enum/Required on direct properties, missing:

- nullable: true (never read at all)
- array item shape (Issue.labels items string->integer was invisible;
  only object-shaped items got recursed into)
- additionalProperties value shape (IssueCount.groups)
- request bodies entirely (Compute() only walked responses, so
  DeleteIssuesRequest.expected_version string->integer, the other half
  of #6053, was invisible)

Also added defensive oneOf flattening alongside the existing allOf merge
(dormant today -- grep confirms this spec uses oneOf nowhere -- but no
longer silently invisible if that changes).

Extracted the golden-vs-computed comparison into wireshape.Compare(),
shared by TestWireShapeDigest and the new wireshape.SafeToWrite(), which
gendigest now calls before writing: it refuses to overwrite golden.json
with changed/removed entries unless the candidate's wire_revision is
strictly greater than the existing golden's. Pure additions always write.
TestSafeToWrite exercises both guard directions.

golden.json is regenerated. This single regen is a one-time exception to
the new guard, done by writing the digest directly rather than through
gendigest: confirmed via a throwaway diff (not checked in) that every one
of the 57 "changed" entries differs only in the NEW fields the wider walk
now populates (ItemType/ItemFormat/Nullable/AdditionalProps*) -- every
pre-existing Type/Format/Required/Enum value is byte-identical. Nothing on
the wire changed; the measurement got more precise. Bumping
CurrentWireRevision for this would have written a false "the protocol
changed here" entry into the revision history table. Going forward, any
REAL change the guard now reports uses the normal bump-then-regenerate
path, same as before.

Verified against the reviewer's mut.py: nested_type, nullable,
nullable_issue, array_items, addlprops, request_body and format all go RED
on TestWireShapeDigest, each reverted after confirming.

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

* fix(httpapi): make bd_version wire_revision inference advisory

Opus review of 12c5144ca (HIGH-3). The spec told a client inferring
wire_revision from bd_version to use the release cutoff >= 1.3.0, and said
nothing about what happens when that inference is wrong -- which it
demonstrably is for real builds already in the field:

- main builds up to commit b3ef65c85 report bd_version 1.2.2 (below any
  1.3.0 cutoff) while already sending the string-typed revision/
  expected_version shape (#6053).
- 1.3.0-rc.N pre-release builds sort BELOW the release cutoff 1.3.0 under
  plain string comparison despite already carrying the string shape.
- The bd-enterprise compatibility line at d3ab32773462 reports bd_version
  1.1.0 while also sending strings.

Moved the cutoff to >= 1.3.0-rc.1 (compared as semver-with-prerelease,
which at least captures the rc builds), documented both named exceptions
inline, and made the whole inference explicitly ADVISORY: a client must
accept revision/expected_version as either a string or a number whenever
wire_revision is absent (or probe directly) rather than let the inferred
value choose a decoder, and must never refuse solely because the inferred
revision is 0. Mirrored into engdocs/design/bd-serve-v0.md.

This is spec/doc prose only -- there is no server-side inference code to
change, since this server always sends wire_revision directly; the
inference is guidance for clients reading a pre-signal server's response
(this server, past builds, or an unrelated implementation).

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

* fix(httpapi): LOW-7/8/9/10 review follow-ups for wire-revision signal

LOW-7: WireRevisionUnsupported now also sets Problem.wire_revision (this
server's CurrentWireRevision) and Problem.bd_version on the
wire_revision_unsupported refusal, alongside the existing
min_wire_revision, so a client logging the refusal has this server's
full self-description without a second /v0/beads/context call.

LOW-8: gazelle + make bazel-sync add the BUILD.bazel entries the prior
commits were missing: wire_revision.go/wire_revision_test.go in
internal/httpapi's srcs, new BUILD.bazel files for wireshape and
wireshape/cmd/gendigest, and a testdata glob on httpapi's go_test so
the pretoken_*.json baselines are visible under `bazel test`. Verified
with `bazel build //internal/httpapi/...` and
`bazel test //internal/httpapi/... --test_env=BEADS_TEST_SKIP=dolt`
(both green) and `python3 tools/bazel/go_srcs.py --check` (clean).

LOW-9: narrowed CHANGELOG.md and engdocs/design/bd-serve-v0.md to
describe the digest's actual final coverage (format/enum/required/
nullable, array items, additionalProperties, request bodies, $ref/
allOf/oneOf recursion, the SafeToWrite revision-bump guard) and the
token rule's actual final shape (three pinned baselines, request-body
members, Capabilities()-membership validation, new-operation
exemption) instead of the original, narrower claims.

LOW-10: Bd-Wire-Revision now parses via a strict decimal-only
parseStrictNonNegativeInt (no leading '+', no leading zero except a
bare "0") instead of strconv.Atoi alone, so two different header
bytes can no longer name the same revision. New malformed-header test
cases: "+1", "01", "007".

Regenerated apigen/types.gen.go (make api-gen) for the new Problem
fields and wireshape/testdata/golden.json (go run
.../wireshape/cmd/gendigest) for the two new additive Problem members;
the latter wrote cleanly through SafeToWrite itself, since both are
pure additions.

go test ./... and bazel test //internal/httpapi/... both green.

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

* fix(httpapi): re-review LOW follow-ups — retirement test, gendigest -init, docs

1. TestRetiredRevisionsStayBelowTheFloor pins the PRESENCE guarantee the
   wire_revision property doc relies on: CurrentWireRevision >= 2 (so 0
   and 1 stay permanently retired) and MinClientWireRevision <=
   CurrentWireRevision (so this build's own floor never refuses every
   request against itself).

2. gendigest now refuses to create a golden.json that does not exist yet
   unless run with -init. Previously a missing file (moved testdata,
   wrong path, accidental delete) was indistinguishable from a real first
   run and silently wrote a fresh golden with no revision history checked
   against anything. writeGolden() is extracted out of main() so this is
   covered directly: TestWriteGoldenRequiresInitWhenMissing,
   TestWriteGoldenInitCreatesWhenMissing,
   TestWriteGoldenIgnoresInitWhenGoldenExists (the existing-golden path is
   still governed only by SafeToWrite, -init or not).

3. Narrowed the two remaining stale claims that still described the
   digest's original, narrower coverage: the wire_revision property's
   prose in openapi.v0.yaml (regenerated into apigen/types.gen.go via
   make api-gen) and wireshape/doc.go now both list nullable, array item
   shape, additionalProperties value shape, request bodies, and
   $ref/allOf/oneOf recursion, plus the new -init guard.

go test ./internal/httpapi/... and make api-check both green;
bazel test //internal/httpapi/... (httpapi, wireshape, and the new
gendigest test target) green; python3 tools/bazel/go_srcs.py --check
clean.

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

* feat(wireshape): cover operation parameters in the wire-shape digest

The digest previously walked only response and request-body schemas, so a
type, enum, required, or removal change on one of the spec's 138 operation
parameters (123 query, 14 path, 1 header) passed the gate silently — the
open item from PR review on #7182.

Each parameter is now recorded as its own Entry, keyed by
"param:"+operationId / location+":"+name (operation-scoped, not
schema-scoped, since two operations' same-named parameter are independent
wire contracts), capturing type, array item shape, enum, required, style,
explode and default. Adding a parameter stays additive; removing,
retyping, narrowing its enum, or changing required/style/explode/default
now trips SafeToWrite exactly like a response or request-body change.

Verified against the live spec: retyping listIssues' `limit` query
parameter from integer to string now fails TestWireShapeDigest (confirmed
red, then reverted — not part of this commit). golden.json regenerated via
gendigest; the new parameter entries are a pure addition, no wire_revision
bump needed. Added TestParameterMutationsAreCaught (remove/retype/narrow-
enum against real golden entries) and updated wireshape's doc.go, the
`wire_revision` spec prose, and the CHANGELOG to describe the new
coverage.

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

* fix(wireshape): review fixes — stale-golden and lowered-revision arms, effective param serialization, digest boundary

Maintainer fixup from the adopt-pr review loop (iterations 1 and 2), on
top of e17ba924f.

- goldenDrift (A, I): TestWireShapeDigest's comparison moves into a
  goldenDrift helper. An addition alongside a moved wire_revision no
  longer passes with a stale golden: it asks for a regenerate, as a
  changed or removed entry after a bump already did. Every message now
  names response/request-body members AND parameters, and TestGoldenDrift
  pins each arm. This takes only the test half of the stranded fixup
  (adopt-pr/bd-47kdge/stranded-fixup-528cd6095); its doc half, which says
  parameters are outside the digest, is false since e17ba924f and is not
  replayed (J).
- Lowered wire_revision (D): a CurrentWireRevision LOWER than the
  golden's is a wrong constant, not a stale golden, so goldenDrift says to
  restore it instead of regenerating, and SafeToWrite (so gendigest)
  refuses any write at a lower revision, whatever the entries.
- Effective style/explode (B): walkParam records style and explode with
  OpenAPI 3.0's defaults filled in (form for query/cookie, simple for
  path/header; explode defaults to style == form). Adding `explode: false`
  to a query array that relied on form's implicit explode is now a
  changed entry, while spelling out a default changes nothing.
  testdata/golden.json is regenerated with -init: 111 parameter entries
  change only in style/explode (96 to form/true, 15 to simple), 828
  entries before and after, wire_revision stays 2. The golden is new in
  this PR and unreleased, so this needs no bump.
- TestWalkParam (H): a package-internal table test
  (wireshape_internal_test.go) pins every field walkParam extracts,
  through a computeFrom(document, revision) seam that Compute now wraps:
  per-location defaults, $ref'd parameters and items, format, nullable and
  default, content parameters, and the nil returns.
  TestEffectiveSerializationIsCompared pins B end to end through Compare
  and SafeToWrite. BUILD.bazel embeds the library in the go_test, which is
  gazelle's own output.
- Required inputs and the digest boundary (C, E, F; docs only): all five
  prose surfaces (openapi.v0.yaml's wire_revision description and the
  regenerated apigen/types.gen.go, wireshape/doc.go, CHANGELOG.md,
  engdocs/design/bd-serve-v0.md) now say that a new REQUIRED request
  input is recorded as an ordinary addition and needs its own review,
  that value constraints and member-level composition are outside the
  digest, and that object and content parameters are recorded only as
  their container. bd-serve-v0.md also gains the parameter coverage it
  was missing.
- G: a brand-new operation is permanently exempt from the
  capability-token rule; its own review decides its capability story.
- Iteration 2 (nit): walkParam's comment now says that the location
  default it records as a `content` parameter's style and explode is a
  placeholder, since OpenAPI 3.0 applies style and explode only to a
  parameter described by `schema`. All 138 operation parameters in the
  spec use `schema`, so the golden does not change.

Validated: go test ./internal/httpapi/... (gms_pure_go), make api-check,
go vet for linux/windows/darwin, gofmt, git diff --check, gazelle on the
package (no drift), make bazel-sync-check, and bazel test
//internal/httpapi/wireshape/... in the local processwrapper sandbox
(2 of 2 pass). Overlay mutation probes: dropping the added-after-bump
arm, the lowered-revision arm, SafeToWrite's lowered check, or the
effective-default fill each turns the new tests red.
Iteration 2 changes only that comment; go test
./internal/httpapi/wireshape/... (gms_pure_go), go vet, gofmt and git
diff --check pass again.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(count): add Counter scope fields (S8) — ParentID, NoParent, ExcludeTypes, ExcludeStatus

Extends issueops.CountRequest with ParentID, NoParent, ExcludeTypes and
ExcludeStatus, closing the gap where bd count could not express the
filters bd list already has, forcing downstream consumers like gc to
fall back to listing everything just to get a count.

- issueops.Counter: four new CountRequest fields, documented against the
  List equivalents they mirror (ParentID/ExcludeTypes) or newly define
  (NoParent, ExcludeStatus has no List counterpart). Status "all" is
  pinned as equivalent to unset, matching BuildListFilter's own "all" and
  preserving count/list cardinality parity (the role's reason to exist).
- internal/workapi.BuildCountFilter: maps the four fields onto the one
  types.IssueFilter builder all three storage legs (dolt, embeddeddolt,
  uow) already share via internal/storage/issueops and sqlbuild, so no
  per-leg storage code was needed.
- cmd/bd: --parent, --no-parent, --exclude-type, --exclude-status flags.
- HTTP: adds parent/no_parent/exclude_type/exclude_status to GET
  /v0/beads/issues:count, behind the new issues.count.scope behavior
  token (routes.go), wired in reads.go's countFilters, documented in
  openapi.v0.yaml with per-parameter tokens and an extended capabilities
  description. gendigest confirms a byte-identical golden.json: query
  parameters are outside the wire-shape digest's scope, so this is a
  zero-diff, no-revision-bump change as expected.
- backend/conformance: four new Counter contract cases (ParentID scoping,
  NoParent's edge-only semantics vs ParentID's edge-or-dotted-id match,
  ExcludeTypes composing with include_infra's own exclusions, and
  ExcludeStatus), run identically against all three storage legs via a
  new CounterFixture.AddDependency hook shared with ReaderFixture.

Verified: go build ./...; go test ./internal/httpapi/... ./internal/workapi/...
./issueops/... and the Counter contract on all three legs (dolt via
testcontainers, embeddeddolt, uow via local dolt binary); make api-gen
(additive-only apigen diff) and make api-check; go vet and golangci-lint
clean; gofmt clean; gazelle diff empty (no new files/imports). Mutation
testing: dropping issues.count.scope from behaviorCapabilities turns
TestCapabilitiesAdvertiseEveryImplementedOperation,
TestSpecCapabilityVocabularyMatchesTheRouteTable and
TestNewParameterOnExistingOperationHasABehaviorToken red; no-op'ing
ExcludeStatus in BuildCountFilter turns
TestBuildCountFilterExcludeStatusTakesNamesAsWritten and the
embeddeddolt ExcludeStatusNarrowsThePredicate conformance case red. Both
reverted and reconfirmed green.

Deviation: DESIGN.txt's literal text would make count --status all an
ErrValidation; shipped behind a test and a doc comment instead, since
"all" already means "every status" on both count and list and rejecting
it would break the count/list parity this role exists to guarantee.

S3/S4 note: no OSS HTTP client exists yet to enforce capability-token
skew. A doc comment on CapIssuesCountScope in routes.go specifies the
required behavior once one lands: check issues.count.scope against the
cached handshake capabilities and refuse locally with a typed
ErrUnsupported{Capability} before sending any of the four new params to
an older server.

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

* fix(count): S8 review follow-ups — refusal parity, exclude-status validation, doc fixes, parity tests

Addresses the Opus review's six required changes for S8 (bd count scope
fields):

1. BuildCountFilter now refuses ParentID+NoParent together as ErrValidation,
   matching bd list's CLI refusal wording; wired through the role, the CLI,
   and invalid_argument classification in internal/httpapi/reads.go.
2. Status:"all" is documented in DESIGN.txt as every status, matching List's
   no-filter reading (count/list cardinality parity) — a coordinator decision
   recorded in beads-design/DESIGN.txt, outside this worktree.
3. ExcludeStatus names are now validated against the workspace vocabulary
   (built-in statuses plus workspace-custom ones); an unknown name is
   ErrValidation instead of a silent no-op, since a typo here would overcount.
4. Fixed openapi.v0.yaml and issueops/reader.go doc claims about bd list
   --parent's default tree-walk vs. the one-level role answer that bd count
   --parent agrees with (confirmed by tracing list_show_filter_modes.go); fixed
   an Oxford-comma nit in routes.go and the spec.
5. Added storage-level count == len(List) parity tests for ParentID, NoParent
   and ExcludeTypes (List has no ExcludeStatus counterpart), plus wisp-child
   and closed-child contract cases, across all three backends (dolt,
   embeddeddolt, uow). CounterFixture gained a List hook for this.
6. Extended the routes.go skew note: gc's ErrCountUnsupported fallback to List
   is now named explicitly, with a note that S3/S4 must add a skew test that
   masks the token and asserts the fallback fires.

Also fixed RunCounterExcludeStatusNarrowsThePredicate's now-stale "unrecognized
status excludes nothing" assertion to expect ErrValidation instead.

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

* fix(count): PR #7199 review follow-ups — exclude-status config load, ParentID doc swap

Addresses bee's REQUEST-CHANGES on gastownhall/beads#7199 (S8):

1. BLOCKER: storecounter.filter and uow.countFilter only loaded the
   workspace list config when IncludeInfra was set, so BuildCountFilter's
   ExcludeStatus validation refused a workspace's own custom status unless
   the caller also passed the unrelated IncludeInfra flag. Both legs now
   load the config when IncludeInfra OR len(ExcludeStatus) > 0, with
   comments corrected to say so. Added leg-level regression tests (the
   conformance fixture cannot drive a workspace-configured custom status)
   on embeddeddolt and uow, reproducing the reviewer's CLI repro directly,
   plus an HTTP-level probe in cmd/bd's real-Dolt proxied count test.
2. issueops.ReadyRequest.ParentID's comment had been overwritten with the
   one-level direct-children wording that belongs to ListRequest.ParentID;
   Ready actually walks all descendants via GetDescendantIDsInTx (GH#3396).
   Restored the descendants comment on ReadyRequest.ParentID and moved the
   one-level explanation to ListRequest.ParentID, which had none.

Verified: make api-check; dolt-server, embeddeddolt and uow Counter
contract legs (BEADS_TEST_DOLT_SERVER=local with a pinned dolt binary for
uow; Docker for the dolt-server leg); the new proxied HTTP exclude_status
probe (BEADS_TEST_PROXIED_SERVER=1).

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

* chore(wireshape): add the countIssues scope parameters to the wire-shape golden

#7182 now digests operation parameters. The four new issues:count parameters
(parent, no_parent, exclude_type, exclude_status) are additive entries, so no
wire_revision bump is needed; regenerated with gendigest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(conformance): register the S8 count-scope cases with RunRoleContracts (adopt-pr #7199)

The PR adds nine RunCounter* contract cases to counter_contract.go and wires
them into the three in-tree TestCounterContract legs, but not into the
Counter row of roleContractCases. TestRoleContractCasesCoverEveryContractCase
derives the expected set from source, so it fails on the PR head, and an
external backend running RunRoleContracts would never see the new cases.

Register them in source-declaration order (after
RunCounterAnUnknownStatusMatchesNothing), which the same guard enforces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(count): correct the S8 scope docs the review found wrong (adopt-pr #7199)

Comment and spec-description fixes only; no behavior change. Review-loop
iterations 1 and 2 of the #7199 relaunch.

- ListRequest.ParentID (issueops/reader.go) said "DIRECT children only
  ... the same one-level clause". The sqlbuild clause has two arms and
  neither walks: the parent-child edge arm stops at one level, but the
  dotted-prefix arm (`id LIKE CONCAT(?, '.%')` for rows with no
  parent-child edge) reaches every edge-less dotted id at any depth, which
  RunReaderListParentReachesEveryDescendantAndOnlyItsOwn pins with an
  edge-less X.1.1. State both arms, and say the CLI tree view re-runs the
  clause against the store once per level (findAllDescendants calls
  SearchIssues, not the role). Document ListRequest.NoParent, which had no
  doc. The contributor's ReadyRequest.ParentID text is kept; only its
  cross-reference to this field changes from "one-level" to "non-walking".
- CountRequest.NoParent (issueops/counter.go) and the count flag comment
  (cmd/bd/count.go) said NoParent counts rows with "neither" an edge nor a
  dotted prefix. Its SQL checks only the edge table, so an edge-less X.1
  is counted by both --parent X and --no-parent, as bd list lists it.
- RunCounterExcludeStatusNarrowsThePredicate's header said an
  unrecognized name "excludes nothing rather than failing" while its body
  asserts ErrValidation. The header now matches the body.
- The OpCountIssues entry in problem.go's operationCodes said the role has
  "exactly one reachable refusal". It has three: an invalid metadata key,
  an unrecognized exclude_status name, and parent with no_parent (named
  no_parent), all classified by invalidFilterParam. The code set is
  unchanged.
- BuildCountFilter's header said cfg is "only read under IncludeInfra".
  It is also read to validate ExcludeStatus against the workspace's
  custom statuses, which is why both callers load it when ExcludeStatus is
  non-empty.
- The countIssues `parent` description in openapi.v0.yaml carried the
  same one-level claim as ListRequest.ParentID; it now states both arms.
  types.gen.go is regenerated (make api-gen); make api-check passes.

Review fixes (iteration 2), still comment and spec text only:
- The iteration-1 problem.go rewrite called all three count refusals
  ErrValidation. Only the exclude_status and parent-with-no_parent
  refusals wrap issueops.ErrValidation (internal/workapi/count.go). The
  metadata-key refusal is ValidateMetadataFilters' plain fmt.Errorf
  chain, so errors.Is(err, ErrValidation) is false for it; it reaches the
  wire as a 400 only because invalidFilterParam matches message prefixes.
  The comment now says that, so a later move to typed errors cannot trust
  it and demote the metadata-key refusal to a 500. The sentinel itself is
  not added here: ValidateMetadataFilters is shared with the list and
  ready builders.
- invalidFilterParam's comment on the count rows pointed at the
  metadata-key rows as "above"; they come after it in the switch.
- The countIssues `parent` description said the CLI tree mode walks
  "every edge-linked descendant". findAllDescendants re-runs the full
  two-arm predicate per level, so it also descends through edge-less
  dotted ids; it now says "every descendant reachable through either
  arm". types.gen.go is regenerated; make api-check passes.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(wireshape): re-record the count scope params under the base's param digest (adopt-pr #7199)

The base branch (feat/wire-revision-signal, #7182 be1f0bad72) now digests
the effective style/explode of scalar query parameters. This PR's golden
entries for countIssues query:parent and query:no_parent were written by
the old algorithm, so after the base refresh TestWireShapeDigest reported
them as "changed without a wire_revision bump".

No bump is owed: all four count-scope entries (parent, no_parent,
exclude_type, exclude_status) are additions this PR introduces and are
absent from the base golden. golden.json was reset to the base copy and
regenerated with `go run ./internal/httpapi/wireshape/cmd/gendigest`. The
result is four pure additions against the base (+35/-0); parent and
no_parent gain "style": "form" and "explode": true, and wire_revision
stays 2.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: place the PR's new embedded counter test in the shard manifest

TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra,
added to internal/storage/embeddeddolt in f23bf5ddbf, is a new top-level
embedded storage test. The 15-shard block of
.github/scripts/embedded-storage-test-shards.txt must list every
discovered test exactly once. Without the entry,
TestStorageEmbeddedShardManifestGeneratorNotStale (scripts/) fails, both
on the reviewed head 89a387de6c and on the merge. CI never ran the check
on this PR: pr.yml runs only for PRs based on main, release/** or
hotfix/**, and this PR was based on feat/wire-revision-signal until the
retarget.

Generated with
`python3 scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration --write`.
The incremental write adds this one line, in shard 4, and moves no other
test.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
This commit is contained in:
Julian Knutsen 2026-10-05 02:57:14 -07:00 • committed by GitHub
commit 4af58c97fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 1391 additions and 37 deletions

View file

@ -211,6 +211,7 @@
15 3 TestUpdateMergeOps_DoltEngine_TwoIssues
15 3 TestWithPeerAuth_RestoresAbsentEnv
15 4 TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra
15 4 TestEmbeddedBatchCloserSettlesTheDependersOfWhatItClosed
15 4 TestEmbeddedBlockedRecheckSettlesWhatTheWriteRecorded
15 4 TestEmbeddedClaimIssueWrapperClaimsTheWispPlane

View file

@ -57,6 +57,19 @@ type CounterFixture struct {
// A nil hook means "this backend cannot observe history", and the case
// that needs it SKIPS rather than passing quietly.
CountHistory func(context.Context) (int, error)
// AddDependency seeds one dependency edge, the same hook
// ReaderFixture/DependencyEditorFixture take it from (role_fixture_kit's
// shared AddDependency). It exists here only for the ParentID/NoParent
// scope cases (S8): NoParent excludes by PARENT-CHILD EDGE alone
// (sqlbuild/filter.go), unlike ParentID's dotted-id-prefix fallback, so
// pinning it needs a real edge and not just a naming convention.
AddDependency func(context.Context, *types.Dependency, string) error
// List runs the List role's query directly (the store's IssueReader), so
// the storage-level parity cases below (S8 review, follow-up #5) can
// compare Count's answer against len(List's rows) for the same scope
// without going through a second builder. A nil hook skips those cases
// rather than failing: not every backend wiring has a Reader to hand.
List func(context.Context, publicops.ListRequest) (publicops.IssuePage, error)
}
// RunCounterCountsTheDurablePlaneByDefault pins counter.go:123-126 from the
@ -176,6 +189,323 @@ func RunCounterAnUnknownStatusMatchesNothing(t *testing.T, ctx context.Context,
assertCounterTotal(t, ctx, fixture, scope, 0)
}
// RunCounterParentIDScopesToChildren pins CountRequest.ParentID (counter.go,
// S8): restricted to ONE issue's children, reached two ways at once, exactly
// as ListRequest.ParentID is (sqlbuild/filter.go) — a parent-child dependency
// edge, OR (for a row with no such edge) a dotted-id prefix match. The parent
// itself, an unrelated row and a same-prefix DECOY (sibling id with no
// separator, e.g. "parent2") are all seeded so neither arm can pass by
// over-matching.
func RunCounterParentIDScopesToChildren(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-parentid-parent"
byEdge := fixture.IssuePrefix + "-parentid-byedge"
byDotted := parent + ".1"
decoy := parent + "x"
unrelated := fixture.IssuePrefix + "-parentid-unrelated"
for _, id := range []string{parent, byEdge, byDotted, decoy, unrelated} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
requireCounterAddDependency(t, fixture)
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: byEdge, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", byEdge, parent, err)
}
scope := counterScope(parent, byEdge, byDotted, decoy, unrelated)
scope.ParentID = parent
// Both children count; the parent, the decoy and the unrelated row do not.
assertCounterTotal(t, ctx, fixture, scope, 2)
}
// RunCounterNoParentExcludesChildren pins CountRequest.NoParent
// (counter.go, S8): restricted to rows with NO parent-child edge.
//
// Unlike ParentID, NoParent's SQL clause (sqlbuild/filter.go) checks ONLY the
// parent-child dependency table, not the dotted-id convention — a row that is
// a dotted-id child with no edge at all still passes NoParent. That asymmetry
// is exactly what the "byDotted" row below pins: it is excluded from
// ParentID's answer by nothing (RunCounterParentIDScopesToChildren already
// admits it), but NoParent admits it too, because it carries no edge.
func RunCounterNoParentExcludesChildren(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-noparent-parent"
child := fixture.IssuePrefix + "-noparent-child"
byDotted := parent + ".1"
for _, id := range []string{parent, child, byDotted} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
requireCounterAddDependency(t, fixture)
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
scope := counterScope(parent, child, byDotted)
assertCounterTotal(t, ctx, fixture, scope, 3)
scope.NoParent = true
// child is excluded (has an edge); parent and byDotted remain (neither
// carries a parent-child edge, and NoParent does not consult the dotted
// naming convention at all).
assertCounterTotal(t, ctx, fixture, scope, 2)
}
// RunCounterExcludeTypesNarrowsThePredicate pins CountRequest.ExcludeTypes
// (counter.go, S8): named types are excluded from the count, composing with
// (rather than replacing) IncludeInfra's own "gate" exclusion.
func RunCounterExcludeTypesNarrowsThePredicate(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
task := fixture.IssuePrefix + "-extype-task"
chore := fixture.IssuePrefix + "-extype-chore"
gate := fixture.IssuePrefix + "-extype-gate"
seedCounterIssue(t, ctx, fixture, counterSeed(task))
choreSeed := counterSeed(chore)
choreSeed.IssueType = types.TypeChore
seedCounterIssue(t, ctx, fixture, choreSeed)
gateSeed := counterSeed(gate)
gateSeed.IssueType = types.IssueType("gate")
seedCounterIssue(t, ctx, fixture, gateSeed)
scope := counterScope(task, chore, gate)
assertCounterTotal(t, ctx, fixture, scope, 3)
scope.ExcludeTypes = []string{"chore"}
assertCounterTotal(t, ctx, fixture, scope, 2)
// Composes with IncludeInfra's own default gate exclusion: both the
// explicit chore exclusion and the include-infra gate exclusion apply at
// once, leaving only task.
scope.IncludeInfra = true
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterExcludeStatusNarrowsThePredicate pins CountRequest.ExcludeStatus
// (counter.go, S8): a Count-only field with no List counterpart. Named
// statuses are excluded, and — UNLIKE Status — an unrecognized name is
// refused as ErrValidation rather than excluding nothing, because a typo
// would silently overcount (counter.go).
func RunCounterExcludeStatusNarrowsThePredicate(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
open := fixture.IssuePrefix + "-exstatus-open"
closed := fixture.IssuePrefix + "-exstatus-closed"
seedCounterIssue(t, ctx, fixture, counterSeed(open))
closedSeed := counterSeed(closed)
closedSeed.Status = types.StatusClosed
seedCounterIssue(t, ctx, fixture, closedSeed)
scope := counterScope(open, closed)
assertCounterTotal(t, ctx, fixture, scope, 2)
scope.ExcludeStatus = []string{"closed"}
assertCounterTotal(t, ctx, fixture, scope, 1)
// Unlike Status and IssueType, ExcludeStatus IS validated (S8 review,
// follow-up #3): a misspelled entry would silently exclude nothing and
// OVERCOUNT, so an unrecognized name is refused as ErrValidation instead
// of treated as a no-op.
scope.ExcludeStatus = []string{"no-such-status"}
if _, err := fixture.Counter.Count(ctx, scope); !errors.Is(err, publicops.ErrValidation) {
t.Errorf("Count with an unrecognized exclude-status = %v, want ErrValidation", err)
}
}
// requireCounterAddDependency skips a case that needs a real parent-child
// edge when the fixture offers no way to create one, rather than failing with
// a nil-pointer call — mirroring counterHistoryCount's optional-hook pattern.
func requireCounterAddDependency(t *testing.T, fixture CounterFixture) {
t.Helper()
if fixture.AddDependency == nil {
t.Skip("fixture cannot seed a dependency edge: AddDependency is nil")
}
}
// requireCounterList skips a case that needs the List role when the fixture
// offers no way to reach it, mirroring requireCounterAddDependency.
func requireCounterList(t *testing.T, fixture CounterFixture) {
t.Helper()
if fixture.List == nil {
t.Skip("fixture cannot run the List role: List is nil")
}
}
// assertCounterMatchesList compares Count's Total against len(List's rows)
// for the same scope, with List's AllFlag and IncludeAllTypes both set so
// List's own default exclusions (status, pinned, template, gate, infra-plane)
// are lifted exactly as far as Count's own default lifts none of them
// (workapi.BuildCountFilter's doc, count.go) — the one combination that
// makes the two cardinalities comparable at all for an arbitrary scope.
//
// This is a DIFFERENT check than
// TestBuildCountFilterParentFieldsMatchListFilter
// (internal/workapi/count_test.go), which compares the two FILTERS a shared
// request builds without touching a store; this one runs both roles against
// a real backend and compares what they actually return (S8 review, follow-up
// #5).
func assertCounterMatchesList(t *testing.T, ctx context.Context, fixture CounterFixture, idFilter, parentID string, noParent bool, excludeTypes []string) {
t.Helper()
countReq := publicops.CountRequest{
IDFilter: idFilter,
ParentID: parentID,
NoParent: noParent,
ExcludeTypes: excludeTypes,
}
total := counterTotal(t, ctx, fixture, countReq)
listReq := publicops.ListRequest{
IDFilter: idFilter,
ParentID: parentID,
NoParent: noParent,
ExcludeTypes: excludeTypes,
AllFlag: true,
IncludeAllTypes: true,
}
page, err := fixture.List(ctx, listReq)
if err != nil {
t.Fatalf("List(%+v): %v", listReq, err)
}
if got := int64(len(page.Items)); got != total {
t.Errorf("Count(%+v) = %d, len(List(%+v).Items) = %d, want equal", countReq, total, listReq, got)
}
}
// RunCounterParentIDMatchesListCardinality pins the storage-level half of
// CountRequest.ParentID's promise (S8 review, follow-up #5a): for one scope,
// Count's Total equals len(List's rows) for the equivalent ParentID scope.
func RunCounterParentIDMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-parity-parentid-parent"
byEdge := fixture.IssuePrefix + "-parity-parentid-byedge"
byDotted := parent + ".1"
unrelated := fixture.IssuePrefix + "-parity-parentid-unrelated"
for _, id := range []string{parent, byEdge, byDotted, unrelated} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: byEdge, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", byEdge, parent, err)
}
idFilter := counterScope(parent, byEdge, byDotted, unrelated).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, parent, false, nil)
}
// RunCounterNoParentMatchesListCardinality pins the storage-level half of
// CountRequest.NoParent's promise (S8 review, follow-up #5a).
func RunCounterNoParentMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-parity-noparent-parent"
child := fixture.IssuePrefix + "-parity-noparent-child"
byDotted := parent + ".1"
for _, id := range []string{parent, child, byDotted} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
idFilter := counterScope(parent, child, byDotted).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, "", true, nil)
}
// RunCounterExcludeTypesMatchesListCardinality pins the storage-level half of
// CountRequest.ExcludeTypes' promise (S8 review, follow-up #5a). ExcludeStatus
// has no List counterpart (counter.go) so it is not part of this parity
// family; RunCounterExcludeStatusNarrowsThePredicate above is its only
// coverage.
func RunCounterExcludeTypesMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
task := fixture.IssuePrefix + "-parity-extype-task"
chore := fixture.IssuePrefix + "-parity-extype-chore"
seedCounterIssue(t, ctx, fixture, counterSeed(task))
choreSeed := counterSeed(chore)
choreSeed.IssueType = types.TypeChore
seedCounterIssue(t, ctx, fixture, choreSeed)
idFilter := counterScope(task, chore).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, "", false, []string{"chore"})
}
// RunCounterParentIDIncludesAWispChild pins that ParentID's edge match reaches
// into the wisp tier exactly as IncludeInfra's merge does (S8 review,
// follow-up #5b): a child seeded in the ephemeral/wisp tier, linked to its
// parent by the same parent-child edge ParentID matches on, is invisible to
// Count's durable-only default and counted once IncludeInfra merges the wisps
// table in.
func RunCounterParentIDIncludesAWispChild(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-wispchild-parent"
wispChild := fixture.IssuePrefix + "-wispchild-child"
seedCounterIssue(t, ctx, fixture, counterSeed(parent))
seedCounterWisp(t, ctx, fixture, counterSeed(wispChild))
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: wispChild, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", wispChild, parent, err)
}
scope := counterScope(parent, wispChild)
scope.ParentID = parent
// Durable-only default (counter.go, RunCounterCountsTheDurablePlaneByDefault):
// the wisp child is invisible without IncludeInfra.
assertCounterTotal(t, ctx, fixture, scope, 0)
scope.IncludeInfra = true
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterParentIDAndExcludeStatusComposeOnAClosedChild pins that ParentID
// and ExcludeStatus apply as a conjunction, not alternatives (S8 review,
// follow-up #5b): a closed child under its parent is counted by ParentID
// alone (Count hides nothing by default), and excluded once ExcludeStatus
// names its status, leaving only the open child.
func RunCounterParentIDAndExcludeStatusComposeOnAClosedChild(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-closedchild-parent"
openChild := fixture.IssuePrefix + "-closedchild-open"
closedChild := fixture.IssuePrefix + "-closedchild-closed"
seedCounterIssue(t, ctx, fixture, counterSeed(parent))
seedCounterIssue(t, ctx, fixture, counterSeed(openChild))
closedSeed := counterSeed(closedChild)
closedSeed.Status = types.StatusClosed
seedCounterIssue(t, ctx, fixture, closedSeed)
for _, child := range []string{openChild, closedChild} {
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
}
scope := counterScope(parent, openChild, closedChild)
scope.ParentID = parent
assertCounterTotal(t, ctx, fixture, scope, 2)
scope.ExcludeStatus = []string{"closed"}
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterGroupsPartitionTheScalarSet pins counter.go:168-169 and :244-245
// for a dimension whose buckets do NOT overlap: the grouped Total is the same
// number a scalar Count returns, and the buckets partition it exactly.

View file

@ -186,6 +186,15 @@ var roleContractCases = []roleContract{
RunCounterIncludeInfraExcludesGates,
RunCounterCountsClosedRows,
RunCounterAnUnknownStatusMatchesNothing,
RunCounterParentIDScopesToChildren,
RunCounterNoParentExcludesChildren,
RunCounterExcludeTypesNarrowsThePredicate,
RunCounterExcludeStatusNarrowsThePredicate,
RunCounterParentIDMatchesListCardinality,
RunCounterNoParentMatchesListCardinality,
RunCounterExcludeTypesMatchesListCardinality,
RunCounterParentIDIncludesAWispChild,
RunCounterParentIDAndExcludeStatusComposeOnAClosedChild,
RunCounterGroupsPartitionTheScalarSet,
RunCounterLabelBucketsOverlapSoTotalIsNotTheirSum,
RunCounterNamesTheEmptyBuckets,

View file

@ -93,6 +93,13 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun
includeInfra, _ := cmd.Flags().GetBool("include-infra")
metadataFieldFlags, _ := cmd.Flags().GetStringArray("metadata-field")
includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral")
parentID, _ := cmd.Flags().GetString("parent")
noParent, _ := cmd.Flags().GetBool("no-parent")
if parentID != "" && noParent {
return issueops.CountRequest{}, "", HandleErrorRespectJSON("--parent and --no-parent are mutually exclusive")
}
excludeTypes, _ := cmd.Flags().GetStringSlice("exclude-type")
excludeStatus, _ := cmd.Flags().GetStringSlice("exclude-status")
request := issueops.CountRequest{
Status: status,
@ -111,6 +118,10 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun
IncludeInfra: includeInfra,
IncludeEphemeral: includeEphemeral,
ParentID: parentID,
NoParent: noParent,
ExcludeTypes: excludeTypes,
ExcludeStatus: excludeStatus,
}
if len(metadataFieldFlags) > 0 {
request.MetadataFields = make(map[string]string, len(metadataFieldFlags))
@ -271,6 +282,18 @@ func registerCountFlags(cmd *cobra.Command) {
cmd.Flags().String("title", "", "Filter by title text (case-insensitive substring match)")
cmd.Flags().String("id", "", "Filter by specific issue IDs (comma-separated)")
// Hierarchy and exclusions (same spelling as `bd list`'s flags of the same
// name, GH#4387's count/list parity): --parent and --no-parent restrict to
// a parent's children or to rows with no parent-child edge (an edge-less
// dotted-id child still counts as top-level, as in `bd list --no-parent`);
// --exclude-type and --exclude-status narrow the predicate by type and by
// status, composing with --include-infra's own exclusions rather than
// replacing them.
cmd.Flags().String("parent", "", "Filter by parent issue ID (count children of specified issue)")
cmd.Flags().Bool("no-parent", false, "Count only top-level issues (exclude child issues)")
cmd.Flags().StringSlice("exclude-type", nil, "Exclude issue types from the count (comma-separated or repeatable)")
cmd.Flags().StringSlice("exclude-status", nil, "Exclude statuses from the count (comma-separated or repeatable)")
// Pattern matching
cmd.Flags().String("title-contains", "", "Filter by title substring")
cmd.Flags().String("desc-contains", "", "Filter by description substring")

View file

@ -76,10 +76,71 @@ func TestCountIncludeEphemeralFlagShape(t *testing.T) {
}
}
// TestCountScopeFlagsShape pins --parent, --no-parent, --exclude-type and
// --exclude-status: their existence, their defaults, and that setting one
// does not leak into another. These are the Counter-scope fields (S8): the
// behavior token issues.count.scope on the HTTP front door exists because of
// exactly these four flags.
func TestCountScopeFlagsShape(t *testing.T) {
for flag, defValue := range map[string]string{
"parent": "",
"no-parent": "false",
"exclude-type": "[]",
"exclude-status": "[]",
} {
got := countCmd.Flags().Lookup(flag)
if got == nil {
t.Fatalf("bd count must expose a --%s flag", flag)
}
if got.DefValue != defValue {
t.Fatalf("--%s must default to %q, got %q", flag, defValue, got.DefValue)
}
}
request, _, err := parseCountRequest(newCountFlagSet(t))
if err != nil {
t.Fatalf("parseCountRequest with no flags set: %v", err)
}
if request.ParentID != "" || request.NoParent || len(request.ExcludeTypes) != 0 || len(request.ExcludeStatus) != 0 {
t.Errorf("parseCountRequest with no flags set = %#v, want all four scope fields at their zero value", request)
}
flags := newCountFlagSet(t)
if err := flags.Flags().Set("parent", "bd-1"); err != nil {
t.Fatalf("set --parent: %v", err)
}
if err := flags.Flags().Set("exclude-type", "wisp"); err != nil {
t.Fatalf("set --exclude-type: %v", err)
}
request, _, err = parseCountRequest(flags)
if err != nil {
t.Fatalf("parseCountRequest --parent --exclude-type: %v", err)
}
if request.ParentID != "bd-1" {
t.Errorf("ParentID = %q, want %q", request.ParentID, "bd-1")
}
if request.NoParent {
t.Error("NoParent = true with only --parent set; the two flags must not leak into each other")
}
if !reflect.DeepEqual(request.ExcludeTypes, []string{"wisp"}) {
t.Errorf("ExcludeTypes = %v, want [wisp]", request.ExcludeTypes)
}
if len(request.ExcludeStatus) != 0 {
t.Errorf("ExcludeStatus = %v, want empty; only --exclude-type was set", request.ExcludeStatus)
}
}
// TestParseCountRequestCarriesEveryFilterFlag is the tripwire for a flag that
// is registered, documented and silently dropped on the way into the request.
// Every filter flag is set to a value distinguishable from its zero and read
// back off the request.
//
// --no-parent is NOT in this matrix: review S8 follow-up #1 made --parent and
// --no-parent mutually exclusive, and this test already sets --parent to
// cover that field, so setting --no-parent alongside it would refuse the
// whole request instead of pinning a mapping. --no-parent's carriage into the
// request is pinned on its own in TestParseCountRequestRefusesParentAndNoParentTogether's
// sibling cases below and in TestCountScopeFlagsShape above.
func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) {
flags := newCountFlagSet(t)
for flag, value := range map[string]string{
@ -109,6 +170,9 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) {
"priority-max": "4",
"include-infra": "true",
"include-ephemeral": "true",
"parent": "bd-9",
"exclude-type": "wisp,gate",
"exclude-status": "closed,archived",
} {
if err := flags.Flags().Set(flag, value); err != nil {
t.Fatalf("set --%s=%s: %v", flag, value, err)
@ -161,12 +225,59 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) {
HasMetadataKey: "audit_ref",
IncludeInfra: true,
IncludeEphemeral: true,
ParentID: "bd-9",
ExcludeTypes: []string{"wisp", "gate"},
ExcludeStatus: []string{"closed", "archived"},
}
if !reflect.DeepEqual(request, want) {
t.Errorf("parseCountRequest built\n %#v\nwant\n %#v", request, want)
}
}
// TestParseCountRequestRefusesParentAndNoParentTogether pins review S8
// follow-up #1: `bd count --parent X --no-parent` is refused at the CLI flag
// layer, before a request is even built — the same early-refusal shape every
// other mutually-exclusive pair on this CLI gets (e.g. --pinned/--no-pinned).
//
// HandleErrorRespectJSON prints "--parent and --no-parent are mutually
// exclusive" (`bd list`'s own wording, cmd/bd/list_input.go) to stderr/JSON
// and returns an opaque exit error, so — as every other parseCountRequest
// refusal test in this file does — only the refusal itself is asserted here,
// not the string inside the returned error.
func TestParseCountRequestRefusesParentAndNoParentTogether(t *testing.T) {
flags := newCountFlagSet(t)
if err := flags.Flags().Set("parent", "bd-1"); err != nil {
t.Fatalf("set --parent: %v", err)
}
if err := flags.Flags().Set("no-parent", "true"); err != nil {
t.Fatalf("set --no-parent: %v", err)
}
if _, _, err := parseCountRequest(flags); err == nil {
t.Fatal("parseCountRequest accepted --parent with --no-parent, want a refusal")
}
}
// TestParseCountRequestCarriesNoParentAlone pins --no-parent's own mapping,
// split out of TestParseCountRequestCarriesEveryFilterFlag because that test's
// --parent case cannot also set --no-parent now that the two refuse each
// other.
func TestParseCountRequestCarriesNoParentAlone(t *testing.T) {
flags := newCountFlagSet(t)
if err := flags.Flags().Set("no-parent", "true"); err != nil {
t.Fatalf("set --no-parent: %v", err)
}
request, _, err := parseCountRequest(flags)
if err != nil {
t.Fatalf("parseCountRequest --no-parent: %v", err)
}
if !request.NoParent {
t.Error("NoParent = false, want true")
}
if request.ParentID != "" {
t.Errorf("ParentID = %q, want empty: --parent was not set", request.ParentID)
}
}
func TestParseCountRequestRejectsInvalidMetadataField(t *testing.T) {
for _, value := range []string{"team", "bad$key=value"} {
t.Run(value, func(t *testing.T) {

View file

@ -255,6 +255,51 @@ func TestProxiedServerServeCount(t *testing.T) {
}
})
// PR #7199 REVIEW: exclude_status against a WORKSPACE CUSTOM STATUS, over
// the wire and with include_infra left unset. The fake-role tests in
// internal/httpapi cannot write this case — a fake cannot be asked whether a
// custom status is in its own vocabulary — and the bug this pins lived below
// the HTTP layer anyway (storecounter and uow's countFilter only loaded the
// workspace's list configuration when include_infra was set, so
// BuildCountFilter's validation refused a status the workspace itself
// defined unless the caller also happened to pass the unrelated flag).
t.Run("exclude_status accepts a workspace custom status without include_infra", func(t *testing.T) {
label := countSliceLabel + "-customstatus"
scopedCustom := "?label=" + label
if out, err := bdProxiedRun(t, bd, p.dir, "config", "set", "status.custom", "review,qa"); err != nil {
t.Fatalf("bd config set status.custom: %v\n%s", err, out)
}
bdProxiedCreate(t, bd, p.dir, "custom status open row", "-p", "2", "-l", label)
reviewRow := bdProxiedCreate(t, bd, p.dir, "custom status review row", "-p", "2", "-l", label)
if out, err := bdProxiedRun(t, bd, p.dir, "update", reviewRow.ID, "--status", "review"); err != nil {
t.Fatalf("bd update --status review: %v\n%s", err, out)
}
_, total, _ := sp.countIssues(t, scopedCustom)
if total != 2 {
t.Fatalf("total = %d, want 2", total)
}
// include_infra is NOT in this query string. Before the fix this 400'd
// with an "invalid exclude-status" refusal because the config load that
// feeds BuildCountFilter's vocabulary check was gated on include_infra
// alone.
status, narrowed, _ := sp.countIssues(t, scopedCustom+"&exclude_status=review")
if status != http.StatusOK {
t.Fatalf("exclude_status=review (a workspace custom status, include_infra unset): status = %d, want 200", status)
}
if narrowed != 1 {
t.Fatalf("exclude_status=review counted %d, want 1", narrowed)
}
// The parity oracle, same as the sibling cases above.
if cli := bdProxiedCountTotal(t, bd, p.dir, "--label", label, "--exclude-status", "review"); cli != narrowed {
t.Errorf("bd count --exclude-status review = %d, the server said %d", cli, narrowed)
}
})
// The refusals, over the wire: a closed vocabulary and a typed parameter
// set, both refused before any query runs.
t.Run("the document's refusals are refused", func(t *testing.T) {

View file

@ -1010,7 +1010,7 @@ type ContextResponse struct {
// OPTIONAL, and absent means only that this server does not disclose its filesystem layout — never that it has no workspace. A client MUST NOT require it, MUST NOT treat absence as an error, and has no use for the value beyond display: it is a path on the SERVER's filesystem, which the client cannot open. Identify the workspace by `project_id` and `database`, which are required.
BeadsDir *string `json:"beads_dir,omitempty"`
// Capabilities The tokens this server advertises: the OPERATIONS it implements, derived from its route table, and the server-wide BEHAVIORS it enforces. v0's operation vocabulary is `ready.list`, `ready.count`, `issues.list`, `issues.query`, `issues.count`, `issues.get`, `issues.related`, `issues.create`, `issues.addComment`, `issues.batchClose`, `issues.claim`, `issues.claimNext`, `issues.release`, `issues.close`, `issues.reopen`, `issues.update`, `issues.sweep`, `issues.delete`, `issues.batchCreate`, `issues.batchApply`, `stats.get`, `config.list`, `config.get`, `config.set`, `config.unset`, `dependencies.cycles`, `dependencies.list`, `dependencies.count`, `dependencies.blocking`, `dependencies.tree`, `dependencies.add`, `dependencies.remove`, `memories.list`, `memories.get`, `memories.remember`, `memories.forget`, `events.list`, `events.watch`, `issues.casMetadata`; the behavior tokens are `project.enforce`, which announces that a `Bd-Project-Id` stamp for the wrong workspace is refused here rather than silently ignored, `issues.batchApplyLarge`, which announces that `POST /v0/beads/issues:batchApply` accepts the RAISED envelope — up to 1000 items (`ApplyBatchRequest.items.maxItems`), a 16 MiB body, and (for a request over 100 items) a run budget that EXTENDS to an operator-configured ceiling (`bd serve --large-apply-ceiling`, 5 minutes by default) — rather than the original 100-item, 4 MiB bound. The ceiling is a flat whole-run budget, not a value scaled by item count: a 101-item request and a 1000-item request both get the same extended budget. A request at or under 100 items is unaffected either way and keeps the server's ordinary deadline exactly as before. A client that checks for this token before sending a plan over 100 items learns whether THIS server accepts it without paying for a round trip an older server would refuse anyway, and `issues.list.sort`, which announces that `GET /v0/beads/issues` accepts the `sort` query parameter (two closed, pageable total orders — see that parameter) rather than silently answering `unknown_parameter`. The list grows additively, and an operation never appears here unless it is fully implemented. This is how a client checks for an operation or a behavior — never the version string.
// Capabilities The tokens this server advertises: the OPERATIONS it implements, derived from its route table, and the server-wide BEHAVIORS it enforces. v0's operation vocabulary is `ready.list`, `ready.count`, `issues.list`, `issues.query`, `issues.count`, `issues.get`, `issues.related`, `issues.create`, `issues.addComment`, `issues.batchClose`, `issues.claim`, `issues.claimNext`, `issues.release`, `issues.close`, `issues.reopen`, `issues.update`, `issues.sweep`, `issues.delete`, `issues.batchCreate`, `issues.batchApply`, `stats.get`, `config.list`, `config.get`, `config.set`, `config.unset`, `dependencies.cycles`, `dependencies.list`, `dependencies.count`, `dependencies.blocking`, `dependencies.tree`, `dependencies.add`, `dependencies.remove`, `memories.list`, `memories.get`, `memories.remember`, `memories.forget`, `events.list`, `events.watch`, `issues.casMetadata`; the behavior tokens are `project.enforce`, which announces that a `Bd-Project-Id` stamp for the wrong workspace is refused here rather than silently ignored, `issues.batchApplyLarge`, which announces that `POST /v0/beads/issues:batchApply` accepts the RAISED envelope — up to 1000 items (`ApplyBatchRequest.items.maxItems`), a 16 MiB body, and (for a request over 100 items) a run budget that EXTENDS to an operator-configured ceiling (`bd serve --large-apply-ceiling`, 5 minutes by default) — rather than the original 100-item, 4 MiB bound. The ceiling is a flat whole-run budget, not a value scaled by item count: a 101-item request and a 1000-item request both get the same extended budget. A request at or under 100 items is unaffected either way and keeps the server's ordinary deadline exactly as before. A client that checks for this token before sending a plan over 100 items learns whether THIS server accepts it without paying for a round trip an older server would refuse anyway, and `issues.list.sort`, which announces that `GET /v0/beads/issues` accepts the `sort` query parameter (two closed, pageable total orders — see that parameter) rather than silently answering `unknown_parameter`, and `issues.count.scope`, which announces that `GET /v0/beads/issues:count` accepts `parent`, `no_parent`, `exclude_type`, and `exclude_status` (see those parameters) rather than silently answering `unknown_parameter` for all four. The list grows additively, and an operation never appears here unless it is fully implemented. This is how a client checks for an operation or a behavior — never the version string.
//
// THIS LIST IS BUILD-LEVEL, NOT WORKSPACE-LEVEL. It says which operations this binary serves, and for every entry but two that is the whole answer. `events.list` and `events.watch` are the exceptions: the durable events journal is a per-workspace setting that is OFF by default, so a server that advertises them may still refuse every request to both with 409 `events_journal_disabled` — correctly, because the operations exist and the workspace has no journal. A consumer of either MUST treat the capability as "this server speaks it" and the 409 as "not on this workspace", and must not read the capability as a promise that records will arrive.
Capabilities []string `json:"capabilities"`
@ -2464,6 +2464,30 @@ type CountIssuesParams struct {
// Unset — and with `include_ephemeral` also unset — the count is durable-plane only and applies none of the four: the historical `bd count` answer, kept exactly so a scripted caller reads the same number it read yesterday.
IncludeInfra *bool `form:"include_infra,omitempty" json:"include_infra,omitempty"`
// Parent Restrict to one issue's children through one predicate with two arms: a parent-child dependency edge onto `parent`, OR — for an issue carrying no parent-child edge at all — a dotted-id prefix match (`parent.anything`). NEITHER ARM WALKS. The edge arm stops at one level, so a grandchild with an edge of its own is not counted, while the prefix arm reaches every edge-less dotted id at any depth (`X.1.1` as well as `X.1`). It is the same predicate `GET /v0/beads/issues`'s own `parent` applies, so `bd count --parent X` agrees in cardinality with `bd list --parent X --flat --all` (or `--json`) for the shared part of the predicate — NOT with a bare `bd list --parent X --all`, whose default tree mode walks every descendant reachable through either arm (grandchildren and below) by re-querying this same predicate once per level client-side (cmd/bd/list_show_filter_modes.go). `--flat` and `--json` both skip that walk and return this field's answer directly.
//
// Sending it beside `no_parent` IS refused: `invalid_argument` on `no_parent` with `reason: invalid_value`, matching `bd list`'s CLI refusal of the same combination.
//
// Behind the `issues.count.scope` behavior token: an older server answers `unknown_parameter` for this name.
Parent *string `form:"parent,omitempty" json:"parent,omitempty"`
// NoParent Only issues carrying NO parent-child dependency edge. Unlike `parent`, this does NOT consult the dotted-id convention — an issue named `X.1` with no edge to `X` is still counted here, which is the one place `parent` and `no_parent` are not exact opposites of each other.
//
// Sending it beside `parent` IS refused: `invalid_argument` on this parameter with `reason: invalid_value`, matching `bd list`'s CLI refusal of the same combination (cmd/bd/list_input.go) rather than the empty-intersection treatment `assignee`/`no_assignee` get.
//
// Behind the `issues.count.scope` behavior token: an older server answers `unknown_parameter` for this name.
NoParent *bool `form:"no_parent,omitempty" json:"no_parent,omitempty"`
// ExcludeType Issue types to exclude from the count. Repeat the parameter, or pass a comma-separated list; entries are split and trimmed inside the role and are NOT validated against this workspace's vocabulary — an unrecognized name excludes nothing rather than failing, `status`'s own treatment. It is NOT ignored when `type` is set (unlike `GET /v0/beads/ready`'s `exclude_type`): the two compose, and it also composes with the exclusions `include_infra` applies on its own rather than replacing them.
//
// Behind the `issues.count.scope` behavior token: an older server answers `unknown_parameter` for this name.
ExcludeType *[]string `form:"exclude_type,omitempty" json:"exclude_type,omitempty"`
// ExcludeStatus Statuses to exclude from the count. Repeat the parameter, or pass a comma-separated list; entries are taken as written (no normalization) but — UNLIKE `status` and `exclude_type` above — each name IS validated against this workspace's vocabulary (built-in statuses plus this workspace's own custom ones): an unrecognized name is `invalid_argument` on this parameter with `reason: invalid_value`, rather than silently excluding nothing and overcounting. There is no listing counterpart to this parameter: `GET /v0/beads/issues` computes its default status exclusions internally from workspace configuration and exposes no equivalent knob, so this is a Count-only capability.
//
// Behind the `issues.count.scope` behavior token: an older server answers `unknown_parameter` for this name.
ExcludeStatus *[]string `form:"exclude_status,omitempty" json:"exclude_status,omitempty"`
// GroupBy Bucket the count by one dimension and return `groups` beside `total`. Absent, the response carries `total` alone.
//
// The set is CLOSED, and a value outside it is a `400` rather than an empty answer: a caller that misspelled a dimension and got zero buckets back has no way to tell that from a workspace with nothing in it. That is the role's own rule, applied at the edge here so the refusal names the parameter.

View file

@ -117,6 +117,10 @@ func TestCountForwardsEveryDocumentedParameter(t *testing.T) {
"has_metadata_key": {"audit_ref"},
"include_infra": {"true"},
"include_ephemeral": {"true"},
"parent": {"bd-9"},
"no_parent": {"true"},
"exclude_type": {"wisp", "gate"},
"exclude_status": {"closed", "archived"},
}.Encode())
if resp.StatusCode != http.StatusOK {
t.Fatalf("status = %d, want 200: %s", resp.StatusCode, readAll(t, resp))
@ -169,6 +173,11 @@ func TestCountForwardsEveryDocumentedParameter(t *testing.T) {
IncludeInfra: true,
IncludeEphemeral: true,
ParentID: "bd-9",
NoParent: true,
ExcludeTypes: []string{"wisp", "gate"},
ExcludeStatus: []string{"closed", "archived"},
}
if !reflect.DeepEqual(got[0], want) {
t.Errorf("request = %+v\nwant %+v", got[0], want)
@ -645,6 +654,10 @@ var countFieldForParameter = map[string]string{
"has_metadata_key": "HasMetadataKey",
"include_infra": "IncludeInfra",
"include_ephemeral": "IncludeEphemeral",
"parent": "ParentID",
"no_parent": "NoParent",
"exclude_type": "ExcludeTypes",
"exclude_status": "ExcludeStatus",
}
// TestEveryCountRequestFieldIsPublished: the wire publishes every filter the

View file

@ -741,11 +741,17 @@ var operationCodes = map[string][]Code{
// Its 400s come from both the transport and the ROLE. The transport refuses
// malformed values, repeated single-valued parameters and a `group_by`
// outside the closed set. countGroupOf stops that last case at the edge.
// The role has exactly one reachable refusal: BuildCountFilter rejects an
// invalid metadata key, from `metadata_field` or `has_metadata_key`.
// failReadErr classifies it through invalidFilterParam as a 400 naming the
// parameter it came from. An unrecognized status or type is not a refusal;
// the role promises it matches nothing and answers 0.
// The role has three reachable refusals, all from BuildCountFilter: an
// invalid metadata key (`metadata_field` or `has_metadata_key`), an
// unrecognized `exclude_status` name, and `parent` set together with
// `no_parent` (named `no_parent`). The last two carry ErrValidation; the
// metadata-key refusal does not, being a plain error from
// ValidateMetadataFilters, which the list and ready builders share.
// failReadErr classifies all three through invalidFilterParam by message
// prefix, not by sentinel, as a 400 naming the parameter each came from.
// An unrecognized `status` or `type` is not a refusal; the role promises
// it matches nothing and answers 0. Nor is an unrecognized `exclude_type`,
// which excludes nothing.
OpCountIssues: {CodeInvalidArgument, CodeUnauthenticated, CodeBusy, CodeDBUnavailable, CodeInternal},
// The listing's vocabulary minus the cursor: this operation has none, so
// invalid_cursor cannot arise. An unparseable EXPRESSION is an

View file

@ -229,6 +229,19 @@ func countFilters(q *query) issueops.CountRequest {
// it reaches the role as its own field and never as IncludeInfra: folded
// into it, a plane-only count would also lose its templates and gates.
IncludeEphemeral: q.boolean("include_ephemeral"),
// The four scope fields behind `issues.count.scope` (S8): ParentID and
// ExcludeTypes are read exactly as the listing reads them (q.str("parent"),
// q.list("exclude_type")), because the role documents its own ParentID and
// ExcludeTypes as spelling ListRequest's fields identically. NoParent and
// ExcludeStatus have no listing counterpart to mirror — NoParent is a new
// boolean switch and ExcludeStatus is a Count-only capability the listing
// never exposed — so both are read with this file's own conventions for
// their kind (q.boolean, q.list) rather than a listing precedent.
ParentID: q.str("parent"),
NoParent: q.boolean("no_parent"),
ExcludeTypes: q.list("exclude_type"),
ExcludeStatus: q.list("exclude_status"),
}
}
@ -598,6 +611,15 @@ func invalidFilterParam(err error) (string, bool) {
switch {
case strings.HasPrefix(msg, "invalid status "):
return "status", true
// The count role's own refusals (S8 review fix): a misspelled
// --exclude-status entry, and --parent set together with --no-parent.
// Both are the ROLE's ErrValidation. They are named here the same way as
// the `status` row above and the metadata-key rows below, so the client
// learns which parameter to fix rather than reading an unclassified 500.
case strings.HasPrefix(msg, "invalid exclude-status "):
return "exclude_status", true
case strings.HasPrefix(msg, "--parent and --no-parent are mutually exclusive"):
return "no_parent", true
case strings.HasPrefix(msg, "invalid issue type "):
return "type", true
case strings.HasPrefix(msg, "invalid sort policy "):

View file

@ -161,6 +161,8 @@ func TestABuilderRefusalIsTheDocumentedBadRequest(t *testing.T) {
{"a has-metadata key on the ready surface", "/v0/beads/ready?has_metadata_key=1bad", "has_metadata_key"},
{"a metadata field key on the count surface", "/v0/beads/issues:count?metadata_field=1bad=x", "metadata_field"},
{"a has-metadata key on the count surface", "/v0/beads/issues:count?has_metadata_key=1bad", "has_metadata_key"},
{"an unknown exclude-status name on the count surface", "/v0/beads/issues:count?exclude_status=bogus", "exclude_status"},
{"parent and no_parent together on the count surface", "/v0/beads/issues:count?parent=bd-1&no_parent=true", "no_parent"},
} {
t.Run(tc.name, func(t *testing.T) {
ts, _ := newReadServer(t, Config{})

View file

@ -76,6 +76,49 @@ const CapBatchApplyLarge = "issues.batchApplyLarge"
// baseline is built from.
const CapIssuesListSort = "issues.list.sort"
// CapIssuesCountScope is the behavior capability that advertises GET
// /v0/beads/issues:count's `parent`, `no_parent`, `exclude_type`, and
// `exclude_status` parameters (reads.go countFilters, spec OpCountIssues).
// Like CapIssuesListSort it names FOUR PARAMETERS added to an existing
// operation rather than a route of its own — `issues.count` is already the
// per-operation token for the route itself — so it rides the same
// behaviorCapabilities list and one token covers all four (internal/beads
// design doc "Count scope", S8): they shipped together, through the one
// shared workapi.BuildCountFilter builder, so there is no partial-support
// state a finer-grained token would need to distinguish.
//
// This is the TestNewParameterOnExistingOperationHasABehaviorToken gate
// CapIssuesListSort's doc describes: `issues:count` is a pretoken-baseline
// operation (internal/httpapi/testdata/pretoken_operations.json), so these
// four NEW parameters on it must each cite a served token in their own
// OpenAPI description, and this is that token.
//
// CLIENT-SKEW NOTE FOR S3/S4 (no OSS HTTP client exists yet to wire this
// into): a server predating this token answers any of the four parameters
// with `400 invalid_argument`/`reason: "unknown_parameter"` naming the
// parameter — the per-parameter capability probe every behavior token on
// this operation already relies on (see CapIssuesListSort). When the HTTP
// client lands, it MUST check `issues.count.scope` against the cached
// `ContextResponse.capabilities` from the handshake and refuse LOCALLY with
// a typed `ErrUnsupported{Capability: "issues.count.scope"}` (or an
// equivalent typed error carrying the token) before sending a request that
// sets `ParentID`, `NoParent`, `ExcludeTypes` or `ExcludeStatus` to an older
// server — never let the caller pay for a round trip that 400s anyway, and
// never silently drop the fields and return a wider count than asked for.
//
// THE DOWNSTREAM FALLBACK THIS PROTECTS (S8 review, follow-up #6): gc's own
// client maps that local `ErrUnsupported{Capability: "issues.count.scope"}`
// refusal to its own `ErrCountUnsupported` and falls back to the List role for
// the same predicate (beads-design DESIGN.txt §3.2, "gc maps this to
// ErrCountUnsupported and falls back to List") rather than surfacing the
// refusal to its own caller or guessing at a count. S3/S4, when they build
// that client, MUST add a skew test that masks this token out of a handshake
// response and asserts the fallback actually fires — not merely that the
// local refusal is raised — because a fallback that compiles but never runs
// in CI is indistinguishable from one that silently regressed to a wrong
// count.
const CapIssuesCountScope = "issues.count.scope"
// customMethodTarget splits the custom method off the segment the router
// matched, and reports the row that claims it.
//
@ -810,7 +853,7 @@ func (r route) specPathOf() string {
// route. project.enforce announces per-request Bd-Project-Id enforcement
// (checkProjectStamp): a stamped client reads it to know the refusal is available
// rather than silently dropped by an older server.
var behaviorCapabilities = []string{CapProjectEnforce, CapBatchApplyLarge, CapIssuesListSort}
var behaviorCapabilities = []string{CapProjectEnforce, CapBatchApplyLarge, CapIssuesListSort, CapIssuesCountScope}
// Capabilities lists what this build advertises in ContextResponse.capabilities:
// the operations it actually implements, gated on `implemented` so a stub can

View file

@ -635,7 +635,7 @@ func TestCapabilitiesAdvertiseEveryImplementedOperation(t *testing.T) {
// them; project.enforce and issues.batchApplyLarge are advertised in the
// same list. Both are spelled literally here to keep this an independent
// oracle rather than a second call to the code under test.
want = append(want, "project.enforce", "issues.batchApplyLarge", "issues.list.sort")
want = append(want, "project.enforce", "issues.batchApplyLarge", "issues.list.sort", "issues.count.scope")
slices.Sort(want)
if !slices.Equal(got, want) {
t.Errorf("capabilities = %v, want %v", got, want)

View file

@ -2068,6 +2068,102 @@ paths:
schema:
type: boolean
default: false
- name: parent
in: query
description: >-
Restrict to one issue's children through one predicate with two
arms: a parent-child dependency edge onto `parent`, OR — for an
issue carrying no parent-child edge at all — a dotted-id prefix
match (`parent.anything`). NEITHER ARM WALKS. The edge arm stops
at one level, so a grandchild with an edge of its own is not
counted, while the prefix arm reaches every edge-less dotted id at
any depth (`X.1.1` as well as `X.1`). It is the same predicate
`GET /v0/beads/issues`'s own `parent` applies, so `bd count
--parent X` agrees in cardinality with `bd list --parent X --flat
--all` (or `--json`) for the shared part of the predicate — NOT
with a bare `bd list --parent X --all`, whose default tree mode
walks every descendant reachable through either arm (grandchildren
and below) by re-querying this same predicate once per level
client-side
(cmd/bd/list_show_filter_modes.go). `--flat` and `--json` both
skip that walk and return this field's answer directly.
Sending it beside `no_parent` IS refused: `invalid_argument` on
`no_parent` with `reason: invalid_value`, matching `bd list`'s CLI
refusal of the same combination.
Behind the `issues.count.scope` behavior token: an older server
answers `unknown_parameter` for this name.
schema:
type: string
- name: no_parent
in: query
description: >-
Only issues carrying NO parent-child dependency edge. Unlike
`parent`, this does NOT consult the dotted-id convention — an
issue named `X.1` with no edge to `X` is still counted here, which
is the one place `parent` and `no_parent` are not exact opposites
of each other.
Sending it beside `parent` IS refused: `invalid_argument` on this
parameter with `reason: invalid_value`, matching `bd list`'s CLI
refusal of the same combination (cmd/bd/list_input.go) rather than
the empty-intersection treatment `assignee`/`no_assignee` get.
Behind the `issues.count.scope` behavior token: an older server
answers `unknown_parameter` for this name.
schema:
type: boolean
default: false
- name: exclude_type
in: query
description: >-
Issue types to exclude from the count. Repeat the parameter, or
pass a comma-separated list; entries are split and trimmed inside
the role and are NOT validated against this workspace's
vocabulary — an unrecognized name excludes nothing rather than
failing, `status`'s own treatment. It is NOT ignored when `type`
is set (unlike `GET /v0/beads/ready`'s `exclude_type`): the two
compose, and it also composes with the exclusions `include_infra`
applies on its own rather than replacing them.
Behind the `issues.count.scope` behavior token: an older server
answers `unknown_parameter` for this name.
style: form
explode: true
schema:
type: array
items:
type: string
- name: exclude_status
in: query
description: >-
Statuses to exclude from the count. Repeat the parameter, or pass
a comma-separated list; entries are taken as written (no
normalization) but — UNLIKE `status` and `exclude_type` above —
each name IS validated against this workspace's vocabulary
(built-in statuses plus this workspace's own custom ones): an
unrecognized name is `invalid_argument` on this parameter with
`reason: invalid_value`, rather than silently excluding nothing
and overcounting. There is no listing counterpart to this
parameter: `GET /v0/beads/issues` computes its default status
exclusions internally from workspace configuration and exposes no
equivalent knob, so this is a Count-only capability.
Behind the `issues.count.scope` behavior token: an older server
answers `unknown_parameter` for this name.
style: form
explode: true
schema:
type: array
items:
type: string
- name: group_by
in: query
description: >-
@ -7514,7 +7610,11 @@ components:
older server would refuse anyway, and `issues.list.sort`, which
announces that `GET /v0/beads/issues` accepts the `sort` query
parameter (two closed, pageable total orders — see that
parameter) rather than silently answering `unknown_parameter`. The
parameter) rather than silently answering `unknown_parameter`, and
`issues.count.scope`, which announces that
`GET /v0/beads/issues:count` accepts `parent`, `no_parent`,
`exclude_type`, and `exclude_status` (see those parameters) rather
than silently answering `unknown_parameter` for all four. The
list grows additively, and an operation never appears here unless
it is fully implemented. This is how a client checks for an
operation or a behavior — never the version string.

View file

@ -4594,6 +4594,24 @@
"explode": true,
"default": "false"
},
{
"schema": "param:countIssues",
"member": "query:exclude_status",
"type": "array",
"required": false,
"item_type": "string",
"style": "form",
"explode": true
},
{
"schema": "param:countIssues",
"member": "query:exclude_type",
"type": "array",
"required": false,
"item_type": "string",
"style": "form",
"explode": true
},
{
"schema": "param:countIssues",
"member": "query:group_by",
@ -4688,6 +4706,15 @@
"explode": true,
"default": "false"
},
{
"schema": "param:countIssues",
"member": "query:no_parent",
"type": "boolean",
"required": false,
"style": "form",
"explode": true,
"default": "false"
},
{
"schema": "param:countIssues",
"member": "query:notes_contains",
@ -4696,6 +4723,14 @@
"style": "form",
"explode": true
},
{
"schema": "param:countIssues",
"member": "query:parent",
"type": "string",
"required": false,
"style": "form",
"explode": true
},
{
"schema": "param:countIssues",
"member": "query:priority",

View file

@ -65,6 +65,33 @@ func TestCounterContract(t *testing.T) {
t.Run("WritesNothing", func(t *testing.T) {
conformance.RunCounterWritesNothing(t, ctx, fixture)
})
t.Run("ParentIDScopesToChildren", func(t *testing.T) {
conformance.RunCounterParentIDScopesToChildren(t, ctx, fixture)
})
t.Run("NoParentExcludesChildren", func(t *testing.T) {
conformance.RunCounterNoParentExcludesChildren(t, ctx, fixture)
})
t.Run("ExcludeTypesNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeTypesNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ExcludeStatusNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeStatusNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ParentIDMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterParentIDMatchesListCardinality(t, ctx, fixture)
})
t.Run("NoParentMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterNoParentMatchesListCardinality(t, ctx, fixture)
})
t.Run("ExcludeTypesMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterExcludeTypesMatchesListCardinality(t, ctx, fixture)
})
t.Run("ParentIDIncludesAWispChild", func(t *testing.T) {
conformance.RunCounterParentIDIncludesAWispChild(t, ctx, fixture)
})
t.Run("ParentIDAndExcludeStatusComposeOnAClosedChild", func(t *testing.T) {
conformance.RunCounterParentIDAndExcludeStatusComposeOnAClosedChild(t, ctx, fixture)
})
}
func newDoltCounterFixture(t *testing.T, prefix string) (conformance.CounterFixture, context.Context, func()) {
@ -78,12 +105,20 @@ func newDoltCounterFixture(t *testing.T, prefix string) (conformance.CounterFixt
t.Fatalf("Counter(): %v", err)
}
kit := newDoltRoleFixtureKit(store, prefix)
reader, err := store.IssueReader()
if err != nil {
cancel()
storeCleanup()
t.Fatalf("IssueReader(): %v", err)
}
fixture := conformance.CounterFixture{
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
AddDependency: kit.AddDependency,
List: reader.List,
}
return fixture, ctx, func() {
cancel()

View file

@ -6,6 +6,8 @@ import (
"testing"
"github.com/steveyegge/beads/backend/conformance"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// TestCounterContract runs the Counter contract against the embedded store,
@ -68,6 +70,33 @@ func TestCounterContract(t *testing.T) {
t.Run("WritesNothing", func(t *testing.T) {
conformance.RunCounterWritesNothing(t, ctx, fixture)
})
t.Run("ParentIDScopesToChildren", func(t *testing.T) {
conformance.RunCounterParentIDScopesToChildren(t, ctx, fixture)
})
t.Run("NoParentExcludesChildren", func(t *testing.T) {
conformance.RunCounterNoParentExcludesChildren(t, ctx, fixture)
})
t.Run("ExcludeTypesNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeTypesNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ExcludeStatusNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeStatusNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ParentIDMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterParentIDMatchesListCardinality(t, ctx, fixture)
})
t.Run("NoParentMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterNoParentMatchesListCardinality(t, ctx, fixture)
})
t.Run("ExcludeTypesMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterExcludeTypesMatchesListCardinality(t, ctx, fixture)
})
t.Run("ParentIDIncludesAWispChild", func(t *testing.T) {
conformance.RunCounterParentIDIncludesAWispChild(t, ctx, fixture)
})
t.Run("ParentIDAndExcludeStatusComposeOnAClosedChild", func(t *testing.T) {
conformance.RunCounterParentIDAndExcludeStatusComposeOnAClosedChild(t, ctx, fixture)
})
}
func newEmbeddedCounterFixture(t *testing.T, te *testEnv, prefix string) conformance.CounterFixture {
@ -76,12 +105,82 @@ func newEmbeddedCounterFixture(t *testing.T, te *testEnv, prefix string) conform
if err != nil {
t.Fatalf("Counter(): %v", err)
}
reader, err := te.store.IssueReader()
if err != nil {
t.Fatalf("IssueReader(): %v", err)
}
kit := newEmbeddedRoleFixtureKit(te, prefix)
return conformance.CounterFixture{
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
AddDependency: kit.AddDependency,
List: reader.List,
}
}
// TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra
// pins the PR #7199 review's blocker fix: the store-backed Counter must load
// the workspace's list configuration when ExcludeStatus is non-empty, not
// only when IncludeInfra is set, so BuildCountFilter's validation sees the
// workspace's own custom statuses. A leg-level test, not a conformance case,
// because CounterFixture cannot drive a workspace-configured custom status
// (counter_contract.go's CounterFixture doc) — this needs a real store with
// status.custom set.
//
// Reproduces the reviewer's CLI repro directly against the store: with
// status.custom="review,qa", an issue moved to "review", and IncludeInfra
// left unset, `--exclude-status review` must narrow the count instead of
// being refused as an unrecognized status.
func TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra(t *testing.T) {
skipUnlessEmbeddedDolt(t)
te := newTestEnv(t, "cntcs")
ctx := t.Context()
if err := te.store.SetConfig(ctx, "status.custom", "review,qa"); err != nil {
t.Fatalf("SetConfig(status.custom): %v", err)
}
const openID = "cntcs-open"
const reviewID = "cntcs-review"
for _, id := range []string{openID, reviewID} {
if err := te.store.CreateIssue(ctx, &types.Issue{
ID: id, Title: id, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask,
}, "tester"); err != nil {
t.Fatalf("CreateIssue(%s): %v", id, err)
}
}
if err := te.store.UpdateIssue(ctx, reviewID, map[string]interface{}{
"status": types.Status("review"),
}, "tester"); err != nil {
t.Fatalf("UpdateIssue(%s) to review: %v", reviewID, err)
}
counter, err := te.store.Counter()
if err != nil {
t.Fatalf("Counter(): %v", err)
}
scope := publicops.CountRequest{IDFilter: openID + "," + reviewID}
total, err := counter.Count(ctx, scope)
if err != nil {
t.Fatalf("Count(unfiltered): %v", err)
}
if total.Total != 2 {
t.Fatalf("Count(unfiltered).Total = %d, want 2", total.Total)
}
// IncludeInfra left UNSET: before the fix this refused with "invalid
// exclude-status \"review\"" because the config load was gated on
// IncludeInfra alone.
scope.ExcludeStatus = []string{"review"}
result, err := counter.Count(ctx, scope)
if err != nil {
t.Fatalf("Count(exclude-status=review, IncludeInfra unset): %v, want the custom status accepted", err)
}
if result.Total != 1 {
t.Fatalf("Count(exclude-status=review).Total = %d, want 1", result.Total)
}
}

View file

@ -85,11 +85,14 @@ func (c *counter) CountByGroup(ctx context.Context, req publicops.CountByGroupRe
}
// countFilter builds the storage filter from the unit of work the call already
// holds, loading configuration only when IncludeInfra can read it — the same two
// decisions the store-backed body makes, through the same builder.
// holds, loading configuration only when IncludeInfra or ExcludeStatus can
// read it — the same two decisions the store-backed body makes, through the
// same builder. ExcludeStatus needs the workspace's custom status names so
// BuildCountFilter's validation does not refuse a status the workspace itself
// defines (PR #7199 review).
func countFilter(ctx context.Context, uw UnitOfWork, req publicops.CountRequest) (types.IssueFilter, error) {
var cfg workapi.ListConfig
if req.IncludeInfra {
if req.IncludeInfra || len(req.ExcludeStatus) > 0 {
loaded, err := workapi.LoadUOWListConfig(ctx, uw)
if err != nil {
return types.IssueFilter{}, err

View file

@ -5,6 +5,9 @@ import (
"testing"
"github.com/steveyegge/beads/backend/conformance"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// TestCounterContract runs the Counter contract against the unit-of-work
@ -65,6 +68,33 @@ func TestCounterContract(t *testing.T) {
t.Run("WritesNothing", func(t *testing.T) {
conformance.RunCounterWritesNothing(t, ctx, fixture)
})
t.Run("ParentIDScopesToChildren", func(t *testing.T) {
conformance.RunCounterParentIDScopesToChildren(t, ctx, fixture)
})
t.Run("NoParentExcludesChildren", func(t *testing.T) {
conformance.RunCounterNoParentExcludesChildren(t, ctx, fixture)
})
t.Run("ExcludeTypesNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeTypesNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ExcludeStatusNarrowsThePredicate", func(t *testing.T) {
conformance.RunCounterExcludeStatusNarrowsThePredicate(t, ctx, fixture)
})
t.Run("ParentIDMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterParentIDMatchesListCardinality(t, ctx, fixture)
})
t.Run("NoParentMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterNoParentMatchesListCardinality(t, ctx, fixture)
})
t.Run("ExcludeTypesMatchesListCardinality", func(t *testing.T) {
conformance.RunCounterExcludeTypesMatchesListCardinality(t, ctx, fixture)
})
t.Run("ParentIDIncludesAWispChild", func(t *testing.T) {
conformance.RunCounterParentIDIncludesAWispChild(t, ctx, fixture)
})
t.Run("ParentIDAndExcludeStatusComposeOnAClosedChild", func(t *testing.T) {
conformance.RunCounterParentIDAndExcludeStatusComposeOnAClosedChild(t, ctx, fixture)
})
}
func newUOWCounterFixture(t *testing.T, ctx context.Context, prefix string) conformance.CounterFixture {
@ -80,12 +110,99 @@ func newUOWCounterFixture(t *testing.T, ctx context.Context, prefix string) conf
if err != nil {
t.Fatalf("Counter(): %v", err)
}
readerSource, ok := provider.(IssueReaderSource)
if !ok {
t.Fatalf("provider %T does not offer the IssueReader accessor", provider)
}
reader, err := readerSource.IssueReader()
if err != nil {
t.Fatalf("IssueReader(): %v", err)
}
kit := newUOWRoleFixtureKit(provider, prefix)
return conformance.CounterFixture{
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
IssuePrefix: kit.IssuePrefix,
Counter: counter,
CreateIssue: kit.CreateIssue,
CreateWisp: kit.CreateWisp,
CountHistory: kit.CountHistory,
AddDependency: kit.AddDependency,
List: reader.List,
}
}
// TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra
// pins the PR #7199 review's blocker fix on the unit-of-work leg: countFilter
// must load the workspace's list configuration when ExcludeStatus is
// non-empty, not only when IncludeInfra is set, so BuildCountFilter's
// validation sees the workspace's own custom statuses. A leg-level test, not
// a conformance case, because CounterFixture cannot drive a
// workspace-configured custom status (counter_contract.go's CounterFixture
// doc) — this needs a real provider with status.custom set.
//
// Its own provider (not newUOWCounterFixture's), so status.custom does not
// leak into the other subtests sharing that fixture's one database.
func TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra(t *testing.T) {
ctx := context.Background()
provider := newUOWRoleFixtureProvider(t, ctx, "cntcs")
if err := RunTx(ctx, provider, func(ctx context.Context, uw UnitOfWork) (string, error) {
return "set status.custom", uw.ConfigUseCase().SetConfig(ctx, "status.custom", "review,qa")
}); err != nil {
t.Fatalf("SetConfig(status.custom): %v", err)
}
const openID = "cntcs-open"
const reviewID = "cntcs-review"
for _, id := range []string{openID, reviewID} {
id := id
if err := RunTx(ctx, provider, func(ctx context.Context, uw UnitOfWork) (string, error) {
_, err := uw.IssueUseCase().CreateIssue(ctx, domain.CreateIssueParams{
Issue: &types.Issue{
ID: id, Title: id, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask,
},
ExplicitID: id,
CreateOnly: true,
}, "tester")
return "seed " + id, err
}); err != nil {
t.Fatalf("CreateIssue(%s): %v", id, err)
}
}
if err := RunTx(ctx, provider, func(ctx context.Context, uw UnitOfWork) (string, error) {
return "move to review", uw.IssueUseCase().UpdateIssue(ctx, reviewID, map[string]any{
"status": types.Status("review"),
}, "tester")
}); err != nil {
t.Fatalf("UpdateIssue(%s) to review: %v", reviewID, err)
}
source, ok := provider.(CounterSource)
if !ok {
t.Fatalf("provider %T does not offer the Counter accessor", provider)
}
counter, err := source.Counter()
if err != nil {
t.Fatalf("Counter(): %v", err)
}
scope := publicops.CountRequest{IDFilter: openID + "," + reviewID}
total, err := counter.Count(ctx, scope)
if err != nil {
t.Fatalf("Count(unfiltered): %v", err)
}
if total.Total != 2 {
t.Fatalf("Count(unfiltered).Total = %d, want 2", total.Total)
}
// IncludeInfra left UNSET: before the fix this refused with "invalid
// exclude-status \"review\"" because the config load was gated on
// IncludeInfra alone.
scope.ExcludeStatus = []string{"review"}
result, err := counter.Count(ctx, scope)
if err != nil {
t.Fatalf("Count(exclude-status=review, IncludeInfra unset): %v, want the custom status accepted", err)
}
if result.Total != 1 {
t.Fatalf("Count(exclude-status=review).Total = %d, want 1", result.Total)
}
}

View file

@ -43,8 +43,11 @@ func ValidateCountGroup(group issueops.CountGroup) (string, error) {
// pinned by a golden-style test comparing this builder's output against
// BuildListFilter's for the same request (count_test.go, GH#4387).
//
// cfg supplies the workspace's infra vocabulary and is only read under
// IncludeInfra; a zero ListConfig falls back to the default infra set.
// cfg supplies the workspace's infra vocabulary and its custom status names.
// It is read under IncludeInfra AND whenever ExcludeStatus is non-empty (the
// exclusion is validated against the workspace's statuses), so a caller must
// load it in both cases; a zero ListConfig falls back to the default infra set
// and the built-in statuses only.
func BuildCountFilter(in issueops.CountRequest, cfg ListConfig) (types.IssueFilter, error) {
filter := types.IssueFilter{
TitleSearch: in.TitleSearch,
@ -103,6 +106,59 @@ func BuildCountFilter(in issueops.CountRequest, cfg ListConfig) (types.IssueFilt
filter.IDs = ids
}
// ParentID and NoParent are refused together, matching `bd list`'s CLI
// refusal of the same combination (cmd/bd/list_input.go) with the same
// wording — the role raises it as ErrValidation so a caller reaching this
// builder from any front door (HTTP, proxied CLI, a future client) gets
// the same refusal the primary CLI's flag parser gives, rather than the
// role silently answering the empty intersection.
if in.ParentID != "" && in.NoParent {
return types.IssueFilter{}, fmt.Errorf("--parent and --no-parent are mutually exclusive%.0w", issueops.ErrValidation)
}
if in.ParentID != "" {
parentID := in.ParentID
filter.ParentID = &parentID
}
if in.NoParent {
filter.NoParent = true
}
// ExcludeTypes is appended to, not assigned: applyCountIncludeInfra (below)
// contributes its own "gate" exclusion, and the two sets must compose
// rather than one silently discarding the other, exactly as
// BuildListFilter's ExcludeTypes and applyTypeSuppressions compose.
for _, raw := range in.ExcludeTypes {
for _, t := range strings.Split(raw, ",") {
t = strings.TrimSpace(t)
if t != "" {
filter.ExcludeTypes = append(filter.ExcludeTypes, types.IssueType(utils.NormalizeIssueType(t)))
}
}
}
// ExcludeStatus takes names as written but — unlike Status and IssueType
// above — IS validated against the workspace vocabulary (built-in statuses
// plus cfg's custom ones, the same set ApplyStatusFilter checks in
// list.go). An exclusion list is built by hand from a status name, so a
// misspelled entry here would silently exclude nothing and OVERCOUNT
// rather than undercount, which is a worse failure mode than the
// match-nothing treatment Status and IssueType accept above — so a typo
// is ErrValidation instead.
for _, raw := range in.ExcludeStatus {
for _, s := range strings.Split(raw, ",") {
s = strings.TrimSpace(s)
if s == "" {
continue
}
status := types.Status(s)
if !status.IsValidWithCustom(cfg.CustomStatusNames()) {
return types.IssueFilter{}, fmt.Errorf("invalid exclude-status %q (valid: %s)%.0w",
s, ValidStatusList(cfg.CustomStatusNames()), issueops.ErrValidation)
}
filter.ExcludeStatus = append(filter.ExcludeStatus, status)
}
}
if in.IncludeInfra {
applyCountIncludeInfra(&filter, in.IssueType, cfg)
} else if !in.IncludeEphemeral {

View file

@ -158,6 +158,204 @@ func TestBuildCountFilterNormalizesLabelsAndIDs(t *testing.T) {
}
}
// TestBuildCountFilterMapsParentAndNoParent pins ParentID/NoParent's mapping
// into types.IssueFilter, mirroring BuildListFilter's ParentID/NoParent
// mapping (internal/workapi/list.go) field for field.
func TestBuildCountFilterMapsParentAndNoParent(t *testing.T) {
got, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1"}, ListConfig{})
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
if got.ParentID == nil || *got.ParentID != "bd-1" {
t.Errorf("ParentID = %v, want \"bd-1\"", countPtrStr(got.ParentID))
}
if got.NoParent {
t.Errorf("NoParent = true, want false: request did not set it")
}
got, err = BuildCountFilter(issueops.CountRequest{NoParent: true}, ListConfig{})
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
if got.ParentID != nil {
t.Errorf("ParentID = %v, want nil: request did not set it", countPtrStr(got.ParentID))
}
if !got.NoParent {
t.Error("NoParent = false, want true")
}
}
// TestBuildCountFilterExcludeTypesSplitsAndNormalizes pins ExcludeTypes'
// mapping: comma-separated entries split, trim and normalize exactly as
// BuildListFilter's ExcludeTypes does, and the result APPENDS to (rather than
// replaces) whatever applyCountIncludeInfra later contributes.
func TestBuildCountFilterExcludeTypesSplitsAndNormalizes(t *testing.T) {
got, err := BuildCountFilter(issueops.CountRequest{
// "feat" is an alias (-> "feature", internal/utils/strings.go);
// "bug" is not, so it passes through unchanged.
ExcludeTypes: []string{" bug , feat", "", "chore"},
}, ListConfig{})
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
want := []types.IssueType{"bug", "feature", "chore"}
if !reflect.DeepEqual(got.ExcludeTypes, want) {
t.Errorf("ExcludeTypes = %v, want %v", got.ExcludeTypes, want)
}
// Composes with IncludeInfra's own "gate" exclusion rather than
// discarding it.
got, err = BuildCountFilter(issueops.CountRequest{
ExcludeTypes: []string{"chore"},
IncludeInfra: true,
}, ListConfig{})
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
want = []types.IssueType{"chore", "gate"}
if !reflect.DeepEqual(got.ExcludeTypes, want) {
t.Errorf("ExcludeTypes = %v, want %v (explicit exclusions composed with IncludeInfra's)", got.ExcludeTypes, want)
}
}
// TestBuildCountFilterParentFieldsMatchListFilter extends the GH#4387
// count/list cardinality-parity pin to the three new Count fields that DO
// have a List counterpart: ParentID, NoParent and ExcludeTypes must produce
// the identical types.IssueFilter contribution BuildListFilter does for the
// same request, since a filter contract test (backend/conformance) can only
// show the two AGREE on one backend's rows — this shows WHY, at the one place
// both builders share.
func TestBuildCountFilterParentFieldsMatchListFilter(t *testing.T) {
cfg := ListConfig{}
countGot, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1"}, cfg)
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
listGot, err := BuildListFilter(issueops.ListRequest{ParentID: "bd-1", AllFlag: true}, cfg)
if err != nil {
t.Fatalf("BuildListFilter: %v", err)
}
if !reflect.DeepEqual(countGot.ParentID, listGot.ParentID) {
t.Errorf("Count ParentID = %v, List ParentID = %v, want equal", countPtrStr(countGot.ParentID), countPtrStr(listGot.ParentID))
}
countGot, err = BuildCountFilter(issueops.CountRequest{NoParent: true}, cfg)
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
listGot, err = BuildListFilter(issueops.ListRequest{NoParent: true, AllFlag: true}, cfg)
if err != nil {
t.Fatalf("BuildListFilter: %v", err)
}
if countGot.NoParent != listGot.NoParent {
t.Errorf("Count NoParent = %v, List NoParent = %v, want equal", countGot.NoParent, listGot.NoParent)
}
countGot, err = BuildCountFilter(issueops.CountRequest{ExcludeTypes: []string{"wisp,feat"}}, cfg)
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
// IncludeAllTypes on the list side skips applyTypeSuppressions' OWN
// exclusions (template/gate/infra defaults), isolating the one thing this
// case compares: the explicit --exclude-type mapping.
listGot, err = BuildListFilter(issueops.ListRequest{ExcludeTypes: []string{"wisp,feat"}, AllFlag: true, IncludeAllTypes: true}, cfg)
if err != nil {
t.Fatalf("BuildListFilter: %v", err)
}
if !reflect.DeepEqual(countGot.ExcludeTypes, listGot.ExcludeTypes) {
t.Errorf("Count ExcludeTypes = %v, List ExcludeTypes = %v, want equal", countGot.ExcludeTypes, listGot.ExcludeTypes)
}
}
// TestBuildCountFilterExcludeStatusTakesNamesAsWritten pins ExcludeStatus: a
// Count-only field with no List counterpart (ListRequest computes its default
// exclusions internally and exposes no caller-facing knob for them). Entries
// split and trim like ExcludeTypes. UNLIKE Status and ExcludeTypes, each name
// IS validated against the workspace vocabulary (review S8 follow-up #3): a
// built-in name passes as written, and an unrecognized one is ErrValidation
// rather than silently excluding nothing.
func TestBuildCountFilterExcludeStatusTakesNamesAsWritten(t *testing.T) {
got, err := BuildCountFilter(issueops.CountRequest{
ExcludeStatus: []string{" closed , pinned", ""},
}, ListConfig{})
if err != nil {
t.Fatalf("BuildCountFilter: %v", err)
}
want := []types.Status{"closed", "pinned"}
if !reflect.DeepEqual(got.ExcludeStatus, want) {
t.Errorf("ExcludeStatus = %v, want %v", got.ExcludeStatus, want)
}
}
// TestBuildCountFilterExcludeStatusRejectsAnUnknownName pins the ErrValidation
// refusal (review S8 follow-up #3): a typo'd status name in --exclude-status
// must fail loudly rather than silently excluding nothing and overcounting.
func TestBuildCountFilterExcludeStatusRejectsAnUnknownName(t *testing.T) {
_, err := BuildCountFilter(issueops.CountRequest{
ExcludeStatus: []string{"no-such-status"},
}, ListConfig{})
if err == nil {
t.Fatal("BuildCountFilter accepted an unknown exclude-status name, want ErrValidation")
}
if !errors.Is(err, issueops.ErrValidation) {
t.Errorf("err = %v, want errors.Is(err, issueops.ErrValidation)", err)
}
}
// TestBuildCountFilterExcludeStatusAllowsAWorkspaceCustomStatus pins the other
// half of #3: a workspace-defined custom status is NOT a typo and must be
// accepted, following ApplyStatusFilter's own IsValidWithCustom precedent in
// list.go.
func TestBuildCountFilterExcludeStatusAllowsAWorkspaceCustomStatus(t *testing.T) {
cfg := ListConfig{CustomStatuses: []types.CustomStatus{{Name: "triaged"}}}
got, err := BuildCountFilter(issueops.CountRequest{
ExcludeStatus: []string{"triaged"},
}, cfg)
if err != nil {
t.Fatalf("BuildCountFilter rejected the workspace's own custom status: %v", err)
}
want := []types.Status{"triaged"}
if !reflect.DeepEqual(got.ExcludeStatus, want) {
t.Errorf("ExcludeStatus = %v, want %v", got.ExcludeStatus, want)
}
}
// TestBuildCountFilterRefusesParentAndNoParentTogether pins review S8
// follow-up #1: the role refuses the combination as ErrValidation, with the
// same wording `bd list`'s CLI already uses for the same combination
// (cmd/bd/list_input.go), so a caller reaching this role from any front door
// gets the identical refusal.
func TestBuildCountFilterRefusesParentAndNoParentTogether(t *testing.T) {
_, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1", NoParent: true}, ListConfig{})
if err == nil {
t.Fatal("BuildCountFilter accepted --parent with --no-parent, want ErrValidation")
}
if !errors.Is(err, issueops.ErrValidation) {
t.Errorf("err = %v, want errors.Is(err, issueops.ErrValidation)", err)
}
const want = "--parent and --no-parent are mutually exclusive"
if err.Error() != want {
t.Errorf("err = %q, want %q", err.Error(), want)
}
}
// TestBuildCountFilterStatusAllIsNotValidation pins DESIGN's requirement that
// Status "all" have well-defined semantics: it is the no-filter spelling
// (same as empty), NOT ErrValidation, because BuildListFilter's own "all"
// selector means the same thing and a count must stay able to answer the
// cardinality of `bd list --status all --all` for the shared predicate
// (GH#4387 count/list parity).
func TestBuildCountFilterStatusAllIsNotValidation(t *testing.T) {
got, err := BuildCountFilter(issueops.CountRequest{Status: "all"}, ListConfig{})
if err != nil {
t.Fatalf(`BuildCountFilter(status="all") returned an error, want nil: %v`, err)
}
if got.Status != nil {
t.Errorf(`status "all" produced Status = %v, want no status predicate`, countPtrStr(got.Status))
}
}
func TestBuildCountFilterCarriesMetadataFields(t *testing.T) {
fields := map[string]string{"team": "platform", "env": "prod"}
got, err := BuildCountFilter(issueops.CountRequest{MetadataFields: fields}, ListConfig{})

View file

@ -75,15 +75,18 @@ func (c *storeCounter) CountByGroup(ctx context.Context, req issueops.CountByGro
// filter builds the storage filter, loading the workspace configuration only
// when the request can read it.
//
// TWO THINGS ARE DELIBERATE. The load is SKIPPED unless IncludeInfra is set,
// because that flag is the only thing in a count request the configuration
// reaches. And when it does run it runs PER CALL rather than once at
// construction: the infra vocabulary is workspace state a caller can change
// between two counts, and a counter that cached it would answer for the older
// workspace.
// TWO THINGS ARE DELIBERATE. The load is SKIPPED unless IncludeInfra is set OR
// ExcludeStatus is non-empty — those are the two things in a count request the
// configuration reaches: IncludeInfra needs the infra vocabulary, and
// ExcludeStatus needs the workspace's custom status names so
// BuildCountFilter's validation does not refuse a status the workspace itself
// defines (PR #7199 review). And when it does run it runs PER CALL rather
// than once at construction: the infra vocabulary and custom statuses are
// workspace state a caller can change between two counts, and a counter that
// cached it would answer for the older workspace.
func (c *storeCounter) filter(ctx context.Context, req issueops.CountRequest) (types.IssueFilter, error) {
var cfg workapi.ListConfig
if req.IncludeInfra {
if req.IncludeInfra || len(req.ExcludeStatus) > 0 {
loaded, err := workapi.LoadStoreListConfig(ctx, c.store)
if err != nil {
return types.IssueFilter{}, err

View file

@ -54,6 +54,17 @@ type CountRequest struct {
// than quietly tightened, because a scripted caller that counts a status
// its workspace has since dropped currently reads 0 and would start reading
// an error.
//
// "all" is this field's one well-defined non-literal spelling, and it is
// NOT ErrValidation: it is equivalent to leaving Status empty, and
// BuildListFilter treats its own "all" selector identically (the no-filter
// spelling), so `bd count --status all <predicate>` and `bd list --status
// all <predicate> --all` already agree on cardinality for the shared part
// of the predicate. Rejecting it here would break that count/list parity
// (the whole point of this role, GH#4387) for every caller already
// spelling it, and there is no caller-visible ambiguity it would resolve:
// "no status" is a filter that excludes every row, which "all" has never
// meant on either front door.
Status string
// IssueType restricts the type, with the same match-nothing-rather-than-fail
// treatment Status gets and no alias expansion at all.
@ -66,6 +77,24 @@ type CountRequest struct {
// written and answer with the empty intersection.
Assignee string
// ParentID restricts to one issue's children, spelled as
// ListRequest.ParentID spells it: a parent-child dependency edge, OR (for
// an issue with no such edge) a dotted-id prefix match. NoParent restricts
// to rows with no parent-child dependency edge. It does not consult the
// dotted-id convention, so an edge-less dotted-id child (X.1) still counts
// as top-level — it is counted by BOTH ParentID X and NoParent, as it is
// listed by both `bd list --parent X --flat` and `bd list --no-parent`.
//
// Setting both IS refused, as ErrValidation, UNLIKE Assignee/NoAssignee
// above: `bd list`'s CLI already refuses `--parent` with `--no-parent`
// (cmd/bd/list_input.go) with this same wording, and a caller reaching
// this role directly — over HTTP, or through a future client that skips
// the primary CLI's flag parser — gets the identical refusal rather than
// a silent empty-intersection answer the primary CLI would never have let
// it ask for.
ParentID string
NoParent bool
// Priority is an exact priority; PriorityMin and PriorityMax bound a range
// inclusively. All three are pointers because 0 is a real priority, for the
// reason ReadyRequest.Priority gives.
@ -86,6 +115,25 @@ type CountRequest struct {
// rather than a slice it had to prepare.
IDFilter string
// ExcludeTypes names types to exclude, spelled as ListRequest.ExcludeTypes
// spells it: entries may be comma-separated, splitting and normalization
// happen inside, and an entry is NOT validated against the workspace
// vocabulary — an unrecognized type excludes nothing rather than failing.
// It composes with IncludeInfra's own "gate" exclusion rather than
// replacing it: both contribute to the same exclusion set.
ExcludeTypes []string
// ExcludeStatus names statuses to exclude. Unlike Status, this has no
// List counterpart — ListRequest computes its default status exclusions
// internally from workspace configuration and exposes no caller-facing
// knob for them. Here it is a new, Count-only capability (behavior token
// `issues.count.scope`): entries may be comma-separated, and — UNLIKE
// Status and ExcludeTypes above — each name IS validated against the
// workspace vocabulary (built-in statuses plus the workspace's own custom
// ones). An unrecognized name is ErrValidation rather than excluding
// nothing: a caller building an exclusion list by hand gets a loud failure
// on a typo instead of a silently wider, overcounted answer.
ExcludeStatus []string
// TitleContains, DescContains and NotesContains are substring matches on
// the three long fields, spelled as ListRequest spells them so the two
// requests cannot drift apart in naming while meaning the same thing.

View file

@ -54,7 +54,15 @@ type ReadyRequest struct {
// the other, and P0 has already been lost that way once.
Priority *int
// ParentID restricts to recursive descendants of one issue.
// ParentID restricts to ALL TRANSITIVE DESCENDANTS of one issue, not just
// its direct children: internal/storage/issueops/ready_work.go calls
// GetDescendantIDsInTx(ctx, tx, *filter.ParentID, 0), the recursive walk.
// GH#3396: this used to be a one-hop subquery against the dependency
// table, so grandchildren were silently dropped despite this comment and
// the help text both promising "descendants (recursive)" — do not
// mistake this for ListRequest.ParentID's non-walking clause, which is a
// DIFFERENT query (PR #7199 review: an earlier pass here wrongly copied
// that one-level wording onto this field).
ParentID string
// MolType restricts to one molecule type.
MolType *MolType
@ -339,6 +347,29 @@ type ListRequest struct {
// ExcludeTypes entries may be comma-separated; splitting happens inside.
ExcludeTypes []string
// ParentID restricts to one issue's children through one SQL clause, the
// same one CountRequest.ParentID compiles to
// (internal/storage/sqlbuild/filter.go): a parent-child dependency edge
// onto ParentID, OR, for a row with no parent-child edge at all, an id
// under ParentID's dotted prefix ("X.1", "X.1.1"). NEITHER ARM WALKS. The
// edge arm stops at one level, so a grandchild with an edge of its own is
// not in the answer, while the prefix arm reaches every edge-less dotted
// id at any depth (backend/conformance/reader_contract.go pins that arm).
// It is NOT the recursive descendants walk — that is ReadyRequest.ParentID
// above, a DIFFERENT field on a different request, backed by
// GetDescendantIDsInTx (GH#3396); on the ReadyFlag arm this field crosses
// to that query and resolves recursively there.
// The recursive tree that `bd list --parent X` renders by DEFAULT comes
// from cmd/bd/list_show_filter_modes.go's findAllDescendants re-running
// this clause against the store once per level and accumulating the
// results client-side, not from this field answering a deeper question.
// --flat, --json and --format skip that walk and return exactly this
// field's answer, which is why the flat listing is the invocation that
// agrees with `bd count --parent X`'s cardinality.
//
// NoParent restricts to rows with no parent-child dependency edge. It has
// no dotted-id arm, so an edge-less "X.1" matches BOTH ParentID X and
// NoParent. The ReadyFlag arm refuses it; see that field.
ParentID string
NoParent bool
MolType *MolType