feat(filter-builder): the group header is the ALL/ANY switch

The group header ("MATCH"/"GROUP") was a dead label while the engine
honored group modes all along — buildGroupClause parenthesizes nested
groups and joins each by its own mode, and validation accepted
all/any from day one. The only thing missing was the UI: + Group
birthed ALL groups and no control anywhere could flip one, so the
user's target structures (GROUP(GROUP(... or ...) ...) — 3-level
mixed-mode nesting) were constructible only through the invisible
row-level chips, and standalone ANY-groups not at all (2026-11-01
user report: "MATCH cannot be clicked").

- The header is now the control: MATCH ALL ⇄ MATCH ANY (root — a
  synthetic header row, since the root was never projected and its
  mode was invisible too), GROUP ALL ⇄ GROUP ANY (nested). ANY is
  accented; aria-pressed carries the state. Labels are path-based
  (root reads Match, explicit groups read Group) instead of
  depth-based, which previously mislabeled top-level groups.
- The row-level chips are untouched — they mix AND/OR inside a group
  (A AND (B OR C)), which a global mode toggle cannot express; the
  header is the discoverable entry point, the chips the refinement.
- Dropdown audit (the "would it bug out" check): suggestTree is
  mode-generic — root-ANY drops group siblings, sibling ANY-groups
  survive into the constraint with their mode intact, empty groups
  never emit (no 400s) — now pinned. Deep-nesting Go pin: a 3-level
  mixed-mode tree evaluated through composed search + the suggestion
  endpoint (200, never the empty-group 400). 192 web tests green.
This commit is contained in:
John O'Keefe committed 2026-11-01 15:43:52 -05:00
1 parent 5fb80f82ed
commit 2344f5686a
7 files changed
+254 -5

No files matched your search

+82
View File
@@ -903,3 +903,85 @@ func TestFilterFlatEquivalence(t *testing.T) {
require.Equal(t, statusFlat, statusTree, "same result status")
assert.ElementsMatch(t, qfTitles(t, flatRows), qfTitles(t, treeRows))
}
// ---- deep group nesting (2026-11-01 group ALL/ANY header toggle): ----
// the UI can now produce 3+-level mixed-mode trees; pin the engine's
// parenthesized evaluation for the user's target structure
// GROUP(GROUP(Field and (Field or Field)) or GROUP(Field and Field and
// (Field or Field)) and GROUP(Field)) — plus a suggestion request
// carrying a nested-any constraint (the mode-aware menu under real
// nesting) — must be 200, never the empty-group 400.
func TestFilterDeepGroupNesting(t *testing.T) {
setup := setupTestServer(t)
t.Cleanup(func() { _ = setup.Close() })
userID := getRegularUserID(t, setup.DB)
libUUID, _ := builderFixtureLib(t, setup, userID, "Deep")
titles := func(qf string) []string {
p := url.Values{"library_id": {libUUID.String()}, "qf": {qf}}
status, rows := qfSearch(t, setup, setup.RegularToken, p)
require.Contains(t, []int{http.StatusOK, http.StatusNotFound}, status)
return qfTitles(t, rows)
}
// root ALL[
// ANY[ ALL[fantasy, ANY[>=250p, abridged]] , ALL[Dar, >=500p] ],
// author not_contains Quill
// ]
// => Tide (fantasy + 300p), Wick (Dar + 700p); Fen dies at the root
// AND (Quill); Stone fails branch A (history) and branch B (Voss).
deep := map[string]interface{}{
"mode": "all",
"children": []interface{}{
map[string]interface{}{
"mode": "any",
"children": []interface{}{
map[string]interface{}{
"mode": "all",
"children": []interface{}{
qfRule("genre", "is", "fantasy"),
map[string]interface{}{
"mode": "any",
"children": []interface{}{
qfRule("page_count", "at_least", "250"),
qfRule("abridged", "is_true"),
},
},
},
},
map[string]interface{}{
"mode": "all",
"children": []interface{}{
qfRule("author", "contains", "Dar"),
qfRule("page_count", "at_least", "500"),
},
},
},
},
qfRule("author", "not_contains", "Quill"),
},
}
deepJSON, merr := json.Marshal(deep)
require.NoError(t, merr)
got := titles(string(deepJSON))
assert.ElementsMatch(t, []string{"Deep Tide", "Deep Wick"}, got,
"3-level mixed-mode nesting evaluates parenthesized")
// The same shape riding the SUGGEST endpoint (the mode-aware menu's
// constraint) — nested any must be a 200, never the empty-group 400.
p := url.Values{
"library_id": {libUUID.String()},
"author": {""},
"limit": {"20"},
"qf": {string(deepJSON)},
}
req, _ := http.NewRequest("GET", setup.Server.URL+"/api/media-items/search?"+p.Encode(), nil)
req.Header.Set("Authorization", "Bearer "+setup.RegularToken)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer func() { _ = resp.Body.Close() }()
assert.Equal(t, http.StatusOK, resp.StatusCode,
"a nested-any constraint rides the suggestion endpoint cleanly: %s", p.Encode())
}