* fix(storage): include custom active-category statuses in bd ready (#5831) (#5918) bd ready pins WorkFilter.Status to StatusOpen. BuildReadyWorkWhere treated that pin as an exact match, so issues in a custom status with category active never appeared — even though bd statuses --help, the ready_issues view (migration 0025), and ClaimableSourceStatusesInTx all treat that category as ready-eligible. Widen the singular StatusOpen clause to the same predicate the view uses: status = ? OR status IN (SELECT name FROM custom_statuses WHERE category = 'active') Non-open singular statuses stay exact. Built-in open still matches. Custom wip/done/frozen/unspecified statuses stay out, matching claim's GH-3570 anti-steal set. Reported by Justin Clemens (@justin-candor). Addresses #5831 (cherry picked from commit66aa73bb99) * fix(cli): `bd list --wisp-type` cannot match a row — register the plane knob it needs (#6098) `bd list --wisp-type heartbeat` returns an empty listing for EVERY input, and `bd list` exposes no flag that changes that. ListRequest.WispType is a predicate, not a plane selector — its own doc says so, and RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt pins it. That contract is right and this does not touch it. The doc also names the way out: The combination that answers with rows is IncludeEphemeral (or IncludeInfra) plus this, and it is lawful rather than refused. `bd list` registers neither `--include-ephemeral` nor `--all-types`. So of the two combinations the doc names, the CLI can express only IncludeInfra — which admits the plane AND lifts the infra-type exclusions AND changes the template treatment, three decisions a caller who wanted one classification did not ask for. The narrow knob the doc names FIRST has no flag at all. That is the whole defect: the API composes correctly, and the CLI is missing the other half of the pair. ## What this does 1. Registers `--include-ephemeral` on `bd list`, wired to `ListRequest.IncludeEphemeral` — the plane knob alone, off by default, so the default listing is byte-identical. 2. Refuses `--wisp-type` when no plane is admitted, with the fix in the hint, instead of printing an empty listing. The refusal is at the CLI layer ONLY. At the API layer the combination stays lawful and still composes to an empty page: that is the pinned contract, and a programmatic caller composing filters may legitimately land on it. A human typing `--wisp-type heartbeat` cannot have meant "prove to me that durable rows carry no classification", so the CLI is where the guess is safe to make. An explicit `--type` is deliberately left alone: an infra type routes to the plane by itself, so the request may well be satisfiable, and this layer cannot tell which types those are without loading the workspace's infra vocabulary. Refusing there would reject lawful, answerable requests. ## Verification --- PASS: TestListRegistersIncludeEphemeral --- PASS: TestGatherListInput_WispTypeWithoutAPlaneIsRefused --- PASS: TestGatherListInput_WispTypeWithAPlaneIsAccepted (3 subtests) --- PASS: TestGatherListInput_IncludeEphemeralReachesTheRequest The pair discriminates rather than being trivially green: a guard that refused every `--wisp-type` would pass the refusal test and fail all three acceptance subtests, one per route that admits the plane. `ok github.com/steveyegge/beads/cmd/bd`, `ok github.com/steveyegge/beads/internal/workapi`, `go build ./...` and `go vet` clean. `internal/workapi/list.go` and the golden corpus are untouched. docs/CLI_REFERENCE.md is not regenerated here: the docs pipeline builds from the release tag in docs/cli-docs.pin (v1.2.2), not from this checkout, so the new flag appears at the next release bump. Claude-Session: https://claude.ai/code/session_01X1jMLQTSrCwtzFRS1xeUC6 (cherry picked from commitcbf84cb1c0) * fix(list): honor --status when combined with --ready (#5924) * fix(list): honor --status when combined with --ready (#5832) `bd list --status X --ready` silently dropped --status and returned the unfiltered ready set (typically open issues). BuildListFilter pinned StatusOpen whenever ReadyFlag was set, and ReadyFilterFromIssueFilter hard-coded the same pin, so a custom status or in_progress selector never reached GetReadyWork. --ready without --status still defaults to open. An explicit --status is now the ready-work status selector, matching how other list filters already compose with --ready. `--status all` remains the no-filter spelling and keeps the open default. * fix(list): status-aware --ready footer and honor-path contract docs (#5832) The query intersection from the prior commit is unchanged. Round-1 review asked the ReadyFlag/Statuses contract comments and the text footer to describe the honor path: default --ready is still open, an explicit --status is named instead of "excludes in_progress". (cherry picked from commitf5a20fb66b) * fix(doctor): ignore the generated dolt-server-config.yaml (#5978) doltserver.Start() writes .beads/dolt-server-config.yaml when the resolved dolt binary supports auto_gc_behavior.archive_level. Its own doc comment says the file "lives alongside the other gitignored server state files in beadsDir", but the hyphenated name falls outside the "dolt-server." prefix shared by the other five entries, so both GitignoreTemplate and requiredPatterns missed it. The file holds an absolute cfg_dir and a per-machine port, so committing it breaks every other clone -- the same reason the template already gives for 'redirect'. It shows up as untracked in every consumer repo whose dolt supports archive_level. This repo does not see it because its own root .gitignore has a blanket .beads/* rule. Add the pattern to requiredPatterns as well as the template: the template only helps repos initialised after this change, while requiredPatterns is what missingGitignorePatterns() iterates, so it is what lets bd doctor --fix append the rule to an existing .beads/.gitignore. Co-authored-by: Adam Spiers <ai@adamspiers.org> (cherry picked from commit671db6560d) * fix(storage): stop recommending an inert config.yaml key for a missing prefix (#5936) ReadConfigPrefix gates on the database's config table row `issue_prefix`. When that row is absent its error told the operator that, "if using config.yaml, use key 'issue-prefix', not 'issue_prefix'" — but this gate never consults config.yaml. The YAML value is read one line above the error solely to populate a debug.Logf diagnostic; it is discarded, so setting `issue-prefix` in config.yaml leaves the gate failing exactly as before. Following the advice produces a tracked config field that changes nothing and misleads the next reader. Point the message at what actually writes the row — `bd init --prefix` or `bd bootstrap`, both of which it already named — and say plainly that the check reads the database's config table so the config.yaml key does not satisfy it. No resolution behavior changes; this is the error text only. Reported-by: @ncljesus Closes #5916 (cherry picked from commit61ec85181f) * fix(create): say --file is one issue per ## heading (#5921) bd create --file/-f is a batch-import route: it creates one issue per H2 ("##") heading, and ### subsections attach fields to that issue. The old Usage was "Create multiple issues from markdown file", which never named those semantics or --body-file. Callers who wanted "one issue, description loaded from a file" reached for the shortest flag and got a silent bulk import instead -- reported by @seanmartinsmith with a 3-section briefing file (## Problem / ## Context / ## Acceptance Criteria) that became 3 issues instead of one. gatherCreateInput already rejects a positional title combined with --file. That is the reporter's literal repro, so this keeps the rejection and adds a --body-file hint on the error they actually see. The remaining trap -- --file used alone on a section-headed file -- is unchanged, because bd cannot tell that apart from a genuine batch file by content. Tests: parseMarkdownFile reproduces the trap file; gatherCreateInput locks in the title+--file rejection and --body-file hint; flag Usage names the per-heading behavior. The existing TestCreateFromMarkdownFile binary path already covers well-formed --file creates. (cherry picked from commit67b066b58e) * fix(list): stop truncation hint padding a blank TTY line (#5927) printTruncationHint fed surrounding newlines through ui.RenderWarn. lipgloss treats that as a block, pads the blank lines to the widest-line width (alignTextHorizontal shortAmount = widestLine - lineWidth), and drops the trailing newline (GH#5685). The next shell prompt then prints on the same line as a run of spaces. Keep the newlines outside RenderWarn so the hint is one colored line with a real trailing newline. Tests construct an explicitly styled lipgloss Style so the padded blank-line shape fails if the helper is reverted. Fixes #5685. (cherry picked from commit766c0bd15a) * fix(setup/claude): keep settings.json's trailing newline and skip no-op rewrites (#5944) * fix(setup/claude): keep settings.json's trailing newline and skip no-op rewrites (#5693) bd setup claude (and bd init, which calls it) marshalled the Claude settings map with json.MarshalIndent and wrote it unconditionally. MarshalIndent emits no trailing newline, so every run stripped the one Claude Code's own writes leave behind, and re-wrote the file even when no hook changed. Because bd init git-adds .claude/settings.json, that surfaced as a staged diff with no semantic content. The same marshal-then-write pattern appears at four call sites in claude.go: installClaude's settings write and its settings.local.json migration, and removeClaude's settings write and its settings.local.json cleanup. Fixing one would have left the bug live in the other three, so both halves are now shared helpers -- marshalSettings appends the newline, writeSettingsIfChanged compares against the bytes already on disk and returns early when they match -- and all four sites go through them. Reported by @maphew. * chore(setup/claude): use the repo spelling "marshaled" in the new comments The misspell linter flags British "marshalled"; CI pins golangci-lint v2.10.1 and runs it with --new-from-merge-base, so both new comment lines are in scope. Comment text only, no behaviour change. (cherry picked from commitcad7e17d70) * fix(gate): evaluate cross-rig bead gates via prefix routes (#5859) * fix(gate): route cross-rig bead checks (#5857) Evaluate historical rig:bead gate targets through the current read-only prefix routing seam in direct and proxied-server modes. Preserve local bead gates, reject malformed cross-rig values, and cover the real two-store route with a Dolt integration test. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Klas Hesselman * fix(gate): address cross-rig review feedback (#5857) Preserve the original local not-found error when prefix routing is unavailable, document the user-visible behavior, and lock the proxied error contract with a regression test. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Klas Hesselman (cherry picked from commitcbfc505e39) * fix(storage/uow): retry transient ping failures during openDB bootstrap (#6003) * test(uow): red — pingWithRetry does not exist yet for openDB's boot-time ping Adds TestPingWithRetryRecoversFromATransientBadConn (be-x49l6): a fake pinger exercising three cases — transient error retries then recovers, non-transient error fails without retrying, and an already-cancelled context fails promptly. Fails to compile until pingWithRetry/pinger are added to dolt_sql_provider.go. * feat: green — Fix: unretried ping in uow openDB turns a transient Dolt connection drop into a hard CI failure (refs be-x49l6) * refactor: drop what-comment on pingWithRetry (self-review, refs be-x49l6) Self-review flagged it as restating the function's own signature/behavior rather than explaining a non-obvious why; the pinger and isTransientPingError comments stay since they carry rationale the code doesn't otherwise convey. * test(uow): red — a hung boot ping is not bounded per attempt Adds the two behaviours review #6003 asked for, both failing: - a_hung_ping_is_capped_per_attempt_and_retried: blockingPinger stalls until its context is cancelled. backoff.Retry bounds only the gap between attempts, so with the caller's context handed straight to PingContext the call never returns at all. The subtest runs the call off-goroutine so this reports as "never returned" instead of a package timeout. - connection-level_net_error_retries_then_recovers: a *net.OpError (connection refused / reset / broken pipe) is currently classified non-transient and fails the boot ping outright. the_caller's_own_deadline_fails_without_retrying passes already and is kept as the regression guard for the trap #6000 fell into: making context.DeadlineExceeded retryable must not make the caller's own expiry retryable too. pingWithRetry takes attemptTimeout here but does not honour it yet, so the red is behavioural rather than a compile error. Refs be-g1i7n. * fix(uow): bound each boot ping attempt and widen the transient classifier Review #6003, point 1. backoff.Retry bounds the gap between attempts but cannot interrupt one in flight, and the DSN sets a dial Timeout (5s) with no ReadTimeout — so a server that accepts TCP and then stalls mid-handshake blocked for the caller's entire context, which is the exact scenario the PR summary claims to fix. Each attempt now runs under its own context.WithTimeout (pingAttemptTimeout, 10s — above the 5s dial timeout so a real dial timeout still surfaces as itself), and context.DeadlineExceeded is classified transient so the retry loop actually continues. pingWithRetry checks the caller's context *before* classifying. That is what keeps the retryable DeadlineExceeded from swallowing the caller's own expiry — the inverse of the regression #6000 introduced by capping each attempt and then treating the resulting DeadlineExceeded as permanent. Covered from both sides: a_hung_ping_is_capped_per_attempt_and_retried and the_caller's_own_deadline_fails_without_retrying. Review #6003, point 2. isTransientPingError stays separate from internal/storage/dolt's isRetryableError, and now says why in full: that one is a query-time classifier matching on error text, admitting migration-lock, read-only and MySQL-1105 shapes a boot ping cannot be in because nothing has executed on the connection yet. The coverage gap the review named is closed on this side instead — *net.OpError is transient, which is refused/reset/broken-pipe portably and by type rather than by substring, with permanent DNS failures excluded so an unresolvable host still fails fast instead of spending the whole budget. Refs be-g1i7n. (cherry picked from commitc0d8da42de) * fix(deps): bump dolt/go past upstream manifest-missing-chunk defense (#4070) (#5931) * fix(deps): bump dolt/go past upstream manifest-missing-chunk defense (#4070) Pin github.com/dolthub/dolt/go to 796d074977417da931df65202a79e0a7f532a3db. That hop includes: - 23ccbf9442275166f168939277a5b4a348a63c9d — reject a file manifest update that references a missing table file (the defense itself) - 796d074977417da931df65202a79e0a7f532a3db — doc/test follow-up to the defense commit (no production-semantics change) A non-atomic backup sync can leave the backup manifest ahead of chunk files; subsequent syncs then fail with "table file not found" and stay broken. The upstream defense turns that silent corruption into a loud failed sync. Beads' previous pin (a6690826d767, 2026-07-15) predates both commits. Minimal-churn pin: do not bump to today's dolt tip. go mod tidy did not force a later version. This is a mitigation, not a root-cause fix: backup file+manifest publish remains non-atomic, and backups already in the manifest-ahead state are not repaired by this change. Mitigates #4070 * fix(nix): update vendorHash for the dolt/go bump The go.mod/go.sum bump in this PR invalidates the pinned vendorHash, so `nix build .#default` fails with a fixed-output hash mismatch. Update it to the value CI computed: specified: sha256-D+KDoLFJHpt9D9rCrtE3NMfL4fgK7UxpdKlCxp5yz5Y= got: sha256-wDU1tw/4t2CetwQl4+zUhlDI70dSasLLI2Gy66ZyhQQ= The repo documents this coupling in .github/dependabot.yml; the existing "Update vendorHash for dependabot Go bumps" workflow only fires for dependabot PRs, so a manual bump is needed here. (cherry picked from commit851aa2f20a) * docs(changelog): record the 1.3.1 cherry-pick behaviour deltas Documents all eleven picks under the existing `## [1.3.1]` heading. The six behaviour deltas go under Changed, including the two that are not pure wins and that a user is most likely to hit without knowing why: - bd doctor now warns on every pre-existing workspace until --fix appends the new .beads/dolt-server-config.yaml gitignore rule. - opening a store against a dead server takes up to ~30s to fail instead of failing instantly, because the boot ping is retried. Also called out as non-obvious: the ready set grows where custom active-category statuses exist, bare --wisp-type becomes a refusal rather than an empty success, and the Dolt bump converts a quietly corrupting backup sync into a loud failing one without repairing backups already in that state. The dated `## [1.3.0]` section is shipped and is left byte-identical: the diff is 165 insertions and 0 deletions, and the [1.3.0]-to-EOF region still hashes to 798a2ee0b0f0b7a3f0fc017ae01c919807740348a34f5ea8719b82a008533d00. The `## [1.3.1]` date is left for a later release prep to restamp. * fix(nix): recompute vendorHash for the release-branch dependency set The #5931 cherry-pick (510675948) bumps four dolt module pins, which invalidates the pinned vendorHash. Neither side's value was usable: the release branch already carried its own dependency bump (d594092eb), so this pick lands on a vendor set that has existed on neither release/1.3.0 nor main, and #5931's own hash was computed against main's graph. Taken from the `got:` value the nix-build lane reported for this branch: specified: sha256-wDU1tw/4t2CetwQl4+zUhlDI70dSasLLI2Gy66ZyhQQ= got: sha256-DQdauEx5g48Xbxrz4wGLx4vkrQoYQX3FUx+7N/Y6YV4= go mod tidy after the pick was a no-op, and the dependency delta against the release tip is exactly the four intended pins, so this hash covers that change and nothing else. * docs(changelog): scope the #6003 open-latency entry and correct its bound The 1.3.1 entry for the openDB bootstrap-ping retry said "up to ~30s" and named no topology. Both were misleading: - 30s is the retry BUDGET, not the wall-clock bound. backoff stops scheduling new attempts at 30s (MaxElapsedTime, dolt_sql_provider.go) but cannot cancel one in flight, and pingAttemptTimeout caps an attempt at 10s — so a single open can take ~40s. openAndInitSchema pings twice, each with a fresh budget, so the narrow case where the backend satisfies the first ping and the schema init and is then unreachable for the second reaches ~80s. - Only unit-of-work provider construction takes that ping, which is a minority of topologies: proxied-server (local and external) on every command, plus `bd serve` in server/external-server/shared-server workspaces, which funnels through newSQLServerUOWProvider. Embedded never reaches it (bd serve refuses embedded outright), and an ordinary CLI command in a server or shared-server workspace opens a DoltStore that takes no such ping. An embedded reader of the old entry would have triaged a slowdown that cannot affect them. CHANGELOG only; the dated [1.3.0] section is unchanged (verified byte-identical, sha256 798a2ee0…, 9169 lines). --------- Co-authored-by: Vishnu J <vishnuj81093@gmail.com> Co-authored-by: Karel Bourgois <karel@voxist.com> Co-authored-by: Adam Spiers <github@adamspiers.org> Co-authored-by: Adam Spiers <ai@adamspiers.org> Co-authored-by: swedeinasia-flow <klas@flownetworks.io> Co-authored-by: Jim Wordelman <jim@wordelman.name>
190 lines
8 KiB
Go
190 lines
8 KiB
Go
package workapi
|
|
|
|
import (
|
|
"cmp"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/utils"
|
|
)
|
|
|
|
// CompareIssuesBy orders two issues by one of `bd list --sort`'s fields.
|
|
// An unknown field compares equal, which leaves the underlying order intact.
|
|
func CompareIssuesBy(a, b *types.Issue, sortBy string) int {
|
|
switch sortBy {
|
|
case "priority":
|
|
return cmp.Compare(a.Priority, b.Priority)
|
|
case "created":
|
|
return b.CreatedAt.Compare(a.CreatedAt)
|
|
case "updated":
|
|
return b.UpdatedAt.Compare(a.UpdatedAt)
|
|
case "closed":
|
|
if a.ClosedAt == nil && b.ClosedAt == nil {
|
|
return 0
|
|
} else if a.ClosedAt == nil {
|
|
return 1
|
|
} else if b.ClosedAt == nil {
|
|
return -1
|
|
}
|
|
return b.ClosedAt.Compare(*a.ClosedAt)
|
|
case "status":
|
|
return cmp.Compare(a.Status, b.Status)
|
|
case "id":
|
|
return utils.NaturalCompareIDs(a.ID, b.ID)
|
|
case "title":
|
|
return cmp.Compare(strings.ToLower(a.Title), strings.ToLower(b.Title))
|
|
case "type":
|
|
return cmp.Compare(a.IssueType, b.IssueType)
|
|
case "assignee":
|
|
return cmp.Compare(a.Assignee, b.Assignee)
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// ReadyFilterFromIssueFilter projects a list filter onto the ready-work
|
|
// filter, which is how `--ready` reuses the whole list vocabulary against the
|
|
// blocker-aware query. WorkFilter is the narrower of the two, so this is a
|
|
// deliberate lossy projection: what it does not carry, ready work does not
|
|
// filter on.
|
|
func ReadyFilterFromIssueFilter(filter types.IssueFilter) types.WorkFilter {
|
|
wf := types.WorkFilter{
|
|
Limit: filter.Limit,
|
|
Offset: filter.Offset,
|
|
Labels: filter.Labels,
|
|
LabelsAny: filter.LabelsAny,
|
|
ExcludeLabels: filter.ExcludeLabels,
|
|
LabelPattern: filter.LabelPattern,
|
|
LabelRegex: filter.LabelRegex,
|
|
ParentID: filter.ParentID,
|
|
MolType: filter.MolType,
|
|
WispType: filter.WispType,
|
|
ExcludeTypes: filter.ExcludeTypes,
|
|
MetadataFields: filter.MetadataFields,
|
|
HasMetadataKey: filter.HasMetadataKey,
|
|
MaxRows: filter.MaxRows,
|
|
MaxRowsSource: filter.MaxRowsSource,
|
|
// Carried, where SkipLabels and SkipCounts are dropped: those two hide
|
|
// a number the ready renderings print, and this bounds a body no
|
|
// listing prints. Dropping it here would answer `bd list --ready
|
|
// --brief` with full rows and nothing to say why.
|
|
Lite: filter.Lite,
|
|
}
|
|
// Status is copied the same way as assignee/priority/labels: an explicit
|
|
// selector on the list filter is the ready-work selector too. The open
|
|
// default is only the fallback when BuildListFilter did not write one
|
|
// (plain `--ready`, or `--ready --status all`). Hard-coding StatusOpen
|
|
// here used to drop `--status` even after the builder honored it (GH#5832).
|
|
if filter.Status != nil {
|
|
wf.Status = *filter.Status
|
|
} else if len(filter.Statuses) > 0 {
|
|
wf.Statuses = append([]types.Status(nil), filter.Statuses...)
|
|
} else {
|
|
wf.Status = types.StatusOpen
|
|
}
|
|
if filter.IssueType != nil {
|
|
wf.Type = string(*filter.IssueType)
|
|
}
|
|
if filter.Priority != nil {
|
|
wf.Priority = filter.Priority
|
|
}
|
|
if filter.Assignee != nil {
|
|
wf.Assignee = filter.Assignee
|
|
}
|
|
if filter.NoAssignee {
|
|
wf.Unassigned = true
|
|
}
|
|
// The ephemeral PLANE, which the two filters spell differently: a list
|
|
// filter admits it by leaving SkipWisps off (or, for an infra type, by
|
|
// routing to it outright), and a work filter by setting IncludeEphemeral.
|
|
// Reading both spellings is what carries ListRequest.IncludeEphemeral —
|
|
// and IncludeInfra's plane half with it — onto the --ready arm instead of
|
|
// dropping it there, which would answer a request that named the plane
|
|
// with the durable set and no error.
|
|
//
|
|
// THE PREDICATE IS NEGATIVE, on a field whose ZERO VALUE means admit. That
|
|
// is deliberate but it is a footgun worth naming: this fires for any filter
|
|
// that merely never set SkipWisps, not only for one that asked. Every
|
|
// caller today is handed a filter built by BuildListFilter, which decides
|
|
// that field for every request, so "unset" is not reachable here — a
|
|
// hand-built types.IssueFilter{} passed in from somewhere new would get the
|
|
// wisp plane it never asked for. Keep the construction on the builder.
|
|
if (filter.Ephemeral != nil && *filter.Ephemeral) || !filter.SkipWisps {
|
|
wf.IncludeEphemeral = true
|
|
}
|
|
return wf
|
|
}
|
|
|
|
// WithFetchOneExtra bumps Limit by one so the caller can detect "more results
|
|
// than the limit" (GH#3212) by comparing the row count against the original
|
|
// limit.
|
|
//
|
|
// `--limit N --max-rows N` (equal) needs special handling so this bump doesn't
|
|
// collide with the MaxRows cap check: EffectiveSearchLimit treats
|
|
// Limit==MaxRows as "no overage sniff" (returns Limit verbatim, no +1 — see
|
|
// EffectiveSearchLimit's doc and the WithLimit_LimitAtCap_NoError storage
|
|
// test), but bumping Limit to N+1 alone flips that to Limit>MaxRows, which
|
|
// *does* sniff for overage — so the probe row itself would trip
|
|
// EnforceMaxRowsCap(N+1, N, ...) even though the delivered set is always
|
|
// trimmed back to N. Bumping MaxRows by one in lockstep, only in this exact
|
|
// N==M case, keeps the probe row inside the (temporarily N+1) cap so
|
|
// EnforceMaxRowsCap never fires on it while still fetching N+1 rows for the
|
|
// truncation check. This can't false-negative a real violation: the query's
|
|
// own LIMIT is capped at N+1 either way, so "more than N+1 matches exist" was
|
|
// already undetectable at Limit==MaxRows before this bump ever existed (the
|
|
// same "no overage detection above the equal cap" contract EffectiveSearchLimit
|
|
// documents for the unbumped case).
|
|
//
|
|
// This does not change the Limit>MaxRows (tighter-cap) or Limit<MaxRows cases:
|
|
// EffectiveSearchLimit's branch selection there is unaffected by a one-row bump
|
|
// to Limit, and MaxRows is left untouched, so a genuine tighter-cap violation
|
|
// still fires with the correct (unbumped) Cap value in the error message.
|
|
// The pair of steps this performs — bump the cap in lockstep at Limit==MaxRows,
|
|
// then bump Limit — is also written as one function for the seam that renders
|
|
// its probe row inside the query rather than onto a filter; see
|
|
// internal/storage/issueops.SearchProbeLimit. Change one and change the other,
|
|
// or the two implementations of issueops.Reader.List stop agreeing about when a
|
|
// cap fires.
|
|
func WithFetchOneExtra(filter types.IssueFilter) types.IssueFilter {
|
|
if filter.Limit > 0 {
|
|
if filter.MaxRows > 0 && filter.Limit == filter.MaxRows {
|
|
filter.MaxRows++
|
|
}
|
|
filter.Limit++
|
|
}
|
|
return filter
|
|
}
|
|
|
|
// WithRowsBeforeThePage moves an OFFSET off the query and onto the epilogue: it
|
|
// widens the filter's row bound to cover the rows the epilogue will skip, and
|
|
// clears the Offset the builder carried so the query does not skip them too.
|
|
// An unbounded filter needs no widening — it already carries every matching row.
|
|
//
|
|
// It is the filter half of FinishPageAt, and the reason both halves exist is
|
|
// there: the skip belongs after the display order, and the rows it drops are
|
|
// rows the MaxRows cap has to have counted. Apply it BEFORE WithFetchOneExtra,
|
|
// which sizes the probe row against the bound this leaves.
|
|
//
|
|
// The builders still write Offset onto the filter, for the callers that consume
|
|
// it as a VALUE and run their own query — `bd list --watch`, the proxied
|
|
// hierarchical --parent walk, proxied `bd ready` — where there is no shared
|
|
// epilogue to move it to. Those callers get the same cap boundary anyway: the
|
|
// seam beneath them widens its own bound by the offset and keeps the skip
|
|
// whenever a cap is set, for the reason stated above (internal/storage/domain/db,
|
|
// searchWindow).
|
|
func WithRowsBeforeThePage(filter types.IssueFilter, offset int) types.IssueFilter {
|
|
filter.Offset = 0
|
|
if offset > 0 && filter.Limit > 0 {
|
|
filter.Limit += offset
|
|
}
|
|
return filter
|
|
}
|
|
|
|
// WithReadyRowsBeforeThePage is WithRowsBeforeThePage for the ready-work filter,
|
|
// which is a different type carrying the same two fields.
|
|
func WithReadyRowsBeforeThePage(filter types.WorkFilter, offset int) types.WorkFilter {
|
|
filter.Offset = 0
|
|
if offset > 0 && filter.Limit > 0 {
|
|
filter.Limit += offset
|
|
}
|
|
return filter
|
|
}
|