Skip to content

refactor(platform-api-docs): isolate discovery strategies - #11184

Open
gaohan1994 wants to merge 1 commit into
MetaMask:mainfrom
gaohan1994:refactor/platform-api-docs-strategies
Open

gaohan1994 wants to merge 1 commit into
MetaMask:mainfrom
gaohan1994:refactor/platform-api-docs-strategies

Conversation

@gaohan1994

@gaohan1994 gaohan1994 commented Oct 29, 2026 •

Copy link
Copy Markdown

Explanation

Discovery logic is split across generate.ts, extraction.ts, and root-messenger-discovery.ts, making it difficult to see what each strategy owns. Move scan file collection and *Messenger traversal into strategies/scan.ts, and root-messenger resolution and its diagnostics into strategies/root-messenger.ts. Keep declaration classification and packet extraction in the shared capability-extraction.ts.

generate.ts now selects a collection function and handles deduplication, grouping, and writing. Each collector returns capability packets and owns its diagnostics. The existing discriminated options union remains; no strategy interface or factory is added. CLI options, file exclusions and ordering, declaration matching, warnings, and empty-result safeguards are unchanged. ESM declaration matching remains a separate change in #10968.

Move the existing extraction/discovery tests alongside their strategy. Add an exact-file collection test including files with no messenger declarations, so output-equivalent but incorrectly widened scans are detected.

Validation

Based on main 5acb2f996e, using Node 24.13.1:

  • Package suite: 178 tests passed (177 existing plus the collection test). Coverage is unchanged: 100% statements/functions/lines and 97.62% branches.
  • The collection test passes before and after the refactor. Temporarily removing the .spec.ts exclusion makes it fail with the extra file; the exclusion was then restored.
  • Core scan: all 2,294 collected paths, in order, match when running the old and new generators against identical input. All 204 generated Markdown/sidebar files are byte-identical (1,189 actions / 184 events).
  • Extension root-messenger, checkout a98daee58f: all 205 generated files are byte-identical (1,166 actions / 179 events).
  • Mobile root-messenger, checkout e6e5de7f3e: all 183 generated files are byte-identical (1,369 actions / 169 events). Dependencies were installed from its lockfile with build scripts skipped; no native app build was needed for type discovery.
  • Diagnostics match for all three inputs. Existing skipped-capability diagnostics remain: 39 in Extension and 60 in Mobile; this refactor does not resolve those extraction limitations.
  • Immutable Core install, package build, built CLI --help, root yarn lint, changelog validation, and git diff --check passed. Root lint was run after yarn build:only-clean: running it immediately after a full monorepo build first reported an unlisted dependency in the unrelated generated bridge-controller/dist/selectors.d.ts.
  • Independent AI-assisted review found the moved function/type bodies unchanged and no blocking code issues.

The comparisons cover generated documentation trees, not a Docusaurus site build or wallet/native E2E. There are no dependency or consumer-facing changes, so no changelog entry is added under the repository's changelog guidance.

References

AI assistance

This refactor, its test and validation work, and this description were prepared with OpenAI Codex assistance. A separate AI-assisted read-only review checked behavior preservation; maintainer review is still required.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed — not applicable to this internal refactor
  • I've introduced breaking changes and prepared client/consumer pull requests — no breaking changes introduced

Note

Low Risk
Internal refactor with behavior-preserving moves; scan exclusions, ordering, and diagnostics are intended unchanged per validation.

Overview
Splits platform-api-docs discovery into strategy modules so scan vs root-messenger ownership is clear, without changing CLI behavior or generated output.

Shared capability classification and packet extraction stay in capability-extraction.ts (renamed from the old extraction module). *Messenger file scanning, glob exclusions, and per-file traversal move to strategies/scan.ts. Root union resolution, skipped-capability warnings, and collectFromRootMessengerCapabilities move to strategies/root-messenger.ts (replacing root-messenger-discovery.ts). generate.ts now only picks a collector, then deduplicates, groups, and writes markdown.

Tests are colocated with each strategy. A new generate test asserts the scan strategy adds exactly the expected source paths (including files with no messenger types), so regressions that widen the file set are caught.

Reviewed by Cursor Bugbot for commit 4baa109. Bugbot is set up for automated code reviews on this repo. Configure here.

@gaohan1994
gaohan1994 requested a review from a team as a code owner October 29, 2026 02:10

This branch has not been deployed

No deployments
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.

platform-api-docs: make each discovery strategy self-contained

1 participant