mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-10-25 22:10:25 +00:00
71de56f6de
* fix(relations): a relation value stored as text reads as text, not as an unavailable target (BUG-3014, ToolSurfaceVersion 0.50)
HydrateRelationTargetsQ treated every stored relation value as an id. A value
that is not UUID-shaped (a title a bundle import carries verbatim, which is that
door's contract; or legacy free text) resolved to nothing and hydrated as an
id-only entry, which means "the target is gone or not visible". So an imported
workspace showed relations as broken when the title might name a live item.
Such an entry now carries an additive, omitempty `stored_as_text: true`. The
predicate is syntactic ("not UUID-shaped"), decided from the stored bytes alone
and never from a lookup, so the flag discloses nothing about any item, and it is
deliberately not coupled to the resolver's ladder (lead ruling). A UUID-shaped
value, resolved or not, marshals byte-identically to 0.49, and a UUID that fails
to resolve is never marked.
The CLI renders `"<text>" (text, not a reference)`. The web chip, which resolves
locally from its index rather than from relation_targets, uses the same
syntactic predicate and says the same. The MCP instructions tell agents to
render a marked entry as text.
Claude-Session: https://claude.ai/code/session_01RYiqbqXmxQMoKHsGm8B77N
* test(relations): one shared vector table pins the Go and web stored_as_text predicates together (BUG-3014)
The web carries its own copy of the not-UUID predicate, because it resolves
relation chips from its local index rather than from relation_targets. Two
implementations of one contract rule drift. Both now read
internal/store/testdata/relation_stored_as_text_cases.json (21 cases: upper
and mixed case, braces, no dashes, URN form, wrong dash positions, length off
by one, titles, refs, blanks, and padding), and their KEEP IN SYNC comments
point at each other.
The table found a real divergence: the web trimmed with String.prototype.trim,
which disagrees with Go's strings.TrimSpace on U+0085 (Go only) and U+FEFF (JS
only). The web now trims with serverTrimmedTitle, the Go-parity helper the title
limit already uses. Swapping JS trim back in fails exactly those two vectors,
and dropping Go's TrimSpace fails the five padded ones.
Claude-Session: https://claude.ai/code/session_01RYiqbqXmxQMoKHsGm8B77N
68 lines
2.6 KiB
Go
68 lines
2.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/PerpetualSoftware/pad/internal/models"
|
|
)
|
|
|
|
// TestRenderRelationValue covers the three shapes a hydrated relation can
|
|
// arrive in, and one thing the renderer must NOT say.
|
|
func TestRenderRelationValue(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("resolved renders ref and title", func(t *testing.T) {
|
|
t.Parallel()
|
|
got := RenderRelationValue(models.RelationTarget{ID: "abc", Ref: "COLO-3", Title: "Red"})
|
|
if got != "COLO-3 · Red" {
|
|
t.Errorf("got %q, want %q", got, "COLO-3 · Red")
|
|
}
|
|
if strings.Contains(got, "abc") {
|
|
t.Error("the raw id leaked into a fully-resolved render, which is the noise U6 exists to remove")
|
|
}
|
|
})
|
|
|
|
t.Run("id-only keeps the id and claims nothing about it", func(t *testing.T) {
|
|
t.Parallel()
|
|
got := RenderRelationValue(models.RelationTarget{ID: "6f2c-dead"})
|
|
if !strings.Contains(got, "6f2c-dead") {
|
|
t.Errorf("got %q, want the stored id retained — it is all the caller has", got)
|
|
}
|
|
// THE POINT OF THIS LEG. An id-only entry means either the target is
|
|
// gone or the requester may not see it, and this layer cannot tell
|
|
// which. Saying "deleted" asserts non-existence for a target that may
|
|
// be alive and merely hidden — the existence oracle the server's
|
|
// collapse exists to prevent, and the exact defect codex round 12
|
|
// found in the copy dialog's not_found wording.
|
|
for _, forbidden := range []string{"deleted", "removed", "does not exist", "missing"} {
|
|
if strings.Contains(strings.ToLower(got), forbidden) {
|
|
t.Errorf("render %q claims %q; an id-only entry covers BOTH a gone target and a hidden one, so a non-existence claim is false for half the cases", got, forbidden)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("stored text renders as text, not as an unavailable target", func(t *testing.T) {
|
|
t.Parallel()
|
|
// BUG-3014: the value was never an id, so "(unavailable)" would claim a
|
|
// target that is gone or hidden when there was no target at all.
|
|
got := RenderRelationValue(models.RelationTarget{ID: "Red", StoredAsText: true})
|
|
if got != `"Red" (text, not a reference)` {
|
|
t.Errorf("got %q, want %q", got, `"Red" (text, not a reference)`)
|
|
}
|
|
for _, forbidden := range []string{"unavailable", "deleted", "broken"} {
|
|
if strings.Contains(strings.ToLower(got), forbidden) {
|
|
t.Errorf("render %q claims %q about a value that is simply text", got, forbidden)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("ref without a title does not render a dangling separator", func(t *testing.T) {
|
|
t.Parallel()
|
|
got := RenderRelationValue(models.RelationTarget{ID: "abc", Ref: "COLO-3"})
|
|
if got != "COLO-3" {
|
|
t.Errorf("got %q, want %q", got, "COLO-3")
|
|
}
|
|
})
|
|
}
|