Reader is Lifecycle's read counterpart, built as its mirror image: a role in the leaf `issueops` package, reached through a capability accessor on the storage seam, implemented at the same six sites. `Storage` gains `IssueReader() (issueops.Reader, error)` beside `IssueLifecycle()`, and the governing rule holds — a new capability got a new role and a new accessor, not four more methods on an existing one. SUBSUME, NOT COMPOSE. Reader takes the whole high-level request and performs filter and default construction INTERNALLY, supplying its own ConfigSource from the store or unit of work it already holds. Under compose both front doors would each build a ConfigSource, load config, call a builder and execute — two callers again, which is the topology that shipped a bare IssueFilter to a viewer and silently served in_progress rows as "ready". Under subsume the ritual is not callable from a front door: handlers and RunE bodies can only say rd.List(ctx, req), so the failure mode is unwritable rather than merely discouraged. The three read endpoints are implemented against the frozen OpenAPI v0 document and consume the accessor; the 501 stubs and their self-deleting exemption list are gone. `bd show --json` reaches the same role through the same accessor, resolving the canonical id first so fuzzy and cross-repo lookup stay CLI-local. The workapi builders are re-typed onto the leaf request types, so there is no second params struct to drift; both recorded goldens replay byte-identical, which is the proof the re-typing changed nothing. Load-bearing details: - `sort` is forwarded EXPLICITLY as priority when absent. The storage layer reads an empty policy as hybrid, which demotes older high-priority work and therefore changes the item SET once a limit truncates — while the document still reads correctly. Pinned by a handler test on the recorded filter and by the parity oracle's order assertion. - The parity oracle compares FULL ITEM JSON, not id sets. An id-set oracle passes while ready ships a bare Issue against the CLI's IssueWithCounts. - internal/workapi no longer imports internal/storage/uow; it names the slice of a unit of work it reads through, so the uow provider can implement the role without closing an import cycle. - internal/utils' cgo store test moves to an external test package for the same reason, with its two unexported-symbol cases split out. Verified: issueops is still a leaf (internal/types + stdlib only); the protocol corpus is unchanged structurally and behaviourally under BEADS_PROTOCOL_REQUIRE_DOLT=1; a real `bd serve` answers all six operations against a real workspace with CLI and HTTP JSON identical field for field.
97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
package utils
|
|
|
|
import "testing"
|
|
|
|
// TestParseIssueID covers the unexported prefix normalizer, so it lives in
|
|
// package utils. It is split out from the store-backed resolution tests
|
|
// because those import internal/storage/dolt, which reaches this package
|
|
// again through internal/workapi — an import cycle for an in-package test.
|
|
// The store-backed half is an external test package for that reason.
|
|
|
|
func TestParseIssueID(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
prefix string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "already has prefix",
|
|
input: "bd-a3f8e9",
|
|
prefix: "bd-",
|
|
expected: "bd-a3f8e9",
|
|
},
|
|
{
|
|
name: "missing prefix",
|
|
input: "a3f8e9",
|
|
prefix: "bd-",
|
|
expected: "bd-a3f8e9",
|
|
},
|
|
{
|
|
name: "hierarchical with prefix",
|
|
input: "bd-a3f8e9.1.2",
|
|
prefix: "bd-",
|
|
expected: "bd-a3f8e9.1.2",
|
|
},
|
|
{
|
|
name: "hierarchical without prefix",
|
|
input: "a3f8e9.1.2",
|
|
prefix: "bd-",
|
|
expected: "bd-a3f8e9.1.2",
|
|
},
|
|
{
|
|
name: "custom prefix with ID",
|
|
input: "ticket-123",
|
|
prefix: "ticket-",
|
|
expected: "ticket-123",
|
|
},
|
|
{
|
|
name: "custom prefix without ID",
|
|
input: "123",
|
|
prefix: "ticket-",
|
|
expected: "ticket-123",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := parseIssueID(tt.input, tt.prefix)
|
|
if result != tt.expected {
|
|
t.Errorf("parseIssueID(%q, %q) = %q; want %q", tt.input, tt.prefix, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLooksLikePrefixedID(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected bool
|
|
}{
|
|
{"aap-4ar", true},
|
|
{"bd-abc123", true},
|
|
{"hq-xyz", true},
|
|
{"cr-99", true},
|
|
{"myproj-task1", true},
|
|
{"a-b", true}, // minimal valid prefix
|
|
{"abc12345-x", true}, // 8-char prefix (max)
|
|
|
|
// Invalid cases
|
|
{"abc", false}, // no hyphen
|
|
{"", false}, // empty
|
|
{"-abc", false}, // hyphen at start
|
|
{"ABC-123", false}, // uppercase
|
|
{"abcdefghi-x", false}, // prefix too long (9 chars)
|
|
{"abc-", false}, // empty suffix
|
|
{"abc--def", false}, // suffix starts with hyphen
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
result := looksLikePrefixedID(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("looksLikePrefixedID(%q) = %v; want %v", tt.input, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|