Skip to content

fix: read include / sort support off the family's own vocabulary (#294 follow-up) - #300

Merged
thomasfosterau merged 2 commits into
trunkfrom
issue-282-vocabulary-followup
Oct 9, 2026
Merged

thomasfosterau merged 2 commits into
trunkfrom
issue-282-vocabulary-followup

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to #294. Refs #282. Closes #297.

This fixes the review findings on merged #294, which applied the owner decision on #282 that an empty include / sort vocabulary means unsupported. It also swaps Middleware.ts's private declared-name walk for the shared one from #296 (#297). Behaviour changes only where the review found a misclassification (item 3) and for Suspend (item 2). Item 1's guard keeps its behaviour, and the example apps' GET responses are byte-identical to trunk's (see "Behaviour check" below).

1. Should-fix: the untested "no vocabulary" guard and every

I reproduced the reviewer's result on trunk 4a2ba0f. Dropping Arr.isReadonlyArrayNonEmpty(vocabularies) && passed the whole suite (2539 tests), and so did changing every to some.

The new src/Middleware.query.test.ts block, "which declared include / sort an endpoint supports (#282)", serves hand-built endpoints through SchemaErrorsLive. Each "supports" case asserts the 200 and the decoded query:

  • include: Query.IncludeList, with a value and with an empty value;
  • a custom sort: Schema.String;
  • a recursive include codec that has no vocabulary;
  • a union of an empty and a non-empty query: Union([Query.schema(Tag, { include: { paths: [] } }), Query.schema(Post, { include: true })]);
  • sort: Union([Query.Sort([]), Query.Sort(["title"])]);
  • include: Union([Query.Include(Tag), Query.IncludeList]).

On trunk, removing the guard fails the IncludeList, custom-sort and recursive-codec cases. Changing every to some fails both union cases.

2. Nit: Suspend

The new walk follows Suspend both at query level and inside the family's property. It keeps a per-path visited list, so a recursive schema can't loop it. The tests:

  • Schema.suspend(() => Query.schema(Tag, { include: { paths: [] } })) now answers the unsupported 400, for ?include=author and for ?include=. On trunk these gave the codec's 400 and a 200.
  • A Schema.suspend(() => Query.Include(Tag)) property is treated the same way.
  • A recursive codec whose recursive union member comes first must still answer 200. Without the visited list, the walk overflows the stack.

