Skip to content

feat: inject original query into apitester snapshots#5150

Draft
another-rex wants to merge 4 commits intomasterfrom
apitester-inject-queries-730514506246798316
Draft

feat: inject original query into apitester snapshots#5150
another-rex wants to merge 4 commits intomasterfrom
apitester-inject-queries-730514506246798316

Conversation

@another-rex
Copy link
Copy Markdown
Contributor

@another-rex another-rex commented Mar 30, 2026

Modifies the APITester to attach the original request query payload directly into the response JSON output before creating snapshots. This is particularly useful for debugging and tracing batch queries, allowing users to map the output to its input in a 1-to-1 manner.

  • /v1/query responses now include a top-level "query" field reflecting the original payload.
  • /v1/querybatch responses map each item in queries into its corresponding object within the results array under "query".
  • Added required dependency github.com/tidwall/sjson to modify the JSON bodies efficiently.
  • Regenerated all snapshot test files to capture these updates.

**Note: ** This does result in the snapshots not being exactly 1:1 with what our API actually returns. But since this script will likely break if it isn't in the format we expect, I think that's probably fine tradeoff.


PR created automatically by Jules for task 730514506246798316 started by @another-rex

Modifies `normalizeJSONBody` in `tools/apitester/main_test.go` to accept the request body and include the `query` object directly alongside the results in the snapshot output. For single queries, the query is added as a top-level field. For batch queries, each individual query is injected into its corresponding entry in the `results` array. This makes it easier to trace test failures and review data quality by directly mapping responses back to the original request payload. Updated snapshot files to reflect these structural changes.

Co-authored-by: another-rex <106129829+another-rex@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Modifies `normalizeJSONBody` in `tools/apitester/main_test.go` to accept the request body and include the `query` object directly alongside the results in the snapshot output. For single queries, the query is added as a top-level field. For batch queries, each individual query is injected into its corresponding entry in the `results` array. This makes it easier to trace test failures and review data quality by directly mapping responses back to the original request payload. Updated snapshot files to reflect these structural changes.

This also addresses formatting (gofmt) and staticcheck (`QF1003`) issues found in the initial CI run.

Co-authored-by: another-rex <106129829+another-rex@users.noreply.github.com>
@another-rex
Copy link
Copy Markdown
Contributor Author

@jules For clarity, the responses with no vulns should still have the field "vulns: []" to clearly show there are no vulns for that query.

@google-labs-jules
Copy link
Copy Markdown
Contributor

@jules For clarity, the responses with no vulns should still have the field "vulns: []" to clearly show there are no vulns for that query.

I've updated normalizeJSONBody to inject "vulns": [] if it's missing in the response body. This change makes it much clearer when a query returns no vulnerabilities. The snapshots have also been updated to reflect this.

google-labs-jules bot and others added 2 commits March 30, 2026 02:35
Addresses PR feedback by injecting an explicit `"vulns": []` field in the API snapshot output for queries that return no vulnerabilities, improving clarity in the snapshots. Run `go mod tidy` as well.

Co-authored-by: another-rex <106129829+another-rex@users.noreply.github.com>
Addresses PR feedback to consistently order the `query` object before the `vulns` array in the apitester snapshots for better readability. Re-generated snapshots against `api.test.osv.dev` accordingly.

Co-authored-by: another-rex <106129829+another-rex@users.noreply.github.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.

1 participant