beads/internal/workapi/doc.go
CI Bot 1ce5e13cb1 refactor(show): share issue-detail assembly and normalize not-found (bd-hc1)
Lift the detail view - labels, dependencies with metadata, the three
cardinality counts, the comments-omitted flag, the shallow dependent
rows, and epic progress - into internal/workapi/detail.go behind
BuildIssueDetails + DetailSource, with store and UOW adapters. Both
copies in cmd/bd are deleted: bd show's direct assembly block and
proxiedBuildDetails, along with proxiedGetIssueOrWisp, proxiedCountDeps,
and proxiedCountComments. Fuzzy id resolution, --current, watch mode,
and the array-of-one output envelope stay CLI-local; so do
proxiedListDeps and proxiedGetComments, which feed terminal rendering
rather than the shared shape.

The point of the slice is the correctness fix, not the code motion. The
two storage seams disagree about "no such issue": the store wraps
storage.ErrNotFound, while db.issueSQLRepositoryImpl.Get returns a bare
sql.ErrNoRows that issueUseCaseImpl.get wraps with the id - never
storage.ErrNotFound, and never a (nil, nil) pair. workapi.GetIssueOrWisp
normalizes both shapes, plus nil-issue-with-nil-error, to the
storage.ErrNotFound sentinel, and short-circuits hard errors instead of
retrying them against the wisp table. Putting that in the shared
function - not in a caller - is what stops the next frontend
reintroducing either failure mode: `if err != nil || issue == nil` -> 404
reports a dropped connection as a missing issue, and its mirror image
ships a 500 for one.

Six proxied callers inherit the fix. Most visibly, `bd show <missing-id>`
in proxied mode printed "Error fetching x: get x: sql: no rows in result
set" and gate list answered "issue not found" for any backend failure at
all; both now say what actually happened.

Two behaviour deltas, both in error paths the corpus does not cover:
the proxied JSON path no longer swallows a failed --include-dependents /
--include-comments read (it errors like the direct path always has), and
a proxied lookup that fails for a non-not-found reason reports that
reason. Row streams are collected through storage.Iter on both seams,
so the direct path keeps its be-4d36f2 streaming and the proxied path
gains it; the comment collector now copies each value, per Iter's
documented pointer-reuse contract.

Also deletes shallowDependentsForJSON, which had no production caller
left; its be-4d36f2 guard moves to workapi as
TestBuildIssueDetailsShallowDependents.

Verification: protocol corpus unchanged structurally (no diff under
cmd/bd/protocol vs the base) and behaviourally (TestCorpusGolden green
with BEADS_PROTOCOL_REQUIRE_DOLT=1, before and after);
TestProxiedServerShow{,2,3} 50/50 subtests green with
BEADS_TEST_PROXIED_SERVER=1; TestEmbeddedShow 21/21 green with
BEADS_TEST_EMBEDDED_DOLT=1; TestShow_* green individually;
TestCoverage_ShowUpdateClose green; TestProxiedServer{State,SetState,
Label,Comment,GateList,GateCheck} green. TestShow_IDFlag and
TestCoverage_TemplateAndPinnedProtections fail identically on the base
commit (in-process harness state leakage), and TestCoverage_ShowThread
skips on the base commit for want of a reachable Dolt server.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 07:58:46 +00:00

18 lines
1 KiB
Go

// Package workapi holds the work-query contract shared by every bd frontend.
//
// Filter construction, defaults, validation, and response shaping live here
// so the CLI and any other frontend answer the same question the same way
// instead of drifting through parallel copies. Storage sentinels are
// normalized on the way out for the same reason: a frontend should not have
// to know that the store seam reports a missing issue as storage.ErrNotFound
// while the domain seam reports it as a wrapped sql.ErrNoRows (see
// GetIssueOrWisp). The package therefore depends on neither frontend:
// it must not import github.com/spf13/cobra or net/http, and it must not read
// process-local state (client cwd, environment) that is meaningless in a
// long-lived server. internal/config is available only for workspace-scoped
// reads such as GetCustomTypesFromYAML.
//
// The boundary is enforced mechanically, not by review: see the
// workapi-frontend-boundary depguard rule in .golangci.yml and the
// banned-accessor check in scripts/ci/pr-policy.sh.
package workapi