* perf(http): answer a command's repeated reads from one response (port of bd-enterprise e626072b8) Over an http workspace, bd show <id> --json made three identical GET /v0/beads/issues/<id> requests: the id resolver's exact probe, routed.go's GetIssue and show's detail read all build the same URL. Text show made six. Over a gateway each one is a sequential round trip, so the request count is the command's latency floor (mc-5dkzp). This ports bd-enterprise e626072b8 (bts-xpw.3.14.6, #217) verbatim, except cmd/bd/main.go, where OSS still opens the identity preview inline, and bd-enterprise's httpgw dialer test, which has no OSS counterpart: - httpclient.WithSharedConnections: the identity-gate preview and the real open share one transport, so a write makes one handshake. - httpclient.WithReadMemo and a wire.Client read memo, for one-shot commands only (not bd serve, --watch or --follow): identical getIssue, getSetting and listSettings reads are answered from the response already received. An entry ages from the server's answer (5 s), any write clears the memo, a read that overlapped a write is not stored, and expired entries are swept. - bd list's three vocabulary reads come from one memoized listSettings. - bd update --status / --if-status skips the custom-status read for a built-in status. - The hook decorator skips its post-write re-reads when no executable hook exists for the event. - bd dep add reads its confirmation titles before the write, from the memo. Against a loopback bd serve: show --json goes from 3 requests to 1, text show 6 to 3, update 5 to 3, close 6 to 4. Dolt and the other registered backends receive the same ctx and ignore it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(http): BD_HTTP_READ_MEMO=0 turns the per-command read memo off An operator who suspects a stale read can rule the memo out without a rebuild. Any other value, or none, leaves the default. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(http): pin bd show to one fetch per issue (mc-5dkzp) TestE2E_PerCommandRequestBudget allowed show two requests, and a read that drifts to a URL of its own (a mutant whose reader spells brief_deps=false) fits that ceiling on both handshake shapes. These guards pin the single fetch instead: - TestE2E_ShowFetchesTheIssueOnce: the exact requests, path and query, of show --json, show --json --id, show --short, show of two ids and text show, against both handshake shapes, plus a BD_HTTP_READ_MEMO=0 step that must read the row more than once. - TestDefaultIssueReadsShareOneMemoKey: the resolver's exact probe, GetIssue, GetDependenciesWithMetadata, GetLabels and IssueReader().Get build one URL, checked without a server. - TestE2E_CloseRereadsItsOwnWrite: against the MC handshake, closing a lone molecule re-reads its own closed row from the server after the write, and prints no false "completed molecule" note. - Corpus shapes can pin `requests:`, counted on the served run alone (not setup, verify or {rev:ID} reads). The seven gc and mc show shapes pin 1, 4, 1, 1, 3, 1 and 3. Also: TestReadMemoOptInReadsTheRealPollingFlags holds the opt-in to the real show/list --watch and -w, events tail --follow and bd serve; the show budget drops from 2 to 1; requestCounter records each request's query; and ledger row L-read-memo records the memo's bounded difference from local reads. Mutation runs against this tree: brief_deps=true on GetIssue and brief_deps=false on the reader's Get each fail the e2e list and the unit test; show opting out of the memo fails the e2e list; writes that leave the memo standing fail the read-your-own-write e2e; a memo keyed by path alone fails the e2e list; dropping the kill switch fails its unit test and the e2e step. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(config): list BD_HTTP_READ_MEMO Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(http): memoize a read's answer only once it has decoded wire.Client.Do stored a memoable read's 2xx before it checked the body, so an empty or undecodable 200 would have answered every identical read in the command for the memo's whole TTL with the same failure, instead of asking the server again. The answer is now stored only after it decodes; a read that decodes nothing (out == nil) is not stored, and every memoable read in this package decodes its answer. TestReadMemoKeepsOnlyAnswersThatDecoded pins it (empty body, truncated body, undecoded answer). Ledger row L-read-memo says so. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(http): pin the read memo's 5xx, write-method, per-client, in-flight-write and hook-gate behavior Review follow-ups for the per-command read memo (mc-5dkzp): - TestReadMemoNeverKeepsA5xx: a 503, 500 or 502 is not memoized and the 2xx after it is. TestDispatchRetryOfABusyMemoizedReadAsksTheServer holds the same through dispatch's retry loop over a real wire.Client: the retry reaches the server instead of replaying the 503. - TestReadMemoIsDroppedByAnyWrite covers POST, PUT and DELETE, not just PATCH. - TestReadMemoIsPerClient: in either order, one client's read is never answered from another's memo, and opting one client in opts in no other. (A shared memo was otherwise caught only by test-order pollution.) - TestReadMemoDropsAnAnswerReadWhileAWriteWasInFlight pins the clear on the write's way back: a read that starts and ends while the write is on the wire is not answered again once the write has returned. - TestHookFiringStoreReReadsOnlyForAnEventWithAHook pins hookConfigured's probe: the decorator asks the runner about the event it fires, and re-reads the row to build a payload only when a hook for that event exists, through a probing double and through a real hooks.Runner. Each was run against a mutant of the code it pins and fails there: 5xx stored before the status check; only PATCH clearing; one memo shared by every client; no clear after the write returns; hookConfigured answering true, false, or about the wrong event. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(changelog): note the per-command http read memo Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
89 lines
2.9 KiB
Go
89 lines
2.9 KiB
Go
//go:build cgo
|
|
|
|
package bdhttp_test
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestE2E_ShowFetchesTheIssueOnce (mc-5dkzp) pins the exact requests, path AND
|
|
// query, each bd show shape makes over the http backend. bd show resolves the
|
|
// id, fetches the row, then reads it for output: three reads of one URL that
|
|
// the per-command read memo answers with one request. A read that drifts to a
|
|
// URL of its own (a new parameter, or a default spelled out) still fits a
|
|
// request ceiling of two, so this is an exact list, not a budget: a change that
|
|
// makes show cheaper updates the list here too.
|
|
//
|
|
// Text show's dependents and comments sections are separate reads of the same
|
|
// row with include_dependents and include_comments, which the memo cannot
|
|
// collapse; a later change that reads them in one request updates that step.
|
|
func TestE2E_ShowFetchesTheIssueOnce(t *testing.T) {
|
|
skipUnlessEmbeddedDolt(t)
|
|
bin := buildBD(t)
|
|
addr := startE2EServer(t)
|
|
for _, tc := range []struct {
|
|
name string
|
|
mask func(map[string]any)
|
|
}{
|
|
{"current server", advertiseExternalPolicy},
|
|
{"MC server mask", mcContextMask},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
proxyAddr, counter := startMaskingProxy(t, addr, tc.mask)
|
|
f := newHTTPFixture(t, bin, proxyAddr)
|
|
target := f.create("once target", "-t", "task")
|
|
other := f.create("once other", "-t", "task")
|
|
f.mustRun(nil, "dep", "add", target, other)
|
|
f.mustRun(nil, "comments", "add", target, "seed comment")
|
|
|
|
get := func(id, query string) string {
|
|
uri := "GET /v0/beads/issues/" + id
|
|
if query != "" {
|
|
uri += "?" + query
|
|
}
|
|
return uri
|
|
}
|
|
for _, step := range []struct {
|
|
args []string
|
|
want []string
|
|
}{
|
|
{[]string{"show", target, "--json"}, []string{get(target, "")}},
|
|
{[]string{"show", "--json", "--id=" + target}, []string{get(target, "")}},
|
|
{[]string{"show", target, "--short"}, []string{get(target, "")}},
|
|
{[]string{"show", target, other, "--json"}, []string{get(target, ""), get(other, "")}},
|
|
{[]string{"show", target}, []string{
|
|
get(target, ""),
|
|
get(target, "include_dependents=true"),
|
|
get(target, "include_comments=true"),
|
|
}},
|
|
} {
|
|
counter.reset()
|
|
f.mustRun(nil, step.args...)
|
|
if got := counter.uriSnapshot(); !slices.Equal(got, step.want) {
|
|
t.Errorf("bd %s:\n got %q\n want %q", strings.Join(step.args, " "), got, step.want)
|
|
}
|
|
}
|
|
|
|
// BD_HTTP_READ_MEMO=0 turns the memo off: the same show asks
|
|
// the server again for every read of the row.
|
|
counter.reset()
|
|
f.mustRun([]string{"BD_HTTP_READ_MEMO=0"}, "show", target, "--json")
|
|
got := counter.uriSnapshot()
|
|
if bare := countOf(got, get(target, "")); bare < 2 {
|
|
t.Errorf("BD_HTTP_READ_MEMO=0 bd show %s --json read the row %d times (%q); the kill switch must turn the memo off", target, bare, got)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func countOf(list []string, want string) int {
|
|
n := 0
|
|
for _, s := range list {
|
|
if s == want {
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|