Skip to content

[DT-3848][risk=no] Add the typed search response check (5d/6) - #3352

Open
otchet-broad wants to merge 2 commits into
otchet-dt-3848-fixture-testfrom
otchet-dt-3848-response-check
Open

otchet-broad wants to merge 2 commits into
otchet-dt-3848-fixture-testfrom
otchet-dt-3848-response-check

Conversation

@otchet-broad

@otchet-broad otchet-broad commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Addresses

https://broadworkbench.atlassian.net/browse/DT-3848 (epic DT-4500)
Security risk: no — test files only; no application code or configuration changes.

Summary

Adds TypedSearchResponseCheck, which checks a response body against the contract (#3342): the page of the request, a whole total, rows within the page and the projection, no null field (a field without a value is absent), dataUse as an object in each projection that has it, the asset key form (id: with the record id, or pos:), the facet buckets (requested keys, size, order by count, then by UTF-8 bytes), and the ten totals of the counts view.

TypedSearchResponseTest checks the body of each 200 fixture, and a self-test of 11 bodies that each break one rule.

Stacked on 5a (#3350); merge that first. This is slice 5d of 6 for DT-3848.


Have you read CONTRIBUTING.md lately? If not, do that first.

  • Label PR with a Jira ticket number and include a link to the ticket
  • Label PR with a security risk modifier [no, low, medium, high]
  • PR describes scope of changes
  • Get a minimum of one thumbs worth of review, preferably two if enough team members are available
  • Get PO sign-off for all non-trivial UI or workflow changes
  • Verify all tests go green
  • Test this change deployed correctly and works on dev environment after deployment

🤖 Generated with Claude Code

Add TypedSearchResponseCheck, which checks a response body against the contract (page, total,
row fields of the projection, no null fields, dataUse as an object, asset key, facets, counts
totals), and TypedSearchResponseTest: the body of each 200 fixture, and a self-test of 11
bodies that each break one rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@otchet-broad
otchet-broad requested a review from a team as a code owner November 25, 2026 22:00
@otchet-broad
otchet-broad requested review from fboulnois and kevinmarete and removed request for a team November 25, 2026 22:00
…se-check

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

@kevinmarete kevinmarete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few small things in the response check. Also, CI doesn't run tests on stacked PRs (build.yaml and coverage.yaml only trigger on PRs into develop, and maven.yaml builds with -Dmaven.test.skip=true). Could you confirm ./mvnw test -Dtest='TypedSearch*' passes on this branch?

if (!paths.isEmpty()) {
errors.add("row fields outside the projection: " + paths);
}
if (hasNull(row)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Contract §7 says a row has no null and no empty text or list in place of a missing value, but hasNull only catches null, so "datasetName": "" and "study": {} pass. Should empty strings, lists and objects be rejected too?

"{'view':'studies','total':0,'page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}",
"{'view':'datasets','total':0,'page':{'offset':0,'limit':25},'results':[],'facets':{'dac':[]}}",
"{'view':'datasets','total':'3','page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}",
"{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{},{}],'facets':{'dac':[]}}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This body has no dataUse, so the dataUse rule (line 95 of the check) rejects it whether or not the rows-vs-total rule works. Adding dataUse: {primary: [], secondary: []} to each row would make it test the intended rule. A case with more rows than limit would also help; 2 rows with limit 2 doesn't cover it.

"{'view':'datasets','total':'3','page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}",
"{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{},{}],'facets':{'dac':[]}}",
"{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[1],'facets':{'dac':[]}}",
"{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{'deletable':true}],'facets':{'dac':[]}}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here: without dataUse, this body is rejected whether or not the projection rule works.

continue;
}
JsonNode previous = null;
for (JsonNode bucket : buckets) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: duplicate bucket values (A:1, A:1) are accepted. Should each value appear only once per facet?

}
JsonNode dataUse = row.path("dataUse");
if (allowed.contains("dataUse")
&& !(dataUse.path("primary").isArray() && dataUse.path("secondary").isArray())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: {primary: [], secondary: [], extra: 1} passes. Should unknown keys in dataUse be rejected?

@rushtong rushtong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed with Claude and Codex.

1. [Medium] Empty text and empty lists pass the row check: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:90 The check rejects only null in a row. Contract section 7 (typed-search-contract.md:290) also forbids empty text or an empty list in place of a missing value. A row with "datasetName": "" or "url": [] passes.

2. [Medium] Two self-test bodies fail for the wrong reason: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseTest.java:55 The bodies on lines 55 and 57 also lack dataUse, so the dataUse rule fires in each case. The test asserts only that an error exists. The row-count rule and the outside-projection rule are thus not tested. Add a valid dataUse to those rows.

Low Findings

  • Page and total compared after coercion: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:64 A string offset or limit, a total of 3.0, and extra page keys all pass.
  • Wrong type of facets passes: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:141 With no requested facet, "facets": [] or null gives no error.
  • Weak bucket checks: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:155 Duplicate bucket values pass, and an object as a bucket value passes.

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.

3 participants