Skip to content

fix: read include / sort support off the wire name (#300 follow-up) - #306

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

thomasfosterau merged 1 commit into
trunkfrom
issue-282-vocabulary-followup-2

Conversation

@thomasfosterau

Copy link
Copy Markdown
Owner

Summary

Follow-up to #300. Refs #282.

This fixes the review findings on merged #300. The owner decided on #282 (and #261) that an empty include / sort vocabulary means unsupported. Behaviour changes only where item 1 fixes a regression from #300. The example apps' GET responses and OpenAPI documents are byte-identical to trunk's (see "Behaviour check").

1. Should-fix, regression: the support check matched the decoded name, not the wire name

admitsNoValue (src/internal/vocabulary.ts) read the decoded property named include / sort. declaredNames reads the wire name. A query whose wire include decodes into a renamed property was misclassified. I reproduced it on trunk bb1a07f with Schema.Struct({ paths: Schema.optionalKey(Query.Include(Tag)) }).pipe(Schema.encodeKeys({ paths: "include" })):

Fix. The AST does not record an encodeKeys mapping: the rename lives inside an opaque transformation. So admitsNoValue now walks the query AST without first stripping it with toType, and on each struct it reads:

  • the property named after the family, when there is one (as before);
  • otherwise, when the struct's encoded side declares the family's wire name, every property whose name that side does not declare. The renamed property is among them. Every one must draw only from empty vocabularies, so an unrelated property with no vocabulary keeps the family supported. That errs toward "supported", where the codec still answers;
  • otherwise nothing. So a union member whose wire has no include contributes nothing, as on trunk.

I chose this over falling back to the pre-#300 whole-schema walk. That walk would bring back the misclassification #300 fixed for a renamed open include beside an empty vocabulary under another name (see the renamed-open-include test: it fails on 4a2ba0f's sources).

New tests in src/Middleware.query.test.ts, block "which declared include / sort an endpoint supports (#282)":

  • unsupported 400: a renamed empty include, with a value and with an empty value;
  • unsupported 400: a renamed empty include beside a non-empty one under another name;
  • unsupported 400: a union of an empty-include query and a query that declares no include (fields: true);
  • 200: a renamed Query.IncludeList beside an empty vocabulary under another name;
  • 200: a query its own codec decodes whole (to a string). This pins the Arr.isReadonlyArrayNonEmpty(properties) && guard (the reviewer's M13).

Issue filed: #305 (bug), for the pre-existing problem that such a 400 names the decoded paths in source.parameter rather than the wire include. I searched the tracker first and found no duplicate. Not fixed here.

2. Nit: the index-signature branch of drawsOnlyFromEmpty

New case: include: Schema.optionalKey(Schema.Record(Schema.String, Query.Include(Tag))) answers ?include= with the unsupported 400. This pins the reviewer's M12.

3. Nit: bare side-effect imports in dist/index.d.ts

codecs.ts's import type { Vocabulary } from "./vocabulary.js" pulled vocabulary.ts into the declaration bundle. The bundler kept that module's unused imports as import "effect/Option", import "effect/SchemaAST" and import "effect/Schema". import type was already in use, so the fix moves vocabularyAnnotations from internal/codecs.ts into internal/vocabulary.ts. codecs.ts and Query.ts now only value-import it, and a value import is elided from the declarations. vocabularyAnnotation (singular) becomes private. Its only caller was codecs.ts.

I diffed dist/index.d.ts from vp run build against trunk's build (both builds are deterministic; I rebuilt each twice). The only differences are the three removed import "effect/…" lines and the reworded SchemaErrorsLive doc paragraph. media-*.d.ts and schema.d.ts are byte-identical.

4. Nit: the pending changeset

.changeset/empty-vocabulary-unsupported.md (patch, still pending) now says, in wire terms, which codec decides it: the one the include / sort query parameter decodes through. That is the property of that name, or the property its encoding renames to that wire name (Schema.encodeKeys({ paths: "include" })). The regression fixed in item 1 never shipped, because #300 is unreleased. So no further changeset is added.

5. Note for the next change

I posted a comment on #261 about the fields follow-up:

  • admitsNoValue has no type parameter.
  • Its "any member" struct rule would treat fields: { articles: [...], tags: [] } as empty, so fields needs a type-aware variant keyed on the fields[TYPE] wire name.
  • The 400 for undeclared fields / page / filter needs only declaredNames.
  • Family could replace SPEC_FAMILIES / SUPPORT_FAMILIES as the single source of truth for the allow-list's spec-family refusal.

Docs

The SchemaErrorsLive doc, the emptyVocabularies comment in src/Middleware.ts and the admitsNoValue doc now say "the property the wire parameter decodes into", not "the decoded property". The README has no sentence on this.

Mutation checks

Each row ran vp test run src/Middleware.query.test.ts src/Query.test.ts src/Middleware.test.ts (380 tests). Every M row applied one mutation alone to this branch's vocabulary.ts, then reverted it.

# Mutation Failing tests
T0 Trunk bb1a07f's vocabulary.ts (unfixed) with the new tests 3: renamed include (value, empty value) and renamed include beside a non-empty one
T1 Pre-#300 sources (4a2ba0f) with the new tests (-t on the 12 new cases) 2, both from its whole-schema walk: renamed Query.IncludeList beside an empty vocabulary, and renamed empty include beside a non-empty one. The two plain renamed-empty cases pass there, which confirms the regression
A Name match only, with no wire-name fallback (trunk's rule) 3, as T0
B Fallback taken even when the struct's wire lacks the name 1: union with a query that declares no include
C Fallback reads every property, not only those the wire does not name 1: renamed include beside a non-empty one
M12 Index signatures not walked in drawsOnlyFromEmpty 1: a record of empty include codecs
M13 Arr.isReadonlyArrayNonEmpty(properties) && removed 1: a query its own codec decodes whole

Behaviour check

  • Example apps. I added a temporary test to each example (not committed). It sends every GET endpoint, with ids 1 and 2, through 20 query strings, with and without a parameterised Accept. The query strings cover include / sort with names, empty values and bracketed members, plus unknown, fields, page and filter parameters. The test also writes OpenApi.fromApi(Api). Results for blog (480 requests), github (960) and northwind (1680) were byte-identical between trunk's sources and this branch's: status, headers (less date) and body, and the OpenAPI JSON too.
  • Lint warn tier. vp lint per changed file, trunk → head: Middleware.query.test.ts 1 → 1, Middleware.ts 36 → 36, Query.ts 144 → 144, internal/codecs.ts 32 → 32, internal/vocabulary.ts 0 → 0.

Verification

Run in this order in a fresh clone, on the final commit's tree:

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass (0 errors, warn tier only)
  • vp run check (sources, type-level tests, examples, emitted declarations): pass
  • vp run -r test:unit: pass (root 2699, blog 54, github 45, northwind 41)
  • vp run docgen (every JSDoc @example compiled and executed): pass
  • ./node_modules/.bin/fallow audit --format json --quiet --explain --gate-marker agent: verdict pass
  • fallow audit --base origin/trunk: pass. "No issues in 6 changed files". The 4 inherited findings were excluded by the gate (SortTerm unused type export, Sort duplicate export, and the complexity of Query.schema and Middleware.sourceOf, none of which this branch touches).

Changeset

Notes

🤖 Generated with Claude Code


Generated by Claude Code

The empty-vocabulary support check matched the decoded property name,
while the declared-name walk matches the wire name. A query whose wire
`include` decodes into a renamed property (`Schema.encodeKeys`) was
misclassified: `?include=` answered 200 and `?include=author` the codec's
400, where the owner decision on #282 makes both the unsupported 400.

`admitsNoValue` now reads the property of the family's name, or, when a
struct has none but its encoded side declares the name, every property
the wire does not name. A struct whose wire lacks the name reads none, so
unions keep their behaviour.

Also pins the index-signature branch of `drawsOnlyFromEmpty` and the
empty-properties guard, moves `vocabularyAnnotations` into
`internal/vocabulary.ts` so `dist/index.d.ts` loses three bare
side-effect imports, and rephrases the pending changeset in wire terms.

Refs #282

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
@thomasfosterau
thomasfosterau merged commit 3734a6d into trunk Oct 9, 2026
1 check passed
@thomasfosterau
thomasfosterau deleted the issue-282-vocabulary-followup-2 branch October 9, 2026 09:14
thomasfosterau pushed a commit that referenced this pull request Oct 9, 2026
…305)

Review fixes on the #305 wire mapping.

`wireProperties` paired a decoded property with its wire name by place
whenever every place matched by AST identity. That held for
`Schema.encodeKeys`, but not for any other struct transformation: a
passthrough between two structs listing `sort` and `include` in another
order, every wire property carrying the AST a decoded one encodes to,
read the wire `include` as the decoded `sort`. It named the wrong
parameter in `source.parameter` and let an empty `include` vocabulary
through as a 200.

It now runs the struct's one encoding transformation's decode on a probe
object (each wire name holding its own sentinel) and pairs each wire name
with the decoded key its sentinel lands on. `encodeKeys` is
`Struct.renameKeys`, so every rename is read exactly, swaps and
array-index names included. A chain of transformations, a source that is
no plain struct, a `Middleware`, a decode that fails, throws or goes
asynchronous, and a sentinel that lands nowhere or twice pair nothing, and
the callers fall back to #306's by-name rule. The positional rule and its
length guard are gone with it. The probe reads HttpApi's rebuilt query as
well as the endpoint's own, so the endpoint-query threading through
`SchemaErrorsLive` is dropped.

`queryLeaves` also walks through a check on a renamed struct, as the
formatter does, so a `Schema.makeFilter` that reports
`{ path: ["count"], issue }` on a struct renaming `count` to `page[size]`
names `page[size]`, not `count`.

Refs #305.

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.

2 participants