Repository navigation
chore: Add CI logic to start using typed analytics schema contract - #36941
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f956d5228b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
NicolasMassart
left a comment
There was a problem hiding this comment.
Before merge, I’d only ask that we finish the PR readiness housekeeping: complete the changelog/manual-testing/screenshots fields so they match the repository’s Ready for Review requirements, clean up the stale wording saying Typewriter is still included, and wait for the remaining policy checks to finish.



Description
This PR introduces the first Mobile-side consumer flow for deployed typed analytics contracts, focused on CI validation and reproducibility.
It downloads the immutable private Mobile contract through the shared OIDC action, verifies its metadata and hashes, regenerates the public
Quick Buy v1/v2 types, and detects drift in CI.Overall changes
Download and consumes the deployed Mobile contract through a shared GitHub Action (github-tools)
Verifies release metadata, asset digest, semantic contract hash, source SHA,
tracking-plan ID, and rule count.
Adds a pinned contract lock for reproducible local validation.
Publishes strict Quick Buy Amount Selected v1/v2 TypeScript types.
Validates that tracked public types match regenerated output in CI.
Preserves Mobile’s existing analytics runtime and dispatch behavior.
Adds runtime tests for event-name and version-context forwarding.
No production analytics call-site migration.
No changes to
@metamask/analytics-controller.No automatic contract-update PR yet.
No progressive runtime builder yet.
Public generated types
The generated Quick Buy facade is tracked publicly at:
app/util/analytics/generated/QuickBuyAmountSelected.tsapp/util/analytics/generated/QuickBuyAmountSelected.test-d.tsIt provides:
v1andv2APIs;context.protocols.event_version.The raw contract remains private, i.e. the
metamask-mobile.jsoncontract downloaded from segment-schema release is never committed.Generator comparison
We compared two approaches against the same immutable Mobile contract and the
same
Quick Buy Amount Selectedv1/v2 fixture.analytics-contracts-67390efdfde3-8db9e9f80441sha256:f75e241c1a832b22c80f9537765e51dac0ba380133f1ec90a6f3e7c77235c4c3Quick Buy Amount Selectedv1/v2Lightweight custom generator
The custom generator consumes the verified deployed Mobile contract and a
reviewed caller-property boundary. It generates:
context.protocols.event_version;Stock Typewriter
The Typewriter comparison used TypeScript with
analytics-react-nativeand atemporary local
plan.jsonderived from the same pinned contract. Its outputwas used only as reference material. Typewriter was included only for evaluation and should have been removed before the final merge; it is not a production dependency or the selected implementation.
Stock Typewriter:
produces v2 but loses the explicit v1 API;
[property: string]: anyindex signature;Result
The lightweight generator is the better fit for this Mobile pilot because it
preserves event versions, enforces exact properties, and supplies the Segment
event-version context without adding a runtime dependency or requiring Segment
credentials.
This is not yet a final decision for the all-events generator. Typewriter’s
schema normalization and generation code may still provide reusable ideas.
The Typewriter dependency and comparison files are temporary spike material and
will be removed after review.
The temporary evaluation files are available in the initial spike commit:
comparison spike
The Typewriter comparison was used as a temporary design spike and has been
removed from the final implementation. The comparison showed that the narrow
generator is a better fit for this versioned Mobile pilot because it preserves
v1/v2, rejects unknown properties, and adds event-version context.
Security and privacy
temp/.Validation
Passed:
yarn analytics:contract:check:lockedyarn analytics:contract:compareyarn jest scripts/analytics/typed-events --runInBand --coverage=false --forceExitTargeted checks passed.
Follow-up
main.Slack notification.
production Quick Buy call.
contract.lock.json;Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
In description
Screenshots/Recordings
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Low Risk
CI/tooling and generated types only; no production analytics path or runtime behavior changes.
Overview
Adds typed analytics contract validation: Mobile can download the immutable Segment schema release (
metamask-mobile.json), verify hashes and metadata, regenerate a strict TypeScript facade, and fail when tracked types drift.New
yarn analytics:contract:check/check:locked(plusscripts/analytics/typed-events/*) handle release resolution,contract.lock.json, semantic hash checks, and a narrow generator for Quick Buy Amount Selected v1/v2 with exact properties andcontext.protocols.event_version. Committed pilot output lives underapp/util/analytics/generated/with runtime and compile-time tests.A scheduled
check-analytics-contractworkflow uses the shared download action, runs the check,diffs regenerated files against the repo, writes a job summary, and posts Slack on failure. Docs describe the lifecycle; production analytics dispatch is unchanged (no call-site migration yet).Reviewed by Cursor Bugbot for commit 0b54ef4. Bugbot is set up for automated code reviews on this repo. Configure here.