Skip to content

Declare the page feedback request rules as named constraints - #4904

Open
Mpdreamz wants to merge 7 commits into
mainfrom
split/16-page-feedback
Open

Mpdreamz wants to merge 7 commits into
mainfrom
split/16-page-feedback

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The page feedback endpoint's validation becomes ten named rules on PageFeedbackRequest. Accepted and rejected requests, and the 400 answer (today's generic application/problem+json titled "Invalid arguments", with no field names), stay the same.

Affects: Internals only

Stack: 16 of 16 in the split of #4530, on top of the foundation #4888.

Why

IsValidPageFeedback is one long boolean expression, so a rejected request cannot say which rule it broke and the rules cannot be listed or tested one by one.

What

Rules in the domain

PageFeedbackRequest and its two enums move to Elastic.Documentation.PageFeedback, unchanged apart from implementing IHaveConstraints. PageFeedbackRequestConstraints declares ten rules: URL present, short, a local path; title present and short; reaction thumbs up or down; comment short; reasons come with a version; a comment needs reasons; reasons fit the reaction. The JSON contexts and wire format are unchanged.

Endpoint

IsValidPageFeedback checks the request through Check and returns false on any error. The response stays today's generic 400 application/problem+json ("Invalid arguments", no field names). Check does not catch exceptions, so a rule that threw would still fail the request as the old check would; the differential test covers hostile values and none throws. Configuration makes its internals visible to the API assembly for Check. Consumers only gain a using for the new namespace.

Tests

A differential test holds the rules to the old hand-written check, kept in the test as the specification, for 3,000 generated requests with hostile values. Example tests name the rule and field each breakage hits. The existing .http snapshots of the endpoint did not change.

Deferred behaviour changes

  • Answering a request that breaks a rule with a 400 application/problem+json that names the offending field (main's problem+json is generic: "Check pageUrl, pageTitle, reaction, reasons and comment.") (Nullean.Entities.AspNetCore).

Verify

dotnet test --project tests/Elastic.Documentation.Api.Tests
mise run test
mise run snap:status

No verified snapshot changed. Golden site build compare skipped: API only, no site build path.

🤖 Generated with Claude Code

Found by generated data

Nothing: no rule throws on hostile requests and all ten rules can fire.

@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4904/

Mpdreamz and others added 2 commits November 18, 2026 20:23
The endpoint's hand-written IsValidPageFeedback becomes ten named rules on PageFeedbackRequest, which now lives in the domain assembly. A differential test holds the rules to the old check for 3,000 generated requests. The endpoint still answers a bare 400.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Main added OpenAPI examples that import PageFeedbackRequest from the Api namespace. This branch moves the type to Elastic.Documentation.PageFeedback, so the merge no longer compiled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AutoTest runs every rule over generated legal requests at the boundary of each limit and proves each rule can fire. A second generator adds blank and over-long text, nulls, undefined enum values, mismatched and duplicate reasons and out-of-range versions, and checks that no rule throws. It found no defect.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… wording

The legal generator filtered through the rules under test, so a rule that rejected a legal boundary value would have dropped the case silently. It now selects with the old hand-written check. The comments on the rules and the endpoint said "bare 400"; the endpoint answers a generic invalid-arguments problem.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keep every InternalsVisibleTo entry and the union of the domain
namespaces in DomainPurityTests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
reason is PageFeedbackReason.Inaccurate or PageFeedbackReason.MissingInformation or PageFeedbackReason.HardToUnderstand or PageFeedbackReason.CodeSampleErrors or PageFeedbackReason.OutOfDate or PageFeedbackReason.AnotherReason,
_ => false
};
!request.Check("page-feedback").Findings.Any(d => d.Severity == Severity.Error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

The endpoint now builds a full report even though it only needs a yes/no verdict. A request with a missing reason-set version still walks its entire reasons list if the entries fit the reaction; the previous validator rejected it before walking the list. Keep the named rules, but preserve fail-fast validation for this caller so work on already-invalid requests does not scale with the reasons list.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

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.

Not changing. The response is identical (the generic 400, locked by the page-feedback-validation S8 snapshot). The only difference is that a request with reasons but no version is walked once, linearly (Enum.IsDefined per entry), before being rejected, instead of rejected in O(1). The old validator also walked the whole list for any request with a version, and the body size is already capped by the host, so this is not a scaling risk. Keeping the named rules as a single pass is the design of this PR; fail-fast ordering would need a rule-ordering feature in Nullean.Entities.

…read

The API only uses public Check, so Configuration internals stay hidden from it. The sample callback mutates a shared set and counter, which is unsafe under concurrent iterations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
docs-preview — 073f6776 Deployed Nov 30, 2026 by github-actions[bot]
assembler-preview — 073f6776 Deployed Nov 30, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant