Skip to content

refactor(agent-bff): extract the filter-schema derivation out of unfolded-paths.ts - #2036

Merged
Tonours merged 2 commits into
mainfrom
feature/prd-1546-extract-filter-schema
Oct 23, 2026
Merged

Tonours merged 2 commits into
mainfrom
feature/prd-1546-extract-filter-schema

Conversation

@Tonours

@Tonours Tonours commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Moves the per-collection filter schema derivation out of unfolded-paths.ts into unfolded-filter-schema.ts. Pure move: the served document is byte-identical.

fixes PRD-1546

What

File Change
packages/agent-bff/src/openapi/unfolded-filter-schema.ts (new, 176 lines) AGGREGATORS, isFieldSetKnown, isFilterSetKnown, groupByOperators, leafShape, filterLeaves, filterSchema (default export), copied verbatim with their comments
packages/agent-bff/src/openapi/unfolded-paths.ts (786 to 618 lines) Keeps request bodies, relation and action schemas, operation registration

Why

  • Follow-up promised in the R1 review (PRD-1542): this file mixed three jobs and took 13 commits in 90 days.
  • isFieldSetKnown moves too and is exported back: isFilterSetKnown needs it and fieldRefs still reads it, so leaving it behind would make the two files import each other.
  • filterSchema and filterLeaves now type their inputs as { pool } and { key, collection } instead of Deps and Pick<CollectionPlan, ...>, the same shapes, so the new module needs nothing from unfolded-paths.ts.
  • AGGREGATORS had no other user (data/agent-query.ts declares its own).

How to test

Check Result
Render of generateOpenApiDocument + serializeOpenApi before and after, 8 cases: generic, generic with AI route, generic with publicUrl + basePath, unfolded (test fixture), unfolded with AI route, unfolded without actions, unfolded with no_fields, unfolded with an empty filterable marked undocumentableFilter diff -r empty, 8 files identical
Trust bench, subject 1c6ab81 vs baseline e98f1bd (main), real stack: smoke (forest-bff CLI against a v1-express agent, API key, includes the served OpenAPI check) and gateway-api-rename (generic and unfolded document served over cli, bff and gateway mounts) 0 differences over 164 assertions; smoke PASS on both roles; api-rename fails the same 13 assertions on both roles (recipe pins old package versions and fixture tables), so no PR effect
yarn workspace @forestadmin/agent-bff test 111 suites, 2290 tests passed
git diff --stat origin/main -- packages/agent-bff/test empty, no test touched
npx tsc --noEmit -p packages/agent-bff, npx eslint on both files clean

Definition of Done

General

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • Test manually the implemented changes
  • Validate the code quality (indentation, syntax, style, simplicity, readability)

Security

  • Consider the security impact of the changes made

@linear-code

linear-code Bot commented Oct 23, 2026

Copy link
Copy Markdown

PRD-1546

@qltysh

qltysh Bot commented Oct 23, 2026

Copy link
Copy Markdown

1 new issue

Tool Category Rule Count
qlty Structure Function with many returns (count = 4): filterSchema 1

@qltysh

qltysh Bot commented Oct 23, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/agent-bff/src/openapi/unfolded-paths.ts100.0%
New file Coverage rating: A
packages/agent-bff/src/openapi/unfolded-filter-schema.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@Tonours
Tonours marked this pull request as ready for review October 23, 2026 12:17

@PMerlet PMerlet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec (PRD-1546): conforms. The filter schema moves to its own module with no behaviour change, and no test assertion was edited.


filterable.forEach(field => {
// An empty set would emit `enum: []`, which forbids every value and makes the leaf unsatisfiable —
// the trap `fieldsEnum` guards above. `collectFilterableFields` cannot produce one, but `Unfolding`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Opus 5.5 (claude-opus-5-5): Preferential: a reader of this guard looks for fieldsEnum above and does not find it in this file.

Code

The comment at unfolded-filter-schema.ts:50 points above, but fieldsEnum stayed behind at unfolded-paths.ts:84.

A way out: name unfolded-paths.ts in the comment instead of saying above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0abca46: the comment is gone rather than reworded, since the guard reads on its own. For the record, the reason it exists: an empty operator set would emit enum: [], which makes the filter leaf unsatisfiable (the same trap fieldsEnum guards in unfolded-paths.ts).

@PMerlet PMerlet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after /validator run 2036-20261023150129-PMerlet: nothing blocking posted, 1 preferential or code style, 0 suppressed below all.

@Tonours
Tonours merged commit 5ba5605 into main Oct 23, 2026
43 checks passed
@Tonours
Tonours deleted the feature/prd-1546-extract-filter-schema branch October 23, 2026 15:27
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