beads/internal/storage/metadata_jsonpath_test.go
Julian Knutsen 2a9b8af4c5
fix: quote dotted metadata keys in JSON path expressions (#2865)
Metadata keys containing dots (e.g., `gc.routed_to`, `gc.kind`) were
passed to SQL JSON_EXTRACT as `$.gc.routed_to`, which Dolt interprets
as a nested path (`{gc: {routed_to: ...}}`). The correct path for a
flat key with dots is `$."gc.routed_to"`.

This broke `--metadata-field` and `--has-metadata-key` filters for any
key containing a dot. Since Gas City's pool routing uses `gc.routed_to`
metadata, no pool work query using the default `--metadata-field` filter
could find matching beads, causing workflow stalls.

The fix adds `storage.JSONMetadataPath()` which quotes keys containing
dots, and applies it to all 6 call sites across queries.go,
transaction.go, filters.go, and ready_work.go.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 23:50:25 -07:00

35 lines
888 B
Go

package storage
import "testing"
func TestJSONMetadataPathSimpleKey(t *testing.T) {
got := JSONMetadataPath("status")
want := "$.status"
if got != want {
t.Errorf("JSONMetadataPath(%q) = %q, want %q", "status", got, want)
}
}
func TestJSONMetadataPathDottedKey(t *testing.T) {
got := JSONMetadataPath("gc.routed_to")
want := `$."gc.routed_to"`
if got != want {
t.Errorf("JSONMetadataPath(%q) = %q, want %q", "gc.routed_to", got, want)
}
}
func TestJSONMetadataPathMultipleDots(t *testing.T) {
got := JSONMetadataPath("gc.scope.ref")
want := `$."gc.scope.ref"`
if got != want {
t.Errorf("JSONMetadataPath(%q) = %q, want %q", "gc.scope.ref", got, want)
}
}
func TestJSONMetadataPathUnderscoredKey(t *testing.T) {
got := JSONMetadataPath("my_field")
want := "$.my_field"
if got != want {
t.Errorf("JSONMetadataPath(%q) = %q, want %q", "my_field", got, want)
}
}