From 356df9f00c15fa0677a90b21f34d6df79abe9557 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Sat, 14 Nov 2026 13:04:54 +0000 Subject: [PATCH] test(schema): keep the catalog's distribution identifier types in step with the schema enum and to the AAO catalog's own copy, DISTRIBUTION_IDENTIFIER_TYPE_VALUES. Nothing checked that the two lists match, and they had drifted before. The server unit test now reads the schema enum and asserts the catalog list has the same members, naming any value missing from either side, and that isValidDistributionIdentifierType accepts every enum value and rejects an unknown one. New tests/social-distribution-identifiers.test.cjs, in test:schemas, validates each of the eight types as a distribution identifier on core/collection-distribution.json, rejects an unknown type, checks every value has an enumDescriptions entry and the ID-over-handle wording, and pins the order of the values that existed before 3.3. Tests only; no changeset. Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- ...ollection-identifier-normalization.test.ts | 29 ++++++ .../social-distribution-identifiers.test.cjs | 90 +++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tests/social-distribution-identifiers.test.cjs diff --git a/package.json b/package.json index ca0e0ccc2b..f251ff57cc 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "verify:schema-discovery": "node scripts/verify-schema-discovery.mjs", "typecheck": "tsc --project server/tsconfig.json --noEmit && npm run typecheck:fixed-trace-rollout-tests", "typecheck:fixed-trace-rollout-tests": "node scripts/typecheck-fixed-trace-rollout-tests.mjs", - "test:schemas": "node tests/schema-validation.test.cjs && node --test tests/account-ref.test.cjs tests/canonical-account-ref.test.cjs tests/image-bleed.test.cjs tests/sync-plans-reserved-names.test.cjs tests/seller-offers-contract.test.cjs tests/service-commitments.test.cjs tests/sync-platform-id.test.cjs tests/assignment-landing-page.test.cjs tests/assignment-trackers.test.cjs tests/assignment-replace.test.cjs tests/assignment-operations-capability.test.cjs tests/outcome-target.test.cjs tests/trusted-match-offer-creative-data.test.cjs tests/accessibility-violation-details.test.cjs tests/portfolio-routing-scope.test.cjs tests/catalog-item-availability-updates.test.cjs tests/catalog-ingestion-capabilities.test.cjs tests/sdk-implementation-metadata.test.cjs tests/seller-optimized-package-controls.test.cjs tests/compact-product-lifecycle-storyboards.test.cjs tests/timezone-resolution-storyboards.test.cjs tests/terminal-package-retention-storyboard.test.cjs tests/total-budget-redistribution-currency.test.cjs tests/dooh-allocation.test.cjs tests/x-added-in-3-3-sweep.test.cjs tests/url-pattern-loosening.test.cjs tests/performance-standard-metric-id.test.cjs tests/identity-absence-coherence.test.cjs tests/match-keys.test.cjs tests/execution-requirements.test.cjs tests/execution-readiness.test.cjs tests/schema-deprecation-metadata.test.cjs tests/products-only-brief-compatibility.test.cjs tests/async-identity-convergence.test.cjs tests/creative-rotation.test.cjs tests/creative-start-policy.test.cjs tests/canonical-forecast-point-parity.test.cjs tests/creative-revisions.test.cjs tests/creative-live-updates.test.cjs tests/creative-delivery-contracts.test.cjs tests/tracker-execution-contracts.test.cjs tests/tracker-execution-package-integration.test.cjs tests/metric-identity-coherence.test.cjs tests/print-metrics.test.cjs tests/installment-lifecycle-reporting.test.cjs tests/rights-channel-restrictions.test.cjs tests/daypart-time-of-day.test.cjs tests/audience-size-range.test.cjs tests/media-buy-lineage.test.cjs tests/delivery-projection.test.cjs tests/viewable-rate-optimization-goal.test.cjs tests/sort-contract-delivery-reporting.test.cjs tests/time-based-views-contract.test.cjs tests/metric-qualifier-parity.test.cjs tests/collection-mechanism.test.cjs tests/requested-metrics-contract.test.cjs tests/auto-breakdown-negotiation-contract.test.cjs tests/format-delivery-reporting-contract.test.cjs tests/inventory-delivery-reporting-contract.test.cjs tests/property-delivery-conformance.test.cjs tests/lint-schema-enum-drift.test.cjs tests/lint-schema-required-declared.test.cjs tests/format-asset-type-parity.test.cjs tests/canonical-manifest-constructibility.test.cjs tests/synthetic-depiction.test.cjs tests/creative-rendering-authority.test.cjs tests/buyer-reason.test.cjs tests/mutation-outcome.test.cjs tests/error-recovery-vectors.test.cjs tests/reporting-status-contract.test.cjs tests/reporting-reconciliation-fixture.test.cjs tests/reporting-report-definition-vectors.test.cjs tests/reporting-core-fixture.test.cjs tests/reporting-native-version-ref-bounds.test.cjs tests/trust-json-v1.test.cjs tests/refine-proposals-expected-confirmation-at.test.cjs tests/hold-policy.test.cjs tests/hold-policy-vectors.test.cjs tests/canonical-installments.test.cjs tests/withdrawn-to-4-0.test.cjs tests/installment-refinement.test.cjs tests/installment-creative-assignment.test.cjs tests/get-products-deprecated-withdrawals.test.cjs tests/deprecated-task-withdrawals.test.cjs tests/collection-catalog.test.cjs tests/collection-copies-vectors.test.cjs tests/account-change-record.test.cjs tests/notification-config-payload-view.test.cjs tests/account-requests.test.cjs tests/reporting-subscriptions.test.cjs tests/reporting-subscription-probe.test.cjs tests/reporting-subscription-coverage-vectors.test.cjs tests/reporting-subscription-coverage-properties.test.cjs tests/product-roster-coverage-vectors.test.cjs && npm run test:premium-display-formats && npm run test:geo-region-targeting", + "test:schemas": "node tests/schema-validation.test.cjs && node --test tests/account-ref.test.cjs tests/canonical-account-ref.test.cjs tests/image-bleed.test.cjs tests/sync-plans-reserved-names.test.cjs tests/seller-offers-contract.test.cjs tests/service-commitments.test.cjs tests/sync-platform-id.test.cjs tests/assignment-landing-page.test.cjs tests/assignment-trackers.test.cjs tests/assignment-replace.test.cjs tests/assignment-operations-capability.test.cjs tests/outcome-target.test.cjs tests/trusted-match-offer-creative-data.test.cjs tests/accessibility-violation-details.test.cjs tests/portfolio-routing-scope.test.cjs tests/catalog-item-availability-updates.test.cjs tests/catalog-ingestion-capabilities.test.cjs tests/sdk-implementation-metadata.test.cjs tests/seller-optimized-package-controls.test.cjs tests/compact-product-lifecycle-storyboards.test.cjs tests/timezone-resolution-storyboards.test.cjs tests/terminal-package-retention-storyboard.test.cjs tests/total-budget-redistribution-currency.test.cjs tests/dooh-allocation.test.cjs tests/x-added-in-3-3-sweep.test.cjs tests/url-pattern-loosening.test.cjs tests/performance-standard-metric-id.test.cjs tests/identity-absence-coherence.test.cjs tests/match-keys.test.cjs tests/execution-requirements.test.cjs tests/execution-readiness.test.cjs tests/schema-deprecation-metadata.test.cjs tests/products-only-brief-compatibility.test.cjs tests/async-identity-convergence.test.cjs tests/creative-rotation.test.cjs tests/creative-start-policy.test.cjs tests/canonical-forecast-point-parity.test.cjs tests/creative-revisions.test.cjs tests/creative-live-updates.test.cjs tests/creative-delivery-contracts.test.cjs tests/tracker-execution-contracts.test.cjs tests/tracker-execution-package-integration.test.cjs tests/metric-identity-coherence.test.cjs tests/print-metrics.test.cjs tests/installment-lifecycle-reporting.test.cjs tests/rights-channel-restrictions.test.cjs tests/daypart-time-of-day.test.cjs tests/audience-size-range.test.cjs tests/media-buy-lineage.test.cjs tests/delivery-projection.test.cjs tests/viewable-rate-optimization-goal.test.cjs tests/sort-contract-delivery-reporting.test.cjs tests/time-based-views-contract.test.cjs tests/metric-qualifier-parity.test.cjs tests/collection-mechanism.test.cjs tests/requested-metrics-contract.test.cjs tests/auto-breakdown-negotiation-contract.test.cjs tests/format-delivery-reporting-contract.test.cjs tests/inventory-delivery-reporting-contract.test.cjs tests/property-delivery-conformance.test.cjs tests/lint-schema-enum-drift.test.cjs tests/lint-schema-required-declared.test.cjs tests/format-asset-type-parity.test.cjs tests/canonical-manifest-constructibility.test.cjs tests/synthetic-depiction.test.cjs tests/creative-rendering-authority.test.cjs tests/buyer-reason.test.cjs tests/mutation-outcome.test.cjs tests/error-recovery-vectors.test.cjs tests/reporting-status-contract.test.cjs tests/reporting-reconciliation-fixture.test.cjs tests/reporting-report-definition-vectors.test.cjs tests/reporting-core-fixture.test.cjs tests/reporting-native-version-ref-bounds.test.cjs tests/trust-json-v1.test.cjs tests/refine-proposals-expected-confirmation-at.test.cjs tests/hold-policy.test.cjs tests/hold-policy-vectors.test.cjs tests/canonical-installments.test.cjs tests/withdrawn-to-4-0.test.cjs tests/installment-refinement.test.cjs tests/installment-creative-assignment.test.cjs tests/get-products-deprecated-withdrawals.test.cjs tests/deprecated-task-withdrawals.test.cjs tests/collection-catalog.test.cjs tests/collection-copies-vectors.test.cjs tests/social-distribution-identifiers.test.cjs tests/account-change-record.test.cjs tests/notification-config-payload-view.test.cjs tests/account-requests.test.cjs tests/reporting-subscriptions.test.cjs tests/reporting-subscription-probe.test.cjs tests/reporting-subscription-coverage-vectors.test.cjs tests/reporting-subscription-coverage-properties.test.cjs tests/product-roster-coverage-vectors.test.cjs && npm run test:premium-display-formats && npm run test:geo-region-targeting", "test:performance-feedback": "node --test --test-force-exit --test-timeout=30000 tests/performance-feedback-contract.test.cjs", "test:dist-schema-version-ids": "node --test --test-force-exit --test-timeout=30000 tests/dist-schema-version-ids.test.cjs", "test:examples": "node tests/example-validation-simple.test.cjs && npm run test:tmp-context-merge", diff --git a/server/tests/unit/services/collection-identifier-normalization.test.ts b/server/tests/unit/services/collection-identifier-normalization.test.ts index 81ebef1529..646306e24f 100644 --- a/server/tests/unit/services/collection-identifier-normalization.test.ts +++ b/server/tests/unit/services/collection-identifier-normalization.test.ts @@ -1,5 +1,8 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { describe, it, expect } from 'vitest'; import { + DISTRIBUTION_IDENTIFIER_TYPE_VALUES, isValidDistributionIdentifierType, normalizeCollectionDistributionIdentifier, } from '../../../src/services/collection-identifier-normalization.js'; @@ -34,3 +37,29 @@ describe('social distribution identifier types', () => { expect(normalizeCollectionDistributionIdentifier('x_user_id', '783214')).toEqual({ type: 'x_user_id', value: '783214' }); }); }); + +describe('distribution identifier type parity with the schema enum', () => { + const schema = JSON.parse(readFileSync( + join(process.cwd(), 'static/schemas/source/enums/distribution-identifier-type.json'), + 'utf8', + )); + const schemaValues: string[] = schema.enum; + + it('matches the schema enum as a set', () => { + const server = new Set(DISTRIBUTION_IDENTIFIER_TYPE_VALUES); + const missing = schemaValues.filter((v) => !server.has(v)); + const extra = [...server].filter((v) => !schemaValues.includes(v)); + expect( + { missing, extra }, + `server list is missing [${missing.join(', ')}] and has extra [${extra.join(', ')}] vs distribution-identifier-type.json`, + ).toEqual({ missing: [], extra: [] }); + }); + + it.each(schemaValues)('accepts schema value %s', (type) => { + expect(isValidDistributionIdentifierType(type)).toBe(true); + }); + + it('rejects a value outside the schema enum', () => { + expect(isValidDistributionIdentifierType('myspace_id')).toBe(false); + }); +}); diff --git a/tests/social-distribution-identifiers.test.cjs b/tests/social-distribution-identifiers.test.cjs new file mode 100644 index 0000000000..fcc82fb086 --- /dev/null +++ b/tests/social-distribution-identifiers.test.cjs @@ -0,0 +1,90 @@ +const assert = require('node:assert/strict'); +const test = require('node:test'); +const Ajv = require('ajv'); +const addFormats = require('ajv-formats'); +const { ensureBuiltSchemas, readBuiltSchema } = require('../scripts/built-schemas.cjs'); + +ensureBuiltSchemas(); + +const read = (name) => readBuiltSchema(`/schemas/${name}`); +const typeSchema = read('enums/distribution-identifier-type.json'); +let compiled; +function compile() { + if (!compiled) { + const ajv = new Ajv({ + allErrors: true, strict: false, + loadSchema: async (uri) => { + assert.ok(uri.startsWith('/schemas/'), `unexpected schema reference: ${uri}`); + return read(uri.slice('/schemas/'.length)); + }, + }); + addFormats(ajv); + compiled = ajv.compileAsync(read('core/collection-distribution.json')); + } + return compiled; +} + +const ID_TYPES = [ + ['instagram_account_id', 'instagram.com', '17841400008460056'], + ['facebook_page_id', 'facebook.com', '100064267823693'], + ['snapchat_profile_id', 'snapchat.com', 'a1b2c3d4-0000-4000-8000-000000000000'], + ['x_user_id', 'x.com', '783214'], +]; +const HANDLE_TYPES = [ + ['instagram_handle', 'instagram.com', '@example'], + ['facebook_page_handle', 'facebook.com', '@example'], + ['snapchat_handle', 'snapchat.com', '@example'], + ['x_handle', 'x.com', '@example'], +]; +const NEW_VALUES = [...ID_TYPES, ...HANDLE_TYPES]; +const NEW_ORDER = [ + 'instagram_account_id', 'instagram_handle', 'facebook_page_id', 'facebook_page_handle', + 'snapchat_profile_id', 'snapchat_handle', 'x_user_id', 'x_handle', +]; +const EXISTING_ORDER = [ + 'apple_podcast_id', 'spotify_collection_id', 'rss_url', 'podcast_guid', 'amazon_music_id', 'iheart_id', + 'podcast_index_id', 'youtube_channel_id', 'youtube_channel_handle', 'youtube_channel_url', + 'youtube_playlist_id', 'amazon_title_id', 'platform_channel_id', 'roku_channel_id', 'pluto_channel_id', + 'tubi_id', 'peacock_id', 'tiktok_id', 'twitch_channel', +]; + +for (const [type, publisher_domain, value] of NEW_VALUES) { + test(`distribution accepts identifier type ${type}`, async () => { + const validate = await compile(); + const entry = { publisher_domain, identifiers: [{ type, value }] }; + assert.equal(validate(entry), true, JSON.stringify(validate.errors, null, 2)); + }); +} + +test('distribution rejects an identifier type outside the enum', async () => { + const validate = await compile(); + assert.equal(validate({ publisher_domain: 'myspace.com', identifiers: [{ type: 'myspace_id', value: '1' }] }), false); +}); + +test('every enum value has an enumDescriptions entry', () => { + assert.deepEqual(Object.keys(typeSchema.enumDescriptions).sort(), [...typeSchema.enum].sort()); + for (const v of typeSchema.enum) assert.ok(typeSchema.enumDescriptions[v].length > 0, v); +}); + +test('ID descriptions say they are the preferred canonical identifier', () => { + for (const [v] of ID_TYPES) { + assert.match(typeSchema.enumDescriptions[v], /preferred/i, v); + assert.match(typeSchema.enumDescriptions[v], /canonical/i, v); + } +}); + +test('handle descriptions say the ID is preferred for canonical matching', () => { + for (const [v] of HANDLE_TYPES) { + assert.match(typeSchema.enumDescriptions[v], /preferred/i, v); + assert.match(typeSchema.enumDescriptions[v], /canonical/i, v); + } +}); + +test('new values sit together after twitch_channel without reordering existing ones', () => { + const e = typeSchema.enum; + const tail = EXISTING_ORDER.length + NEW_ORDER.length; + assert.deepEqual(e.slice(0, EXISTING_ORDER.length), EXISTING_ORDER); + assert.deepEqual(e.slice(EXISTING_ORDER.length, tail), NEW_ORDER); + // Later additions may be appended; only the values that followed twitch_channel before 3.3 are pinned. + assert.deepEqual(e.slice(tail, tail + 5), ['imdb_id', 'gracenote_id', 'eidr_id', 'domain', 'substack_id']); +});