-
Notifications
You must be signed in to change notification settings - Fork 74
feat(reporting): add requested_metrics to get_media_buy_delivery #6626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bokelley
wants to merge
4
commits into
reporting-sort-contract
Choose a base branch
from
reporting-requested-metrics
base: reporting-sort-contract
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d54be3e
feat(reporting): add requested_metrics to get_media_buy_delivery
bokelley 99490a9
Merge branch 'reporting-sort-contract' into reporting-requested-metrics
bokelley cd9acc2
fix(reporting): true webhook parity for requested_metrics
bokelley 26b9efe
fix(reporting): define webhook empty requested_metrics on its own sur…
bokelley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "adcontextprotocol": minor | ||
| --- | ||
|
|
||
| Add `requested_metrics` to `get_media_buy_delivery`, giving the GET path the same metric narrowing the reporting webhook already has. Omitted means unchanged full payloads; impressions and spend are always included; requesting a leaf metric identity returns its canonical nested carrier; and `missing_metrics` MUST NOT flag absences caused solely by request narrowing. Implements RFC #6624. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const Ajv = require("ajv"); | ||
| const addFormats = require("ajv-formats"); | ||
| const { describe, it, before } = require("node:test"); | ||
| const assert = require("node:assert/strict"); | ||
|
|
||
| const SCHEMA_ROOT = path.join(__dirname, "..", "static", "schemas", "source"); | ||
|
|
||
| function readSchema(uri) { | ||
| assert.match(uri, /^\/schemas\//); | ||
| return JSON.parse( | ||
| fs.readFileSync(path.join(SCHEMA_ROOT, uri.slice("/schemas/".length)), "utf8") | ||
| ); | ||
| } | ||
|
|
||
| async function compile(schema) { | ||
| const ajv = new Ajv({ | ||
| allErrors: true, | ||
| strict: false, | ||
| loadSchema: async (ref) => readSchema(ref), | ||
| }); | ||
| addFormats(ajv); | ||
| return ajv.compileAsync(schema); | ||
| } | ||
|
|
||
| describe("requested_metrics contract (get_media_buy_delivery)", () => { | ||
| let validateRequest; | ||
| let requestJson; | ||
| let responseJson; | ||
| let webhookJson; | ||
|
|
||
| before(async () => { | ||
| requestJson = readSchema( | ||
| "/schemas/media-buy/get-media-buy-delivery-request.json" | ||
| ); | ||
| responseJson = readSchema( | ||
| "/schemas/media-buy/get-media-buy-delivery-response.json" | ||
| ); | ||
| webhookJson = readSchema("/schemas/core/reporting-webhook.json"); | ||
|
|
||
| validateRequest = await compile(requestJson); | ||
| }); | ||
|
|
||
| it("accepts a valid requested_metrics list of standard metrics", () => { | ||
| assert.equal( | ||
| validateRequest({ | ||
| requested_metrics: ["impressions", "spend", "quartile_100"], | ||
| }), | ||
| true, | ||
| JSON.stringify(validateRequest.errors) | ||
| ); | ||
| }); | ||
|
|
||
| it("accepts a requested_metrics list containing a leaf metric identity", () => { | ||
| assert.equal( | ||
| validateRequest({ requested_metrics: ["viewable_rate"] }), | ||
| true, | ||
| JSON.stringify(validateRequest.errors) | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects an empty requested_metrics array (minItems)", () => { | ||
| assert.equal(validateRequest({ requested_metrics: [] }), false); | ||
| }); | ||
|
|
||
| it("rejects a requested_metrics value outside the available-metric enum", () => { | ||
| assert.equal( | ||
| validateRequest({ requested_metrics: ["bogus_metric"] }), | ||
| false | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects duplicate entries in requested_metrics (uniqueItems)", () => { | ||
| assert.equal( | ||
| validateRequest({ requested_metrics: ["clicks", "clicks"] }), | ||
| false | ||
| ); | ||
| }); | ||
|
|
||
| it("request field description states impressions and spend are always included", () => { | ||
| assert.match( | ||
| requestJson.properties.requested_metrics.description, | ||
| /impressions and spend are always included/ | ||
| ); | ||
| }); | ||
|
|
||
| it("response missing_metrics description states requested_metrics narrowing MUST NOT be flagged", () => { | ||
| const missingMetricsDescription = | ||
| responseJson.properties.media_buy_deliveries.items.properties.by_package | ||
| .items.allOf[1].properties.missing_metrics.description; | ||
|
|
||
| assert.match( | ||
| missingMetricsDescription, | ||
| /MUST NOT list a committed metric here solely because the buyer excluded it/ | ||
| ); | ||
| }); | ||
|
|
||
| it("reporting_webhook still declares requested_metrics with available-metric items (parity guard)", () => { | ||
| const webhookField = webhookJson.properties.requested_metrics; | ||
| assert.ok(webhookField, "reporting-webhook.json is missing requested_metrics"); | ||
| assert.equal(webhookField.type, "array"); | ||
| assert.equal( | ||
| webhookField.items.$ref, | ||
| "/schemas/enums/available-metric.json" | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Medium: "Same semantics as reporting_webhook.requested_metrics" isn't literally true, in two ways. (1) This field adds
minItems: 1; the webhook field (core/reporting-webhook.json:53-59) has nominItems, so[]is valid on the webhook and rejected here — a client sharing metric-narrowing validation across both paths hits the divergence. (2) The "impressions and spend are always included" rule is asserted here but absent from the webhook description; if the webhook shares that behavior, it belongs on the webhook side too (single source of truth), otherwise the two contracts genuinely differ. The parity guard intests/requested-metrics-contract.test.cjsonly checkstypeanditems.$ref, so it won't catch either drift. Either align the constraints or soften the "identical semantics" wording in both schemas and the two docs pages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit: the always-included impressions/spend rule now lives on the webhook field too, the webhook's empty-array case is defined as equivalent to omission, and both descriptions state the one intentional shape difference (GET requires ≥1 entry when present; omit for full payloads) instead of claiming identical semantics.