3. Design: a dedicated vocabulary annotation, read off the family's own property

  • New src/internal/vocabulary.ts. Query.Include and the sort codec now publish a Vocabulary annotation ({ family, values }) in place of the generic error-meta annotation. internal/errorMeta.ts reads that annotation to render meta.includablePaths / meta.sortableFields. The family-to-meta-key mapping lives there, so the rendered meta is unchanged. The generic errorMeta(...) producer had no other caller, so it is removed.
  • Reusable by the next change. Vocabulary is a union. It already spells page and filter, and fields with a required type (the TYPE of fields[TYPE]). So the owner-decided 400 for undeclared fields / page / filter (bug: ?include= / ?sort= on an endpoint that does not support them is ignored, though the spec makes it a 400 #261) can publish those vocabularies under the same annotation. That change is not implemented here.
  • admitsNoValue(query, family). It reads only the decoded property named include / sort, across union members and through Suspend. A family is unsupported only when every such property draws all its values from empty vocabularies:
    • a vocabulary of another family doesn't count;
    • a union counts as empty only when all its members are empty (an undefined member, as from Schema.optional, carries no value);
    • a struct or array counts as empty when any member is empty;
    • a node with no vocabulary admits values.
  • The reviewer's two misclassifications are now HTTP tests:
    • { include: Query.IncludeList, Other: Query.Include(Tag) } now answers ?include=author with 200. Trunk answered the unsupported 400.
    • { include: Query.Include(Tag), other: Query.Include(Post) } now answers ?include=author with the unsupported 400. Trunk answered the codec's "This endpoint supports no include paths." 400 with meta. The same holds for sort beside a non-empty order.

4. Nits

  • 406/415 precedence on an empty-vocabulary endpoint. New test, run under Middleware.layer and under schemaErrorsLayer beside ContentNegotiationLive. /tags/1?include=author with a parameterised Accept gets the 400, and /tags/1 alone gets the 406. /tags?sort= with a parameterised Content-Type gets the 400, and /tags alone gets the 415. On the commit before fix: treat an include / sort with an empty vocabulary as unsupported (#282) #294 (2521e53 sources), the same test gets the 406.
  • Changeset. The pending .changeset/empty-vocabulary-unsupported.md now says that such a request with an unacceptable Accept or unsupported Content-Type answers this 400 where it used to answer 406/415. A second paragraph says only the family's own decoded property counts, followed through unions and Schema.suspend.
  • "Ignored" wording. The QueryParameterOptions.allowedQueryParameters doc, the pending reject-unsupported-include-sort.md and the README's "Reserved query parameters" now say the same thing. With the family allow-listed, an endpoint that doesn't declare it ignores it, and one that declares it with an empty vocabulary decodes it, so the codec rejects any path or field. The SchemaErrorsLive doc also says which property decides it.

5. #297: the shared declared-name walk

src/Middleware.ts now imports declaredNames from ./internal/declaredQuery.js and drops its private declaredNames / familyPrefix and the now-unused Predicate import. Behaviour is identical: trunk's private copy and declaredQuery.ts differ only by export (I diffed the function bodies). So no differential test is added, because only one implementation is left to test. The existing "what an endpoint's query schema declares" tests (union, suspend, open record) cover the walk. fallow audit no longer reports the clone group (duplication: 0 introduced, 0 inherited).

Mutation checks

T0 to T2 ran the new tests against trunk's sources. Every M row applied one mutation alone to the final code. I ran vp test run src/Middleware.query.test.ts src/Query.test.ts src/Middleware.test.ts (373 tests), then reverted the mutation.

# Mutation Failing tests
T0 Trunk d3f63b1 sources, unfixed (the new tests only) 7 of 111 in Middleware.query.test.ts: Include(Tag) | IncludeList, IncludeList beside Other, the two "beside another name" cases and the three Suspend cases
T1 Trunk, with the guard removed (the reviewer's mutation) 9, including the IncludeList, custom-sort and recursive-codec cases
T2 Trunk, with every → some (the reviewer's mutation) 7, including both union cases
M1 A node with no vocabulary counts as empty (item 1's guard) 9, including IncludeList ×2, custom sort, both union cases and the foreign-family case
M2 Union inside a property: every → some (item 1) 2: the sort union, Include(Tag) | IncludeList
M3 Union of queries: every → some over the properties 1: the union of an empty and a non-empty query
M4 Walk not scoped to the family's property (item 3) 9, including both "beside another name" cases and sort: true / include: true over nothing
M5 Suspend not followed at query level (item 2) 2: the suspended query, with a value and with an empty value
M6 Suspend not followed inside the property (item 2) 1: the suspended include codec
M7 No visited list 1: the recursive codec (stack overflow)
M8 Family not matched 1: a Query.Sort([]) under include
M9 undefined union member not skipped 1: Schema.optional(Query.Include(Tag))
M10 errorMeta renders no meta 3: the existing meta tests
M11 Struct members: some → every 6: every sort empty-vocabulary case
M12 Arrays not walked 17
M13 An empty vocabulary counts as non-empty 17
M14 Every vocabulary counts as empty 4

Behaviour check

  • Example apps. I added a temporary (uncommitted) test to each example that sends every GET endpoint, with ids 1 and 2, through 19 query strings, with and without a parameterised Accept. The query strings include include / sort with names, empty values and bracketed members, plus unknown, fields, page and filter parameters. Responses were compared on status, headers and body. blog (456 requests), github (912) and northwind (1596) were byte-identical between trunk sources and this branch's.
  • Lint warn tier. vp lint per changed file, trunk → head:
    • src/Middleware.ts 37 → 36;
    • src/internal/errorMeta.ts 18 → 13;
    • src/internal/vocabulary.ts (new) 0;
    • src/Query.ts 144 → 144, src/internal/codecs.ts 32 → 32, src/Middleware.query.test.ts 1 → 1, test/entry-points.test.ts 29 → 29.
  • test/entry-points.test.ts lists internal/vocabulary.ts in HTTP_TIER. The module uses effect subpath imports, as declaredQuery.ts does.

Verification

Run one at a time in a fresh clone, at head 4c58211 (rebased on trunk d3f63b1; the second commit only moves a sentence in the SchemaErrorsLive doc, and every gate was re-run on it):

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass ("Build complete")
  • vp check: pass ("Found 0 errors and 4333 warnings in 131 files"; no changed file's count rose, see above)
  • vp run check (sources, type-level tests, examples, emitted declarations): pass ("check: every type gate green")
  • vp run -r test:unit: pass (root 2570; examples 45 / 41 / 54)
  • vp run docgen (every JSDoc @example compiled and executed): pass ("Docs generation succeeded!", "every class example compiled and ran")
  • fallow audit --base origin/trunk: pass ("No issues in 10 changed files"; it excluded 5 inherited findings: unused SortTerm and the duplicate Sort export in codecs.ts / Query.ts, and complexity in Query.schema, Middleware.sourceOf and the entry-points visit). Agent gate fallow audit --format json --quiet --explain --gate-marker agent: verdict pass, 0 introduced.

Changeset

Notes

https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits October 9, 2026 07:38
…follow-up)

Follow-up to #294 (refs #282) and the shared declared-name walk (closes #297).

- The include and sort codecs publish a dedicated internal vocabulary
  annotation (src/internal/vocabulary.ts), which the error-meta renderer
  also reads, in place of the generic error-meta annotation. Its shape
  also covers the page, filter and per-type fields vocabularies.
- The support check reads only the decoded property named include / sort,
  follows unions and Schema.suspend with a visited set, and counts a family
  unsupported only when every value it can decode draws on an empty
  vocabulary. A codec with no vocabulary, or a non-empty vocabulary in any
  union member, keeps it supported.
- Middleware.ts imports declaredNames from src/internal/declaredQuery.ts
  instead of carrying its own copy.
- Tests: the hand-built queries the review reproduced, Suspend, the
  mixed-vocabulary unions, and 406/415 precedence on an empty vocabulary.
- Docs and pending changesets: allow-listed empty vocabularies are decoded
  rather than ignored; empty-vocabulary endpoints now answer 400 where they
  used to answer 406/415.

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
…r the spec citation

The sentence sat between the empty-vocabulary list and "JSON:API 1.1
requires it", so "it" no longer read as the 400.

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: import the shared query declared-name walk in Middleware.ts

2 participants